@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,1111 @@
|
|
|
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. Since T6 the
|
|
12
|
+
// fixtures carry the front-matter head (the §2.2 delivery seam: validate() splits
|
|
13
|
+
// the raw content, feeds the typed head into parse + the judged context, and the
|
|
14
|
+
// front-matter-home elements judge the head record).
|
|
15
|
+
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
import { describe, expect, it } from "vitest";
|
|
18
|
+
import { Words } from "../../face/words.ts";
|
|
19
|
+
import type { ParsedDoc } from "../doc.ts";
|
|
20
|
+
import { OverallDocType } from "../doc.ts";
|
|
21
|
+
import { FrontMatterExtractor } from "../frontmatter.ts";
|
|
22
|
+
import type { DocFs, Finding } from "../invariants.ts";
|
|
23
|
+
import { Contract } from "../judge.ts";
|
|
24
|
+
import { Translator } from "../translate.ts";
|
|
25
|
+
|
|
26
|
+
/** A conforming overall — every registered element present, lineage self-consistent. */
|
|
27
|
+
const GOOD_OVERALL = [
|
|
28
|
+
"---",
|
|
29
|
+
"title: 测试 Overall",
|
|
30
|
+
"doc-type: overall-spec",
|
|
31
|
+
"version: v1.21",
|
|
32
|
+
"date: 2026-10-07",
|
|
33
|
+
"status: Approved",
|
|
34
|
+
'author: "[human]"',
|
|
35
|
+
"---",
|
|
36
|
+
"",
|
|
37
|
+
"## Document scope",
|
|
38
|
+
"scope prose",
|
|
39
|
+
"",
|
|
40
|
+
"## File paths",
|
|
41
|
+
"| Artifact | Path |",
|
|
42
|
+
"| --- | --- |",
|
|
43
|
+
"| overall | docs/kairos/specs/x-overall.md |",
|
|
44
|
+
"",
|
|
45
|
+
"## Program charter",
|
|
46
|
+
"### Goal",
|
|
47
|
+
"- goal text",
|
|
48
|
+
"",
|
|
49
|
+
"### Non-goals",
|
|
50
|
+
"- non-goal text",
|
|
51
|
+
"",
|
|
52
|
+
"### Cross-cutting",
|
|
53
|
+
"- cross text",
|
|
54
|
+
"",
|
|
55
|
+
"## Issue inventory",
|
|
56
|
+
"| Phase | Issue (ref) | Title summary |",
|
|
57
|
+
"| --- | --- | --- |",
|
|
58
|
+
"| P1 | #123 | issue one |",
|
|
59
|
+
"| P2 | none | issue two |",
|
|
60
|
+
"",
|
|
61
|
+
"## Phase inventory",
|
|
62
|
+
"| # | Phase | Scope | Design spec | Implementation plan | Acceptance criteria | Dependency |",
|
|
63
|
+
"| --- | --- | --- | --- | --- | --- | --- |",
|
|
64
|
+
"| P1 | DocType 抽象 + schema 工厂 | scope a | [P1-design](docs/kairos/specs/x-p1-design.md) | [P1 plan](docs/kairos/plans/x-p1.md) | criteria a | |",
|
|
65
|
+
"| P2 | 判定面 + 协调器 | scope b | P2-design | [P2 plan](docs/kairos/plans/x-p2.md) | criteria b | |",
|
|
66
|
+
"",
|
|
67
|
+
"## Dependency graph",
|
|
68
|
+
"P1 -> P2",
|
|
69
|
+
"- `->` = hard block(依赖前置 phase 发布后方可启动)",
|
|
70
|
+
"",
|
|
71
|
+
"## Boundary rules",
|
|
72
|
+
"- boundary rule",
|
|
73
|
+
"",
|
|
74
|
+
"## Constraints",
|
|
75
|
+
"",
|
|
76
|
+
"- 全部约定自动生效",
|
|
77
|
+
"",
|
|
78
|
+
"## Maintenance",
|
|
79
|
+
"- maintenance note",
|
|
80
|
+
"",
|
|
81
|
+
"## Change history",
|
|
82
|
+
"| Version | Date | Summary |",
|
|
83
|
+
"| --- | --- | --- |",
|
|
84
|
+
"| v1.20 | 2026-10-06 | prior change |",
|
|
85
|
+
"| v1.21 | 2026-10-07 | merged change |",
|
|
86
|
+
].join("\n");
|
|
87
|
+
|
|
88
|
+
const OVERALL_PATH = "docs/kairos/specs/x-overall.md";
|
|
89
|
+
const PLAN_PATH = "docs/kairos/plans/x-p3.md";
|
|
90
|
+
const SPEC_PATH = "docs/kairos/specs/x-p3-design.md";
|
|
91
|
+
|
|
92
|
+
/** The sibling-doc fs the conforming doc resolves into. */
|
|
93
|
+
const GOOD_OVERALL_FS: DocFs = {
|
|
94
|
+
exists: () => true,
|
|
95
|
+
read: () => null,
|
|
96
|
+
list: (dir) =>
|
|
97
|
+
dir.endsWith("/specs") || dir.endsWith("specs")
|
|
98
|
+
? ["x-overall.md", "x-p1-design.md", "x-p2-design.md"]
|
|
99
|
+
: ["x-p1.md", "x-p2.md"],
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** One empty fs — chains resolve nowhere (for the file-existence negative). */
|
|
103
|
+
const EMPTY_FS: DocFs = {
|
|
104
|
+
exists: () => false,
|
|
105
|
+
read: () => null,
|
|
106
|
+
list: () => [],
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const judge = (
|
|
110
|
+
docKey: "overall-spec" | "plan" | "phase-spec",
|
|
111
|
+
content: string,
|
|
112
|
+
fs: DocFs = EMPTY_FS,
|
|
113
|
+
phaseId?: string,
|
|
114
|
+
root = ".",
|
|
115
|
+
): Finding[] =>
|
|
116
|
+
new Contract().validate({
|
|
117
|
+
docKey,
|
|
118
|
+
path: docKey === "overall-spec" ? OVERALL_PATH : docKey === "plan" ? PLAN_PATH : SPEC_PATH,
|
|
119
|
+
content,
|
|
120
|
+
root,
|
|
121
|
+
fs,
|
|
122
|
+
phaseId,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const withKind = (findings: readonly Finding[], kind: string, field?: string): boolean =>
|
|
126
|
+
findings.some(
|
|
127
|
+
(finding) => finding.kind === kind && (field === undefined || finding.field === field),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
describe("the conforming overall — zero findings (no false positives)", () => {
|
|
131
|
+
it("judges a conforming overall clean under a sane fs", () => {
|
|
132
|
+
expect(judge("overall-spec", GOOD_OVERALL, GOOD_OVERALL_FS)).toEqual([]);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("P7 — the structure-plane canonicalize seam (Contract.validate row-source)", () => {
|
|
137
|
+
/** The GOOD_OVERALL charter carrying the legacy Chinese markers the English
|
|
138
|
+
* canonical element patterns match THROUGH the canonicalize view: the
|
|
139
|
+
* doc-arch-overall decision-group / endorsements leaves (`#### M 组` … /
|
|
140
|
+
* `#### 上游先例背书`). The markers are UNREGISTERED zh prose to the element
|
|
141
|
+
* table (English canonicals only) — any match is the row-source seam talking.
|
|
142
|
+
* The Goal facet stays in its English form (the zh Goal face carries no
|
|
143
|
+
* registered alternate). */
|
|
144
|
+
const ZH_CHARTER_OVERALL = GOOD_OVERALL.replace(
|
|
145
|
+
"### Goal\n- goal text",
|
|
146
|
+
[
|
|
147
|
+
"### Goal",
|
|
148
|
+
"- goal text",
|
|
149
|
+
"",
|
|
150
|
+
"#### M 组(skill-ref 映射,M1–M4 全关)",
|
|
151
|
+
"- m leaf",
|
|
152
|
+
"",
|
|
153
|
+
"#### F 组(文档平面结构,提案)",
|
|
154
|
+
"- f leaf",
|
|
155
|
+
"",
|
|
156
|
+
"#### R 组(ref 统一身份,提案)",
|
|
157
|
+
"- r leaf",
|
|
158
|
+
"",
|
|
159
|
+
"#### B 组(正文内容,提案)",
|
|
160
|
+
"- b leaf",
|
|
161
|
+
"",
|
|
162
|
+
"#### E 组(经验债,驱动本整体)",
|
|
163
|
+
"- e leaf",
|
|
164
|
+
"",
|
|
165
|
+
"#### 上游先例背书",
|
|
166
|
+
"- endorsement text",
|
|
167
|
+
].join("\n"),
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
it("the structure judge matches the legacy Chinese charter markers through the canonicalize view", () => {
|
|
171
|
+
const findings = judge("overall-spec", ZH_CHARTER_OVERALL, GOOD_OVERALL_FS);
|
|
172
|
+
// the zh decision-group leaves (`#### M 组` …) conform to the canonical
|
|
173
|
+
// `#### [MFRBEN] group` facet through the view
|
|
174
|
+
expect(withKind(findings, "presence", "#### [MFRBEN] group")).toBe(false);
|
|
175
|
+
expect(withKind(findings, "domain", "#### [MFRBEN] group")).toBe(false);
|
|
176
|
+
// the zh endorsements leaf conforms to the canonical facet through the view
|
|
177
|
+
expect(withKind(findings, "domain", "#### Upstream Endorsements")).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("a zh title outside the registered canonicals stays identity — a 目标 Goal face is still missing", () => {
|
|
181
|
+
const content = GOOD_OVERALL.replace("### Goal\n- goal text", "### 目标\n- goal text");
|
|
182
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
183
|
+
expect(withKind(findings, "presence", "### Goal")).toBe(true);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("the view never writes back — the judged source content stays byte-identical", () => {
|
|
187
|
+
const input = {
|
|
188
|
+
docKey: "overall-spec" as const,
|
|
189
|
+
path: OVERALL_PATH,
|
|
190
|
+
content: ZH_CHARTER_OVERALL,
|
|
191
|
+
root: ".",
|
|
192
|
+
fs: GOOD_OVERALL_FS,
|
|
193
|
+
};
|
|
194
|
+
const findings = new Contract().validate(input);
|
|
195
|
+
expect(input.content).toBe(ZH_CHARTER_OVERALL);
|
|
196
|
+
expect(findings).toEqual([]);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("base nine invariants — one negative case each", () => {
|
|
201
|
+
it("presence: a missing required section is reported", () => {
|
|
202
|
+
const content = GOOD_OVERALL.replace("## Maintenance\n- maintenance note", "");
|
|
203
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
204
|
+
expect(withKind(findings, "presence", "## Maintenance")).toBe(true);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("uniqueness: a duplicated section heading is reported", () => {
|
|
208
|
+
const content = GOOD_OVERALL.replace(
|
|
209
|
+
"## Document scope",
|
|
210
|
+
"## Document scope\nscope one\n\n## Document scope\nscope two",
|
|
211
|
+
);
|
|
212
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
213
|
+
expect(withKind(findings, "uniqueness", "## Document scope")).toBe(true);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("domain: a front-matter value outside its declared shape is reported", () => {
|
|
217
|
+
const content = GOOD_OVERALL.replace("status: Approved", "status: Deleted");
|
|
218
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
219
|
+
expect(withKind(findings, "domain", "status")).toBe(true);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("crosslink: an issue row referencing an unregistered phase is reported", () => {
|
|
223
|
+
const content = GOOD_OVERALL.replace("| P2 | none | issue two |", "| P9 | none | issue nine |");
|
|
224
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
225
|
+
expect(withKind(findings, "crosslink", "Issue inventory")).toBe(true);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("order: the section sequence must follow the declared registry order", () => {
|
|
229
|
+
// A phase-spec with Constraints BEFORE Design inverts the declared sequence.
|
|
230
|
+
const content = [
|
|
231
|
+
"---",
|
|
232
|
+
"title: Test Spec",
|
|
233
|
+
"doc-type: phase-spec",
|
|
234
|
+
"version: v1.0",
|
|
235
|
+
"date: 2026-10-09",
|
|
236
|
+
"status: Draft",
|
|
237
|
+
"author: x",
|
|
238
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
239
|
+
"parent-version: v1.0",
|
|
240
|
+
"depends-on: P1",
|
|
241
|
+
"---",
|
|
242
|
+
"",
|
|
243
|
+
"## Constraints",
|
|
244
|
+
"",
|
|
245
|
+
"- delta",
|
|
246
|
+
"",
|
|
247
|
+
"## Design",
|
|
248
|
+
"",
|
|
249
|
+
"### 1. 数据面",
|
|
250
|
+
"#### 1.1 登记表",
|
|
251
|
+
"- text",
|
|
252
|
+
"",
|
|
253
|
+
"### Acceptance criteria",
|
|
254
|
+
"",
|
|
255
|
+
"- `c`",
|
|
256
|
+
].join("\n");
|
|
257
|
+
const findings = judge("phase-spec", content, EMPTY_FS);
|
|
258
|
+
expect(withKind(findings, "order")).toBe(true);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("continuity: plan task ids must be contiguous from 1", () => {
|
|
262
|
+
const content = [
|
|
263
|
+
"---",
|
|
264
|
+
"title: Test Plan",
|
|
265
|
+
"doc-type: plan",
|
|
266
|
+
"version: v1.0",
|
|
267
|
+
"date: 2026-10-09",
|
|
268
|
+
"spec: docs/kairos/specs/x-design.md",
|
|
269
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
270
|
+
"parent-version: v1.21",
|
|
271
|
+
"---",
|
|
272
|
+
"",
|
|
273
|
+
...planTask(1),
|
|
274
|
+
...planTask(3),
|
|
275
|
+
].join("\n");
|
|
276
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
277
|
+
expect(withKind(findings, "continuity")).toBe(true);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("residue: conditional content leaks while its section is absent", () => {
|
|
281
|
+
const content = [
|
|
282
|
+
"---",
|
|
283
|
+
"title: Test Spec",
|
|
284
|
+
"doc-type: phase-spec",
|
|
285
|
+
"version: v1.0",
|
|
286
|
+
"date: 2026-10-09",
|
|
287
|
+
"status: Draft",
|
|
288
|
+
"author: x",
|
|
289
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
290
|
+
"parent-version: v1.0",
|
|
291
|
+
"depends-on: P1",
|
|
292
|
+
"---",
|
|
293
|
+
"",
|
|
294
|
+
"## Design",
|
|
295
|
+
"",
|
|
296
|
+
"### 1. 数据面",
|
|
297
|
+
"#### 1.1 登记表",
|
|
298
|
+
"- text",
|
|
299
|
+
"",
|
|
300
|
+
"### Acceptance criteria",
|
|
301
|
+
"",
|
|
302
|
+
"- `c`",
|
|
303
|
+
"",
|
|
304
|
+
"## Constraints",
|
|
305
|
+
"",
|
|
306
|
+
"- delta",
|
|
307
|
+
"",
|
|
308
|
+
"| overall decision | 决定 | Yes |",
|
|
309
|
+
].join("\n");
|
|
310
|
+
const findings = judge("phase-spec", content, EMPTY_FS);
|
|
311
|
+
expect(withKind(findings, "residue")).toBe(true);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("hollow: a present table section with zero data rows is reported", () => {
|
|
315
|
+
const content = GOOD_OVERALL.replace(
|
|
316
|
+
[
|
|
317
|
+
"## File paths",
|
|
318
|
+
"| Artifact | Path |",
|
|
319
|
+
"| --- | --- |",
|
|
320
|
+
"| overall | docs/kairos/specs/x-overall.md |",
|
|
321
|
+
].join("\n"),
|
|
322
|
+
"## File paths\n",
|
|
323
|
+
);
|
|
324
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
325
|
+
expect(withKind(findings, "hollow", "## File paths")).toBe(true);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("selfBounded: the header version must be the change-history's newest row", () => {
|
|
329
|
+
const content = GOOD_OVERALL.replace(
|
|
330
|
+
"| v1.21 | 2026-10-07 | merged change |",
|
|
331
|
+
"| v1.20 | 2026-10-06 | older only |",
|
|
332
|
+
);
|
|
333
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
334
|
+
expect(withKind(findings, "selfBounded", "version")).toBe(true);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
describe("T6 — prose task mentions carry zero crosslink findings (the WARN-only observation surface)", () => {
|
|
339
|
+
/** The sibling-doc fs a conforming plan's chain resolves into (exists + the
|
|
340
|
+
* same-family listings the file-existence/sibling-scan surfaces judge). */
|
|
341
|
+
const GOOD_PLAN_FS: DocFs = {
|
|
342
|
+
exists: () => true,
|
|
343
|
+
read: () => null,
|
|
344
|
+
list: (dir) =>
|
|
345
|
+
dir.endsWith("/specs") || dir.endsWith("specs")
|
|
346
|
+
? ["x-overall.md", "x-design.md", "x-p3-design.md"]
|
|
347
|
+
: ["x-p3.md"],
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/** A structurally conforming plan — every registered plan element present
|
|
351
|
+
* (front-matter head + version lineage + task fields + Change history) carrying
|
|
352
|
+
* a prose mention of an unregistered historical task id in its Objective. */
|
|
353
|
+
function conformingPlanWithProse(objective: string): string {
|
|
354
|
+
return [
|
|
355
|
+
"---",
|
|
356
|
+
"title: Test Plan",
|
|
357
|
+
"doc-type: plan",
|
|
358
|
+
"version: v1.1",
|
|
359
|
+
"date: 2026-10-09",
|
|
360
|
+
"spec: docs/kairos/specs/x-design.md",
|
|
361
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
362
|
+
"parent-version: v1.21",
|
|
363
|
+
"---",
|
|
364
|
+
"",
|
|
365
|
+
"## Constraints",
|
|
366
|
+
"",
|
|
367
|
+
"- delta",
|
|
368
|
+
"",
|
|
369
|
+
"### Task 1: task",
|
|
370
|
+
`- **Objective**: ${objective}`,
|
|
371
|
+
"- **Files**: file",
|
|
372
|
+
"- **Consumes**: consumes",
|
|
373
|
+
"- **Produces**: produces",
|
|
374
|
+
"- **Steps**:",
|
|
375
|
+
" - step one — checkable: green",
|
|
376
|
+
"- **Acceptance**: acceptance",
|
|
377
|
+
"- **DependsOn**: none",
|
|
378
|
+
"",
|
|
379
|
+
"## Change history",
|
|
380
|
+
"",
|
|
381
|
+
"| Version | date | summary | author |",
|
|
382
|
+
"|---|---|---|---|",
|
|
383
|
+
"| v1.0 | 2026-10-08 | prior | [human] |",
|
|
384
|
+
"| v1.1 | 2026-10-09 | merged | [human] |",
|
|
385
|
+
].join("\n");
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
it("a conforming plan prose-referencing an unregistered historical task id scores ZERO findings", () => {
|
|
389
|
+
const content = conformingPlanWithProse(
|
|
390
|
+
"承接 P3.2 的 T25 段既有约定(历史任务序号 · 非本 plan 任务)",
|
|
391
|
+
);
|
|
392
|
+
const findings = judge("plan", content, GOOD_PLAN_FS);
|
|
393
|
+
// the prose mention is the reference-lint WARN observation's — the crosslink
|
|
394
|
+
// invariant never consumes it, and no other surface reports the mention
|
|
395
|
+
expect(withKind(findings, "crosslink", "Task prose reference")).toBe(false);
|
|
396
|
+
expect(findings).toEqual([]);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it("the DependsOn out-of-bounds hard gate stays — an unregistered DEPENDENCY is still a crosslink finding", () => {
|
|
400
|
+
const content = conformingPlanWithProse("objective").replace(
|
|
401
|
+
"- **DependsOn**: none",
|
|
402
|
+
"- **DependsOn**: 25",
|
|
403
|
+
);
|
|
404
|
+
const findings = judge("plan", content, GOOD_PLAN_FS);
|
|
405
|
+
expect(withKind(findings, "crosslink", "Task 1")).toBe(true);
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
describe("the canonical repo forms (no false positives on real conventions)", () => {
|
|
410
|
+
it("presence: the token-in-heading task id is satisfied by the parsed task blocks (not a line scan)", () => {
|
|
411
|
+
const content = [
|
|
412
|
+
"---",
|
|
413
|
+
"title: Test Plan",
|
|
414
|
+
"doc-type: plan",
|
|
415
|
+
"version: v1.0",
|
|
416
|
+
"date: 2026-10-09",
|
|
417
|
+
"spec: docs/kairos/specs/x-design.md",
|
|
418
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
419
|
+
"parent-version: v1.21",
|
|
420
|
+
"---",
|
|
421
|
+
"",
|
|
422
|
+
"## Constraints",
|
|
423
|
+
"",
|
|
424
|
+
"- delta",
|
|
425
|
+
"",
|
|
426
|
+
...planTask(1),
|
|
427
|
+
].join("\n");
|
|
428
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
429
|
+
expect(withKind(findings, "presence", "Task id token")).toBe(false);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it("presence: the graph legend tolerates the canonical backticked form — and its absence is reported", () => {
|
|
433
|
+
const removed = GOOD_OVERALL.replace(
|
|
434
|
+
"- `->` = hard block(依赖前置 phase 发布后方可启动)",
|
|
435
|
+
"P1 -> P1b",
|
|
436
|
+
);
|
|
437
|
+
expect(
|
|
438
|
+
withKind(judge("overall-spec", removed, GOOD_OVERALL_FS), "presence", "Graph legend"),
|
|
439
|
+
).toBe(true);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it("presence: a task block missing a registry-declared task field is reported (derived field set)", () => {
|
|
443
|
+
const content = [
|
|
444
|
+
"---",
|
|
445
|
+
"title: Test Plan",
|
|
446
|
+
"doc-type: plan",
|
|
447
|
+
"version: v1.0",
|
|
448
|
+
"date: 2026-10-09",
|
|
449
|
+
"spec: docs/kairos/specs/x-design.md",
|
|
450
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
451
|
+
"parent-version: v1.21",
|
|
452
|
+
"---",
|
|
453
|
+
"",
|
|
454
|
+
"## Constraints",
|
|
455
|
+
"",
|
|
456
|
+
"- delta",
|
|
457
|
+
"",
|
|
458
|
+
"### Task 1: task",
|
|
459
|
+
"- **Objective**: objective",
|
|
460
|
+
"- **Files**: file",
|
|
461
|
+
"- **Consumes**: consumes",
|
|
462
|
+
"- **Produces**: produces",
|
|
463
|
+
"- **Steps**:",
|
|
464
|
+
" - step one",
|
|
465
|
+
"- **DependsOn**: none",
|
|
466
|
+
].join("\n");
|
|
467
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
468
|
+
expect(withKind(findings, "presence", "**Acceptance**")).toBe(true);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it("domain: a backticked citation of an anchor literal is not judged as a value", () => {
|
|
472
|
+
const content = [
|
|
473
|
+
"---",
|
|
474
|
+
"title: Test Plan",
|
|
475
|
+
"doc-type: plan",
|
|
476
|
+
"version: v1.0",
|
|
477
|
+
"date: 2026-10-09",
|
|
478
|
+
"spec: docs/kairos/specs/x-design.md",
|
|
479
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
480
|
+
"parent-version: v1.21",
|
|
481
|
+
"---",
|
|
482
|
+
"",
|
|
483
|
+
"## Constraints",
|
|
484
|
+
"",
|
|
485
|
+
"- delta",
|
|
486
|
+
"",
|
|
487
|
+
"### Task 1: task",
|
|
488
|
+
"- **Objective**: 引用 `### Task N:` 块归口 doc.ts",
|
|
489
|
+
"- **Files**: file",
|
|
490
|
+
"- **Consumes**: consumes",
|
|
491
|
+
"- **Produces**: produces",
|
|
492
|
+
"- **Steps**:",
|
|
493
|
+
" - step one",
|
|
494
|
+
"- **Acceptance**: acceptance",
|
|
495
|
+
"- **DependsOn**: none",
|
|
496
|
+
].join("\n");
|
|
497
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
498
|
+
expect(withKind(findings, "domain", "### Task N:")).toBe(false);
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
it("domain: a table-cell citation of a section anchor is not judged as a value", () => {
|
|
502
|
+
const content = GOOD_OVERALL.replace(
|
|
503
|
+
"| v1.20 | 2026-10-06 | prior change |",
|
|
504
|
+
"| v1.20 | 2026-10-06 | `## Program charter` 重构 |",
|
|
505
|
+
);
|
|
506
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
507
|
+
expect(withKind(findings, "domain", "## Program charter")).toBe(false);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it("presence+domain: the TITLED task heading is a valid `### Task N:` (the tree-wide form)", () => {
|
|
511
|
+
// find #8: the registry's bare-heading pattern rejected the titled form — the
|
|
512
|
+
// wave's own plan (25/25 plans use `### Task N: <title>`) was reported missing
|
|
513
|
+
const content = [
|
|
514
|
+
"---",
|
|
515
|
+
"title: Test Plan",
|
|
516
|
+
"doc-type: plan",
|
|
517
|
+
"version: v1.0",
|
|
518
|
+
"date: 2026-10-09",
|
|
519
|
+
"spec: docs/kairos/specs/x-design.md",
|
|
520
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
521
|
+
"parent-version: v1.21",
|
|
522
|
+
"---",
|
|
523
|
+
"",
|
|
524
|
+
"## Constraints",
|
|
525
|
+
"",
|
|
526
|
+
"- delta",
|
|
527
|
+
"",
|
|
528
|
+
"### Task 1: task title",
|
|
529
|
+
"- **Objective**: objective",
|
|
530
|
+
"- **Files**: file",
|
|
531
|
+
"- **Consumes**: consumes",
|
|
532
|
+
"- **Produces**: produces",
|
|
533
|
+
"- **Steps**:",
|
|
534
|
+
" - step one",
|
|
535
|
+
"- **Acceptance**: acceptance",
|
|
536
|
+
"- **DependsOn**: none",
|
|
537
|
+
].join("\n");
|
|
538
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
539
|
+
expect(withKind(findings, "presence", "### Task N:")).toBe(false);
|
|
540
|
+
expect(withKind(findings, "domain", "### Task N:")).toBe(false);
|
|
541
|
+
// the bare heading is the same pattern's canonical form — both conform
|
|
542
|
+
const bare = content.replace("### Task 1: task title", "### Task 1:");
|
|
543
|
+
expect(withKind(judge("plan", bare, EMPTY_FS), "presence", "### Task N:")).toBe(false);
|
|
544
|
+
// a non-numeric heading is still outside the domain
|
|
545
|
+
expect(
|
|
546
|
+
withKind(
|
|
547
|
+
judge("plan", content.replace("### Task 1:", "### Task X:"), EMPTY_FS),
|
|
548
|
+
"presence",
|
|
549
|
+
"### Task N:",
|
|
550
|
+
),
|
|
551
|
+
).toBe(true);
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
it("domain: a nested backtick citation (`outer quote … inner `anchor`) is not judged as a value", () => {
|
|
555
|
+
// find #8: the old span-by-span strip consumed the outer quote's opener and left
|
|
556
|
+
// the nested `…` citation naked — quoted prose was judged as `## Constraints`
|
|
557
|
+
// values (the plan's front-matter `version:` is a head scalar: a body citation
|
|
558
|
+
// of `version:` is outside the judged surface entirely)
|
|
559
|
+
const content = [
|
|
560
|
+
"---",
|
|
561
|
+
"title: Test Plan",
|
|
562
|
+
"doc-type: plan",
|
|
563
|
+
"version: v1.0",
|
|
564
|
+
"date: 2026-10-09",
|
|
565
|
+
"spec: docs/kairos/specs/x-design.md",
|
|
566
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
567
|
+
"parent-version: v1.21",
|
|
568
|
+
"---",
|
|
569
|
+
"",
|
|
570
|
+
"## Constraints",
|
|
571
|
+
"",
|
|
572
|
+
"- delta",
|
|
573
|
+
"",
|
|
574
|
+
"### Task 1: task",
|
|
575
|
+
"- **Objective**: T1(`read the plan's `## Constraints` (at INPUT_PLAN)`)·「`the `**Version**` header`」零残留",
|
|
576
|
+
"- **Files**: file",
|
|
577
|
+
"- **Consumes**: consumes",
|
|
578
|
+
"- **Produces**: produces",
|
|
579
|
+
"- **Steps**:",
|
|
580
|
+
" - step one",
|
|
581
|
+
"- **Acceptance**: acceptance",
|
|
582
|
+
"- **DependsOn**: none",
|
|
583
|
+
].join("\n");
|
|
584
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
585
|
+
expect(withKind(findings, "domain", "## Constraints")).toBe(false);
|
|
586
|
+
expect(withKind(findings, "domain", "version")).toBe(false);
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
it("two adjacent backtick spans read as ONE quoted region — the mid-span prose is not judged (the pinned first-last strip)", () => {
|
|
590
|
+
// The find-#8 first-last strip consumes the whole first→last backtick region as
|
|
591
|
+
// quoted. On a line carrying TWO separate spans, the prose BETWEEN them is part
|
|
592
|
+
// of that region — an anchor quoted only there is invisible to the domain rule.
|
|
593
|
+
// Pinned tradeoff (the comment on #withoutCodeSpans): the enforced docs' quoted
|
|
594
|
+
// shapes are the simple `span` and the nested citation, neither of which hides a
|
|
595
|
+
// real structural anchor between two adjacent spans; a span-by-span strip would
|
|
596
|
+
// judge this middle prose and reopen the nested-citation gap the pin closes.
|
|
597
|
+
const content = phaseSpec("v1.1").replace(
|
|
598
|
+
"- delta",
|
|
599
|
+
"- `p1` then ## Constraints: Deleted then `p2`",
|
|
600
|
+
);
|
|
601
|
+
const findings = judge("phase-spec", content, EMPTY_FS);
|
|
602
|
+
expect(withKind(findings, "domain", "## Constraints")).toBe(false);
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
it("order: the change-history rows must be version-ascending (canonical oldest-first)", () => {
|
|
606
|
+
const content = GOOD_OVERALL.replace(
|
|
607
|
+
["| v1.20 | 2026-10-06 | prior change |", "| v1.21 | 2026-10-07 | merged change |"].join(
|
|
608
|
+
"\n",
|
|
609
|
+
),
|
|
610
|
+
["| v1.21 | 2026-10-07 | merged change |", "| v1.20 | 2026-10-06 | prior change |"].join(
|
|
611
|
+
"\n",
|
|
612
|
+
),
|
|
613
|
+
);
|
|
614
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
615
|
+
expect(withKind(findings, "order", "Change history")).toBe(true);
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
it("residue: a legitimate design-body table does not count as Deviations residue", () => {
|
|
619
|
+
const content = phaseSpec("v1.1").replace(
|
|
620
|
+
"### 1. 数据面\n#### 1.1 登记表\n- text",
|
|
621
|
+
"### 1. 数据面\n#### 1.1 技能集合\n| skill | 角色 | 说明 |\n| --- | --- | --- |\n| cdd-design | 编排 | brainstorm 路由 |\n| cdd-analysis | spec-writer | 参数化模板 |",
|
|
622
|
+
);
|
|
623
|
+
const findings = judge("phase-spec", content, EMPTY_FS);
|
|
624
|
+
expect(withKind(findings, "residue")).toBe(false);
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
describe("the four context-seam invariants — one negative case each", () => {
|
|
629
|
+
it("file-existence: a chain link target that does not resolve is reported", () => {
|
|
630
|
+
const content = GOOD_OVERALL.replace(
|
|
631
|
+
"[P1-design](docs/kairos/specs/x-p1-design.md)",
|
|
632
|
+
"[P1-design](docs/kairos/specs/ghost-design.md)",
|
|
633
|
+
);
|
|
634
|
+
const findings = judge("overall-spec", content, EMPTY_FS);
|
|
635
|
+
expect(withKind(findings, "file-existence")).toBe(true);
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
it("sibling-scan: a cross-linked doc outside the same-family scan is reported", () => {
|
|
639
|
+
const content = GOOD_OVERALL.replace(
|
|
640
|
+
"[P1-design](docs/kairos/specs/x-p1-design.md)",
|
|
641
|
+
"[P1-design](docs/kairos/specs/ghost-design.md)",
|
|
642
|
+
);
|
|
643
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
644
|
+
expect(withKind(findings, "sibling-scan")).toBe(true);
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
it("P9 T5 — #scanRoots composes the doc dir + doc roots on ONE basis (ctx.root)", () => {
|
|
648
|
+
// The scan roots resolve through the SAME `ctx.root` basis the rest of the
|
|
649
|
+
// judgment reads (never a bare relative string against process.cwd()): with a
|
|
650
|
+
// non-trivial root, the doc's own dir and BOTH declared doc roots join it.
|
|
651
|
+
const seen: string[] = [];
|
|
652
|
+
const fs: DocFs = {
|
|
653
|
+
exists: () => true,
|
|
654
|
+
read: () => null,
|
|
655
|
+
list: (dir) => {
|
|
656
|
+
seen.push(dir);
|
|
657
|
+
return dir.endsWith("/specs") || dir.endsWith("specs")
|
|
658
|
+
? ["x-overall.md", "x-p1-design.md", "x-p2-design.md"]
|
|
659
|
+
: ["x-p1.md", "x-p2.md"];
|
|
660
|
+
},
|
|
661
|
+
};
|
|
662
|
+
judge("overall-spec", GOOD_OVERALL, fs, undefined, "/abs/repo");
|
|
663
|
+
// Every scan root carries the root basis (`/abs/repo`) — the doc dir + both
|
|
664
|
+
// doc roots, never a bare relative against process.cwd().
|
|
665
|
+
expect(seen.every((dir) => dir.startsWith("/abs/repo/"))).toBe(true);
|
|
666
|
+
expect(seen.some((dir) => dir.endsWith("/docs/kairos/specs"))).toBe(true);
|
|
667
|
+
expect(seen.some((dir) => dir.endsWith("/docs/kairos/plans"))).toBe(true);
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
it("T6 — the spec link-text drift judgment retired: a spec reference carries zero cross-doc-chain findings", () => {
|
|
671
|
+
// The plan's spec reference is a HEAD scalar (the `spec:` key) — the link text
|
|
672
|
+
// face is gone, so no Class-A drift judgment can fire. The cross-doc-chain
|
|
673
|
+
// surface judges the chain FACTS (presence + lineage), never a textual match.
|
|
674
|
+
const content = [
|
|
675
|
+
"---",
|
|
676
|
+
"title: Test Plan",
|
|
677
|
+
"doc-type: plan",
|
|
678
|
+
"version: v1.0",
|
|
679
|
+
"date: 2026-10-09",
|
|
680
|
+
"spec: docs/kairos/specs/x-design.md",
|
|
681
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
682
|
+
"parent-version: v1.21",
|
|
683
|
+
"---",
|
|
684
|
+
"",
|
|
685
|
+
"## Constraints",
|
|
686
|
+
"",
|
|
687
|
+
"- delta",
|
|
688
|
+
"",
|
|
689
|
+
...planTask(1),
|
|
690
|
+
].join("\n");
|
|
691
|
+
const findings = judge("plan", content, EMPTY_FS);
|
|
692
|
+
expect(withKind(findings, "cross-doc-chain", "spec")).toBe(false);
|
|
693
|
+
expect(findings.filter((finding) => finding.kind === "cross-doc-chain")).toEqual([]);
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
it("cross-doc-chain: an unregistered dispatch phase is reported (face ④)", () => {
|
|
697
|
+
const findings = judge("overall-spec", GOOD_OVERALL, GOOD_OVERALL_FS, "P9");
|
|
698
|
+
expect(withKind(findings, "cross-doc-chain", "Phase inventory")).toBe(true);
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
it("section-scoped-domain: an issue ref outside the declared form is judged only in scope", () => {
|
|
702
|
+
const content = GOOD_OVERALL.replace(
|
|
703
|
+
"| P1 | #123 | issue one |",
|
|
704
|
+
"| P1 | prose ref | issue one |",
|
|
705
|
+
);
|
|
706
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
707
|
+
expect(withKind(findings, "section-scoped-domain", "Issue inventory")).toBe(true);
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
describe("the coordinator", () => {
|
|
712
|
+
it("aggregates findings from multiple strategies on one document", () => {
|
|
713
|
+
const content = GOOD_OVERALL.replace("status: Approved", "status: Deleted").replace(
|
|
714
|
+
"| P2 | none | issue two |",
|
|
715
|
+
"| P9 | prose | issue nine |",
|
|
716
|
+
);
|
|
717
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS, "P9");
|
|
718
|
+
expect(withKind(findings, "domain", "status")).toBe(true);
|
|
719
|
+
expect(withKind(findings, "crosslink", "Issue inventory")).toBe(true);
|
|
720
|
+
expect(withKind(findings, "section-scoped-domain", "Issue inventory")).toBe(true);
|
|
721
|
+
expect(withKind(findings, "presence", "Issue inventory")).toBe(false); // sections are present
|
|
722
|
+
expect(findings.length).toBeGreaterThanOrEqual(3);
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
// ---------------------------------------------------------------------------
|
|
727
|
+
// P4.1 T2 — the three-type homogeneity: `version:` required + strict (number · date) ·
|
|
728
|
+
// `## Change history` required ×3 · selfBounded ×3 (header = the newest in-row)
|
|
729
|
+
// ---------------------------------------------------------------------------
|
|
730
|
+
|
|
731
|
+
/** A minimal phase-spec carrying the canonical version lineage (a strict `version:`
|
|
732
|
+
* front-matter scalar + a Change-history table) — the T2 judgment surface. */
|
|
733
|
+
const specLineage = (headerVersion: string, rows: readonly string[]): string => {
|
|
734
|
+
return [
|
|
735
|
+
"---",
|
|
736
|
+
"title: Test Spec",
|
|
737
|
+
"doc-type: phase-spec",
|
|
738
|
+
`version: ${headerVersion}`,
|
|
739
|
+
"date: 2026-10-09",
|
|
740
|
+
"status: Draft",
|
|
741
|
+
"author: x",
|
|
742
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
743
|
+
"parent-version: v1.0",
|
|
744
|
+
"depends-on: P1",
|
|
745
|
+
"---",
|
|
746
|
+
"",
|
|
747
|
+
"## Design",
|
|
748
|
+
"",
|
|
749
|
+
"intro — the double-layer skeleton semantics.",
|
|
750
|
+
"",
|
|
751
|
+
"### 1. 数据面",
|
|
752
|
+
"#### 1.1 登记表",
|
|
753
|
+
"- text",
|
|
754
|
+
"",
|
|
755
|
+
"### Acceptance criteria",
|
|
756
|
+
"",
|
|
757
|
+
"- `c`",
|
|
758
|
+
"",
|
|
759
|
+
"## Constraints",
|
|
760
|
+
"",
|
|
761
|
+
"- delta",
|
|
762
|
+
"",
|
|
763
|
+
"## Change history",
|
|
764
|
+
"",
|
|
765
|
+
"| Version | date | summary | author |",
|
|
766
|
+
"|---|---|---|---|",
|
|
767
|
+
...rows,
|
|
768
|
+
].join("\n");
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
/** A minimal plan carrying the canonical version lineage. */
|
|
772
|
+
const planLineage = (headerVersion: string, rows: readonly string[]): string => {
|
|
773
|
+
return [
|
|
774
|
+
"---",
|
|
775
|
+
"title: Test Plan",
|
|
776
|
+
"doc-type: plan",
|
|
777
|
+
`version: ${headerVersion}`,
|
|
778
|
+
"date: 2026-10-09",
|
|
779
|
+
"spec: docs/kairos/specs/x-design.md",
|
|
780
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
781
|
+
"parent-version: v1.0",
|
|
782
|
+
"---",
|
|
783
|
+
"",
|
|
784
|
+
"## Constraints",
|
|
785
|
+
"",
|
|
786
|
+
"- delta",
|
|
787
|
+
"",
|
|
788
|
+
...planTask(1),
|
|
789
|
+
"",
|
|
790
|
+
"## Change history",
|
|
791
|
+
"",
|
|
792
|
+
"| Version | date | summary | author |",
|
|
793
|
+
"|---|---|---|---|",
|
|
794
|
+
...rows,
|
|
795
|
+
].join("\n");
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
const ROW_100 = "| v1.0 | 2026-10-08 | prior | [human] |";
|
|
799
|
+
const ROW_101 = "| v1.1 | 2026-10-09 | merged | [human] |";
|
|
800
|
+
|
|
801
|
+
describe("P4.1 T2 — `version:` presence required ×3 (plan optional → required)", () => {
|
|
802
|
+
it("a plan without the version front-matter key is reported", () => {
|
|
803
|
+
const content = planLineage("v1.0", [ROW_100]).replace("\nversion: v1.0", "");
|
|
804
|
+
const findings = judge("plan", content);
|
|
805
|
+
expect(withKind(findings, "presence", "version")).toBe(true);
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
it("a phase-spec without the version front-matter key is reported", () => {
|
|
809
|
+
const content = specLineage("v1.0", [ROW_100]).replace("\nversion: v1.0", "");
|
|
810
|
+
const findings = judge("phase-spec", content);
|
|
811
|
+
expect(withKind(findings, "presence", "version")).toBe(true);
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
it("an overall without the version front-matter key is reported (the requiredness holds)", () => {
|
|
815
|
+
const content = GOOD_OVERALL.replace("version: v1.21", "");
|
|
816
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
817
|
+
expect(withKind(findings, "presence", "version")).toBe(true);
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
describe("P4.1 T2 — the `version:` strict form (a bare `vX.Y` scalar · zero supplement/link/bold)", () => {
|
|
822
|
+
it("a trailing parenthetical supplement is refused (plan and spec)", () => {
|
|
823
|
+
for (const [docKey, doc] of [
|
|
824
|
+
["plan", planLineage("v1.0 (v1.0 补充)", [ROW_100])],
|
|
825
|
+
["phase-spec", specLineage("v1.0 (v1.0 补充)", [ROW_100])],
|
|
826
|
+
] as const) {
|
|
827
|
+
expect(withKind(judge(docKey, doc), "domain", "version")).toBe(true);
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
it("a trailing prose supplement after the date is refused (plan and spec)", () => {
|
|
832
|
+
for (const [docKey, doc] of [
|
|
833
|
+
["plan", planLineage("v1.0 · 2026-10-09 说明应在 Change history", [ROW_100])],
|
|
834
|
+
["phase-spec", specLineage("v1.0 · 2026-10-09 说明应在 Change history", [ROW_100])],
|
|
835
|
+
] as const) {
|
|
836
|
+
expect(withKind(judge(docKey, doc), "domain", "version")).toBe(true);
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
it("a bold **vX.Y** form is refused (plan and spec)", () => {
|
|
841
|
+
for (const [docKey, doc] of [
|
|
842
|
+
["plan", planLineage('"**v1.0** · 2026-10-09"', [ROW_100])],
|
|
843
|
+
["phase-spec", specLineage('"**v1.0** · 2026-10-09"', [ROW_100])],
|
|
844
|
+
] as const) {
|
|
845
|
+
expect(withKind(judge(docKey, doc), "domain", "version")).toBe(true);
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
it("the canonical bare `vX.Y` form carries no `version:` domain finding (plan and spec)", () => {
|
|
850
|
+
for (const docKey of ["plan", "phase-spec"] as const) {
|
|
851
|
+
const doc =
|
|
852
|
+
docKey === "plan" ? planLineage("v1.0", [ROW_100]) : specLineage("v1.0", [ROW_100]);
|
|
853
|
+
expect(withKind(judge(docKey, doc), "domain", "version")).toBe(false);
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
describe("P4.1 T2 — `## Change history` presence required ×3", () => {
|
|
859
|
+
it("a plan without the Change-history section is reported", () => {
|
|
860
|
+
const content = planLineage("v1.0", [ROW_100]).replace(
|
|
861
|
+
[
|
|
862
|
+
"## Change history",
|
|
863
|
+
"",
|
|
864
|
+
"| Version | date | summary | author |",
|
|
865
|
+
"|---|---|---|---|",
|
|
866
|
+
ROW_100,
|
|
867
|
+
].join("\n"),
|
|
868
|
+
"",
|
|
869
|
+
);
|
|
870
|
+
const findings = judge("plan", content);
|
|
871
|
+
expect(withKind(findings, "presence", "## Change history")).toBe(true);
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
it("a phase-spec without the Change-history section is reported", () => {
|
|
875
|
+
const content = specLineage("v1.0", [ROW_100]).replace(
|
|
876
|
+
[
|
|
877
|
+
"## Change history",
|
|
878
|
+
"",
|
|
879
|
+
"| Version | date | summary | author |",
|
|
880
|
+
"|---|---|---|---|",
|
|
881
|
+
ROW_100,
|
|
882
|
+
].join("\n"),
|
|
883
|
+
"",
|
|
884
|
+
);
|
|
885
|
+
const findings = judge("phase-spec", content);
|
|
886
|
+
expect(withKind(findings, "presence", "## Change history")).toBe(true);
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
it("an overall without the Change-history section is reported (the requiredness holds)", () => {
|
|
890
|
+
const content = GOOD_OVERALL.replace(
|
|
891
|
+
[
|
|
892
|
+
"## Change history",
|
|
893
|
+
"| Version | Date | Summary |",
|
|
894
|
+
"| --- | --- | --- |",
|
|
895
|
+
"| v1.20 | 2026-10-06 | prior change |",
|
|
896
|
+
"| v1.21 | 2026-10-07 | merged change |",
|
|
897
|
+
].join("\n"),
|
|
898
|
+
"",
|
|
899
|
+
);
|
|
900
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
901
|
+
expect(withKind(findings, "presence", "## Change history")).toBe(true);
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
it("a phase-spec whose parent-program is a markdown link reports the shape rule ONCE — never the resolution cascade (D2 · #342)", () => {
|
|
905
|
+
const content = specLineage("v1.0", [ROW_100]).replace(
|
|
906
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
907
|
+
'parent-program: "[2026-10-02-x-overall.md](docs/kairos/specs/2026-10-02-x-overall.md)"',
|
|
908
|
+
);
|
|
909
|
+
const findings = judge("phase-spec", content);
|
|
910
|
+
// exactly the single link-shape finding — the malformed target is judged
|
|
911
|
+
// BEFORE resolution, so the file-existence dead-tail and the sibling-scan
|
|
912
|
+
// basename cascade never fire on top of it
|
|
913
|
+
expect(findings).toHaveLength(1);
|
|
914
|
+
expect(findings[0].kind).toBe("link-shape");
|
|
915
|
+
expect(findings[0].field).toBe("parent-program");
|
|
916
|
+
expect(findings[0].message).toContain("not a bare relative path");
|
|
917
|
+
});
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
describe("P4.1 T2 — selfBounded applies to spec/plan (header = the newest in-row)", () => {
|
|
921
|
+
it("a phase-spec whose header is NOT the change-history's newest row is reported", () => {
|
|
922
|
+
const findings = judge("phase-spec", specLineage("v1.0", [ROW_100, ROW_101]));
|
|
923
|
+
expect(withKind(findings, "selfBounded", "version")).toBe(true);
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
it("a plan whose header is OUTSIDE the lineage is reported", () => {
|
|
927
|
+
const findings = judge("plan", planLineage("v1.2", [ROW_100, ROW_101]));
|
|
928
|
+
expect(withKind(findings, "selfBounded", "version")).toBe(true);
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
it("a spec/plan whose header IS the newest in-row version carries no selfBounded finding", () => {
|
|
932
|
+
for (const docKey of ["plan", "phase-spec"] as const) {
|
|
933
|
+
const doc =
|
|
934
|
+
docKey === "plan"
|
|
935
|
+
? planLineage("v1.1", [ROW_100, ROW_101])
|
|
936
|
+
: specLineage("v1.1", [ROW_100, ROW_101]);
|
|
937
|
+
expect(withKind(judge(docKey, doc), "selfBounded", "version")).toBe(false);
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
describe("governance greps (the engine-zero criterion)", () => {
|
|
943
|
+
it("dispatches judgment without any switch-case (grep)", () => {
|
|
944
|
+
for (const name of ["judge.ts", "invariants.ts", "doc.ts"]) {
|
|
945
|
+
const source = readFileSync(new URL(`../${name}`, import.meta.url), "utf8");
|
|
946
|
+
expect(source.match(/\bswitch\s*\(/), name).toBeNull();
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
it("exports zero behavior-carrying bare functions from judge/invariants (grep)", () => {
|
|
951
|
+
for (const name of ["judge.ts", "invariants.ts"]) {
|
|
952
|
+
const source = readFileSync(new URL(`../${name}`, import.meta.url), "utf8");
|
|
953
|
+
const functionExports = source.match(/export\s+(?:async\s+)?function\s+\w+/g) ?? [];
|
|
954
|
+
expect(functionExports, name).toEqual([]);
|
|
955
|
+
const behaviorConstExports =
|
|
956
|
+
source.match(/export\s+const\s+\w+\s*=\s*(?:\([^)]*\)|[\w]+)\s*=>/g) ?? [];
|
|
957
|
+
expect(behaviorConstExports, name).toEqual([]);
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
describe("P10 W7 T11 — the migration judgment-regression pins (spec §6 · §5.2)", () => {
|
|
963
|
+
/** A minimal plan carrying a caller-chosen `parent-version:` scalar (the
|
|
964
|
+
* Class-B chain carrier under test). */
|
|
965
|
+
const planWithParentVersion = (parentVersion: string): string =>
|
|
966
|
+
[
|
|
967
|
+
"---",
|
|
968
|
+
"title: Test Plan",
|
|
969
|
+
"doc-type: plan",
|
|
970
|
+
"version: v1.0",
|
|
971
|
+
"date: 2026-10-09",
|
|
972
|
+
"spec: docs/kairos/specs/x-design.md",
|
|
973
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
974
|
+
`parent-version: ${parentVersion}`,
|
|
975
|
+
"---",
|
|
976
|
+
"",
|
|
977
|
+
"## Constraints",
|
|
978
|
+
"",
|
|
979
|
+
"- delta",
|
|
980
|
+
"",
|
|
981
|
+
...planTask(1),
|
|
982
|
+
].join("\n");
|
|
983
|
+
|
|
984
|
+
it("version lineage — a head version OUTSIDE the Change-history lineage still fires selfBounded", () => {
|
|
985
|
+
// The T6 read flip made the version a head scalar — a version the Change-history
|
|
986
|
+
// table never carries must STILL be reported (no false-green from a body scan
|
|
987
|
+
// that can no longer see the head).
|
|
988
|
+
const overall = judge(
|
|
989
|
+
"overall-spec",
|
|
990
|
+
GOOD_OVERALL.replace("version: v1.21", "version: v9.9"),
|
|
991
|
+
GOOD_OVERALL_FS,
|
|
992
|
+
);
|
|
993
|
+
expect(withKind(overall, "selfBounded", "version")).toBe(true);
|
|
994
|
+
const plan = judge("plan", planLineage("v9.9", [ROW_100, ROW_101]));
|
|
995
|
+
expect(withKind(plan, "selfBounded", "version")).toBe(true);
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
it("parent lineage — a parent-version outside the parent overall's lineage fires classB through the chainDocs seam", () => {
|
|
999
|
+
const { head, body } = FrontMatterExtractor.split(GOOD_OVERALL);
|
|
1000
|
+
const parentParsed = new OverallDocType("overall-spec").parse(body.split("\n"), head);
|
|
1001
|
+
const plan = planWithParentVersion("v7.7");
|
|
1002
|
+
// The production seam is not wired in this phase — without chainDocs the
|
|
1003
|
+
// Class-B chain resolves nowhere and stays silent (the preflight call point
|
|
1004
|
+
// does not pass the map).
|
|
1005
|
+
expect(withKind(judge("plan", plan), "cross-doc-chain", "parent-program")).toBe(false);
|
|
1006
|
+
const findings = new Contract().validate({
|
|
1007
|
+
docKey: "plan",
|
|
1008
|
+
path: PLAN_PATH,
|
|
1009
|
+
content: plan,
|
|
1010
|
+
root: ".",
|
|
1011
|
+
chainDocs: new Map<string, ParsedDoc>([["docs/kairos/specs/x-overall.md", parentParsed]]),
|
|
1012
|
+
});
|
|
1013
|
+
// The parentTokens carrier is non-empty (`v7.7` rides the parent-version key)
|
|
1014
|
+
// and the parent lineage is {v1.20, v1.21} — the classB early return is not
|
|
1015
|
+
// the reason this fires; the token is genuinely outside the lineage.
|
|
1016
|
+
expect(withKind(findings, "cross-doc-chain", "parent-program")).toBe(true);
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
it("presence — a doc missing the status key reports exactly one presence finding (typed head, not a line scan)", () => {
|
|
1020
|
+
const presence = judge(
|
|
1021
|
+
"phase-spec",
|
|
1022
|
+
specLineage("v1.1", [ROW_100, ROW_101]).replace("\nstatus: Draft", ""),
|
|
1023
|
+
).filter((finding) => finding.kind === "presence");
|
|
1024
|
+
expect(presence).toHaveLength(1);
|
|
1025
|
+
expect(presence[0]!.field).toBe("status");
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
it("domain — a status outside the declared enum reports exactly one domain finding", () => {
|
|
1029
|
+
const domain = judge(
|
|
1030
|
+
"phase-spec",
|
|
1031
|
+
specLineage("v1.1", [ROW_100, ROW_101]).replace("status: Draft", "status: Bogus"),
|
|
1032
|
+
).filter((finding) => finding.kind === "domain");
|
|
1033
|
+
expect(domain).toHaveLength(1);
|
|
1034
|
+
expect(domain[0]!.field).toBe("status");
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
it("RAW — the head value extracts verbatim while the body still canonicalizes (both sides of the same doc)", () => {
|
|
1038
|
+
const content = GOOD_OVERALL.replace("title: 测试 Overall", "title: 任务组总体").replace(
|
|
1039
|
+
"### Goal\n- goal text",
|
|
1040
|
+
"### Goal\n- goal text\n\n#### M 组(skill-ref 映射,M1–M4 全关)\n- m leaf",
|
|
1041
|
+
);
|
|
1042
|
+
// The head channel reads the RAW content — the registered zh alias 组 rides
|
|
1043
|
+
// the title verbatim, never the canonicalize view.
|
|
1044
|
+
const { head } = FrontMatterExtractor.split(content);
|
|
1045
|
+
expect(head.value("title")).toBe("任务组总体");
|
|
1046
|
+
// The body channel canonicalizes in the SAME validate call — the zh 组 leaf
|
|
1047
|
+
// conforms to the `#### [MFRBEN] group` facet only through the view.
|
|
1048
|
+
const findings = judge("overall-spec", content, GOOD_OVERALL_FS);
|
|
1049
|
+
expect(withKind(findings, "presence", "#### [MFRBEN] group")).toBe(false);
|
|
1050
|
+
expect(withKind(findings, "domain", "#### [MFRBEN] group")).toBe(false);
|
|
1051
|
+
// The exact body-line face — the same Translator seam validate applies to
|
|
1052
|
+
// every body row (the canonicalize target of the registered 组 alias).
|
|
1053
|
+
expect(new Translator(new Words()).canonicalize("TaskGraph 分组派生")).toBe(
|
|
1054
|
+
"TaskGraph 分group派生",
|
|
1055
|
+
);
|
|
1056
|
+
});
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
/** A conforming phase-spec — the front-matter head + the double-layer design
|
|
1060
|
+
* skeleton + the Change-history lineage (the shared phase-spec fixture family). */
|
|
1061
|
+
const phaseSpec = (version: string): string => {
|
|
1062
|
+
return [
|
|
1063
|
+
"---",
|
|
1064
|
+
"title: Test Spec",
|
|
1065
|
+
"doc-type: phase-spec",
|
|
1066
|
+
`version: ${version}`,
|
|
1067
|
+
"date: 2026-10-09",
|
|
1068
|
+
"status: Draft",
|
|
1069
|
+
"author: x",
|
|
1070
|
+
"parent-program: docs/kairos/specs/x-overall.md",
|
|
1071
|
+
"parent-version: v1.0",
|
|
1072
|
+
"depends-on: P1",
|
|
1073
|
+
"---",
|
|
1074
|
+
"",
|
|
1075
|
+
"## Design",
|
|
1076
|
+
"",
|
|
1077
|
+
"### 1. 数据面",
|
|
1078
|
+
"#### 1.1 登记表",
|
|
1079
|
+
"- text",
|
|
1080
|
+
"",
|
|
1081
|
+
"### Acceptance criteria",
|
|
1082
|
+
"",
|
|
1083
|
+
"- `c`",
|
|
1084
|
+
"",
|
|
1085
|
+
"## Constraints",
|
|
1086
|
+
"",
|
|
1087
|
+
"- delta",
|
|
1088
|
+
"",
|
|
1089
|
+
"## Change history",
|
|
1090
|
+
"",
|
|
1091
|
+
"| Version | date | summary | author |",
|
|
1092
|
+
"|---|---|---|---|",
|
|
1093
|
+
"| v1.0 | 2026-10-08 | prior | [human] |",
|
|
1094
|
+
"| v1.1 | 2026-10-09 | merged | [human] |",
|
|
1095
|
+
].join("\n");
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
/** One rendered `### Task N:` block with all required fields. */
|
|
1099
|
+
const planTask = (id: number): string[] => {
|
|
1100
|
+
return [
|
|
1101
|
+
`### Task ${id}: task`,
|
|
1102
|
+
`- **Objective**: objective`,
|
|
1103
|
+
`- **Files**: file`,
|
|
1104
|
+
`- **Consumes**: consumes`,
|
|
1105
|
+
`- **Produces**: produces`,
|
|
1106
|
+
`- **Steps**:`,
|
|
1107
|
+
` - step one`,
|
|
1108
|
+
`- **Acceptance**: acceptance`,
|
|
1109
|
+
`- **DependsOn**: none`,
|
|
1110
|
+
];
|
|
1111
|
+
};
|