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