Files
kandev/apps/web/lib/walkthrough-request.test.ts
T
José Almeida 3e237e177a feat: add agent-authored code walkthroughs (#1647)
* feat: add code-walkthrough backend (MCP tool, service, persistence, WS events)

* feat: render agent code walkthroughs as line-anchored cards + editor window

* test: add code-walkthrough re-emit mock-agent scenario

* fix: rework code-walkthrough UX (floating card, line reveal, minimize, clickable file)

* fix: improve code walkthrough editor UX

* fix: backfill walkthrough launcher after websocket connect

* fix: improve walkthrough requests and editor anchors

* fix: clear walkthrough highlights on close

* feat: add walkthrough discard and prompt customization

* fix: send walkthrough requests through saved prompt

* fix: support postgres built-in prompt seeding

* fix: address walkthrough review feedback

* fix: address walkthrough review follow-ups

* fix: harden walkthrough lifecycle races

* fix: reuse walkthrough notification cleanup

* fix: guard stale walkthrough file opens

* fix: abort stale file opens before paint

* fix: stabilize github settings e2e readiness

* fix: use stable github settings e2e selector
2026-07-10 08:34:57 +01:00

67 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
buildChangesWalkthroughPrompt,
formatChangedFilesForWalkthroughPrompt,
} from "./walkthrough-request";
describe("buildChangesWalkthroughPrompt", () => {
it("sends the saved prompt reference visibly and hides the expanded prompt content", () => {
const prompt = buildChangesWalkthroughPrompt("CUSTOM_PROMPT\n{{changed_files}}", [
{ path: "src/app.ts", source: "uncommitted" },
{ path: "src/review.ts", repository_name: "web", source: "pr" },
]);
expect(prompt).toMatch(/^@changes-walkthrough\n\nChanged files:/);
expect(prompt).toContain("<kandev-system>");
expect(prompt).toContain("EXPANDED PROMPT REFERENCES");
expect(prompt).toContain("### @changes-walkthrough");
expect(prompt).toContain("CUSTOM_PROMPT");
expect(prompt).toContain("- src/app.ts [uncommitted]");
expect(prompt).toContain("- web:src/review.ts [pr]");
expect(prompt).not.toContain("{{changed_files}}");
});
it("deduplicates repeated files and caps the file list", () => {
const many = Array.from({ length: 85 }, (_, index) => ({
path: `src/file-${index}.ts`,
source: "committed",
}));
const prompt = buildChangesWalkthroughPrompt("{{changed_files}}", [many[0], ...many]);
expect(prompt.match(/src\/file-0\.ts/g)).toHaveLength(1);
expect(prompt).toContain("5 more file(s) omitted");
});
it("escapes file metadata line breaks before prompt interpolation", () => {
const files = [
{
path: "src/app.ts\n- injected",
repository_name: "web\nrepo",
source: "pr\rsource",
},
];
expect(formatChangedFilesForWalkthroughPrompt(files)).toContain(
"- web\\nrepo:src/app.ts\\n- injected [pr\\rsource]",
);
});
it("keeps the changed file list visible when a customized prompt omits the placeholder", () => {
const prompt = buildChangesWalkthroughPrompt("CUSTOM_WITHOUT_PLACEHOLDER", [
{ path: "src/app.ts", source: "committed" },
]);
expect(prompt).toMatch(/^@changes-walkthrough\n\nChanged files:/);
expect(prompt).toContain("CUSTOM_WITHOUT_PLACEHOLDER");
expect(prompt).toContain("- src/app.ts [committed]");
});
});
describe("formatChangedFilesForWalkthroughPrompt", () => {
it("renders an explicit loading fallback when no files are available", () => {
expect(formatChangedFilesForWalkthroughPrompt([])).toContain(
"No changed files were listed by the UI",
);
});
});