|
| 1 | +import { describe, test, expect } from "bun:test"; |
| 2 | +import { planDenyFeedback } from "./feedback-templates"; |
| 3 | + |
| 4 | +describe("feedback-templates", () => { |
| 5 | + /** |
| 6 | + * The whole point of this module: all three integrations (hook, opencode, pi) |
| 7 | + * produce identical output except for the tool name. If this test fails, |
| 8 | + * the templates have diverged — which is what we're trying to prevent. |
| 9 | + */ |
| 10 | + test("plan deny is identical across integrations (modulo tool name)", () => { |
| 11 | + const normalize = (s: string) => |
| 12 | + s.replace(/ExitPlanMode|submit_plan|exit_plan_mode/g, "TOOL"); |
| 13 | + |
| 14 | + const feedback = "## 1. Remove auth section\n> Not needed anymore."; |
| 15 | + const hook = normalize(planDenyFeedback(feedback, "ExitPlanMode")); |
| 16 | + const opencode = normalize(planDenyFeedback(feedback, "submit_plan")); |
| 17 | + const pi = normalize(planDenyFeedback(feedback, "exit_plan_mode")); |
| 18 | + |
| 19 | + expect(hook).toBe(opencode); |
| 20 | + expect(opencode).toBe(pi); |
| 21 | + }); |
| 22 | + |
| 23 | + /** |
| 24 | + * The deny template must embed the user's feedback verbatim — no truncation, |
| 25 | + * no escaping, no wrapping. The agent needs the raw annotation output. |
| 26 | + */ |
| 27 | + test("plan deny preserves feedback content verbatim", () => { |
| 28 | + const feedback = "## 1. Change auth\n**From:**\n```\nold code\n```\n**To:**\n```\nnew code\n```"; |
| 29 | + const result = planDenyFeedback(feedback); |
| 30 | + expect(result).toContain(feedback); |
| 31 | + }); |
| 32 | + |
| 33 | + /** |
| 34 | + * Empty feedback should not produce a broken message — the agent needs |
| 35 | + * something actionable even if the user didn't write annotations. |
| 36 | + */ |
| 37 | + test("plan deny handles empty feedback gracefully", () => { |
| 38 | + const result = planDenyFeedback(""); |
| 39 | + expect(result.length).toBeGreaterThan(50); |
| 40 | + expect(result).toBe(result.trimEnd()); |
| 41 | + }); |
| 42 | + |
| 43 | + /** |
| 44 | + * Version history is keyed by the plan's first # heading + date. |
| 45 | + * If the agent renames the heading on resubmission, the version chain breaks |
| 46 | + * and the user loses diffs (#296). The deny template must instruct the agent |
| 47 | + * to preserve the title. |
| 48 | + */ |
| 49 | + test("plan deny instructs agent to preserve plan title", () => { |
| 50 | + const result = planDenyFeedback("feedback"); |
| 51 | + expect(result.toLowerCase()).toContain("title"); |
| 52 | + expect(result.toLowerCase()).toContain("heading"); |
| 53 | + }); |
| 54 | + |
| 55 | + test("plan deny can include a plan file hint for file-based integrations", () => { |
| 56 | + const result = planDenyFeedback("feedback", "exit_plan_mode", { |
| 57 | + planFilePath: "plans/auth.md", |
| 58 | + }); |
| 59 | + |
| 60 | + expect(result).toContain("Read plans/auth.md to see the current plan before editing it."); |
| 61 | + expect(result).toContain("exit_plan_mode"); |
| 62 | + }); |
| 63 | +}); |
0 commit comments