@oscaner-skills/cdd-engine 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src-next/bin.ts → dist/bin.js} +18 -21
- package/dist/contract/declare.js +998 -0
- package/dist/contract/doc.js +565 -0
- package/dist/contract/frontmatter.js +209 -0
- package/dist/contract/home-extractors.js +379 -0
- package/dist/contract/invariants.js +1030 -0
- package/dist/contract/judge.js +109 -0
- package/dist/contract/lint.js +206 -0
- package/dist/contract/project.js +371 -0
- package/dist/contract/skill-anatomy.js +156 -0
- package/dist/contract/translate.js +85 -0
- package/dist/face/artifacts.js +189 -0
- package/dist/face/board-view.js +522 -0
- package/dist/face/capsule.js +141 -0
- package/dist/face/cli.js +891 -0
- package/dist/face/declare.js +241 -0
- package/dist/face/gate.js +158 -0
- package/dist/face/graph-view.js +66 -0
- package/dist/face/host.js +211 -0
- package/dist/face/lifecycle.js +603 -0
- package/dist/face/preview.js +136 -0
- package/dist/face/projection.js +259 -0
- package/dist/face/route-render.js +162 -0
- package/dist/face/termination.js +482 -0
- package/dist/face/words.js +220 -0
- package/{src-next/infra/config.ts → dist/infra/config.js} +19 -24
- package/{src-next/infra/doc-roots.ts → dist/infra/doc-roots.js} +3 -13
- package/dist/infra/git.js +37 -0
- package/dist/infra/process.js +22 -0
- package/{src-next/infra/root.ts → dist/infra/root.js} +25 -36
- package/dist/infra/runtime.js +85 -0
- package/dist/infra/workspace.js +276 -0
- package/dist/render/brief.js +82 -0
- package/dist/render/issue-body.js +129 -0
- package/dist/render/skeleton.js +434 -0
- package/dist/render/templates.js +520 -0
- package/dist/session/faces.js +38 -0
- package/dist/session/graph.js +309 -0
- package/dist/session/handoff-schema.js +295 -0
- package/dist/session/ledger.js +762 -0
- package/dist/session/next.js +211 -0
- package/dist/session/preflight.js +194 -0
- package/dist/session/round-naming.js +73 -0
- package/dist/session/run.js +441 -0
- package/dist/session/state.js +8 -0
- package/dist/session/wave.js +92 -0
- package/package.json +5 -5
- package/src-next/__tests__/bin.test.ts +0 -128
- package/src-next/__tests__/dead-decl.guard.test.ts +0 -39
- package/src-next/__tests__/floor.guard.test.ts +0 -69
- package/src-next/__tests__/issue-body.guard.test.ts +0 -66
- package/src-next/__tests__/phase-suffix.guard.test.ts +0 -72
- package/src-next/__tests__/smoke.integration.test.ts +0 -185
- package/src-next/__tests__/support/strip-comments.ts +0 -99
- package/src-next/__tests__/zero-dep.test.ts +0 -94
- package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +0 -256
- package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +0 -165
- package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +0 -190
- package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +0 -106
- package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +0 -240
- package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +0 -165
- package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +0 -190
- package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +0 -100
- package/src-next/contract/__tests__/declare.test.ts +0 -481
- package/src-next/contract/__tests__/doc.test.ts +0 -527
- package/src-next/contract/__tests__/dockey.guard.test.ts +0 -58
- package/src-next/contract/__tests__/edge-conditions.guard.test.ts +0 -81
- package/src-next/contract/__tests__/frontmatter.test.ts +0 -164
- package/src-next/contract/__tests__/judge.test.ts +0 -1111
- package/src-next/contract/__tests__/lint.test.ts +0 -324
- package/src-next/contract/__tests__/project.test.ts +0 -460
- package/src-next/contract/__tests__/structure-pin.test.ts +0 -186
- package/src-next/contract/__tests__/translate.test.ts +0 -96
- package/src-next/contract/declare.ts +0 -1071
- package/src-next/contract/doc.ts +0 -816
- package/src-next/contract/frontmatter.ts +0 -233
- package/src-next/contract/home-extractors.ts +0 -397
- package/src-next/contract/invariants.ts +0 -1413
- package/src-next/contract/judge.ts +0 -151
- package/src-next/contract/lint.ts +0 -239
- package/src-next/contract/project.ts +0 -656
- package/src-next/contract/skill-anatomy.ts +0 -301
- package/src-next/contract/translate.ts +0 -113
- package/src-next/face/__tests__/board-view.test.ts +0 -1151
- package/src-next/face/__tests__/capsule.test.ts +0 -300
- package/src-next/face/__tests__/channel-closure.guard.test.ts +0 -129
- package/src-next/face/__tests__/cli.test.ts +0 -4897
- package/src-next/face/__tests__/face.test.ts +0 -289
- package/src-next/face/__tests__/graph-view.test.ts +0 -61
- package/src-next/face/__tests__/host.test.ts +0 -24
- package/src-next/face/__tests__/install-rows.guard.test.ts +0 -58
- package/src-next/face/__tests__/negation.ts +0 -6
- package/src-next/face/__tests__/preview.test.ts +0 -374
- package/src-next/face/__tests__/projection.test.ts +0 -303
- package/src-next/face/__tests__/repo-root.guard.test.ts +0 -120
- package/src-next/face/__tests__/termination.test.ts +0 -650
- package/src-next/face/__tests__/words.guard.test.ts +0 -93
- package/src-next/face/artifacts.ts +0 -248
- package/src-next/face/board-view.ts +0 -652
- package/src-next/face/capsule.ts +0 -163
- package/src-next/face/cli.ts +0 -1028
- package/src-next/face/declare.ts +0 -323
- package/src-next/face/gate.ts +0 -171
- package/src-next/face/graph-view.ts +0 -74
- package/src-next/face/host.ts +0 -302
- package/src-next/face/lifecycle.ts +0 -725
- package/src-next/face/preview.ts +0 -151
- package/src-next/face/projection.ts +0 -285
- package/src-next/face/route-render.ts +0 -185
- package/src-next/face/termination.ts +0 -573
- package/src-next/face/words.ts +0 -314
- package/src-next/infra/__tests__/infra.test.ts +0 -333
- package/src-next/infra/__tests__/root.test.ts +0 -56
- package/src-next/infra/git.ts +0 -39
- package/src-next/infra/process.ts +0 -34
- package/src-next/infra/runtime.ts +0 -132
- package/src-next/infra/workspace.ts +0 -322
- package/src-next/render/__tests__/render.test.ts +0 -550
- package/src-next/render/__tests__/skeleton.test.ts +0 -684
- package/src-next/render/brief.ts +0 -121
- package/src-next/render/issue-body.ts +0 -162
- package/src-next/render/skeleton.ts +0 -502
- package/src-next/render/templates.ts +0 -645
- package/src-next/session/__tests__/graph.test.ts +0 -277
- package/src-next/session/__tests__/handoff-plane.guard.test.ts +0 -48
- package/src-next/session/__tests__/handoff-schema.test.ts +0 -310
- package/src-next/session/__tests__/ledger.test.ts +0 -745
- package/src-next/session/__tests__/next.test.ts +0 -460
- package/src-next/session/__tests__/preflight.test.ts +0 -545
- package/src-next/session/__tests__/round-naming.test.ts +0 -142
- package/src-next/session/__tests__/run.test.ts +0 -1026
- package/src-next/session/__tests__/wave-line-phase.guard.test.ts +0 -49
- package/src-next/session/__tests__/wave.test.ts +0 -476
- package/src-next/session/faces.ts +0 -110
- package/src-next/session/graph.ts +0 -411
- package/src-next/session/handoff-schema.ts +0 -373
- package/src-next/session/ledger.ts +0 -1076
- package/src-next/session/next.ts +0 -293
- package/src-next/session/preflight.ts +0 -271
- package/src-next/session/round-naming.ts +0 -84
- package/src-next/session/run.ts +0 -610
- package/src-next/session/state.ts +0 -30
- package/src-next/session/wave.ts +0 -139
|
@@ -1,527 +0,0 @@
|
|
|
1
|
-
// packages/cdd-engine/src-next/contract/__tests__/doc.test.ts
|
|
2
|
-
// T4 parse-layer suite (contract/doc.ts) — the brief's positive checkables:
|
|
3
|
-
// · the four tables of the overall parse as header + data rows;
|
|
4
|
-
// · the plan's `### Task N:` blocks parse into fields + steps;
|
|
5
|
-
// · the phase-spec's `## Design` double-layer skeleton parses into groups + items;
|
|
6
|
-
// · the cross-doc chain root parses the Class-A/B head scalars verbatim (unresolved);
|
|
7
|
-
// · the DocType class face carries zero judgment methods (spec §2.2 — the machine
|
|
8
|
-
// assertion surface: extract-only classes).
|
|
9
|
-
// Since T6 the fixtures carry the front-matter head (the §2.2 delivery seam's
|
|
10
|
-
// canonical document form) and every parse runs dual-param — the title face is the
|
|
11
|
-
// head scalar, never the `---` fence line the split consumed, and the chain root
|
|
12
|
-
// reads the head scalars (the `{ target }`-only ChainLink face).
|
|
13
|
-
// The parse records and known-good document literals are the independent sources of
|
|
14
|
-
// truth — every assertion compares against the fixture doc the parser must extract.
|
|
15
|
-
|
|
16
|
-
import { readFileSync } from "node:fs";
|
|
17
|
-
import { describe, expect, it } from "vitest";
|
|
18
|
-
import { SkeletonAssembler } from "../../render/skeleton.ts";
|
|
19
|
-
import { declaredRegistries } from "../declare.ts";
|
|
20
|
-
import type { DocType, ParsedDoc } from "../doc.ts";
|
|
21
|
-
import { docTypeParsers, OverallDocType, PhaseSpecDocType, PlanDocType } from "../doc.ts";
|
|
22
|
-
import { FrontMatterExtractor } from "../frontmatter.ts";
|
|
23
|
-
import {
|
|
24
|
-
DesignBodyExtractor,
|
|
25
|
-
GraphExtractor,
|
|
26
|
-
HeadingScanner,
|
|
27
|
-
TableExtractor,
|
|
28
|
-
TaskExtractor,
|
|
29
|
-
} from "../home-extractors.ts";
|
|
30
|
-
import { Contract } from "../judge.ts";
|
|
31
|
-
import type { DocKey } from "../project.ts";
|
|
32
|
-
import { Projector } from "../project.ts";
|
|
33
|
-
|
|
34
|
-
/** A conforming overall — the front-matter head, the four tables and the graph. */
|
|
35
|
-
const OVERALL = [
|
|
36
|
-
"---",
|
|
37
|
-
"title: 文档架构方法论 v2 — 测试 Overall",
|
|
38
|
-
"doc-type: overall-spec",
|
|
39
|
-
"version: v1.1",
|
|
40
|
-
"date: 2026-10-07",
|
|
41
|
-
"status: Approved",
|
|
42
|
-
'author: "[human]"',
|
|
43
|
-
"---",
|
|
44
|
-
"",
|
|
45
|
-
"## Document scope",
|
|
46
|
-
"scope prose",
|
|
47
|
-
"",
|
|
48
|
-
"## File paths",
|
|
49
|
-
"| Artifact | Path |",
|
|
50
|
-
"| --- | --- |",
|
|
51
|
-
"| overall-spec | docs/kairos/specs/test-overall.md |",
|
|
52
|
-
"",
|
|
53
|
-
"## Program charter",
|
|
54
|
-
"### Goal",
|
|
55
|
-
"- goal text",
|
|
56
|
-
"",
|
|
57
|
-
"### Non-goals",
|
|
58
|
-
"- non-goal text",
|
|
59
|
-
"",
|
|
60
|
-
"### Cross-cutting",
|
|
61
|
-
"- cross text",
|
|
62
|
-
"",
|
|
63
|
-
"## Issue inventory",
|
|
64
|
-
"| Phase | Issue (ref) | Title summary |",
|
|
65
|
-
"| --- | --- | --- |",
|
|
66
|
-
"| P1 | #123 | issue one |",
|
|
67
|
-
"| P2 | none | issue two |",
|
|
68
|
-
"",
|
|
69
|
-
"## Phase inventory",
|
|
70
|
-
"| # | Phase | Scope | Design spec | Implementation plan | Acceptance criteria | Dependency |",
|
|
71
|
-
"| --- | --- | --- | --- | --- | --- | --- |",
|
|
72
|
-
"| P1 | DocType 抽象 + schema 工厂 | scope a | [P1-design](docs/kairos/specs/x-p1-design.md) | [P1 plan](docs/kairos/plans/x-p1.md) | criteria a | |",
|
|
73
|
-
"| P2 | 判定面 + 协调器 | scope b | P2-design | [P2 plan](docs/kairos/plans/x-p2.md) | criteria b | |",
|
|
74
|
-
"",
|
|
75
|
-
"## Dependency graph (ASCII)",
|
|
76
|
-
"P1 -> P2",
|
|
77
|
-
"-> = hard block",
|
|
78
|
-
"",
|
|
79
|
-
"## Boundary rules",
|
|
80
|
-
"- boundary rule",
|
|
81
|
-
"",
|
|
82
|
-
"## Maintenance",
|
|
83
|
-
"- maintenance note",
|
|
84
|
-
"",
|
|
85
|
-
"## Change history",
|
|
86
|
-
"| Version | Date | Summary |",
|
|
87
|
-
"| --- | --- | --- |",
|
|
88
|
-
"| v1.20 | 2026-10-06 | prior change |",
|
|
89
|
-
"| v1.21 | 2026-10-07 | merged change |",
|
|
90
|
-
];
|
|
91
|
-
|
|
92
|
-
/** A conforming plan — the front-matter head (Class-A/B chain scalars) + the `### Task N:` blocks. */
|
|
93
|
-
const PLAN = [
|
|
94
|
-
"---",
|
|
95
|
-
"title: 文档架构方法论 v2 — 测试 Plan",
|
|
96
|
-
"doc-type: plan",
|
|
97
|
-
"version: v1.1",
|
|
98
|
-
"date: 2026-10-07",
|
|
99
|
-
"spec: docs/kairos/specs/x-design.md",
|
|
100
|
-
"parent-program: docs/kairos/specs/x-overall.md",
|
|
101
|
-
"parent-version: v1.21",
|
|
102
|
-
"depends-on: P1 design v1.1",
|
|
103
|
-
"base: develop",
|
|
104
|
-
"---",
|
|
105
|
-
"",
|
|
106
|
-
"## Constraints",
|
|
107
|
-
"",
|
|
108
|
-
"- delta constraint",
|
|
109
|
-
"",
|
|
110
|
-
"### Task 1: skeleton",
|
|
111
|
-
"- **Objective**: establish the skeleton",
|
|
112
|
-
"- **Files**: src-next/ | tsconfig.json",
|
|
113
|
-
"- **Consumes**: none",
|
|
114
|
-
"- **Produces**: skeleton",
|
|
115
|
-
"- **Steps**:",
|
|
116
|
-
" - step one",
|
|
117
|
-
" - step two — checkable: second step check",
|
|
118
|
-
"- **Acceptance**: skeleton green",
|
|
119
|
-
"- **DependsOn**: none",
|
|
120
|
-
"",
|
|
121
|
-
"### Task 2: registry",
|
|
122
|
-
"- **Objective**: declare the registries",
|
|
123
|
-
"- **Files**: src-next/contract/declare.ts",
|
|
124
|
-
"- **Consumes**: T1 skeleton",
|
|
125
|
-
"- **Produces**: registry data",
|
|
126
|
-
"- **Steps**:",
|
|
127
|
-
" - write the registry — checkable: types compile",
|
|
128
|
-
"- **Acceptance**: registry green",
|
|
129
|
-
"- **DependsOn**: 1",
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
/** A conforming phase-spec — the front-matter head (the five-tuple scalars) + the design skeleton. */
|
|
133
|
-
const PHASE_SPEC = [
|
|
134
|
-
"---",
|
|
135
|
-
"title: 文档架构方法论 v2 — 测试 Design Spec",
|
|
136
|
-
"doc-type: phase-spec",
|
|
137
|
-
"version: v1.2",
|
|
138
|
-
"date: 2026-10-07",
|
|
139
|
-
"status: Draft",
|
|
140
|
-
'author: "[human]"',
|
|
141
|
-
"parent-program: docs/kairos/specs/x-overall.md",
|
|
142
|
-
"parent-version: v1.21",
|
|
143
|
-
"depends-on: P1(Done)",
|
|
144
|
-
"---",
|
|
145
|
-
"",
|
|
146
|
-
"## Design",
|
|
147
|
-
"",
|
|
148
|
-
"### 1. 判定面",
|
|
149
|
-
"#### 1.1 策略类族",
|
|
150
|
-
"- 判定多态",
|
|
151
|
-
"",
|
|
152
|
-
"### 2. 编排面",
|
|
153
|
-
"#### 2.1 波次",
|
|
154
|
-
"- 波次计算",
|
|
155
|
-
"",
|
|
156
|
-
"### Acceptance criteria",
|
|
157
|
-
"",
|
|
158
|
-
"- `acceptance entry`",
|
|
159
|
-
"",
|
|
160
|
-
"## Constraints",
|
|
161
|
-
"",
|
|
162
|
-
"- delta constraint",
|
|
163
|
-
"",
|
|
164
|
-
"## Review record",
|
|
165
|
-
"- review note",
|
|
166
|
-
];
|
|
167
|
-
|
|
168
|
-
/** Parse a known-good literal with its front-matter head — the §2.2 delivery seam
|
|
169
|
-
* the judge's chain-docs producers use (RAW content → fence split → dual-param parse). */
|
|
170
|
-
const parseWithHead = <P extends ParsedDoc>(parser: DocType<P>, doc: readonly string[]): P => {
|
|
171
|
-
const split = FrontMatterExtractor.split(doc.join("\n"));
|
|
172
|
-
return parser.parse(FrontMatterExtractor.lineSplit(split.body), split.head);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
describe("OverallDocType.parse — the four tables + the chain root", () => {
|
|
176
|
-
const parsed = parseWithHead(new OverallDocType("overall-spec"), OVERALL);
|
|
177
|
-
|
|
178
|
-
it("parses the front-matter head and the section skeleton", () => {
|
|
179
|
-
expect(parsed.docType).toBe("overall-spec");
|
|
180
|
-
// the title face is the head scalar — never the `---` fence line
|
|
181
|
-
expect(parsed.title).toBe("文档架构方法论 v2 — 测试 Overall");
|
|
182
|
-
expect(parsed.title).not.toBe("---");
|
|
183
|
-
expect(parsed.head?.docType).toBe("overall-spec");
|
|
184
|
-
expect(parsed.head?.version).toBe("v1.1");
|
|
185
|
-
expect(parsed.head?.status).toBe("Approved");
|
|
186
|
-
expect(parsed.sections.map((section) => section.heading)).toEqual([
|
|
187
|
-
"## Document scope",
|
|
188
|
-
"## File paths",
|
|
189
|
-
"## Program charter",
|
|
190
|
-
"## Issue inventory",
|
|
191
|
-
"## Phase inventory",
|
|
192
|
-
"## Dependency graph (ASCII)",
|
|
193
|
-
"## Boundary rules",
|
|
194
|
-
"## Maintenance",
|
|
195
|
-
"## Change history",
|
|
196
|
-
]);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it("parses the File-paths table into a header row + data rows", () => {
|
|
200
|
-
const table = parsed.tables["File paths"];
|
|
201
|
-
expect(table.headerRow).toEqual(["Artifact", "Path"]);
|
|
202
|
-
expect(table.rows).toEqual([["overall-spec", "docs/kairos/specs/test-overall.md"]]);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("parses the Issue-inventory table rows", () => {
|
|
206
|
-
const table = parsed.tables["Issue inventory"];
|
|
207
|
-
expect(table.headerRow).toEqual(["Phase", "Issue (ref)", "Title summary"]);
|
|
208
|
-
expect(table.rows).toEqual([
|
|
209
|
-
["P1", "#123", "issue one"],
|
|
210
|
-
["P2", "none", "issue two"],
|
|
211
|
-
]);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("parses the Phase-inventory table (id from the canonical first-column cell -> chain phases)", () => {
|
|
215
|
-
const table = parsed.tables["Phase inventory"];
|
|
216
|
-
expect(table.rows).toHaveLength(2);
|
|
217
|
-
expect(parsed.chain.phases.map((phase) => phase.id)).toEqual(["P1", "P2"]);
|
|
218
|
-
expect(parsed.chain.phases[0].designCell).toBe("[P1-design](docs/kairos/specs/x-p1-design.md)");
|
|
219
|
-
expect(parsed.chain.phases[0].planCell).toBe("[P1 plan](docs/kairos/plans/x-p1.md)");
|
|
220
|
-
// a tokenized (non-linked) design cell is carried verbatim, never judged here.
|
|
221
|
-
expect(parsed.chain.phases[1].designCell).toBe("P2-design");
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("parses the Change-history rows with their version tokens", () => {
|
|
225
|
-
const table = parsed.tables["Change history"];
|
|
226
|
-
expect(table.rows.map((row) => row[0])).toEqual(["v1.20", "v1.21"]);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it("parses the dependency-graph edge lines into from/to tokens", () => {
|
|
230
|
-
expect(parsed.graphEdges).toEqual([{ text: "P1 -> P2", from: "P1", to: "P2" }]);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it("parses the chain root — the overall is the root (no parent/spec links)", () => {
|
|
234
|
-
expect(parsed.chain.docType).toBe("overall-spec");
|
|
235
|
-
expect(parsed.chain.parentLink).toBeNull();
|
|
236
|
-
expect(parsed.chain.specLink).toBeNull();
|
|
237
|
-
expect(parsed.chain.parentTokens).toEqual([]);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
describe("PlanDocType.parse — the task blocks + the Class-A/B chain root", () => {
|
|
242
|
-
const parsed = parseWithHead(new PlanDocType("plan"), PLAN);
|
|
243
|
-
|
|
244
|
-
it("parses the front-matter head and the section skeleton", () => {
|
|
245
|
-
expect(parsed.docType).toBe("plan");
|
|
246
|
-
// the title face is the head scalar — never the `---` fence line
|
|
247
|
-
expect(parsed.title).toBe("文档架构方法论 v2 — 测试 Plan");
|
|
248
|
-
expect(parsed.title).not.toBe("---");
|
|
249
|
-
expect(parsed.head?.spec).toBe("docs/kairos/specs/x-design.md");
|
|
250
|
-
expect(parsed.head?.parentProgram).toBe("docs/kairos/specs/x-overall.md");
|
|
251
|
-
expect(parsed.head?.parentVersion).toBe("v1.21");
|
|
252
|
-
expect(parsed.head?.dependsOn).toBe("P1 design v1.1");
|
|
253
|
-
expect(parsed.sections.map((section) => section.heading)).toEqual(["## Constraints"]);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it("parses every `### Task N:` block into fields + steps", () => {
|
|
257
|
-
expect(parsed.taskBlocks.map((block) => block.id)).toEqual([1, 2]);
|
|
258
|
-
const first = parsed.taskBlocks[0];
|
|
259
|
-
expect(first.heading).toBe("### Task 1: skeleton");
|
|
260
|
-
expect(first.fields.map((field) => field.key)).toEqual([
|
|
261
|
-
"Objective",
|
|
262
|
-
"Files",
|
|
263
|
-
"Consumes",
|
|
264
|
-
"Produces",
|
|
265
|
-
"Steps",
|
|
266
|
-
"Acceptance",
|
|
267
|
-
"DependsOn",
|
|
268
|
-
]);
|
|
269
|
-
expect(first.steps.map((step) => step.action)).toEqual(["step one", "step two"]);
|
|
270
|
-
expect(first.steps[1].checkable).toBe("second step check");
|
|
271
|
-
const dependsOn = first.fields.find((field) => field.key === "DependsOn");
|
|
272
|
-
expect(dependsOn?.lines[0]).toBe("none");
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("parses the Class-A `spec:` + Class-B `parent-program:` chain root from the head scalars", () => {
|
|
276
|
-
expect(parsed.chain.specLink).toEqual({ target: "docs/kairos/specs/x-design.md" });
|
|
277
|
-
expect(parsed.chain.parentLink).toEqual({ target: "docs/kairos/specs/x-overall.md" });
|
|
278
|
-
expect(parsed.chain.parentTokens).toEqual(["v1.21"]);
|
|
279
|
-
expect(parsed.chain.dependsOn).toBe("P1 design v1.1");
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
describe("PhaseSpecDocType.parse — the design skeleton + the Class-B chain root", () => {
|
|
284
|
-
const parsed = parseWithHead(new PhaseSpecDocType("phase-spec"), PHASE_SPEC);
|
|
285
|
-
|
|
286
|
-
it("parses the front-matter head (the five-tuple scalars) and the section skeleton", () => {
|
|
287
|
-
expect(parsed.docType).toBe("phase-spec");
|
|
288
|
-
// the title face is the head scalar — never the `---` fence line
|
|
289
|
-
expect(parsed.title).toBe("文档架构方法论 v2 — 测试 Design Spec");
|
|
290
|
-
expect(parsed.title).not.toBe("---");
|
|
291
|
-
expect(parsed.head?.status).toBe("Draft");
|
|
292
|
-
expect(parsed.head?.parentProgram).toBe("docs/kairos/specs/x-overall.md");
|
|
293
|
-
expect(parsed.head?.parentVersion).toBe("v1.21");
|
|
294
|
-
expect(parsed.sections.map((section) => section.heading)).toEqual([
|
|
295
|
-
"## Design",
|
|
296
|
-
"## Constraints",
|
|
297
|
-
"## Review record",
|
|
298
|
-
]);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it("parses the double-layer design skeleton into groups + items", () => {
|
|
302
|
-
expect(parsed.design.map((group) => group.number)).toEqual(["1", "2"]);
|
|
303
|
-
expect(parsed.design.map((group) => group.heading)).toEqual(["判定面", "编排面"]);
|
|
304
|
-
expect(parsed.design[0].items.map((item) => item.number)).toEqual(["1.1"]);
|
|
305
|
-
expect(parsed.design[0].items[0].heading).toBe("策略类族");
|
|
306
|
-
expect(parsed.design[1].items.map((item) => item.number)).toEqual(["2.1"]);
|
|
307
|
-
// the `### Acceptance criteria` leaf is a design-body anchor, not a numbered group.
|
|
308
|
-
expect(parsed.design.some((group) => group.heading.startsWith("Acceptance"))).toBe(false);
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it("parses the Class-B chain root — parent link + version tokens from the head scalars", () => {
|
|
312
|
-
expect(parsed.chain.parentLink).toEqual({ target: "docs/kairos/specs/x-overall.md" });
|
|
313
|
-
expect(parsed.chain.parentTokens).toEqual(["v1.21"]);
|
|
314
|
-
expect(parsed.chain.specLink).toBeNull();
|
|
315
|
-
expect(parsed.chain.dependsOn).toBe("P1(Done)");
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
describe("the home-driven extractors (T3 · spec §3.2) — the fixed structure rules over the registry's anchors", () => {
|
|
320
|
-
it("TaskExtractor — block heads + aligned id tokens + the scoped field/step occurrences", () => {
|
|
321
|
-
const extracted = new TaskExtractor().extract(declaredRegistries.plan, PLAN);
|
|
322
|
-
expect(extracted["### Task N:"]).toEqual(["### Task 1: skeleton", "### Task 2: registry"]);
|
|
323
|
-
expect(extracted["Task id token"]).toEqual(["1", "2"]);
|
|
324
|
-
expect(extracted["**Objective**"]).toEqual([
|
|
325
|
-
"- **Objective**: establish the skeleton",
|
|
326
|
-
"- **Objective**: declare the registries",
|
|
327
|
-
]);
|
|
328
|
-
expect(extracted["**DependsOn**"]).toEqual(["- **DependsOn**: none", "- **DependsOn**: 1"]);
|
|
329
|
-
// the step bullets are scoped to the `**Steps**` field and matched on the
|
|
330
|
-
// trimmed form — the header / constraint bullets never leak in
|
|
331
|
-
expect(extracted["Step action"]).toEqual([
|
|
332
|
-
" - step one",
|
|
333
|
-
" - step two — checkable: second step check",
|
|
334
|
-
" - write the registry — checkable: types compile",
|
|
335
|
-
]);
|
|
336
|
-
expect(extracted["Step checkable"]).toEqual([
|
|
337
|
-
" - step two — checkable: second step check",
|
|
338
|
-
" - write the registry — checkable: types compile",
|
|
339
|
-
]);
|
|
340
|
-
// the front-matter head scalars never become line occurrences of a body anchor
|
|
341
|
-
expect(extracted["spec"]).toBeUndefined();
|
|
342
|
-
expect(extracted["parent-program"]).toBeUndefined();
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
it("DesignBodyExtractor — the numbered group/item headings and the design leaves", () => {
|
|
346
|
-
const extracted = new DesignBodyExtractor().extract(
|
|
347
|
-
declaredRegistries["phase-spec"],
|
|
348
|
-
PHASE_SPEC,
|
|
349
|
-
);
|
|
350
|
-
expect(extracted["## Design"]).toEqual(["## Design"]);
|
|
351
|
-
expect(extracted["### N. group heading"]).toEqual(["### 1. 判定面", "### 2. 编排面"]);
|
|
352
|
-
expect(extracted["#### N.M item heading"]).toEqual(["#### 1.1 策略类族", "#### 2.1 波次"]);
|
|
353
|
-
expect(extracted["### Acceptance criteria"]).toEqual(["### Acceptance criteria"]);
|
|
354
|
-
expect(new DesignBodyExtractor().groupOf("### 1. 判定面")).toEqual({
|
|
355
|
-
number: "1",
|
|
356
|
-
heading: "判定面",
|
|
357
|
-
});
|
|
358
|
-
expect(new DesignBodyExtractor().itemOf("#### 2.1 波次")).toEqual({
|
|
359
|
-
number: "2.1",
|
|
360
|
-
heading: "波次",
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it("GraphExtractor — the declared graph edge lines on their trimmed form", () => {
|
|
365
|
-
const sections = new OverallDocType("overall-spec").parse(OVERALL).sections;
|
|
366
|
-
const graphSection = sections.find((section) =>
|
|
367
|
-
section.heading.startsWith("## Dependency graph"),
|
|
368
|
-
);
|
|
369
|
-
expect(graphSection).toBeDefined();
|
|
370
|
-
const extracted = new GraphExtractor().extract(declaredRegistries["overall-spec"], [
|
|
371
|
-
...(graphSection?.lines ?? []),
|
|
372
|
-
]);
|
|
373
|
-
expect(extracted["Hard edge"]).toEqual(["P1 -> P2"]);
|
|
374
|
-
expect(extracted["Graph legend"]).toEqual(["-> = hard block"]);
|
|
375
|
-
expect(extracted["Soft edge"]).toBeUndefined();
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
it("TableExtractor — the declared column-header and data rows", () => {
|
|
379
|
-
const extracted = new TableExtractor().extract(declaredRegistries["overall-spec"], [
|
|
380
|
-
"| Phase | Issue (ref) | Title summary |",
|
|
381
|
-
"| --- | --- | --- |",
|
|
382
|
-
"| P1 | #123 | issue one |",
|
|
383
|
-
]);
|
|
384
|
-
expect(extracted["Issue inventory columns"]).toEqual([
|
|
385
|
-
"| Phase | Issue (ref) | Title summary |",
|
|
386
|
-
]);
|
|
387
|
-
expect(extracted["Issue row"]).toEqual(["| P1 | #123 | issue one |"]);
|
|
388
|
-
// the separator row never matches a data anchor
|
|
389
|
-
expect(extracted["Change history row"]).toBeUndefined();
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
it("HeadingScanner — the registered section/facet headings by their declared rank", () => {
|
|
393
|
-
const extracted = new HeadingScanner().extract(declaredRegistries["overall-spec"], OVERALL);
|
|
394
|
-
expect(extracted["## Document scope"]).toEqual(["## Document scope"]);
|
|
395
|
-
expect(extracted["### Goal"]).toEqual(["### Goal"]);
|
|
396
|
-
expect(extracted["### Non-goals"]).toEqual(["### Non-goals"]);
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
it("HeadingScanner.sectionsOf — the declared rank-2 sections in document order, an undeclared heading excluded", () => {
|
|
400
|
-
const scanner = new HeadingScanner();
|
|
401
|
-
const sections = scanner.sectionsOf(declaredRegistries["overall-spec"], [
|
|
402
|
-
"## Document scope",
|
|
403
|
-
"scope prose",
|
|
404
|
-
"## Review Focus",
|
|
405
|
-
"undeclared prose",
|
|
406
|
-
"## Change history",
|
|
407
|
-
"| v1.1 |",
|
|
408
|
-
]);
|
|
409
|
-
// the undeclared rank-2 heading is not a section (and does not swallow the
|
|
410
|
-
// declared section that follows it)
|
|
411
|
-
expect(sections.map((section) => section.heading)).toEqual([
|
|
412
|
-
"## Document scope",
|
|
413
|
-
"## Change history",
|
|
414
|
-
]);
|
|
415
|
-
expect(sections[0].lines).toEqual(["scope prose"]);
|
|
416
|
-
// the phase-spec's conditional `## Review record` is a declared section surface
|
|
417
|
-
const phaseSections = scanner.sectionsOf(declaredRegistries["phase-spec"], [
|
|
418
|
-
"## Design",
|
|
419
|
-
"## Review record",
|
|
420
|
-
"- note",
|
|
421
|
-
]);
|
|
422
|
-
expect(phaseSections.map((section) => section.heading)).toEqual([
|
|
423
|
-
"## Design",
|
|
424
|
-
"## Review record",
|
|
425
|
-
]);
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
it("TableExtractor.tableLinesOf / headerLineOf — the table rows and the registry-declared header row", () => {
|
|
429
|
-
const extractor = new TableExtractor();
|
|
430
|
-
const lines = [
|
|
431
|
-
"prose line",
|
|
432
|
-
"| Phase | Issue (ref) | Title summary |",
|
|
433
|
-
"| --- | --- | --- |",
|
|
434
|
-
"| P1 | #123 | issue one |",
|
|
435
|
-
];
|
|
436
|
-
expect(extractor.tableLinesOf(lines)).toEqual([
|
|
437
|
-
"| Phase | Issue (ref) | Title summary |",
|
|
438
|
-
"| P1 | #123 | issue one |",
|
|
439
|
-
]);
|
|
440
|
-
expect(extractor.headerLineOf(declaredRegistries["overall-spec"], lines)).toBe(
|
|
441
|
-
"| Phase | Issue (ref) | Title summary |",
|
|
442
|
-
);
|
|
443
|
-
// a table whose declared column anchor is absent has no declared header
|
|
444
|
-
expect(extractor.headerLineOf(declaredRegistries["overall-spec"], ["| a | b |"])).toBeNull();
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
describe("the doc-type composition root", () => {
|
|
449
|
-
it("exposes one parser per doc key", () => {
|
|
450
|
-
expect(docTypeParsers["overall-spec"]).toBeInstanceOf(OverallDocType);
|
|
451
|
-
expect(docTypeParsers.plan).toBeInstanceOf(PlanDocType);
|
|
452
|
-
expect(docTypeParsers["phase-spec"]).toBeInstanceOf(PhaseSpecDocType);
|
|
453
|
-
});
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
describe("the DocType class face (spec §2.2)", () => {
|
|
457
|
-
it("carries zero judgment methods — no validate/audit/detect/judge symbols on the class face", () => {
|
|
458
|
-
const source = readFileSync(new URL("../doc.ts", import.meta.url), "utf8");
|
|
459
|
-
const judgementSymbols = source.match(/\b(validate|audit|detect|judge|assert)\s*\(/g) ?? [];
|
|
460
|
-
expect(judgementSymbols, "doc.ts must be judge-free (extract-only)").toEqual([]);
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
it("has no exported behavior-carrying bare function", () => {
|
|
464
|
-
const source = readFileSync(new URL("../doc.ts", import.meta.url), "utf8");
|
|
465
|
-
const functionExports = source.match(/export\s+(?:async\s+)?function\s+\w+/g) ?? [];
|
|
466
|
-
expect(functionExports).toEqual([]);
|
|
467
|
-
const arrowExports = source.match(/export\s+const\s+\w+\s*=\s*(?:\([^)]*\)|[\w]+)\s*=>/g) ?? [];
|
|
468
|
-
expect(arrowExports).toEqual([]);
|
|
469
|
-
});
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
describe("P2 — the four doc skeletons judge clean (spec §7.2 colocated pin)", () => {
|
|
473
|
-
/** The empty fs seam — every chain link of a skeleton is a `<…>` placeholder
|
|
474
|
-
* target (the judge's exemption chain), so the file-existence / sibling-scan
|
|
475
|
-
* surfaces never fire and the skeleton is green by construction. */
|
|
476
|
-
const EMPTY_FS = { exists: () => false, read: () => null, list: () => [] };
|
|
477
|
-
const contract = new Contract();
|
|
478
|
-
const projector = new Projector(declaredRegistries);
|
|
479
|
-
const PATH_OF: Record<DocKey, string> = {
|
|
480
|
-
"overall-spec": "docs/kairos/specs/x-overall.md",
|
|
481
|
-
plan: "docs/kairos/plans/x-p1.md",
|
|
482
|
-
"phase-spec": "docs/kairos/specs/x-p1-design.md",
|
|
483
|
-
"single-spec": "docs/kairos/specs/x-single-spec.md",
|
|
484
|
-
};
|
|
485
|
-
/** The fixed run date — the version-row date truth (never a live clock). */
|
|
486
|
-
const DATE = "2026-10-11";
|
|
487
|
-
|
|
488
|
-
/** The fixed-date skeleton bytes of one doc type. */
|
|
489
|
-
const renderOf = (key: DocKey): string =>
|
|
490
|
-
new SkeletonAssembler(projector.skeleton()[key], DATE).render();
|
|
491
|
-
|
|
492
|
-
it("judges each type's skeleton clean — zero findings (the §4.1 placeholder-anchored by-construction green)", () => {
|
|
493
|
-
for (const key of ["overall-spec", "plan", "phase-spec", "single-spec"] as const) {
|
|
494
|
-
const findings = contract.validate({
|
|
495
|
-
docKey: key,
|
|
496
|
-
path: PATH_OF[key],
|
|
497
|
-
content: renderOf(key),
|
|
498
|
-
root: ".",
|
|
499
|
-
fs: EMPTY_FS,
|
|
500
|
-
});
|
|
501
|
-
expect(findings, `${key} skeleton findings`).toEqual([]);
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
it("keeps every `:::fill` inside the content positions — zero hits on the link anchors / structure rows", () => {
|
|
506
|
-
for (const key of ["overall-spec", "plan", "phase-spec", "single-spec"] as const) {
|
|
507
|
-
for (const line of renderOf(key).split("\n")) {
|
|
508
|
-
if (!line.includes(":::fill")) continue;
|
|
509
|
-
// the placeholder-link anchors (`](<`), the version/status truths, the
|
|
510
|
-
// table column headers and the separator rows never carry a fill
|
|
511
|
-
expect(line, `${key}: ${line}`).not.toMatch(/\]\(</);
|
|
512
|
-
expect(line, `${key}: ${line}`).not.toMatch(/^- \*\*Version\*\*:|^- \*\*Status\*\*:/);
|
|
513
|
-
expect(line, `${key}: ${line}`).not.toMatch(/^\| (Artifact|Phase|#|Version) \|/);
|
|
514
|
-
expect(line, `${key}: ${line}`).not.toMatch(/^\| ?---/);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
it("the numeric headings are true values — the shape `### 1.` / `#### 1.1` / `### Task 1:` land, a literal `N` never", () => {
|
|
520
|
-
const spec = renderOf("phase-spec");
|
|
521
|
-
expect(spec).toContain("### 1. :::fill group-title");
|
|
522
|
-
expect(spec).toContain("#### 1.1 :::fill item-title");
|
|
523
|
-
expect(renderOf("plan")).toContain("### Task 1: :::fill task-title");
|
|
524
|
-
expect(spec).not.toContain("Task N:");
|
|
525
|
-
expect(renderOf("plan")).not.toContain("Task N:");
|
|
526
|
-
});
|
|
527
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// packages/cdd-engine/src-next/contract/__tests__/dockey.guard.test.ts
|
|
2
|
-
// T11 (spec §3.2 ③) — the DocKey single-source gate. The four doc-type keys were
|
|
3
|
-
// hand-copied across the tree (project.ts declaration · judge.ts DOC_KEYS ·
|
|
4
|
-
// declare.ts DOC_TYPE_VALUES · board-view.ts DOC_TYPE_DOMAIN · doc.ts inline
|
|
5
|
-
// unions); this gate asserts every runtime array and type surface over the domain
|
|
6
|
-
// derives from the ONE declaration (declare.ts DOC_TYPE_VALUES, re-exported by
|
|
7
|
-
// project.ts as DOC_KEYS + aliased as DocKey). A drifted second list — a member
|
|
8
|
-
// dropped or added anywhere — fails here, never silently.
|
|
9
|
-
|
|
10
|
-
import { readFileSync } from "node:fs";
|
|
11
|
-
import { fileURLToPath } from "node:url";
|
|
12
|
-
import { describe, expect, it } from "vitest";
|
|
13
|
-
import { DOC_TYPE_VALUES } from "../declare.ts";
|
|
14
|
-
import { DOC_KEYS } from "../project.ts";
|
|
15
|
-
|
|
16
|
-
/** The canonical value domain — the ONE declaration (declare.ts). */
|
|
17
|
-
const CANONICAL = ["overall-spec", "plan", "phase-spec", "single-spec"];
|
|
18
|
-
|
|
19
|
-
describe("DocKey single-source derivation (spec §3.2 ③)", () => {
|
|
20
|
-
it("the canonical declaration carries the four keys in order", () => {
|
|
21
|
-
expect([...DOC_TYPE_VALUES]).toEqual(CANONICAL);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("project.ts re-exports the SAME tuple as DOC_KEYS — one array, zero copy", () => {
|
|
25
|
-
// The re-export is the same runtime array instance, never a re-typed literal.
|
|
26
|
-
expect(DOC_KEYS).toBe(DOC_TYPE_VALUES);
|
|
27
|
-
expect([...DOC_KEYS]).toEqual(CANONICAL);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("the judge + declare + board-view consumers derive from the single source (zero re-typed literal)", () => {
|
|
31
|
-
const contractRoot = fileURLToPath(new URL("..", import.meta.url));
|
|
32
|
-
// A hand-written four-key literal array is the drift form this gate bans: the
|
|
33
|
-
// three consumers must never carry their own copy.
|
|
34
|
-
const files = ["judge.ts", "declare.ts", "../face/board-view.ts"].map((rel) =>
|
|
35
|
-
readFileSync(`${contractRoot}/${rel}`, "utf8"),
|
|
36
|
-
);
|
|
37
|
-
for (const [index, src] of files.entries()) {
|
|
38
|
-
// The literal "[ \"overall-spec\", ... ]" re-typed in a consumer is the drift
|
|
39
|
-
// signature; the canonical declare.ts keeps its ONE declaration and the two
|
|
40
|
-
// consumers must not carry a second literal array.
|
|
41
|
-
const literalArrays = src.match(/"overall-spec"\s*,\s*"plan"\s*,\s*"phase-spec"/g) ?? [];
|
|
42
|
-
if (index === 1) {
|
|
43
|
-
// declare.ts is the declaration root — its one literal is the single source.
|
|
44
|
-
expect(literalArrays.length).toBeLessThanOrEqual(1);
|
|
45
|
-
} else {
|
|
46
|
-
expect(literalArrays, `${files.length}`).toEqual([]);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("doc.ts carries zero inline doc-key union — the two surfaces alias DocKey", () => {
|
|
52
|
-
const docSrc = readFileSync(fileURLToPath(new URL("../doc.ts", import.meta.url)), "utf8");
|
|
53
|
-
// The collapsed inline unions read `DocKey`; a re-typed four-member union in
|
|
54
|
-
// doc.ts is the drift this gate bans.
|
|
55
|
-
const inlineUnion = docSrc.match(/docType\w*:\s*"overall-spec"\s*\|\s*"plan"/g) ?? [];
|
|
56
|
-
expect(inlineUnion).toEqual([]);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// packages/cdd-engine/src-next/contract/__tests__/edge-conditions.guard.test.ts
|
|
2
|
-
// T13 ④ (spec §3.3 ④) — the edgeConditionWords real-derivation gate. The contract's
|
|
3
|
-
// `edgeConditionWords` docstring claimed a wording test pinned its derivation from the
|
|
4
|
-
// engine word table / Route lexicon, but the array had ZERO reader (a false pin: the
|
|
5
|
-
// declared value could drift from the engine sources silently). This gate IS that pin:
|
|
6
|
-
// it derives the expected set by family concatenation from the engine's OWN single
|
|
7
|
-
// sources and asserts the declared contract value equals it —
|
|
8
|
-
// · the NEXT-LOOP phrases — the contract's own `digraph.nextLoopConditions`
|
|
9
|
-
// (the contract IS the authoritative home for this one family: the phrases are
|
|
10
|
-
// the SKILL-digraph edge-label vocabulary, a consumer-surface prose face the
|
|
11
|
-
// runtime `next:` never emits, so no engine runtime constant carries them — see
|
|
12
|
-
// the contract slot's docstring · P9 branch-review-1 F9);
|
|
13
|
-
// · the review-closure status words — `CAPSULE_WORDS.status` (face/words.ts) minus
|
|
14
|
-
// the failure statuses `FAILED_STATUS` (session/next.ts), cross-checked against the
|
|
15
|
-
// `RoundStatus` union (session/ledger.ts — the status type's single home);
|
|
16
|
-
// · the Route decision words — `ROUTE_DECISION_WORDS` (session/next.ts, the Route
|
|
17
|
-
// lexicon's single home).
|
|
18
|
-
// A drifted engine word re-projects the expected set and fails here — never a silent
|
|
19
|
-
// second list. Domicile: engine suite (§3.6 — the engine-internal ④ fact).
|
|
20
|
-
|
|
21
|
-
import { readFileSync } from "node:fs";
|
|
22
|
-
import { fileURLToPath } from "node:url";
|
|
23
|
-
import { describe, expect, it } from "vitest";
|
|
24
|
-
|
|
25
|
-
import { CAPSULE_WORDS } from "../../face/words.ts";
|
|
26
|
-
import { FAILED_STATUS, ROUTE_DECISION_WORDS } from "../../session/next.ts";
|
|
27
|
-
import { SKILL_ANATOMY } from "../skill-anatomy.ts";
|
|
28
|
-
|
|
29
|
-
const SRC = fileURLToPath(new URL("../../", import.meta.url));
|
|
30
|
-
|
|
31
|
-
/** The `RoundStatus` union members declared in session/ledger.ts — the status type's
|
|
32
|
-
* single home (parsed from the source: a string-literal union carries no runtime face). */
|
|
33
|
-
const roundStatusMembers = (): string[] => {
|
|
34
|
-
const src = readFileSync(`${SRC}/session/ledger.ts`, "utf8");
|
|
35
|
-
const match = /export type RoundStatus =([^;]+);/.exec(src);
|
|
36
|
-
if (match === null) throw new Error("ledger.ts RoundStatus shape changed");
|
|
37
|
-
return [...(match[1] ?? "").matchAll(/"([^"]+)"/g)].map((m) => m[1]!);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/** The expected engine-lexicon condition set — derived by family concatenation from
|
|
41
|
-
* the engine's own single sources (the contract's loop conditions + the word table's
|
|
42
|
-
* non-failure status vocabulary + the router's Route decision lexicon). */
|
|
43
|
-
const deriveExpected = (): string[] => [
|
|
44
|
-
...SKILL_ANATOMY.digraph.nextLoopConditions,
|
|
45
|
-
...CAPSULE_WORDS.status.filter((status) => !FAILED_STATUS.has(status)),
|
|
46
|
-
...ROUTE_DECISION_WORDS,
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
describe("edgeConditionWords — the real derivation pin (spec §3.3 ④)", () => {
|
|
50
|
-
it("equals the family-concatenation derivation from words.ts + next.ts + the contract's loop conditions", () => {
|
|
51
|
-
expect([...SKILL_ANATOMY.edgeConditionWords]).toEqual(deriveExpected());
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("carries the three families and no re-typed drift — the set is exactly loop + status + route words", () => {
|
|
55
|
-
const derived = deriveExpected();
|
|
56
|
-
// Each family contributes at least one word (a dropped family is a finding).
|
|
57
|
-
expect(SKILL_ANATOMY.digraph.nextLoopConditions.length).toBeGreaterThan(0);
|
|
58
|
-
expect(ROUTE_DECISION_WORDS.length).toBeGreaterThan(0);
|
|
59
|
-
expect(CAPSULE_WORDS.status.filter((s) => !FAILED_STATUS.has(s)).length).toBeGreaterThan(0);
|
|
60
|
-
expect(SKILL_ANATOMY.edgeConditionWords.length).toBe(derived.length);
|
|
61
|
-
// The failure statuses are excluded (a BLOCKED/TIMEOUT round carries no closure edge).
|
|
62
|
-
for (const failed of FAILED_STATUS) {
|
|
63
|
-
expect(SKILL_ANATOMY.edgeConditionWords).not.toContain(failed);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("the closure status words derive from the RoundStatus union (ledger.ts — the status type's single home)", () => {
|
|
68
|
-
const members = roundStatusMembers();
|
|
69
|
-
const closure = CAPSULE_WORDS.status.filter((status) => !FAILED_STATUS.has(status));
|
|
70
|
-
// Every closure status word is a declared RoundStatus member; the word table's
|
|
71
|
-
// status vocabulary stays a subset of the type's union (never a status word the
|
|
72
|
-
// carrier cannot hold — the ledger × words cross-leg).
|
|
73
|
-
for (const word of closure) {
|
|
74
|
-
expect(members, `"${word}" is not a declared RoundStatus member`).toContain(word);
|
|
75
|
-
}
|
|
76
|
-
// The failure statuses ride the same union (the exclusion is a real subset filter).
|
|
77
|
-
for (const failed of FAILED_STATUS) {
|
|
78
|
-
expect(members, `"${failed}" is not a declared RoundStatus member`).toContain(failed);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|