Open History to see the last commit
1import { describe, expect, it } from "vitest";
2
3import {
4 buildCollapsedProposedPlanPreviewMarkdown,
5 buildPlanImplementationThreadTitle,
6 buildPlanImplementationPrompt,
7 buildProposedPlanMarkdownFilename,
8 proposedPlanTitle,
9 resolvePlanFollowUpSubmission,
10 stripDisplayedPlanMarkdown,
11} from "./proposedPlan";
12
13describe("proposedPlanTitle", () => {
14 it("reads the first markdown heading as the plan title", () => {
15 expect(proposedPlanTitle("# Integrate RPC\n\nBody")).toBe("Integrate RPC");
16 });
17
18 it("returns null when the plan has no heading", () => {
19 expect(proposedPlanTitle("- step 1")).toBeNull();
20 });
21});
22
23describe("buildPlanImplementationPrompt", () => {
24 it("formats the plan exactly like the Codex follow-up handoff prompt", () => {
25 expect(buildPlanImplementationPrompt("## Ship it\n\n- step 1\n")).toBe(
26 "PLEASE IMPLEMENT THIS PLAN:\n## Ship it\n\n- step 1",
27 );
28 });
29});
30
31describe("buildCollapsedProposedPlanPreviewMarkdown", () => {
32 it("drops the redundant title heading and preserves the following markdown lines", () => {
33 expect(
34 buildCollapsedProposedPlanPreviewMarkdown(
35 "# Integrate RPC\n\n## Summary\n\n- step 1\n- step 2",
36 {
37 maxLines: 4,
38 },
39 ),
40 ).toBe("- step 1\n- step 2");
41 });
42
43 it("appends an overflow marker when the preview truncates remaining content", () => {
44 expect(
45 buildCollapsedProposedPlanPreviewMarkdown("# Integrate RPC\n\n- step 1\n- step 2\n- step 3", {
46 maxLines: 2,
47 }),
48 ).toBe("- step 1\n- step 2\n\n...");
49 });
50});
51
52describe("stripDisplayedPlanMarkdown", () => {
53 it("drops the leading title heading from displayed plan markdown", () => {
54 expect(stripDisplayedPlanMarkdown("# Integrate RPC\n\n## Summary\n\n- step 1\n")).toBe(
55 "- step 1",
56 );
57 });
58
59 it("preserves non-summary headings after dropping the title heading", () => {
60 expect(stripDisplayedPlanMarkdown("# Integrate RPC\n\n## Scope\n\n- step 1\n")).toBe(
61 "## Scope\n\n- step 1",
62 );
63 });
64});
65
66describe("resolvePlanFollowUpSubmission", () => {
67 it("switches to default mode when implementing the ready plan without extra text", () => {
68 expect(
69 resolvePlanFollowUpSubmission({
70 draftText: " ",
71 planMarkdown: "## Ship it\n\n- step 1\n",
72 }),
73 ).toEqual({
74 text: "PLEASE IMPLEMENT THIS PLAN:\n## Ship it\n\n- step 1",
75 interactionMode: "default",
76 });
77 });
78
79 it("stays in plan mode when the user adds a follow-up prompt", () => {
80 expect(
81 resolvePlanFollowUpSubmission({
82 draftText: "Refine step 2 first",
83 planMarkdown: "## Ship it\n\n- step 1\n",
84 }),
85 ).toEqual({
86 text: "Refine step 2 first",
87 interactionMode: "plan",
88 });
89 });
90});
91
92describe("buildPlanImplementationThreadTitle", () => {
93 it("uses the plan heading when building the implementation thread title", () => {
94 expect(buildPlanImplementationThreadTitle("# Integrate RPC\n\nBody")).toBe(
95 "Implement Integrate RPC",
96 );
97 });
98
99 it("falls back when the plan has no markdown heading", () => {
100 expect(buildPlanImplementationThreadTitle("- step 1")).toBe("Implement plan");
101 });
102});
103
104describe("buildProposedPlanMarkdownFilename", () => {
105 it("derives a stable markdown filename from the plan heading", () => {
106 expect(buildProposedPlanMarkdownFilename("# Integrate Effect RPC Into Server App")).toBe(
107 "integrate-effect-rpc-into-server-app.md",
108 );
109 });
110
111 it("falls back to a generic filename when the plan has no heading", () => {
112 expect(buildProposedPlanMarkdownFilename("- step 1")).toBe("plan.md");
113 });
114});