@oscaner-skills/cdd-engine 1.0.0 → 2.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 +9 -8
- package/README.zh-CN.md +9 -8
- package/package.json +15 -22
- package/src-next/__tests__/bin.test.ts +128 -0
- package/src-next/__tests__/smoke.integration.test.ts +202 -0
- package/src-next/__tests__/zero-dep.test.ts +134 -0
- package/src-next/bin.ts +61 -0
- package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +238 -0
- package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +153 -0
- package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +173 -0
- package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +89 -0
- package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +225 -0
- package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +155 -0
- package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +175 -0
- package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +85 -0
- package/src-next/contract/__tests__/declare.test.ts +242 -0
- package/src-next/contract/__tests__/doc.test.ts +358 -0
- package/src-next/contract/__tests__/judge.test.ts +873 -0
- package/src-next/contract/__tests__/lint.test.ts +314 -0
- package/src-next/contract/__tests__/project.test.ts +419 -0
- package/src-next/contract/__tests__/translate.test.ts +96 -0
- package/src-next/contract/declare.ts +983 -0
- package/src-next/contract/doc.ts +753 -0
- package/src-next/contract/invariants.ts +1268 -0
- package/src-next/contract/judge.ts +142 -0
- package/src-next/contract/lint.ts +275 -0
- package/src-next/contract/project.ts +596 -0
- package/src-next/contract/skill-anatomy.ts +273 -0
- package/src-next/contract/translate.ts +113 -0
- package/src-next/face/__tests__/board-view.test.ts +948 -0
- package/src-next/face/__tests__/capsule.test.ts +276 -0
- package/src-next/face/__tests__/channel-closure.guard.test.ts +102 -0
- package/src-next/face/__tests__/cli.test.ts +4643 -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__/negation.ts +6 -0
- package/src-next/face/__tests__/projection.test.ts +301 -0
- package/src-next/face/__tests__/sync-runner.test.ts +70 -0
- package/src-next/face/__tests__/words.guard.test.ts +93 -0
- package/src-next/face/artifacts.ts +195 -0
- package/src-next/face/board-view.ts +662 -0
- package/src-next/face/capsule.ts +149 -0
- package/src-next/face/cli.ts +819 -0
- package/src-next/face/declare.ts +326 -0
- package/src-next/face/gate.ts +170 -0
- package/src-next/face/graph-view.ts +74 -0
- package/src-next/face/host.ts +326 -0
- package/src-next/face/lifecycle.ts +700 -0
- package/src-next/face/projection.ts +282 -0
- package/src-next/face/route-render.ts +160 -0
- package/src-next/face/words.ts +296 -0
- package/src-next/infra/__tests__/infra.test.ts +287 -0
- package/src-next/infra/config.ts +42 -0
- package/src-next/infra/git.ts +39 -0
- package/src-next/infra/process.ts +34 -0
- package/src-next/infra/runtime.ts +185 -0
- package/src-next/infra/workspace.ts +232 -0
- package/src-next/render/__tests__/render.test.ts +499 -0
- package/src-next/render/__tests__/skeleton.test.ts +466 -0
- package/src-next/render/brief.ts +121 -0
- package/src-next/render/issue-body.ts +159 -0
- package/src-next/render/skeleton.ts +437 -0
- package/src-next/render/templates.ts +650 -0
- package/src-next/session/__tests__/graph.test.ts +270 -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 +744 -0
- package/src-next/session/__tests__/next.test.ts +368 -0
- package/src-next/session/__tests__/preflight.test.ts +491 -0
- package/src-next/session/__tests__/run.test.ts +1014 -0
- package/src-next/session/__tests__/wave-line-phase.guard.test.ts +49 -0
- package/src-next/session/__tests__/wave.test.ts +469 -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 +1004 -0
- package/src-next/session/next.ts +192 -0
- package/src-next/session/preflight.ts +240 -0
- package/src-next/session/run.ts +606 -0
- package/src-next/session/state.ts +30 -0
- package/src-next/session/wave.ts +139 -0
- package/templates/report/issue-body.json +18 -20
- 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,873 @@
|
|
|
1
|
+
// packages/cdd-engine/src-next/contract/__tests__/judge.test.ts
|
|
2
|
+
// T4 judge suite — the interpreter's acceptance surface:
|
|
3
|
+
// · one negative case per invariant class (base nine + the four context-seam
|
|
4
|
+
// strategies) — each must fire a Finding on a non-conforming document;
|
|
5
|
+
// · a conforming overall under a sane fs resolves to ZERO findings (no false
|
|
6
|
+
// positives — the coordinator's single strongest assertion);
|
|
7
|
+
// · the coordinator mixes multiple strategies on one document (aggregation);
|
|
8
|
+
// · the grep assertions: zero switch-case judgment dispatch + zero exported
|
|
9
|
+
// behavior-carrying bare functions in judge/invariants.
|
|
10
|
+
// Fixtures are known-good document literals (independent sources of truth) and an
|
|
11
|
+
// injected in-memory fs seam — hermetic, no real filesystem here.
|
|
12
|
+
|
|
13
|
+
import { readFileSync } from "node:fs";
|
|
14
|
+
import { describe, expect, it } from "vitest";
|
|
15
|
+
import type { DocFs, Finding } from "../invariants.ts";
|
|
16
|
+
import { Contract } from "../judge.ts";
|
|
17
|
+
|
|
18
|
+
/** A conforming overall — every registered element present, lineage self-consistent. */
|
|
19
|
+
const GOOD_OVERALL = [
|
|
20
|
+
"# 测试 Overall",
|
|
21
|
+
"- **Version**: v1.21 · 2026-10-07",
|
|
22
|
+
"- **Status**: Approved",
|
|
23
|
+
"- **Author**: [human]",
|
|
24
|
+
"- **Constraints**: 全部约定自动生效",
|
|
25
|
+
"",
|
|
26
|
+
"## Document scope",
|
|
27
|
+
"scope prose",
|
|
28
|
+
"",
|
|
29
|
+
"## File paths",
|
|
30
|
+
"| Artifact | Path |",
|
|
31
|
+
"| --- | --- |",
|
|
32
|
+
"| overall | docs/kairos/specs/x-overall.md |",
|
|
33
|
+
"",
|
|
34
|
+
"## Program charter",
|
|
35
|
+
"### Goal",
|
|
36
|
+
"- goal text",
|
|
37
|
+
"",
|
|
38
|
+
"### Non-goals",
|
|
39
|
+
"- non-goal text",
|
|
40
|
+
"",
|
|
41
|
+
"### Cross-cutting",
|
|
42
|
+
"- cross text",
|
|
43
|
+
"",
|
|
44
|
+
"## Issue inventory",
|
|
45
|
+
"| Phase | Issue (ref) | Title summary |",
|
|
46
|
+
"| --- | --- | --- |",
|
|
47
|
+
"| P1 | #123 | issue one |",
|
|
48
|
+
"| P2 | none | issue two |",
|
|
49
|
+
"",
|
|
50
|
+
"## Phase inventory",
|
|
51
|
+
"| # | Phase | Scope | Design spec | Implementation plan | Acceptance criteria | Dependency |",
|
|
52
|
+
"| --- | --- | --- | --- | --- | --- | --- |",
|
|
53
|
+
"| P1 | DocType 抽象 + schema 工厂 | scope a | [P1-design](docs/kairos/specs/x-p1-design.md) | [P1 plan](docs/kairos/plans/x-p1.md) | criteria a | |",
|
|
54
|
+
"| P2 | 判定面 + 协调器 | scope b | P2-design | [P2 plan](docs/kairos/plans/x-p2.md) | criteria b | |",
|
|
55
|
+
"",
|
|
56
|
+
"## Dependency graph",
|
|
57
|
+
"P1 -> P2",
|
|
58
|
+
"- `->` = hard block(依赖前置 phase 发布后方可启动)",
|
|
59
|
+
"",
|
|
60
|
+
"## Boundary rules",
|
|
61
|
+
"- boundary rule",
|
|
62
|
+
"",
|
|
63
|
+
"## Maintenance",
|
|
64
|
+
"- maintenance note",
|
|
65
|
+
"",
|
|
66
|
+
"## Change history",
|
|
67
|
+
"| Version | Date | Summary |",
|
|
68
|
+
"| --- | --- | --- |",
|
|
69
|
+
"| v1.20 | 2026-10-06 | prior change |",
|
|
70
|
+
"| v1.21 | 2026-10-07 | merged change |",
|
|
71
|
+
].join("\n");
|
|
72
|
+
|
|
73
|
+
const OVERALL_PATH = "docs/kairos/specs/x-overall.md";
|
|
74
|
+
const PLAN_PATH = "docs/kairos/plans/x-p3.md";
|
|
75
|
+
const SPEC_PATH = "docs/kairos/specs/x-p3-design.md";
|
|
76
|
+
|
|
77
|
+
/** The sibling-doc fs the conforming doc resolves into. */
|
|
78
|
+
const GOOD_OVERALL_FS: DocFs = {
|
|
79
|
+
exists: () => true,
|
|
80
|
+
read: () => null,
|
|
81
|
+
list: (dir) =>
|
|
82
|
+
dir.endsWith("/specs") || dir.endsWith("specs")
|
|
83
|
+
? ["x-overall.md", "x-p1-design.md", "x-p2-design.md"]
|
|
84
|
+
: ["x-p1.md", "x-p2.md"],
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** One empty fs — chains resolve nowhere (for the file-existence negative). */
|
|
88
|
+
const EMPTY_FS: DocFs = {
|
|
89
|
+
exists: () => false,
|
|
90
|
+
read: () => null,
|
|
91
|
+
list: () => [],
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const judge = (
|
|
95
|
+
docKey: "overall-spec" | "plan" | "phase-spec",
|
|
96
|
+
content: string,
|
|
97
|
+
fs: DocFs = EMPTY_FS,
|
|
98
|
+
phaseId?: string,
|
|
99
|
+
): Finding[] =>
|
|
100
|
+
new Contract().validate({
|
|
101
|
+
docKey,
|
|
102
|
+
path: docKey === "overall-spec" ? OVERALL_PATH : docKey === "plan" ? PLAN_PATH : SPEC_PATH,
|
|
103
|
+
content,
|
|
104
|
+
root: ".",
|
|
105
|
+
fs,
|
|
106
|
+
phaseId,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const withKind = (findings: readonly Finding[], kind: string, field?: string): boolean =>
|
|
110
|
+
findings.some(
|
|
111
|
+
(finding) => finding.kind === kind && (field === undefined || finding.field === field),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
describe("the conforming overall — zero findings (no false positives)", () => {
|
|
115
|
+
it("judges a conforming overall clean under a sane fs", () => {
|
|
116
|
+
expect(judge("overall-spec", GOOD_OVERALL, GOOD_OVERALL_FS)).toEqual([]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("P7 — the structure-plane canonicalize seam (Contract.validate row-source)", () => {
|
|
121
|
+
/** The GOOD_OVERALL charter carrying the legacy Chinese markers the English
|
|
122
|
+
* canonical element patterns match THROUGH the canonicalize view: the
|
|
123
|
+
* doc-arch-overall decision-group / endorsements leaves (`#### M 组` … /
|
|
124
|
+
* `#### 上游先例背书`). The markers are UNREGISTERED zh prose to the element
|
|
125
|
+
* table (English canonicals only) — any match is the row-source seam talking.
|
|
126
|
+
* The Goal facet stays in its English form (the zh Goal face carries no
|
|
127
|
+
* registered alternate). */
|
|
128
|
+
const ZH_CHARTER_OVERALL = GOOD_OVERALL.replace(
|
|
129
|
+
"### Goal\n- goal text",
|
|
130
|
+
[
|
|
131
|
+
"### Goal",
|
|
132
|
+
"- goal text",
|
|
133
|
+
"",
|
|
134
|
+
"#### M 组(skill-ref 映射,M1–M4 全关)",
|
|
135
|
+
"- m leaf",
|
|
136
|
+
"",
|
|
137
|
+
"#### F 组(文档平面结构,提案)",
|
|
138
|
+
"- f leaf",
|
|
139
|
+
"",
|
|
140
|
+
"#### R 组(ref 统一身份,提案)",
|
|
141
|
+
"- r leaf",
|
|
142
|
+
"",
|
|
143
|
+
"#### B 组(正文内容,提案)",
|
|
144
|
+
"- b leaf",
|
|
145
|
+
"",
|
|
146
|
+
"#### E 组(经验债,驱动本整体)",
|
|
147
|
+
"- e leaf",
|
|
148
|
+
"",
|
|
149
|
+
"#### 上游先例背书",
|
|
150
|
+
"- endorsement text",
|
|
151
|
+
].join("\n"),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
it("the structure judge matches the legacy Chinese charter markers through the canonicalize view", () => {
|
|
155
|
+
const findings = judge("overall-spec", ZH_CHARTER_OVERALL, GOOD_OVERALL_FS);
|
|
156
|
+
// the zh decision-group leaves (`#### M 组` …) conform to the canonical
|
|
157
|
+
// `#### [MFRBEN] group` facet through the view
|
|
158
|
+
expect(withKind(findings, "presence", "#### [MFRBEN] group")).toBe(false);
|
|
159
|
+
expect(withKind(findings, "domain", "#### [MFRBEN] group")).toBe(false);
|
|
160
|
+
// the zh endorsements leaf conforms to the canonical facet through the view
|
|
161
|
+
expect(withKind(findings, "domain", "#### Upstream Endorsements")).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("a zh title outside the registered canonicals stays identity — a 目标 Goal face is still missing", () => {
|
|
165
|
+
const content = GOOD_OVERALL.replace("### Goal\n- goal text", "### 目标\n- goal text");
|
|
166
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
167
|
+
expect(withKind(findings, "presence", "### Goal")).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("the view never writes back — the judged source content stays byte-identical", () => {
|
|
171
|
+
const input = {
|
|
172
|
+
docKey: "overall-spec" as const,
|
|
173
|
+
path: OVERALL_PATH,
|
|
174
|
+
content: ZH_CHARTER_OVERALL,
|
|
175
|
+
root: ".",
|
|
176
|
+
fs: GOOD_OVERALL_FS,
|
|
177
|
+
};
|
|
178
|
+
const findings = new Contract().validate(input);
|
|
179
|
+
expect(input.content).toBe(ZH_CHARTER_OVERALL);
|
|
180
|
+
expect(findings).toEqual([]);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("base nine invariants — one negative case each", () => {
|
|
185
|
+
it("presence: a missing required section is reported", () => {
|
|
186
|
+
const content = GOOD_OVERALL.replace("## Maintenance\n- maintenance note", "");
|
|
187
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
188
|
+
expect(withKind(findings, "presence", "## Maintenance")).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("uniqueness: a duplicated section heading is reported", () => {
|
|
192
|
+
const content = GOOD_OVERALL.replace(
|
|
193
|
+
"## Document scope",
|
|
194
|
+
"## Document scope\nscope one\n\n## Document scope\nscope two",
|
|
195
|
+
);
|
|
196
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
197
|
+
expect(withKind(findings, "uniqueness", "## Document scope")).toBe(true);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("domain: a header value outside its declared shape is reported", () => {
|
|
201
|
+
const content = GOOD_OVERALL.replace("- **Status**: Approved", "- **Status**: Deleted");
|
|
202
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
203
|
+
expect(withKind(findings, "domain", "**Status**")).toBe(true);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("crosslink: an issue row referencing an unregistered phase is reported", () => {
|
|
207
|
+
const content = GOOD_OVERALL.replace("| P2 | none | issue two |", "| P9 | none | issue nine |");
|
|
208
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
209
|
+
expect(withKind(findings, "crosslink", "Issue inventory")).toBe(true);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("order: the section sequence must follow the declared registry order", () => {
|
|
213
|
+
// A phase-spec with Constraints BEFORE Design inverts the declared sequence.
|
|
214
|
+
const content = [
|
|
215
|
+
"# Test Spec",
|
|
216
|
+
"- **Version**: v1.0",
|
|
217
|
+
"- **Status**: Draft",
|
|
218
|
+
"- **Author**: x",
|
|
219
|
+
"- **Parent program**: [x-overall.md v1.0](docs/kairos/specs/x-overall.md)",
|
|
220
|
+
"- **Depends on**: P1",
|
|
221
|
+
"",
|
|
222
|
+
"## Constraints",
|
|
223
|
+
"",
|
|
224
|
+
"- delta",
|
|
225
|
+
"",
|
|
226
|
+
"## Design",
|
|
227
|
+
"",
|
|
228
|
+
"### 1. 数据面",
|
|
229
|
+
"#### 1.1 登记表",
|
|
230
|
+
"- text",
|
|
231
|
+
"",
|
|
232
|
+
"### Acceptance criteria",
|
|
233
|
+
"",
|
|
234
|
+
"- `c`",
|
|
235
|
+
].join("\n");
|
|
236
|
+
const findings = judge("phase-spec", content, EMPTY_FS);
|
|
237
|
+
expect(withKind(findings, "order")).toBe(true);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("continuity: plan task ids must be contiguous from 1", () => {
|
|
241
|
+
const content = [
|
|
242
|
+
"# Test Plan",
|
|
243
|
+
"**Spec:** [x-design.md](docs/kairos/specs/x-design.md)",
|
|
244
|
+
"- **Parent program**: [x-overall.md v1.21](docs/kairos/specs/x-overall.md)",
|
|
245
|
+
"",
|
|
246
|
+
...planTask(1),
|
|
247
|
+
...planTask(3),
|
|
248
|
+
].join("\n");
|
|
249
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
250
|
+
expect(withKind(findings, "continuity")).toBe(true);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("residue: conditional content leaks while its section is absent", () => {
|
|
254
|
+
const content = [
|
|
255
|
+
"# Test Spec",
|
|
256
|
+
"- **Version**: v1.0",
|
|
257
|
+
"- **Status**: Draft",
|
|
258
|
+
"- **Author**: x",
|
|
259
|
+
"- **Parent program**: [x-overall.md v1.0](docs/kairos/specs/x-overall.md)",
|
|
260
|
+
"- **Depends on**: P1",
|
|
261
|
+
"",
|
|
262
|
+
"## Design",
|
|
263
|
+
"",
|
|
264
|
+
"### 1. 数据面",
|
|
265
|
+
"#### 1.1 登记表",
|
|
266
|
+
"- text",
|
|
267
|
+
"",
|
|
268
|
+
"### Acceptance criteria",
|
|
269
|
+
"",
|
|
270
|
+
"- `c`",
|
|
271
|
+
"",
|
|
272
|
+
"## Constraints",
|
|
273
|
+
"",
|
|
274
|
+
"- delta",
|
|
275
|
+
"",
|
|
276
|
+
"| overall decision | 决定 | Yes |",
|
|
277
|
+
].join("\n");
|
|
278
|
+
const findings = judge("phase-spec", content, EMPTY_FS);
|
|
279
|
+
expect(withKind(findings, "residue")).toBe(true);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("hollow: a present table section with zero data rows is reported", () => {
|
|
283
|
+
const content = GOOD_OVERALL.replace(
|
|
284
|
+
[
|
|
285
|
+
"## File paths",
|
|
286
|
+
"| Artifact | Path |",
|
|
287
|
+
"| --- | --- |",
|
|
288
|
+
"| overall | docs/kairos/specs/x-overall.md |",
|
|
289
|
+
].join("\n"),
|
|
290
|
+
"## File paths\n",
|
|
291
|
+
);
|
|
292
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
293
|
+
expect(withKind(findings, "hollow", "## File paths")).toBe(true);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("selfBounded: the header version must be the change-history's newest row", () => {
|
|
297
|
+
const content = GOOD_OVERALL.replace(
|
|
298
|
+
"| v1.21 | 2026-10-07 | merged change |",
|
|
299
|
+
"| v1.20 | 2026-10-06 | older only |",
|
|
300
|
+
);
|
|
301
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
302
|
+
expect(withKind(findings, "selfBounded", "**Version**")).toBe(true);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe("T6 — prose task mentions carry zero crosslink findings (the WARN-only observation surface)", () => {
|
|
307
|
+
/** The sibling-doc fs a conforming plan's chain resolves into (exists + the
|
|
308
|
+
* same-family listings the file-existence/sibling-scan surfaces judge). */
|
|
309
|
+
const GOOD_PLAN_FS: DocFs = {
|
|
310
|
+
exists: () => true,
|
|
311
|
+
read: () => null,
|
|
312
|
+
list: (dir) =>
|
|
313
|
+
dir.endsWith("/specs") || dir.endsWith("specs")
|
|
314
|
+
? ["x-overall.md", "x-design.md", "x-p3-design.md"]
|
|
315
|
+
: ["x-p3.md"],
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
/** A structurally conforming plan — every registered plan element present
|
|
319
|
+
* (header tuple + version lineage + task fields + Change history) carrying a
|
|
320
|
+
* prose mention of an unregistered historical task id in its Objective. */
|
|
321
|
+
function conformingPlanWithProse(objective: string): string {
|
|
322
|
+
return [
|
|
323
|
+
"# Test Plan",
|
|
324
|
+
"**Spec:** [x-design.md](docs/kairos/specs/x-design.md)",
|
|
325
|
+
"- **Parent program**: [x-overall.md v1.21](docs/kairos/specs/x-overall.md)",
|
|
326
|
+
"- **Version**: v1.1 · 2026-10-09",
|
|
327
|
+
"",
|
|
328
|
+
"## Constraints",
|
|
329
|
+
"",
|
|
330
|
+
"- delta",
|
|
331
|
+
"",
|
|
332
|
+
"### Task 1: task",
|
|
333
|
+
`- **Objective**: ${objective}`,
|
|
334
|
+
"- **Files**: file",
|
|
335
|
+
"- **Consumes**: consumes",
|
|
336
|
+
"- **Produces**: produces",
|
|
337
|
+
"- **Steps**:",
|
|
338
|
+
" - step one — checkable: green",
|
|
339
|
+
"- **Acceptance**: acceptance",
|
|
340
|
+
"- **DependsOn**: none",
|
|
341
|
+
"",
|
|
342
|
+
"## Change history",
|
|
343
|
+
"",
|
|
344
|
+
"| Version | date | summary | author |",
|
|
345
|
+
"|---|---|---|---|",
|
|
346
|
+
"| v1.0 | 2026-10-08 | prior | [human] |",
|
|
347
|
+
"| v1.1 | 2026-10-09 | merged | [human] |",
|
|
348
|
+
].join("\n");
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
it("a conforming plan prose-referencing an unregistered historical task id scores ZERO findings", () => {
|
|
352
|
+
const content = conformingPlanWithProse(
|
|
353
|
+
"承接 P3.2 的 T25 段既有约定(历史任务序号 · 非本 plan 任务)",
|
|
354
|
+
);
|
|
355
|
+
const findings = judge("plan", content, GOOD_PLAN_FS);
|
|
356
|
+
// the prose mention is the reference-lint WARN observation's — the crosslink
|
|
357
|
+
// invariant never consumes it, and no other surface reports the mention
|
|
358
|
+
expect(withKind(findings, "crosslink", "Task prose reference")).toBe(false);
|
|
359
|
+
expect(findings).toEqual([]);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it("the DependsOn out-of-bounds hard gate stays — an unregistered DEPENDENCY is still a crosslink finding", () => {
|
|
363
|
+
const content = conformingPlanWithProse("objective").replace(
|
|
364
|
+
"- **DependsOn**: none",
|
|
365
|
+
"- **DependsOn**: 25",
|
|
366
|
+
);
|
|
367
|
+
const findings = judge("plan", content, GOOD_PLAN_FS);
|
|
368
|
+
expect(withKind(findings, "crosslink", "Task 1")).toBe(true);
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
describe("the canonical repo forms (no false positives on real conventions)", () => {
|
|
373
|
+
it("presence: the token-in-heading task id is satisfied by the parsed task blocks (not a line scan)", () => {
|
|
374
|
+
const content = [
|
|
375
|
+
"# Test Plan",
|
|
376
|
+
"**Spec:** [x-design.md](docs/kairos/specs/x-design.md)",
|
|
377
|
+
"- **Parent program**: [x-overall.md v1.21](docs/kairos/specs/x-overall.md)",
|
|
378
|
+
"",
|
|
379
|
+
...planTask(1),
|
|
380
|
+
].join("\n");
|
|
381
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
382
|
+
expect(withKind(findings, "presence", "Task id token")).toBe(false);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("presence: the graph legend tolerates the canonical backticked form — and its absence is reported", () => {
|
|
386
|
+
const removed = GOOD_OVERALL.replace(
|
|
387
|
+
"- `->` = hard block(依赖前置 phase 发布后方可启动)",
|
|
388
|
+
"P1 -> P1b",
|
|
389
|
+
);
|
|
390
|
+
expect(
|
|
391
|
+
withKind(judge("overall-spec", removed, GOOD_OVERALL_FS), "presence", "Graph legend"),
|
|
392
|
+
).toBe(true);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("presence: a task block missing a registry-declared task field is reported (derived field set)", () => {
|
|
396
|
+
const content = [
|
|
397
|
+
"# Test Plan",
|
|
398
|
+
"**Spec:** [x-design.md](docs/kairos/specs/x-design.md)",
|
|
399
|
+
"- **Parent program**: [x-overall.md v1.21](docs/kairos/specs/x-overall.md)",
|
|
400
|
+
"",
|
|
401
|
+
"### Task 1: task",
|
|
402
|
+
"- **Objective**: objective",
|
|
403
|
+
"- **Files**: file",
|
|
404
|
+
"- **Consumes**: consumes",
|
|
405
|
+
"- **Produces**: produces",
|
|
406
|
+
"- **Steps**:",
|
|
407
|
+
" - step one",
|
|
408
|
+
"- **DependsOn**: none",
|
|
409
|
+
].join("\n");
|
|
410
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
411
|
+
expect(withKind(findings, "presence", "**Acceptance**")).toBe(true);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it("domain: a backticked citation of an anchor literal is not judged as a value", () => {
|
|
415
|
+
const content = [
|
|
416
|
+
"# Test Plan",
|
|
417
|
+
"**Spec:** [x-design.md](docs/kairos/specs/x-design.md)",
|
|
418
|
+
"- **Parent program**: [x-overall.md v1.21](docs/kairos/specs/x-overall.md)",
|
|
419
|
+
"- **Consumes**: T1 骨架 · doc.ts(plan DocType.parse:`### Task N:` 块归口 doc.ts)",
|
|
420
|
+
"",
|
|
421
|
+
...planTask(1),
|
|
422
|
+
].join("\n");
|
|
423
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
424
|
+
expect(withKind(findings, "domain", "### Task N:")).toBe(false);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it("domain: a table-cell citation of a section anchor is not judged as a value", () => {
|
|
428
|
+
const content = GOOD_OVERALL.replace(
|
|
429
|
+
"| v1.20 | 2026-10-06 | prior change |",
|
|
430
|
+
"| v1.20 | 2026-10-06 | `## Program charter` 重构 |",
|
|
431
|
+
);
|
|
432
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
433
|
+
expect(withKind(findings, "domain", "## Program charter")).toBe(false);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it("presence+domain: the TITLED task heading is a valid `### Task N:` (the tree-wide form)", () => {
|
|
437
|
+
// find #8: the registry's bare-heading pattern rejected the titled form — the
|
|
438
|
+
// wave's own plan (25/25 plans use `### Task N: <title>`) was reported missing
|
|
439
|
+
const content = [
|
|
440
|
+
"# Test Plan",
|
|
441
|
+
"**Spec:** [x-design.md](docs/kairos/specs/x-design.md)",
|
|
442
|
+
"- **Parent program**: [x-overall.md v1.21](docs/kairos/specs/x-overall.md)",
|
|
443
|
+
"",
|
|
444
|
+
"### Task 1: task title",
|
|
445
|
+
"- **Objective**: objective",
|
|
446
|
+
"- **Files**: file",
|
|
447
|
+
"- **Consumes**: consumes",
|
|
448
|
+
"- **Produces**: produces",
|
|
449
|
+
"- **Steps**:",
|
|
450
|
+
" - step one",
|
|
451
|
+
"- **Acceptance**: acceptance",
|
|
452
|
+
"- **DependsOn**: none",
|
|
453
|
+
].join("\n");
|
|
454
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
455
|
+
expect(withKind(findings, "presence", "### Task N:")).toBe(false);
|
|
456
|
+
expect(withKind(findings, "domain", "### Task N:")).toBe(false);
|
|
457
|
+
// the bare heading is the same pattern's canonical form — both conform
|
|
458
|
+
const bare = content.replace("### Task 1: task title", "### Task 1:");
|
|
459
|
+
expect(withKind(judge("plan", bare, EMPTY_FS), "presence", "### Task N:")).toBe(false);
|
|
460
|
+
// a non-numeric heading is still outside the domain
|
|
461
|
+
expect(
|
|
462
|
+
withKind(
|
|
463
|
+
judge("plan", content.replace("### Task 1:", "### Task X:"), EMPTY_FS),
|
|
464
|
+
"presence",
|
|
465
|
+
"### Task N:",
|
|
466
|
+
),
|
|
467
|
+
).toBe(true);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it("domain: a nested backtick citation (`outer quote … inner `anchor`) is not judged as a value", () => {
|
|
471
|
+
// find #8: the old span-by-span strip consumed the outer quote's opener and left
|
|
472
|
+
// the nested `…` citation naked — the p4.1 spec's command-quoted prose was judged
|
|
473
|
+
// as `## Constraints` / `**Version**` values
|
|
474
|
+
const content = [
|
|
475
|
+
"# Test Plan",
|
|
476
|
+
"**Spec:** [x-design.md](docs/kairos/specs/x-design.md)",
|
|
477
|
+
"- **Parent program**: [x-overall.md v1.21](docs/kairos/specs/x-overall.md)",
|
|
478
|
+
"- **Depends on**: P1",
|
|
479
|
+
"- **Consumes**: T1(`read the plan's `## Constraints` (at INPUT_PLAN)`)·「`the `**Version**` header`」零残留",
|
|
480
|
+
"",
|
|
481
|
+
...planTask(1),
|
|
482
|
+
].join("\n");
|
|
483
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
484
|
+
expect(withKind(findings, "domain", "## Constraints")).toBe(false);
|
|
485
|
+
expect(withKind(findings, "domain", "**Version**")).toBe(false);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it("two adjacent backtick spans read as ONE quoted region — the mid-span prose is not judged (the pinned first-last strip)", () => {
|
|
489
|
+
// The find-#8 first-last strip consumes the whole first→last backtick region as
|
|
490
|
+
// quoted. On a line carrying TWO separate spans, the prose BETWEEN them is part
|
|
491
|
+
// of that region — an anchor quoted only there is invisible to the domain rule.
|
|
492
|
+
// Pinned tradeoff (the comment on #withoutCodeSpans): the enforced docs' quoted
|
|
493
|
+
// shapes are the simple `span` and the nested citation, neither of which hides a
|
|
494
|
+
// real structural anchor between two adjacent spans; a span-by-span strip would
|
|
495
|
+
// judge this middle prose and reopen the nested-citation gap the pin closes.
|
|
496
|
+
const content = [
|
|
497
|
+
"# Test Spec",
|
|
498
|
+
"- **Version**: v1.1 · 2026-10-09",
|
|
499
|
+
"- **Status**: Draft",
|
|
500
|
+
"- **Author**: x",
|
|
501
|
+
"- **Parent program**: [x-overall.md v1.0](docs/kairos/specs/x-overall.md)",
|
|
502
|
+
"- **Depends on**: P1",
|
|
503
|
+
"",
|
|
504
|
+
"## Design",
|
|
505
|
+
"",
|
|
506
|
+
"intro — the double-layer skeleton semantics.",
|
|
507
|
+
"",
|
|
508
|
+
"### 1. 数据面",
|
|
509
|
+
"#### 1.1 登记表",
|
|
510
|
+
"- text",
|
|
511
|
+
"",
|
|
512
|
+
"### Acceptance criteria",
|
|
513
|
+
"",
|
|
514
|
+
"- `c`",
|
|
515
|
+
"",
|
|
516
|
+
"## Constraints",
|
|
517
|
+
"",
|
|
518
|
+
"- delta",
|
|
519
|
+
"",
|
|
520
|
+
"## Change history",
|
|
521
|
+
"",
|
|
522
|
+
"| Version | date | summary | author |",
|
|
523
|
+
"|---|---|---|---|",
|
|
524
|
+
"| v1.0 | 2026-10-08 | prior | [human] |",
|
|
525
|
+
"| v1.1 | 2026-10-09 | merged | [human] |",
|
|
526
|
+
]
|
|
527
|
+
.join("\n")
|
|
528
|
+
.replace("- **Status**: Draft", "- `p1` then **Status**: Deleted then `p2`");
|
|
529
|
+
const findings = judge("phase-spec", content, EMPTY_FS);
|
|
530
|
+
expect(withKind(findings, "domain", "**Status**")).toBe(false);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
it("order: the change-history rows must be version-ascending (canonical oldest-first)", () => {
|
|
534
|
+
const content = GOOD_OVERALL.replace(
|
|
535
|
+
["| v1.20 | 2026-10-06 | prior change |", "| v1.21 | 2026-10-07 | merged change |"].join(
|
|
536
|
+
"\n",
|
|
537
|
+
),
|
|
538
|
+
["| v1.21 | 2026-10-07 | merged change |", "| v1.20 | 2026-10-06 | prior change |"].join(
|
|
539
|
+
"\n",
|
|
540
|
+
),
|
|
541
|
+
);
|
|
542
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
543
|
+
expect(withKind(findings, "order", "Change history")).toBe(true);
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
it("residue: a legitimate design-body table does not count as Deviations residue", () => {
|
|
547
|
+
const content = [
|
|
548
|
+
"# Test Spec",
|
|
549
|
+
"- **Version**: v1.0",
|
|
550
|
+
"- **Status**: Draft",
|
|
551
|
+
"- **Author**: x",
|
|
552
|
+
"- **Parent program**: [x-overall.md v1.0](docs/kairos/specs/x-overall.md)",
|
|
553
|
+
"- **Depends on**: P1",
|
|
554
|
+
"",
|
|
555
|
+
"## Design",
|
|
556
|
+
"",
|
|
557
|
+
"### 1. 数据面",
|
|
558
|
+
"#### 1.1 技能集合",
|
|
559
|
+
"| skill | 角色 | 说明 |",
|
|
560
|
+
"| --- | --- | --- |",
|
|
561
|
+
"| cdd-design | 编排 | brainstorm 路由 |",
|
|
562
|
+
"| cdd-analysis | spec-writer | 参数化模板 |",
|
|
563
|
+
"",
|
|
564
|
+
"### Acceptance criteria",
|
|
565
|
+
"",
|
|
566
|
+
"- `c`",
|
|
567
|
+
"",
|
|
568
|
+
"## Constraints",
|
|
569
|
+
"",
|
|
570
|
+
"- delta",
|
|
571
|
+
"",
|
|
572
|
+
"## Review record",
|
|
573
|
+
"- review note",
|
|
574
|
+
].join("\n");
|
|
575
|
+
const findings = judge("phase-spec", content, EMPTY_FS);
|
|
576
|
+
expect(withKind(findings, "residue")).toBe(false);
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
describe("the four context-seam invariants — one negative case each", () => {
|
|
581
|
+
it("file-existence: a chain link target that does not resolve is reported", () => {
|
|
582
|
+
const content = GOOD_OVERALL.replace(
|
|
583
|
+
"[P1-design](docs/kairos/specs/x-p1-design.md)",
|
|
584
|
+
"[P1-design](docs/kairos/specs/ghost-design.md)",
|
|
585
|
+
);
|
|
586
|
+
const findings = judge("overall-spec", content, EMPTY_FS);
|
|
587
|
+
expect(withKind(findings, "file-existence")).toBe(true);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it("sibling-scan: a cross-linked doc outside the same-family scan is reported", () => {
|
|
591
|
+
const content = GOOD_OVERALL.replace(
|
|
592
|
+
"[P1-design](docs/kairos/specs/x-p1-design.md)",
|
|
593
|
+
"[P1-design](docs/kairos/specs/ghost-design.md)",
|
|
594
|
+
);
|
|
595
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
596
|
+
expect(withKind(findings, "sibling-scan")).toBe(true);
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
it("cross-doc-chain: a **Spec:** label that drifts from the resolved basename is reported", () => {
|
|
600
|
+
const content = [
|
|
601
|
+
"# Test Plan",
|
|
602
|
+
"**Spec:** [wrong-label](docs/kairos/specs/x-design.md)",
|
|
603
|
+
"- **Parent program**: [x-overall.md v1.21](docs/kairos/specs/x-overall.md)",
|
|
604
|
+
"",
|
|
605
|
+
...planTask(1),
|
|
606
|
+
].join("\n");
|
|
607
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
608
|
+
expect(withKind(findings, "cross-doc-chain", "**Spec:**")).toBe(true);
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
it("cross-doc-chain: an unregistered dispatch phase is reported (face ④)", () => {
|
|
612
|
+
const findings = judge("overall-spec", GOOD_OVERALL, GOOD_OVERALL_FS, "P9");
|
|
613
|
+
expect(withKind(findings, "cross-doc-chain", "Phase inventory")).toBe(true);
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
it("section-scoped-domain: an issue ref outside the declared form is judged only in scope", () => {
|
|
617
|
+
const content = GOOD_OVERALL.replace(
|
|
618
|
+
"| P1 | #123 | issue one |",
|
|
619
|
+
"| P1 | prose ref | issue one |",
|
|
620
|
+
);
|
|
621
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
622
|
+
expect(withKind(findings, "section-scoped-domain", "Issue inventory")).toBe(true);
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
describe("the coordinator", () => {
|
|
627
|
+
it("aggregates findings from multiple strategies on one document", () => {
|
|
628
|
+
const content = GOOD_OVERALL.replace("- **Status**: Approved", "- **Status**: Deleted").replace(
|
|
629
|
+
"| P2 | none | issue two |",
|
|
630
|
+
"| P9 | prose | issue nine |",
|
|
631
|
+
);
|
|
632
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS, "P9");
|
|
633
|
+
expect(withKind(findings, "domain", "**Status**")).toBe(true);
|
|
634
|
+
expect(withKind(findings, "crosslink", "Issue inventory")).toBe(true);
|
|
635
|
+
expect(withKind(findings, "section-scoped-domain", "Issue inventory")).toBe(true);
|
|
636
|
+
expect(withKind(findings, "presence", "Issue inventory")).toBe(false); // sections are present
|
|
637
|
+
expect(findings.length).toBeGreaterThanOrEqual(3);
|
|
638
|
+
});
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
// ---------------------------------------------------------------------------
|
|
642
|
+
// P4.1 T2 — the three-type homogeneity: `**Version**` required + strict (number · date) ·
|
|
643
|
+
// `## Change history` required ×3 · selfBounded ×3 (header = the newest in-row)
|
|
644
|
+
// ---------------------------------------------------------------------------
|
|
645
|
+
|
|
646
|
+
/** A minimal phase-spec carrying the canonical version lineage (strict Version
|
|
647
|
+
* header + a Change-history table) — the T2 judgment surface. */
|
|
648
|
+
const specLineage = (headerVersion: string, rows: readonly string[]): string => {
|
|
649
|
+
return [
|
|
650
|
+
"# Test Spec",
|
|
651
|
+
`- **Version**: ${headerVersion}`,
|
|
652
|
+
"- **Status**: Draft",
|
|
653
|
+
"- **Author**: x",
|
|
654
|
+
"- **Parent program**: [x-overall.md v1.0](docs/kairos/specs/x-overall.md)",
|
|
655
|
+
"- **Depends on**: P1",
|
|
656
|
+
"",
|
|
657
|
+
"## Design",
|
|
658
|
+
"",
|
|
659
|
+
"intro — the double-layer skeleton semantics.",
|
|
660
|
+
"",
|
|
661
|
+
"### 1. 数据面",
|
|
662
|
+
"#### 1.1 登记表",
|
|
663
|
+
"- text",
|
|
664
|
+
"",
|
|
665
|
+
"### Acceptance criteria",
|
|
666
|
+
"",
|
|
667
|
+
"- `c`",
|
|
668
|
+
"",
|
|
669
|
+
"## Constraints",
|
|
670
|
+
"",
|
|
671
|
+
"- delta",
|
|
672
|
+
"",
|
|
673
|
+
"## Change history",
|
|
674
|
+
"",
|
|
675
|
+
"| Version | date | summary | author |",
|
|
676
|
+
"|---|---|---|---|",
|
|
677
|
+
...rows,
|
|
678
|
+
].join("\n");
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
/** A minimal plan carrying the canonical version lineage. */
|
|
682
|
+
const planLineage = (headerVersion: string, rows: readonly string[]): string => {
|
|
683
|
+
return [
|
|
684
|
+
"# Test Plan",
|
|
685
|
+
"**Spec:** [x-design.md](docs/kairos/specs/x-design.md)",
|
|
686
|
+
"- **Parent program**: [x-overall.md v1.0](docs/kairos/specs/x-overall.md)",
|
|
687
|
+
`- **Version**: ${headerVersion}`,
|
|
688
|
+
"",
|
|
689
|
+
"## Constraints",
|
|
690
|
+
"",
|
|
691
|
+
"- delta",
|
|
692
|
+
"",
|
|
693
|
+
...planTask(1),
|
|
694
|
+
"",
|
|
695
|
+
"## Change history",
|
|
696
|
+
"",
|
|
697
|
+
"| Version | date | summary | author |",
|
|
698
|
+
"|---|---|---|---|",
|
|
699
|
+
...rows,
|
|
700
|
+
].join("\n");
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
const ROW_100 = "| v1.0 | 2026-10-08 | prior | [human] |";
|
|
704
|
+
const ROW_101 = "| v1.1 | 2026-10-09 | merged | [human] |";
|
|
705
|
+
|
|
706
|
+
describe("P4.1 T2 — **Version** presence required ×3 (plan optional → required)", () => {
|
|
707
|
+
it("a plan without a **Version** header is reported", () => {
|
|
708
|
+
const content = planLineage("v1.0 · 2026-10-09", [ROW_100]).replace(
|
|
709
|
+
"- **Version**: v1.0 · 2026-10-09",
|
|
710
|
+
"",
|
|
711
|
+
);
|
|
712
|
+
const findings = judge("plan", content);
|
|
713
|
+
expect(withKind(findings, "presence", "**Version**")).toBe(true);
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
it("a phase-spec without a **Version** header is reported", () => {
|
|
717
|
+
const content = specLineage("v1.0 · 2026-10-09", [ROW_100]).replace(
|
|
718
|
+
"- **Version**: v1.0 · 2026-10-09",
|
|
719
|
+
"",
|
|
720
|
+
);
|
|
721
|
+
const findings = judge("phase-spec", content);
|
|
722
|
+
expect(withKind(findings, "presence", "**Version**")).toBe(true);
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
it("an overall without a **Version** header is reported (the requiredness holds)", () => {
|
|
726
|
+
const content = GOOD_OVERALL.replace("- **Version**: v1.21 · 2026-10-07", "");
|
|
727
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
728
|
+
expect(withKind(findings, "presence", "**Version**")).toBe(true);
|
|
729
|
+
});
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
describe("P4.1 T2 — the **Version** strict form (number + date · zero supplement/link/bold)", () => {
|
|
733
|
+
it("a trailing parenthetical supplement is refused (plan and spec)", () => {
|
|
734
|
+
for (const [docKey, doc] of [
|
|
735
|
+
["plan", planLineage("v1.0 (v1.0 补充)", [ROW_100])],
|
|
736
|
+
["phase-spec", specLineage("v1.0 (v1.0 补充)", [ROW_100])],
|
|
737
|
+
] as const) {
|
|
738
|
+
expect(withKind(judge(docKey, doc), "domain", "**Version**")).toBe(true);
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
it("a trailing prose supplement after the date is refused (plan and spec)", () => {
|
|
743
|
+
for (const [docKey, doc] of [
|
|
744
|
+
["plan", planLineage("v1.0 · 2026-10-09 说明应在 Change history", [ROW_100])],
|
|
745
|
+
["phase-spec", specLineage("v1.0 · 2026-10-09 说明应在 Change history", [ROW_100])],
|
|
746
|
+
] as const) {
|
|
747
|
+
expect(withKind(judge(docKey, doc), "domain", "**Version**")).toBe(true);
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
it("a bold **vX.Y** form is refused (plan and spec)", () => {
|
|
752
|
+
for (const [docKey, doc] of [
|
|
753
|
+
["plan", planLineage("**v1.0** · 2026-10-09", [ROW_100])],
|
|
754
|
+
["phase-spec", specLineage("**v1.0** · 2026-10-09", [ROW_100])],
|
|
755
|
+
] as const) {
|
|
756
|
+
expect(withKind(judge(docKey, doc), "domain", "**Version**")).toBe(true);
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
it("the canonical `vX.Y · date` form carries no **Version** domain finding (plan and spec)", () => {
|
|
761
|
+
for (const docKey of ["plan", "phase-spec"] as const) {
|
|
762
|
+
const doc =
|
|
763
|
+
docKey === "plan"
|
|
764
|
+
? planLineage("v1.0 · 2026-10-09", [ROW_100])
|
|
765
|
+
: specLineage("v1.0 · 2026-10-09", [ROW_100]);
|
|
766
|
+
expect(withKind(judge(docKey, doc), "domain", "**Version**")).toBe(false);
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
describe("P4.1 T2 — `## Change history` presence required ×3", () => {
|
|
772
|
+
it("a plan without the Change-history section is reported", () => {
|
|
773
|
+
const content = planLineage("v1.0 · 2026-10-09", [ROW_100]).replace(
|
|
774
|
+
[
|
|
775
|
+
"## Change history",
|
|
776
|
+
"",
|
|
777
|
+
"| Version | date | summary | author |",
|
|
778
|
+
"|---|---|---|---|",
|
|
779
|
+
ROW_100,
|
|
780
|
+
].join("\n"),
|
|
781
|
+
"",
|
|
782
|
+
);
|
|
783
|
+
const findings = judge("plan", content);
|
|
784
|
+
expect(withKind(findings, "presence", "## Change history")).toBe(true);
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
it("a phase-spec without the Change-history section is reported", () => {
|
|
788
|
+
const content = specLineage("v1.0 · 2026-10-09", [ROW_100]).replace(
|
|
789
|
+
[
|
|
790
|
+
"## Change history",
|
|
791
|
+
"",
|
|
792
|
+
"| Version | date | summary | author |",
|
|
793
|
+
"|---|---|---|---|",
|
|
794
|
+
ROW_100,
|
|
795
|
+
].join("\n"),
|
|
796
|
+
"",
|
|
797
|
+
);
|
|
798
|
+
const findings = judge("phase-spec", content);
|
|
799
|
+
expect(withKind(findings, "presence", "## Change history")).toBe(true);
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
it("an overall without the Change-history section is reported (the requiredness holds)", () => {
|
|
803
|
+
const content = GOOD_OVERALL.replace(
|
|
804
|
+
[
|
|
805
|
+
"## Change history",
|
|
806
|
+
"| Version | Date | Summary |",
|
|
807
|
+
"| --- | --- | --- |",
|
|
808
|
+
"| v1.20 | 2026-10-06 | prior change |",
|
|
809
|
+
"| v1.21 | 2026-10-07 | merged change |",
|
|
810
|
+
].join("\n"),
|
|
811
|
+
"",
|
|
812
|
+
);
|
|
813
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
814
|
+
expect(withKind(findings, "presence", "## Change history")).toBe(true);
|
|
815
|
+
});
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
describe("P4.1 T2 — selfBounded applies to spec/plan (header = the newest in-row)", () => {
|
|
819
|
+
it("a phase-spec whose header is NOT the change-history's newest row is reported", () => {
|
|
820
|
+
const findings = judge("phase-spec", specLineage("v1.0 · 2026-10-09", [ROW_100, ROW_101]));
|
|
821
|
+
expect(withKind(findings, "selfBounded", "**Version**")).toBe(true);
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
it("a plan whose header is OUTSIDE the lineage is reported", () => {
|
|
825
|
+
const findings = judge("plan", planLineage("v1.2 · 2026-10-09", [ROW_100, ROW_101]));
|
|
826
|
+
expect(withKind(findings, "selfBounded", "**Version**")).toBe(true);
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
it("a spec/plan whose header IS the newest in-row version carries no selfBounded finding", () => {
|
|
830
|
+
for (const docKey of ["plan", "phase-spec"] as const) {
|
|
831
|
+
const doc =
|
|
832
|
+
docKey === "plan"
|
|
833
|
+
? planLineage("v1.1 · 2026-10-09", [ROW_100, ROW_101])
|
|
834
|
+
: specLineage("v1.1 · 2026-10-09", [ROW_100, ROW_101]);
|
|
835
|
+
expect(withKind(judge(docKey, doc), "selfBounded", "**Version**")).toBe(false);
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
describe("governance greps (the engine-zero criterion)", () => {
|
|
841
|
+
it("dispatches judgment without any switch-case (grep)", () => {
|
|
842
|
+
for (const name of ["judge.ts", "invariants.ts", "doc.ts"]) {
|
|
843
|
+
const source = readFileSync(new URL(`../${name}`, import.meta.url), "utf8");
|
|
844
|
+
expect(source.match(/\bswitch\s*\(/), name).toBeNull();
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
it("exports zero behavior-carrying bare functions from judge/invariants (grep)", () => {
|
|
849
|
+
for (const name of ["judge.ts", "invariants.ts"]) {
|
|
850
|
+
const source = readFileSync(new URL(`../${name}`, import.meta.url), "utf8");
|
|
851
|
+
const functionExports = source.match(/export\s+(?:async\s+)?function\s+\w+/g) ?? [];
|
|
852
|
+
expect(functionExports, name).toEqual([]);
|
|
853
|
+
const behaviorConstExports =
|
|
854
|
+
source.match(/export\s+const\s+\w+\s*=\s*(?:\([^)]*\)|[\w]+)\s*=>/g) ?? [];
|
|
855
|
+
expect(behaviorConstExports, name).toEqual([]);
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
/** One rendered `### Task N:` block with all required fields. */
|
|
861
|
+
const planTask = (id: number): string[] => {
|
|
862
|
+
return [
|
|
863
|
+
`### Task ${id}: task`,
|
|
864
|
+
`- **Objective**: objective`,
|
|
865
|
+
`- **Files**: file`,
|
|
866
|
+
`- **Consumes**: consumes`,
|
|
867
|
+
`- **Produces**: produces`,
|
|
868
|
+
`- **Steps**:`,
|
|
869
|
+
` - step one`,
|
|
870
|
+
`- **Acceptance**: acceptance`,
|
|
871
|
+
`- **DependsOn**: none`,
|
|
872
|
+
];
|
|
873
|
+
};
|