Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

proposedPlan.test.ts

124 lines3.9 KB

1import { describe, expect, it } from "vite-plus/test";
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.each(["", "Consider this "])(
68 "keeps context-bearing feedback in plan mode with prose %j",
69 (prose) => {
70 const draftText = `${prose}[PR #42](t3-context://v1/review-comment/pr-42)`;
71 expect(resolvePlanFollowUpSubmission({ draftText, planMarkdown: "# Plan" })).toEqual({
72 text: draftText,
73 interactionMode: "plan",
74 });
75 },
76 );
77 it("switches to default mode when implementing the ready plan without extra text", () => {
78 expect(
79 resolvePlanFollowUpSubmission({
80 draftText: " ",
81 planMarkdown: "## Ship it\n\n- step 1\n",
82 }),
83 ).toEqual({
84 text: "PLEASE IMPLEMENT THIS PLAN:\n## Ship it\n\n- step 1",
85 interactionMode: "default",
86 });
87 });
88​
89 it("stays in plan mode when the user adds a follow-up prompt", () => {
90 expect(
91 resolvePlanFollowUpSubmission({
92 draftText: "Refine step 2 first",
93 planMarkdown: "## Ship it\n\n- step 1\n",
94 }),
95 ).toEqual({
96 text: "Refine step 2 first",
97 interactionMode: "plan",
98 });
99 });
100});
101​
102describe("buildPlanImplementationThreadTitle", () => {
103 it("uses the plan heading when building the implementation thread title", () => {
104 expect(buildPlanImplementationThreadTitle("# Integrate RPC\n\nBody")).toBe(
105 "Implement Integrate RPC",
106 );
107 });
108​
109 it("falls back when the plan has no markdown heading", () => {
110 expect(buildPlanImplementationThreadTitle("- step 1")).toBe("Implement plan");
111 });
112});
113​
114describe("buildProposedPlanMarkdownFilename", () => {
115 it("derives a stable markdown filename from the plan heading", () => {
116 expect(buildProposedPlanMarkdownFilename("# Integrate Effect RPC Into Server App")).toBe(
117 "integrate-effect-rpc-into-server-app.md",
118 );
119 });
120​
121 it("falls back to a generic filename when the plan has no heading", () => {
122 expect(buildProposedPlanMarkdownFilename("- step 1")).toBe("plan.md");
123 });
124});