@oscaner-skills/cdd-engine 2.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +2 -2
  3. package/{src-next/bin.ts → dist/bin.js} +18 -21
  4. package/dist/contract/declare.js +998 -0
  5. package/dist/contract/doc.js +565 -0
  6. package/dist/contract/frontmatter.js +209 -0
  7. package/dist/contract/home-extractors.js +379 -0
  8. package/dist/contract/invariants.js +1030 -0
  9. package/dist/contract/judge.js +109 -0
  10. package/dist/contract/lint.js +206 -0
  11. package/dist/contract/project.js +371 -0
  12. package/dist/contract/skill-anatomy.js +156 -0
  13. package/dist/contract/translate.js +85 -0
  14. package/dist/face/artifacts.js +189 -0
  15. package/dist/face/board-view.js +522 -0
  16. package/dist/face/capsule.js +141 -0
  17. package/dist/face/cli.js +891 -0
  18. package/dist/face/declare.js +241 -0
  19. package/dist/face/gate.js +158 -0
  20. package/dist/face/graph-view.js +66 -0
  21. package/dist/face/host.js +211 -0
  22. package/dist/face/lifecycle.js +603 -0
  23. package/dist/face/preview.js +136 -0
  24. package/dist/face/projection.js +259 -0
  25. package/dist/face/route-render.js +162 -0
  26. package/dist/face/termination.js +482 -0
  27. package/dist/face/words.js +220 -0
  28. package/{src-next/infra/config.ts → dist/infra/config.js} +19 -24
  29. package/dist/infra/doc-roots.js +19 -0
  30. package/dist/infra/git.js +37 -0
  31. package/dist/infra/process.js +22 -0
  32. package/dist/infra/root.js +62 -0
  33. package/dist/infra/runtime.js +85 -0
  34. package/dist/infra/workspace.js +276 -0
  35. package/dist/render/brief.js +82 -0
  36. package/dist/render/issue-body.js +129 -0
  37. package/dist/render/skeleton.js +434 -0
  38. package/dist/render/templates.js +520 -0
  39. package/dist/session/faces.js +38 -0
  40. package/dist/session/graph.js +309 -0
  41. package/dist/session/handoff-schema.js +295 -0
  42. package/dist/session/ledger.js +762 -0
  43. package/dist/session/next.js +211 -0
  44. package/dist/session/preflight.js +194 -0
  45. package/dist/session/round-naming.js +73 -0
  46. package/dist/session/run.js +441 -0
  47. package/dist/session/state.js +8 -0
  48. package/dist/session/wave.js +92 -0
  49. package/package.json +8 -7
  50. package/templates/report/issue-body.json +0 -46
  51. package/src-next/__tests__/bin.test.ts +0 -128
  52. package/src-next/__tests__/smoke.integration.test.ts +0 -202
  53. package/src-next/__tests__/zero-dep.test.ts +0 -134
  54. package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +0 -238
  55. package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +0 -153
  56. package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +0 -173
  57. package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +0 -89
  58. package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +0 -225
  59. package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +0 -155
  60. package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +0 -175
  61. package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +0 -85
  62. package/src-next/contract/__tests__/declare.test.ts +0 -242
  63. package/src-next/contract/__tests__/doc.test.ts +0 -358
  64. package/src-next/contract/__tests__/judge.test.ts +0 -873
  65. package/src-next/contract/__tests__/lint.test.ts +0 -314
  66. package/src-next/contract/__tests__/project.test.ts +0 -419
  67. package/src-next/contract/__tests__/translate.test.ts +0 -96
  68. package/src-next/contract/declare.ts +0 -983
  69. package/src-next/contract/doc.ts +0 -753
  70. package/src-next/contract/invariants.ts +0 -1268
  71. package/src-next/contract/judge.ts +0 -142
  72. package/src-next/contract/lint.ts +0 -275
  73. package/src-next/contract/project.ts +0 -596
  74. package/src-next/contract/skill-anatomy.ts +0 -273
  75. package/src-next/contract/translate.ts +0 -113
  76. package/src-next/face/__tests__/board-view.test.ts +0 -948
  77. package/src-next/face/__tests__/capsule.test.ts +0 -276
  78. package/src-next/face/__tests__/channel-closure.guard.test.ts +0 -102
  79. package/src-next/face/__tests__/cli.test.ts +0 -4643
  80. package/src-next/face/__tests__/face.test.ts +0 -289
  81. package/src-next/face/__tests__/graph-view.test.ts +0 -61
  82. package/src-next/face/__tests__/host.test.ts +0 -24
  83. package/src-next/face/__tests__/negation.ts +0 -6
  84. package/src-next/face/__tests__/projection.test.ts +0 -301
  85. package/src-next/face/__tests__/sync-runner.test.ts +0 -70
  86. package/src-next/face/__tests__/words.guard.test.ts +0 -93
  87. package/src-next/face/artifacts.ts +0 -195
  88. package/src-next/face/board-view.ts +0 -662
  89. package/src-next/face/capsule.ts +0 -149
  90. package/src-next/face/cli.ts +0 -819
  91. package/src-next/face/declare.ts +0 -326
  92. package/src-next/face/gate.ts +0 -170
  93. package/src-next/face/graph-view.ts +0 -74
  94. package/src-next/face/host.ts +0 -326
  95. package/src-next/face/lifecycle.ts +0 -700
  96. package/src-next/face/projection.ts +0 -282
  97. package/src-next/face/route-render.ts +0 -160
  98. package/src-next/face/words.ts +0 -296
  99. package/src-next/infra/__tests__/infra.test.ts +0 -287
  100. package/src-next/infra/git.ts +0 -39
  101. package/src-next/infra/process.ts +0 -34
  102. package/src-next/infra/runtime.ts +0 -185
  103. package/src-next/infra/workspace.ts +0 -232
  104. package/src-next/render/__tests__/render.test.ts +0 -499
  105. package/src-next/render/__tests__/skeleton.test.ts +0 -466
  106. package/src-next/render/brief.ts +0 -121
  107. package/src-next/render/issue-body.ts +0 -159
  108. package/src-next/render/skeleton.ts +0 -437
  109. package/src-next/render/templates.ts +0 -650
  110. package/src-next/session/__tests__/graph.test.ts +0 -270
  111. package/src-next/session/__tests__/handoff-plane.guard.test.ts +0 -48
  112. package/src-next/session/__tests__/handoff-schema.test.ts +0 -310
  113. package/src-next/session/__tests__/ledger.test.ts +0 -744
  114. package/src-next/session/__tests__/next.test.ts +0 -368
  115. package/src-next/session/__tests__/preflight.test.ts +0 -491
  116. package/src-next/session/__tests__/run.test.ts +0 -1014
  117. package/src-next/session/__tests__/wave-line-phase.guard.test.ts +0 -49
  118. package/src-next/session/__tests__/wave.test.ts +0 -469
  119. package/src-next/session/faces.ts +0 -110
  120. package/src-next/session/graph.ts +0 -411
  121. package/src-next/session/handoff-schema.ts +0 -373
  122. package/src-next/session/ledger.ts +0 -1004
  123. package/src-next/session/next.ts +0 -192
  124. package/src-next/session/preflight.ts +0 -240
  125. package/src-next/session/run.ts +0 -606
  126. package/src-next/session/state.ts +0 -30
  127. package/src-next/session/wave.ts +0 -139
@@ -1,499 +0,0 @@
1
- // packages/cdd-engine/src-next/render/__tests__/render.test.ts
2
- // T12 render suite — the brief's checkables: template assembly over the
3
- // template-contract data plane (with the hard gates) + the task-brief data
4
- // rendering with the step-checkable gate.
5
- // T19 lands the IssueBodyRenderer suite here — the renderer's home is render/ (the
6
- // P7 translation-system render landing): the body render (en/zh label faces through
7
- // the Translator), the langs projection (the word-table locale key projection —
8
- // never a hardcoded list), the input validation, and the type × segment label-data
9
- // completeness pin over the word table.
10
-
11
- import { describe, expect, it } from "vitest";
12
- import { Translator } from "../../contract/translate.ts";
13
- import { Words } from "../../face/words.ts";
14
- import { BriefRenderer } from "../brief.ts";
15
- import { IssueBodyRenderer, type IssueReportInput } from "../issue-body.ts";
16
- import { TEMPLATE_PROMPT, TemplateAssembler } from "../templates.ts";
17
-
18
- /** The full per-dispatch slot values — every declared template token (the v1.8
19
- * INPUT_/OUTPUT_/WORKSPACE_/BASE_BRANCH/ROLE/WAVE vocabulary), optional slots
20
- * legitimately empty (an implement dispatch carries no review/fix slots; the
21
- * review criteria/lens are NOT values — they fold into the review type's fixed
22
- * prefix, §3.7). */
23
- const ALL_VALUES: Record<string, string> = {
24
- ROLE: "implement",
25
- WAVE: "4,12",
26
- INPUT_WAVE_BRIEF: "/ws/tasks-4,12-brief.md",
27
- INPUT_FINDINGS: "",
28
- INPUT_DOC: "",
29
- BASE_BRANCH: "",
30
- OUTPUT_REPORT: "/ws/tasks-4,12-implement-report.md",
31
- OUTPUT_EVIDENCE: "/ws/tasks-4,12-test-evidence.json",
32
- OUTPUT_HANDOFF: "/ws/tasks-4,12-implement.json",
33
- REVIEW_TYPE: "",
34
- WORKSPACE_DIR: "/ws",
35
- WORKSPACE_ID: "2026-10-02-x",
36
- HANDOFF_SCHEMA: "$$SCHEMA$$",
37
- };
38
-
39
- describe("TemplateAssembler — the template assembly + hard gates", () => {
40
- const assembler = new TemplateAssembler();
41
-
42
- it("declares the four-mode dispatch table and the token registry", () => {
43
- // v1.8 — the mode dispatch table; v1.9 — RETURN_JSON / DOCS_FIX retired; the
44
- // review criteria/lens tokens are gone (§3.7).
45
- expect(assembler.workModes()).toEqual(["implement", "fix", "review", "docs-fix"]);
46
- expect(assembler.returnFormats()).toEqual(["RETURN_STDOUT_BLOCK"]);
47
- expect(assembler.declaredTokens()).toContain("ROLE");
48
- expect(assembler.declaredTokens()).toContain("OUTPUT_HANDOFF");
49
- expect(assembler.declaredTokens()).toContain("OUTPUT_REPORT");
50
- expect(assembler.declaredTokens()).toContain("OUTPUT_EVIDENCE");
51
- expect(assembler.declaredTokens()).toContain("BASE_BRANCH");
52
- expect(assembler.declaredTokens()).toContain("HANDOFF_SCHEMA");
53
- // the retired reference tokens — the range/plan/brief range tokens are gone
54
- expect(assembler.declaredTokens()).not.toContain("INPUT_RANGE");
55
- expect(assembler.declaredTokens()).not.toContain("INPUT_PLAN");
56
- expect(assembler.declaredTokens()).not.toContain("FIX_BASE");
57
- expect(assembler.declaredTokens()).not.toContain("OUTPUT_BRIEF");
58
- expect(assembler.declaredTokens()).not.toContain("INPUT_CRITERIA");
59
- expect(assembler.declaredTokens()).not.toContain("INPUT_LENS");
60
- expect(assembler.declaredTokens()).not.toContain("HANDOFF_WRITE_GATE");
61
- expect(assembler.declaredTokens()).not.toContain("INPUT_RULES");
62
- });
63
-
64
- it("renders the two-line return contract — exactly status + artifacts, the commits line retired (§2.4)", () => {
65
- // The `## Return` zone prescribes exactly two command lines inside its fence:
66
- // `status:` then `artifacts:`. The retired `commits:` line must not survive
67
- // anywhere in the assembled prompt (the child returns status + artifacts; the
68
- // engine appends the counters/next lines — never the child's).
69
- const out = assembler.render(ALL_VALUES);
70
- const fence = out.split("```")[1];
71
- expect(fence).toBeDefined();
72
- const commandLines = fence!
73
- .split("\n")
74
- .map((line) => line.trim())
75
- .filter((line) => line.length > 0);
76
- expect(commandLines).toEqual([
77
- "status: <APPROVED|BLOCKED>",
78
- "artifacts: report=<path> test_evidence=<path>",
79
- ]);
80
- expect(out).not.toContain("commits:");
81
- });
82
-
83
- it("assembles the implement mode — the fixed prefix + the reduced round context", () => {
84
- const out = assembler.render(ALL_VALUES);
85
- expect(out.startsWith("# CDD dispatch — implement round")).toBe(true);
86
- expect(out).toContain("## Instructions");
87
- expect(out).toContain("## Handoff schema");
88
- expect(out).toContain("## Return");
89
- expect(out).toContain("## Round context");
90
- expect(out).toContain("- `ROLE`: implement");
91
- expect(out).toContain("- `WAVE`: 4,12");
92
- expect(out).toContain("- `INPUT_WAVE_BRIEF`: /ws/tasks-4,12-brief.md");
93
- expect(out).toContain("$$SCHEMA$$"); // the injected writable-subset fence slot
94
- expect(out).not.toContain("{{"); // zero unresolved slots
95
- // the implement reminder reads the complete plan mirror (INPUT_WAVE_BRIEF) —
96
- // the plan's ## Constraints rides the brief; the OUTPUT_* write paths are
97
- // prescribed (find #5), the brief is a pure read input (no OUTPUT_BRIEF)
98
- expect(out).not.toContain("INPUT_RULES");
99
- expect(out).toContain("the complete plan mirror");
100
- expect(out).not.toContain("- `OUTPUT_BRIEF`");
101
- expect(out).toContain("- `OUTPUT_REPORT`: /ws/tasks-4,12-implement-report.md");
102
- expect(out).toContain("- `OUTPUT_EVIDENCE`: /ws/tasks-4,12-test-evidence.json");
103
- // the v1.9 prose-zeroing — no HANDOFF_WRITE_GATE / ## Handoff prose anywhere
104
- expect(out).not.toContain("HANDOFF_WRITE_GATE");
105
- expect(out).not.toContain("RETURN_JSON");
106
- expect(out).not.toContain("DOCS_FIX");
107
- // the per-mode trimming: an implement round's context carries no review/fix keys
108
- expect(out).not.toContain("INPUT_CRITERIA");
109
- expect(out).not.toContain("INPUT_FINDINGS");
110
- expect(out).not.toContain("FIX_BASE");
111
- expect(out).not.toContain("BASE_BRANCH");
112
- });
113
-
114
- it("renders the docs-fix mode through the same table — its own rules + subset", () => {
115
- const out = assembler.render({
116
- ...ALL_VALUES,
117
- ROLE: "docs-fix",
118
- INPUT_DOC: "docs/x-design.md",
119
- });
120
- expect(out.startsWith("# CDD dispatch — docs-fix round")).toBe(true);
121
- expect(out).toContain("apply `INPUT_FINDINGS` (all severities) directly to `INPUT_DOC`");
122
- expect(out).toContain("- `INPUT_DOC`: docs/x-design.md");
123
- expect(out).not.toContain("BASE_BRANCH");
124
- // the review-only keys stay out of the docs-fix context
125
- expect(out).not.toContain("INPUT_CRITERIA");
126
- });
127
-
128
- it("the fix shell carries the two typed fix-discipline sentences — verify-then-apply + conditional TDD (P5 §2.4)", () => {
129
- const out = assembler.render({
130
- ...ALL_VALUES,
131
- ROLE: "fix",
132
- INPUT_FINDINGS: "/ws/tasks-1-review-1.json",
133
- });
134
- expect(out.startsWith("# CDD dispatch — fix round")).toBe(true);
135
- // verify-then-apply — the receiving-code-review core: VERIFY each finding
136
- // against the codebase's actual state, apply only what is technically sound
137
- expect(out).toContain("technically sound");
138
- expect(out).toMatch(/verify/i);
139
- // conditional TDD — the B1 appliesTo semantics: only when the finding demands a
140
- // behavior change AND the change lacks tests, never a blanket discipline
141
- expect(out).toContain("requires a behavior change");
142
- });
143
-
144
- it("T5 — the fix shell carries the work face's single strict-schema sentence — the schema declaration is the field source, zero enum", () => {
145
- const out = assembler.render({
146
- ...ALL_VALUES,
147
- ROLE: "fix",
148
- INPUT_FINDINGS: "/ws/tasks-1-review-1.json",
149
- });
150
- // the work face's ONE strict-schema directive — the declared properties are the
151
- // draft's field source (the keyset rides the injected `## Handoff schema` fence,
152
- // never an enumerated restate in the shell's own prose)
153
- expect(out).toContain(
154
- "every top-level field of the draft comes from the `## Handoff schema` declared `properties`",
155
- );
156
- expect(out).toContain("zero extra keys");
157
- // keyset zero-residue + the retired guard sentences are gone: the shell prose
158
- // enumerates no field and names no explicit INPUT_FINDINGS mirror ban
159
- expect(out).not.toContain("**Writable fields:**");
160
- expect(out).not.toContain("accepts exactly");
161
- expect(out).not.toContain("**Findings read-only:**");
162
- });
163
-
164
- it("T5 — the docs-fix shell carries the findings face's single strict-schema sentence — the required findings rides from INPUT_FINDINGS verbatim (no contradiction with the required gate)", () => {
165
- const out = assembler.render({
166
- ...ALL_VALUES,
167
- ROLE: "docs-fix",
168
- INPUT_DOC: "docs/x-design.md",
169
- });
170
- // the findings face's ONE strict-schema directive — same schema-first wording,
171
- // the required `findings` told how to fill (the verbatim carry-over), so the
172
- // sentence never reads "findings required but do not write it"
173
- expect(out).toContain(
174
- "every top-level field of the draft comes from the `## Handoff schema` declared `properties`",
175
- );
176
- expect(out).toContain("`findings` (required) rides over from `INPUT_FINDINGS` verbatim");
177
- expect(out).toContain("zero extra keys");
178
- // keyset zero-residue + the retired carried-as-is guard marker is gone
179
- expect(out).not.toContain("**Writable fields:**");
180
- expect(out).not.toContain("accepts exactly");
181
- expect(out).not.toContain("**Findings carried as-is:**");
182
- expect(out).not.toContain("VERBATIM");
183
- });
184
-
185
- it("renders the review mode per type — the criteria/lens fold into the fixed prefix", () => {
186
- // a spec review: the URC criteria + its lens ride the shell (fixed region), the
187
- // round context carries only the review's dynamic facts
188
- const spec = assembler.render({
189
- ...ALL_VALUES,
190
- ROLE: "review",
191
- REVIEW_TYPE: "spec",
192
- INPUT_WAVE_BRIEF: "",
193
- INPUT_DOC: "docs/kairos/specs/s1-design.md",
194
- OUTPUT_HANDOFF: "/ws/spec-review-1.json",
195
- });
196
- expect(spec.startsWith("# CDD dispatch — review round")).toBe(true);
197
- expect(spec).toContain("**Criteria — spec:**");
198
- expect(spec).toContain("Follow URC");
199
- expect(spec).toContain("completeness | consistency | clarity");
200
- // the claimed→pin clause (T4) — every behavior claim must cite a colocated pin;
201
- // the spec + plan review variants carry it (the task/branch variants do not)
202
- expect(spec).toContain("Claimed→pin");
203
- expect(spec).toContain("- `INPUT_DOC`: docs/kairos/specs/s1-design.md");
204
- expect(spec).not.toContain("- `INPUT_WAVE_BRIEF`");
205
- expect(spec).not.toContain("- `INPUT_FINDINGS`");
206
- expect(spec).not.toContain("- `FIX_BASE`");
207
- expect(spec).not.toContain("BASE_BRANCH"); // spec review carries no scope anchor
208
- // a task review selects its own variant — the task axes + lens + the wave brief
209
- const task = assembler.render({
210
- ...ALL_VALUES,
211
- ROLE: "review",
212
- REVIEW_TYPE: "wave",
213
- BASE_BRANCH: "develop",
214
- OUTPUT_HANDOFF: "/ws/tasks-1-review-1.json",
215
- });
216
- expect(task).toContain("**Criteria — wave:**");
217
- expect(task).toContain("Standards axis");
218
- expect(task).toContain("standards | spec | buildability");
219
- expect(task).toContain("- `INPUT_WAVE_BRIEF`: /ws/tasks-4,12-brief.md");
220
- expect(task).toContain("- `BASE_BRANCH`: develop");
221
- expect(task).not.toContain("Follow URC");
222
- expect(task).not.toContain("Claimed→pin"); // the task axes carry no clause
223
- // a branch review carries the single doc anchor (the plan) + the scope anchor
224
- // BASE_BRANCH — the shared review layout carries the slot (§3.1/§3.2)
225
- const branch = assembler.render({
226
- ...ALL_VALUES,
227
- ROLE: "review",
228
- REVIEW_TYPE: "branch",
229
- INPUT_WAVE_BRIEF: "",
230
- INPUT_DOC: "docs/kairos/plans/p.md",
231
- BASE_BRANCH: "develop",
232
- OUTPUT_HANDOFF: "/ws/branch-review-1.json",
233
- });
234
- expect(branch).toContain("- `INPUT_DOC`: docs/kairos/plans/p.md");
235
- expect(branch).toContain("- `BASE_BRANCH`: develop");
236
- // a plan review carries the same claimed→pin clause as the spec variant; the
237
- // semantic spec/plan-absent anchor rule (the tree-review faces only) is the
238
- // lifecycle-injection concern — pinned at the CLI dispatch face (cli.test.ts)
239
- const plan = assembler.render({
240
- ...ALL_VALUES,
241
- ROLE: "review",
242
- REVIEW_TYPE: "plan",
243
- INPUT_WAVE_BRIEF: "",
244
- INPUT_DOC: "docs/kairos/plans/p.md",
245
- OUTPUT_HANDOFF: "/ws/plan-review-1.json",
246
- });
247
- expect(plan).toContain("**Criteria — plan:**");
248
- expect(plan).toContain("Claimed→pin");
249
- });
250
-
251
- it("hard gates: a missing token value throws (named)", () => {
252
- const partial = { ...ALL_VALUES };
253
- delete partial.ROLE;
254
- expect(() => assembler.render(partial)).toThrow(/ROLE/);
255
- // an unknown ROLE is refused by the mode table (never a phantom assemble)
256
- expect(() => assembler.render({ ...ALL_VALUES, ROLE: "bogus" })).toThrow(/work-mode/);
257
- // a review without its REVIEW_TYPE discriminant is refused by the variants
258
- expect(() => assembler.render({ ...ALL_VALUES, ROLE: "review", REVIEW_TYPE: "" })).toThrow(
259
- /review type not declared/,
260
- );
261
- });
262
-
263
- it("hard gates: an undeclared value throws (the guard is the declared token list)", () => {
264
- expect(() => assembler.render({ ...ALL_VALUES, BOGUS: "x" })).toThrow(/undeclared/);
265
- });
266
-
267
- it("the shell↔layout consistency assertion — a shell naming a slot its layout never carries throws", () => {
268
- // construct a rogue mode whose shell references INPUT_PLAN but whose layout
269
- // carries it nowhere (the "claimed but not carried" gap the assertion closes)
270
- const modes = TEMPLATE_PROMPT.modes as Record<string, unknown>;
271
- const saved = modes.bogus;
272
- modes.bogus = {
273
- mode: "bogus",
274
- shell: ["# rogue", "**rogue:** read `INPUT_PLAN`"],
275
- roundContext: ["## Round context", "- `ROLE`: {{ROLE}}"],
276
- };
277
- try {
278
- expect(() => assembler.render({ ...ALL_VALUES, ROLE: "bogus" })).toThrow(
279
- /references INPUT_PLAN not carried by its round context/,
280
- );
281
- } finally {
282
- if (saved === undefined) delete modes.bogus;
283
- else modes.bogus = saved;
284
- }
285
- // every real declared mode renders cleanly under the assertion
286
- expect(() => assembler.render(ALL_VALUES)).not.toThrow();
287
- expect(() =>
288
- assembler.render({ ...ALL_VALUES, ROLE: "fix", INPUT_FINDINGS: "/f.json" }),
289
- ).not.toThrow();
290
- });
291
- });
292
-
293
- /** A two-task plan — task 1 steps all checkable, task 2 carries a bare step. */
294
- const PLAN = [
295
- "# Test Plan",
296
- "**Spec:** [x-design.md](docs/kairos/specs/x-design.md)",
297
- "- **Parent program**: [x-overall.md v1.21](docs/kairos/specs/x-overall.md)",
298
- "",
299
- "### Task 1: one",
300
- "- **Objective**: objective",
301
- "- **Files**: file",
302
- "- **Consumes**: consumes",
303
- "- **Produces**: produces",
304
- "- **Steps**:",
305
- " - step with checkable — checkable: green",
306
- " - step two — checkable: also green",
307
- "- **Acceptance**: acceptance",
308
- "- **DependsOn**: none",
309
- "",
310
- "### Task 2: two",
311
- "- **Objective**: objective",
312
- "- **Files**: file",
313
- "- **Consumes**: consumes",
314
- "- **Produces**: produces",
315
- "- **Steps**:",
316
- " - bare step",
317
- "- **Acceptance**: acceptance",
318
- "- **DependsOn**: none",
319
- ].join("\n");
320
-
321
- describe("BriefRenderer — the brief data rendering + the checkable gate", () => {
322
- const brief = new BriefRenderer();
323
-
324
- it("extracts the requested task blocks with fields, steps and checkables", () => {
325
- const { data, missing } = brief.extract(PLAN, [1, 2]);
326
- expect(missing).toEqual([]);
327
- expect(data.map((task) => task.id)).toEqual([1, 2]);
328
- expect(data[0].steps.map((step) => step.action)).toEqual(["step with checkable", "step two"]);
329
- expect(data[0].steps[1].checkable).toBe("also green");
330
- expect(data[1].fields.map((field) => field.key)).toContain("Objective");
331
- });
332
-
333
- it("checkable gate: a step without — checkable: is reported and blocks the verdict", () => {
334
- const { data } = brief.extract(PLAN, [1, 2]);
335
- expect(data[0].checkableComplete).toBe(true);
336
- expect(data[1].checkableComplete).toBe(false);
337
- expect(data[1].missingCheckables).toEqual(["bare step"]);
338
- });
339
-
340
- it("the task-heading pattern rides the parse face (T3 tokens consumption)", () => {
341
- expect(brief.taskHeadingPattern()?.test("### Task 3:")).toBe(true);
342
- expect(brief.taskHeadingPattern()?.test("### Task 12:")).toBe(true);
343
- });
344
-
345
- it("out-of-bounds: a missing task id is listed and the render blocks", () => {
346
- const { missing } = brief.extract(PLAN, [1, 5]);
347
- expect(missing).toEqual([5]);
348
- expect(() => brief.render(PLAN, [1, 5])).toThrow(/task 5/);
349
- });
350
-
351
- it("renders the brief content — the raw task sections + the plan's ## Constraints mirror", () => {
352
- const planWithConstraints = `${PLAN}\n\n## Constraints\n\n- keep it simple\n`;
353
- const out = brief.render(planWithConstraints, [1]);
354
- expect(out).toContain("### Task 1: one");
355
- expect(out).toContain("- **Objective**: objective");
356
- expect(out).toContain("## Constraints");
357
- expect(out).toContain("- keep it simple");
358
- expect(out).not.toContain("WAVE_BASE");
359
- // a plan without a ## Constraints section renders the task sections alone
360
- const bare = brief.render(PLAN, [1]);
361
- expect(bare).not.toContain("## Constraints");
362
- });
363
- });
364
-
365
- // ---------------------------------------------------------------------------
366
- // the issue-body renderer suite (T19 — the renderer's home is render/, the P7
367
- // translation-system render landing; migrated from the cli.test.ts renderer tests)
368
- // ---------------------------------------------------------------------------
369
-
370
- describe("IssueBodyRenderer — the aggregate issue body (the P7 render face)", () => {
371
- const words = new Words();
372
- const translator = new Translator(words);
373
- const renderer = new IssueBodyRenderer(words, translator);
374
-
375
- /** The canonical en-aggregate input — one bug finding + the dedup/related tails. */
376
- const EN_INPUT: IssueReportInput = {
377
- harness: "claude",
378
- findings: [
379
- {
380
- type: "bug",
381
- lang: "en",
382
- context: "c",
383
- problem: "p",
384
- impact: "i",
385
- suggestedFix: "f",
386
- meta: { skill: "cdd-dev", step: "implement" },
387
- },
388
- ],
389
- related: {
390
- open: [{ issue: 1, component: "cdd", reason: "dup" }],
391
- closed: [{ issue: 9 }],
392
- program: { issue: 2 },
393
- },
394
- };
395
-
396
- it("renders the deterministic body — harness line, the en four-segment labels, attribution, dedup, related", () => {
397
- const out = renderer.renderBody(EN_INPUT);
398
- expect(out).toContain("# CDD aggregate issue");
399
- expect(out).toContain("- Harness: claude");
400
- expect(out).toContain("## Context\n\nc");
401
- expect(out).toContain("## Problem\n\np");
402
- expect(out).toContain("## Impact\n\ni");
403
- expect(out).toContain("## Suggested fix\n\nf");
404
- expect(out).toContain("- Skill: cdd-dev\n- Step: implement");
405
- expect(out).toContain("- Dedup → #1 (open):cdd · dup");
406
- expect(out).toContain("- Regression / follow-up of #9 (closed)");
407
- expect(out).toContain("- Program: #2");
408
- });
409
-
410
- it("renders the zh labels through the translation layer (the locale-normalized render face)", () => {
411
- const zh = renderer.renderBody({
412
- harness: "claude",
413
- findings: [
414
- {
415
- type: "bug",
416
- lang: "zh",
417
- context: "c",
418
- problem: "p",
419
- impact: "i",
420
- suggestedFix: "f",
421
- meta: { skill: "s", step: "t" },
422
- },
423
- ],
424
- });
425
- expect(zh).toContain("## 场景\n\nc");
426
- expect(zh).toContain("## 问题\n\np");
427
- expect(zh).toContain("## 影响\n\ni");
428
- expect(zh).toContain("## 建议修复\n\nf");
429
- });
430
-
431
- it("the type × lang label variants — enhancement carries the Gap + Suggested direction wording", () => {
432
- const out = renderer.renderBody({
433
- harness: "claude",
434
- findings: [
435
- {
436
- type: "enhancement",
437
- lang: "en",
438
- context: "c",
439
- problem: "p",
440
- impact: "i",
441
- suggestedFix: "f",
442
- meta: { skill: "s", step: "t" },
443
- },
444
- ],
445
- });
446
- expect(out).toContain("## Gap\n\np");
447
- expect(out).toContain("## Suggested direction\n\nf");
448
- });
449
-
450
- it("langs — the projected language vocabulary (the word-table locale key projection, never a hardcoded list)", () => {
451
- expect(renderer.langs()).toEqual(words.localeKeys());
452
- // the validation rides the projection — a lang outside the project keys is refused
453
- // with the data-derived vocabulary message
454
- const errors = renderer.validateInput({
455
- harness: "claude",
456
- findings: [
457
- {
458
- type: "bug",
459
- lang: "fr",
460
- context: "c",
461
- problem: "p",
462
- impact: "i",
463
- suggestedFix: "f",
464
- meta: { skill: "s", step: "t" },
465
- },
466
- ],
467
- });
468
- expect(errors).toContain("findings[0].lang: must be one of en | zh");
469
- });
470
-
471
- it("validateInput — field-path errors for the type/enum and the segment/meta shapes", () => {
472
- expect(
473
- renderer.validateInput({
474
- harness: "claude",
475
- findings: [{ type: "bogus", lang: "en", meta: {} }],
476
- }),
477
- ).toEqual([
478
- "findings[0].type: must be one of bug | enhancement | chore",
479
- "findings[0].context: non-empty string required",
480
- "findings[0].problem: non-empty string required",
481
- "findings[0].impact: non-empty string required",
482
- "findings[0].suggestedFix: non-empty string required",
483
- "findings[0].meta.skill: non-empty string required",
484
- "findings[0].meta.step: non-empty string required",
485
- ]);
486
- expect(renderer.validateInput("bogus")).toEqual([
487
- "input: expected an object with harness / findings / related?",
488
- ]);
489
- });
490
-
491
- it("the label data is complete — every declared type × segment resolves on the word table", () => {
492
- const segments = ["context", "problem", "impact", "suggestedFix"];
493
- for (const type of renderer.types) {
494
- for (const segment of segments) {
495
- expect(words.localeRow(`${type}.${segment}`), `${type}.${segment}`).not.toBeNull();
496
- }
497
- }
498
- });
499
- });