@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.
Files changed (143) hide show
  1. package/{src-next/bin.ts → dist/bin.js} +18 -21
  2. package/dist/contract/declare.js +998 -0
  3. package/dist/contract/doc.js +565 -0
  4. package/dist/contract/frontmatter.js +209 -0
  5. package/dist/contract/home-extractors.js +379 -0
  6. package/dist/contract/invariants.js +1030 -0
  7. package/dist/contract/judge.js +109 -0
  8. package/dist/contract/lint.js +206 -0
  9. package/dist/contract/project.js +371 -0
  10. package/dist/contract/skill-anatomy.js +156 -0
  11. package/dist/contract/translate.js +85 -0
  12. package/dist/face/artifacts.js +189 -0
  13. package/dist/face/board-view.js +522 -0
  14. package/dist/face/capsule.js +141 -0
  15. package/dist/face/cli.js +891 -0
  16. package/dist/face/declare.js +241 -0
  17. package/dist/face/gate.js +158 -0
  18. package/dist/face/graph-view.js +66 -0
  19. package/dist/face/host.js +211 -0
  20. package/dist/face/lifecycle.js +603 -0
  21. package/dist/face/preview.js +136 -0
  22. package/dist/face/projection.js +259 -0
  23. package/dist/face/route-render.js +162 -0
  24. package/dist/face/termination.js +482 -0
  25. package/dist/face/words.js +220 -0
  26. package/{src-next/infra/config.ts → dist/infra/config.js} +19 -24
  27. package/{src-next/infra/doc-roots.ts → dist/infra/doc-roots.js} +3 -13
  28. package/dist/infra/git.js +37 -0
  29. package/dist/infra/process.js +22 -0
  30. package/{src-next/infra/root.ts → dist/infra/root.js} +25 -36
  31. package/dist/infra/runtime.js +85 -0
  32. package/dist/infra/workspace.js +276 -0
  33. package/dist/render/brief.js +82 -0
  34. package/dist/render/issue-body.js +129 -0
  35. package/dist/render/skeleton.js +434 -0
  36. package/dist/render/templates.js +520 -0
  37. package/dist/session/faces.js +38 -0
  38. package/dist/session/graph.js +309 -0
  39. package/dist/session/handoff-schema.js +295 -0
  40. package/dist/session/ledger.js +762 -0
  41. package/dist/session/next.js +211 -0
  42. package/dist/session/preflight.js +194 -0
  43. package/dist/session/round-naming.js +73 -0
  44. package/dist/session/run.js +441 -0
  45. package/dist/session/state.js +8 -0
  46. package/dist/session/wave.js +92 -0
  47. package/package.json +5 -5
  48. package/src-next/__tests__/bin.test.ts +0 -128
  49. package/src-next/__tests__/dead-decl.guard.test.ts +0 -39
  50. package/src-next/__tests__/floor.guard.test.ts +0 -69
  51. package/src-next/__tests__/issue-body.guard.test.ts +0 -66
  52. package/src-next/__tests__/phase-suffix.guard.test.ts +0 -72
  53. package/src-next/__tests__/smoke.integration.test.ts +0 -185
  54. package/src-next/__tests__/support/strip-comments.ts +0 -99
  55. package/src-next/__tests__/zero-dep.test.ts +0 -94
  56. package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +0 -256
  57. package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +0 -165
  58. package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +0 -190
  59. package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +0 -106
  60. package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +0 -240
  61. package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +0 -165
  62. package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +0 -190
  63. package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +0 -100
  64. package/src-next/contract/__tests__/declare.test.ts +0 -481
  65. package/src-next/contract/__tests__/doc.test.ts +0 -527
  66. package/src-next/contract/__tests__/dockey.guard.test.ts +0 -58
  67. package/src-next/contract/__tests__/edge-conditions.guard.test.ts +0 -81
  68. package/src-next/contract/__tests__/frontmatter.test.ts +0 -164
  69. package/src-next/contract/__tests__/judge.test.ts +0 -1111
  70. package/src-next/contract/__tests__/lint.test.ts +0 -324
  71. package/src-next/contract/__tests__/project.test.ts +0 -460
  72. package/src-next/contract/__tests__/structure-pin.test.ts +0 -186
  73. package/src-next/contract/__tests__/translate.test.ts +0 -96
  74. package/src-next/contract/declare.ts +0 -1071
  75. package/src-next/contract/doc.ts +0 -816
  76. package/src-next/contract/frontmatter.ts +0 -233
  77. package/src-next/contract/home-extractors.ts +0 -397
  78. package/src-next/contract/invariants.ts +0 -1413
  79. package/src-next/contract/judge.ts +0 -151
  80. package/src-next/contract/lint.ts +0 -239
  81. package/src-next/contract/project.ts +0 -656
  82. package/src-next/contract/skill-anatomy.ts +0 -301
  83. package/src-next/contract/translate.ts +0 -113
  84. package/src-next/face/__tests__/board-view.test.ts +0 -1151
  85. package/src-next/face/__tests__/capsule.test.ts +0 -300
  86. package/src-next/face/__tests__/channel-closure.guard.test.ts +0 -129
  87. package/src-next/face/__tests__/cli.test.ts +0 -4897
  88. package/src-next/face/__tests__/face.test.ts +0 -289
  89. package/src-next/face/__tests__/graph-view.test.ts +0 -61
  90. package/src-next/face/__tests__/host.test.ts +0 -24
  91. package/src-next/face/__tests__/install-rows.guard.test.ts +0 -58
  92. package/src-next/face/__tests__/negation.ts +0 -6
  93. package/src-next/face/__tests__/preview.test.ts +0 -374
  94. package/src-next/face/__tests__/projection.test.ts +0 -303
  95. package/src-next/face/__tests__/repo-root.guard.test.ts +0 -120
  96. package/src-next/face/__tests__/termination.test.ts +0 -650
  97. package/src-next/face/__tests__/words.guard.test.ts +0 -93
  98. package/src-next/face/artifacts.ts +0 -248
  99. package/src-next/face/board-view.ts +0 -652
  100. package/src-next/face/capsule.ts +0 -163
  101. package/src-next/face/cli.ts +0 -1028
  102. package/src-next/face/declare.ts +0 -323
  103. package/src-next/face/gate.ts +0 -171
  104. package/src-next/face/graph-view.ts +0 -74
  105. package/src-next/face/host.ts +0 -302
  106. package/src-next/face/lifecycle.ts +0 -725
  107. package/src-next/face/preview.ts +0 -151
  108. package/src-next/face/projection.ts +0 -285
  109. package/src-next/face/route-render.ts +0 -185
  110. package/src-next/face/termination.ts +0 -573
  111. package/src-next/face/words.ts +0 -314
  112. package/src-next/infra/__tests__/infra.test.ts +0 -333
  113. package/src-next/infra/__tests__/root.test.ts +0 -56
  114. package/src-next/infra/git.ts +0 -39
  115. package/src-next/infra/process.ts +0 -34
  116. package/src-next/infra/runtime.ts +0 -132
  117. package/src-next/infra/workspace.ts +0 -322
  118. package/src-next/render/__tests__/render.test.ts +0 -550
  119. package/src-next/render/__tests__/skeleton.test.ts +0 -684
  120. package/src-next/render/brief.ts +0 -121
  121. package/src-next/render/issue-body.ts +0 -162
  122. package/src-next/render/skeleton.ts +0 -502
  123. package/src-next/render/templates.ts +0 -645
  124. package/src-next/session/__tests__/graph.test.ts +0 -277
  125. package/src-next/session/__tests__/handoff-plane.guard.test.ts +0 -48
  126. package/src-next/session/__tests__/handoff-schema.test.ts +0 -310
  127. package/src-next/session/__tests__/ledger.test.ts +0 -745
  128. package/src-next/session/__tests__/next.test.ts +0 -460
  129. package/src-next/session/__tests__/preflight.test.ts +0 -545
  130. package/src-next/session/__tests__/round-naming.test.ts +0 -142
  131. package/src-next/session/__tests__/run.test.ts +0 -1026
  132. package/src-next/session/__tests__/wave-line-phase.guard.test.ts +0 -49
  133. package/src-next/session/__tests__/wave.test.ts +0 -476
  134. package/src-next/session/faces.ts +0 -110
  135. package/src-next/session/graph.ts +0 -411
  136. package/src-next/session/handoff-schema.ts +0 -373
  137. package/src-next/session/ledger.ts +0 -1076
  138. package/src-next/session/next.ts +0 -293
  139. package/src-next/session/preflight.ts +0 -271
  140. package/src-next/session/round-naming.ts +0 -84
  141. package/src-next/session/run.ts +0 -610
  142. package/src-next/session/state.ts +0 -30
  143. package/src-next/session/wave.ts +0 -139
@@ -1,460 +0,0 @@
1
- // packages/cdd-engine/src-next/contract/__tests__/project.test.ts
2
- // T3 test suite for the projection face (contract/project.ts).
3
- //
4
- // The five projections (shape / schema / slices / tokens / reference) are the
5
- // derived surfaces of the declared registries — this suite pins the brief's
6
- // checkables through the Projector class surface (the derivation carrier
7
- // constructed on the declared registries; its method face is
8
- // shape/schema/slices/tokens/reference/registries, escapeRegExp private):
9
- // · Projector.schema — every schema is JSON-stringify-able and its bytes are
10
- // snapshot-pinned from the new tree's first version;
11
- // · Projector.shape — the shape elements correspond 1:1 with the registered
12
- // elements (grouped into the section skeleton), also snapshot-pinned;
13
- // · Projector.slices — every body element's slice parses its own anchor; the
14
- // frontmatter-home rows carry no compiled pattern (a YAML key is looked up
15
- // directly, never a line scan);
16
- // · Projector.tokens / Projector.reference — both surfaces correspond 1:1
17
- // with the registered elements.
18
- // Every projection is derived: the registered declaration and known-good anchor
19
- // literals (never module output) are the independent sources of truth, so a
20
- // hand-written copy or a derivation drift fails a byte or equality assertion.
21
-
22
- import { describe, expect, it } from "vitest";
23
- import type { ElementRegistry } from "../declare.ts";
24
- import { declaredRegistries } from "../declare.ts";
25
- import { Projector } from "../project.ts";
26
-
27
- const DOC_KEYS = ["overall-spec", "plan", "phase-spec", "single-spec"] as const;
28
- const REGISTRIES = [
29
- declaredRegistries["overall-spec"],
30
- declaredRegistries.plan,
31
- declaredRegistries["phase-spec"],
32
- declaredRegistries["single-spec"],
33
- ] as const satisfies readonly ElementRegistry[];
34
-
35
- /** The shared projection carrier the suite derives every surface from. */
36
- const PROJECTOR = new Projector(declaredRegistries);
37
-
38
- // The exact serialization the snapshots pin: projection JSON with two-space
39
- // indentation and exactly one trailing newline (the package's EOF-newline rule).
40
- const serialize = (value: unknown): string => `${JSON.stringify(value, null, 2)}\n`;
41
-
42
- const REF_KINDS = new Set([
43
- "none",
44
- "version-lineage",
45
- "markdown-link",
46
- "phase-id",
47
- "issue-ref",
48
- "spec-ref",
49
- "parent-program",
50
- "task-id",
51
- ]);
52
-
53
- describe("schema projection (Projector.schema)", () => {
54
- const schemas = PROJECTOR.schema();
55
-
56
- it("emits a JSON-stringify-able schema per doc type that round-trips byte-identically", () => {
57
- for (const [index, registry] of REGISTRIES.entries()) {
58
- const doc = schemas[DOC_KEYS[index]];
59
- expect(() => JSON.stringify(doc), `${registry.docType} stringify`).not.toThrow();
60
- expect(JSON.parse(serialize(doc))).toEqual(doc);
61
- }
62
- });
63
-
64
- it("keys its properties one-per-declared-element, in registry order", () => {
65
- for (const [index, registry] of REGISTRIES.entries()) {
66
- const doc = schemas[DOC_KEYS[index]];
67
- expect(Object.keys(doc.properties)).toEqual(
68
- registry.elements.map((element) => element.anchor),
69
- );
70
- }
71
- });
72
-
73
- it("carries the property description (presence · home · ref) and the declared value pattern", () => {
74
- for (const [index, registry] of REGISTRIES.entries()) {
75
- const doc = schemas[DOC_KEYS[index]];
76
- for (const element of registry.elements) {
77
- const property = doc.properties[element.anchor];
78
- expect(property.description).toBe(
79
- `presence: ${element.presence} · home: ${element.home} · ref: ${element.refKind}`,
80
- );
81
- expect(property.pattern).toBe(element.valuePattern);
82
- }
83
- }
84
- });
85
-
86
- it("derives the required set from the required-presence elements, in registry order", () => {
87
- for (const [index, registry] of REGISTRIES.entries()) {
88
- const doc = schemas[DOC_KEYS[index]];
89
- expect(doc.required).toEqual(
90
- registry.elements
91
- .filter((element) => element.presence === "required")
92
- .map((element) => element.anchor),
93
- );
94
- }
95
- });
96
-
97
- it("pins the schema bytes from the first version (byte snapshots)", async () => {
98
- for (const key of DOC_KEYS) {
99
- await expect(serialize(schemas[key])).toMatchFileSnapshot(
100
- `__snapshots__/project.schema.${key}.snap`,
101
- );
102
- }
103
- });
104
- });
105
-
106
- describe("shape projection (Projector.shape)", () => {
107
- const shapes = PROJECTOR.shape();
108
-
109
- it("corresponds 1:1 with the registered elements (a bijection over the registry rows)", () => {
110
- for (const [index, registry] of REGISTRIES.entries()) {
111
- const doc = shapes[DOC_KEYS[index]];
112
- const flat = doc.structure.flatMap((group) => group.elements);
113
- // One shape element per registered element.
114
- expect(flat).toHaveLength(registry.elements.length);
115
- const byAnchor = new Map(flat.map((element) => [element.anchor, element]));
116
- for (const element of registry.elements) {
117
- const projected = byAnchor.get(element.anchor);
118
- expect(projected, `${registry.docType}:${element.anchor}`).toBeDefined();
119
- expect(projected!.presence).toBe(element.presence);
120
- expect(projected!.refKind).toBe(element.refKind);
121
- }
122
- // The shape carries exactly the registry's anchors — no extra, none missing.
123
- expect(flat.map((element) => element.anchor).sort()).toEqual(
124
- registry.elements.map((element) => element.anchor).sort(),
125
- );
126
- }
127
- });
128
-
129
- it("reads as the section skeleton: non-empty groups in first home-occurrence order", () => {
130
- for (const [index, registry] of REGISTRIES.entries()) {
131
- const doc = shapes[DOC_KEYS[index]];
132
- const expectedGroups: string[] = [];
133
- const seen = new Set<string>();
134
- for (const element of registry.elements) {
135
- if (!seen.has(element.home)) {
136
- seen.add(element.home);
137
- expectedGroups.push(element.home);
138
- }
139
- }
140
- expect(doc.structure.map((group) => group.home)).toEqual(expectedGroups);
141
- expect(doc.structure).toHaveLength(seen.size);
142
- for (const group of doc.structure) {
143
- expect(group.elements.length, `${group.home} group`).toBeGreaterThan(0);
144
- // Each group collects its home's rows in registry order.
145
- expect(group.elements.map((element) => element.anchor)).toEqual(
146
- registry.elements
147
- .filter((element) => element.home === group.home)
148
- .map((element) => element.anchor),
149
- );
150
- }
151
- }
152
- });
153
-
154
- it("pins the shape bytes from the first version (byte snapshots)", async () => {
155
- for (const key of DOC_KEYS) {
156
- await expect(serialize(shapes[key])).toMatchFileSnapshot(
157
- `__snapshots__/project.shape.${key}.snap`,
158
- );
159
- }
160
- });
161
- });
162
-
163
- describe("slices projection (Projector.slices)", () => {
164
- const slices = PROJECTOR.slices();
165
-
166
- it("gives every declared element a slice that parses its own anchor", () => {
167
- for (const [index, registry] of REGISTRIES.entries()) {
168
- const doc = slices[DOC_KEYS[index]];
169
- expect(doc.slices).toHaveLength(registry.elements.length);
170
- for (let i = 0; i < registry.elements.length; i++) {
171
- const element = registry.elements[i];
172
- const slice = doc.slices[i];
173
- expect(slice.anchor).toBe(element.anchor);
174
- if (element.home === "frontmatter") {
175
- // Frontmatter-home elements anchor on a YAML key — never compiled into
176
- // a line scan; both the anchor and value RegExp compilations stop on
177
- // the header leg (§3.3).
178
- expect(slice.anchorPattern, `${registry.docType}:${element.anchor}`).toBeUndefined();
179
- expect(slice.valuePattern, `${registry.docType}:${element.anchor}`).toBeUndefined();
180
- continue;
181
- }
182
- expect(slice.anchorPattern, `${registry.docType}:${element.anchor}`).toBeInstanceOf(RegExp);
183
- // The slice parses its anchor — the escaped anchor literal matches the anchor itself.
184
- // (Non-null: the body-home contract above guarantees a compiled pattern.)
185
- expect(
186
- slice.anchorPattern!.test(element.anchor),
187
- `${registry.docType}:${element.anchor} anchorPattern`,
188
- ).toBe(true);
189
- }
190
- }
191
- });
192
-
193
- it("derives the anchor pattern from the anchor literal (known-good escapes)", () => {
194
- const overall = slices["overall-spec"];
195
- // The two leading rows are front-matter keys — the slice carries the key as
196
- // a literal, no compiled line scan.
197
- expect(overall.slices[0].anchor).toBe("title");
198
- expect(overall.slices[0].anchorPattern).toBeUndefined();
199
- expect(overall.slices.find((s) => s.anchor === "version")?.anchorPattern).toBeUndefined();
200
- // `## Document scope` — no metacharacters: the anchor is its own pattern.
201
- const scope = overall.slices.find((s) => s.anchor === "## Document scope")!;
202
- expect(scope.anchorPattern?.source).toBe("## Document scope");
203
- // `#### [MFRBEN] group` — brackets escaped (the anchor is the English canonical;
204
- // the legacy zh leaf matches through the judge's canonicalize view, never here).
205
- const mfrben = overall.slices.find((slice) => slice.anchor === "#### [MFRBEN] group")!;
206
- expect(mfrben.anchorPattern?.source).toBe("#### \\[MFRBEN\\] group");
207
- });
208
-
209
- it("derives the value slice from the declared value pattern (body surfaces only)", () => {
210
- for (const [index, registry] of REGISTRIES.entries()) {
211
- const doc = slices[DOC_KEYS[index]];
212
- for (let i = 0; i < registry.elements.length; i++) {
213
- const element = registry.elements[i];
214
- const slice = doc.slices[i];
215
- if (element.home === "frontmatter") {
216
- // The registry still declares the scalar shape (the domain judgment
217
- // reads it from the registry, never a compiled line slice).
218
- expect(slice.valuePattern, `${registry.docType}:${element.anchor}`).toBeUndefined();
219
- continue;
220
- }
221
- expect(slice.valuePattern, `${registry.docType}:${element.anchor}`).toBeInstanceOf(RegExp);
222
- if (element.valuePattern !== undefined) {
223
- expect(slice.valuePattern?.source).toBe(element.valuePattern);
224
- }
225
- }
226
- }
227
- });
228
- });
229
-
230
- describe("tokens projection (Projector.tokens)", () => {
231
- const tokens = PROJECTOR.tokens();
232
-
233
- it("corresponds 1:1 with the registered elements", () => {
234
- for (const [index, registry] of REGISTRIES.entries()) {
235
- const doc = tokens[DOC_KEYS[index]];
236
- expect(doc.tokens).toHaveLength(registry.elements.length);
237
- for (let i = 0; i < registry.elements.length; i++) {
238
- const element = registry.elements[i];
239
- const token = doc.tokens[i];
240
- expect(token.anchor).toBe(element.anchor);
241
- expect(token.presence).toBe(element.presence);
242
- expect(token.home).toBe(element.home);
243
- expect(token.refKind).toBe(element.refKind);
244
- }
245
- }
246
- });
247
-
248
- it("keeps the vocabulary exactly the registry's anchor set", () => {
249
- for (const [index, registry] of REGISTRIES.entries()) {
250
- const doc = tokens[DOC_KEYS[index]];
251
- const anchors = doc.tokens.map((token) => token.anchor);
252
- expect(new Set(anchors).size).toBe(anchors.length);
253
- expect(new Set(anchors)).toEqual(new Set(registry.elements.map((element) => element.anchor)));
254
- }
255
- });
256
- });
257
-
258
- describe("reference projection (Projector.reference)", () => {
259
- const reference = PROJECTOR.reference();
260
-
261
- it("corresponds 1:1 with the registered elements, carrying refKind and value pattern", () => {
262
- for (const [index, registry] of REGISTRIES.entries()) {
263
- const doc = reference[DOC_KEYS[index]];
264
- expect(doc.entries).toHaveLength(registry.elements.length);
265
- for (let i = 0; i < registry.elements.length; i++) {
266
- const element = registry.elements[i];
267
- const entry = doc.entries[i];
268
- expect(entry.anchor).toBe(element.anchor);
269
- expect(entry.refKind).toBe(element.refKind);
270
- if (element.valuePattern !== undefined) {
271
- expect(entry.valuePattern).toBe(element.valuePattern);
272
- }
273
- }
274
- }
275
- });
276
-
277
- it("keeps the reference vocabulary inside the declared ref kinds", () => {
278
- for (const [index, registry] of REGISTRIES.entries()) {
279
- const doc = reference[DOC_KEYS[index]];
280
- for (const entry of doc.entries) {
281
- expect(REF_KINDS.has(entry.refKind), `${registry.docType}:${entry.anchor}`).toBe(true);
282
- }
283
- }
284
- });
285
- });
286
-
287
- describe("skeleton projection (Projector.skeleton)", () => {
288
- const skeletons = PROJECTOR.skeleton();
289
-
290
- it("keys the projection record by the DocKey domain and carries each doc's type identity", () => {
291
- // The skeleton record rides the projection DocKey domain (overall-spec | plan |
292
- // phase-spec | single-spec) — the same single spelling as the DocType literals (spec §5.2).
293
- expect(Object.keys(skeletons)).toEqual([...DOC_KEYS]);
294
- expect(skeletons["overall-spec"].docType).toBe("overall-spec");
295
- expect(skeletons.plan.docType).toBe("plan");
296
- expect(skeletons["phase-spec"].docType).toBe("phase-spec");
297
- expect(skeletons["single-spec"].docType).toBe("single-spec");
298
- });
299
-
300
- it("projects exactly the required elements — optional/conditional generate zero slots", () => {
301
- for (const [index, registry] of REGISTRIES.entries()) {
302
- const doc = skeletons[DOC_KEYS[index]];
303
- // The projected slot SET equals the required element set of the live
304
- // registry (the shape's home-group order, not the flat registry order,
305
- // is the projection's sequence — asserted separately below).
306
- expect(new Set(doc.slots.map((slot) => slot.anchor))).toEqual(
307
- new Set(
308
- registry.elements
309
- .filter((element) => element.presence === "required")
310
- .map((element) => element.anchor),
311
- ),
312
- );
313
- expect(doc.slots.length).toBe(
314
- registry.elements.filter((element) => element.presence === "required").length,
315
- );
316
- for (const slot of doc.slots) expect(slot.presence).toBe("required");
317
- }
318
- });
319
-
320
- it("projects the front-matter emission list — every head key but `parent-version`, required and optional alike", () => {
321
- // §4.2: the head emission list is independent of the slot channel — it
322
- // carries the required head keys plus the type's optional head keys, and
323
- // excludes `parent-version` (its shape-typed domain admits no placeholder).
324
- for (const [index, registry] of REGISTRIES.entries()) {
325
- const doc = skeletons[DOC_KEYS[index]];
326
- const expected = registry.elements
327
- .filter((element) => element.home === "frontmatter" && element.anchor !== "parent-version")
328
- .map((element) => element.anchor);
329
- expect(doc.frontmatter.map((slot) => slot.anchor)).toEqual(expected);
330
- expect(doc.frontmatter.some((slot) => slot.home !== "frontmatter")).toBe(false);
331
- }
332
- expect(skeletons.plan.frontmatter.map((slot) => slot.anchor)).toContain("base");
333
- expect(skeletons.plan.frontmatter.map((slot) => slot.anchor)).toContain("depends-on");
334
- expect(skeletons["single-spec"].frontmatter.map((slot) => slot.anchor)).toContain("issues");
335
- });
336
-
337
- it("keeps the shape home-group order — the slot homes run the shape's group sequence", () => {
338
- for (const [index] of REGISTRIES.entries()) {
339
- const doc = skeletons[DOC_KEYS[index]];
340
- const shape = PROJECTOR.shape()[DOC_KEYS[index]];
341
- const expectedHomes = shape.structure.flatMap((group) =>
342
- group.elements.filter((element) => element.presence === "required").map(() => group.home),
343
- );
344
- expect(doc.slots.map((slot) => slot.home)).toEqual(expectedHomes);
345
- }
346
- });
347
-
348
- it("classifies the parent-program / spec-ref link anchors as link slots", () => {
349
- for (const [index, registry] of REGISTRIES.entries()) {
350
- const doc = skeletons[DOC_KEYS[index]];
351
- const linkSlots = doc.slots.filter((slot) => slot.slot === "link");
352
- for (const slot of linkSlots) {
353
- const element = registry.elements.find((e) => e.anchor === slot.anchor);
354
- // the link class is exactly the frontmatter-home parent-program / spec-ref
355
- // keys (never the enum-typed table cells that also mention spec/ref)
356
- expect(element?.home).toBe("frontmatter");
357
- expect(["parent-program", "spec-ref"]).toContain(slot.refKind);
358
- }
359
- }
360
- expect(skeletons.plan.slots.find((s) => s.anchor === "spec")?.slot).toBe("link");
361
- expect(skeletons.plan.slots.find((s) => s.anchor === "parent-program")?.slot).toBe("link");
362
- expect(skeletons["phase-spec"].slots.find((s) => s.anchor === "parent-program")?.slot).toBe(
363
- "link",
364
- );
365
- });
366
-
367
- it("classifies the digit-family headings of the task-block / design-body surfaces as numeric-heading", () => {
368
- for (const [index] of REGISTRIES.entries()) {
369
- const doc = skeletons[DOC_KEYS[index]];
370
- for (const slot of doc.slots) {
371
- if (
372
- ![
373
- "### Task N:",
374
- "Task id token",
375
- "### N. group heading",
376
- "#### N.M item heading",
377
- ].includes(slot.anchor)
378
- )
379
- continue;
380
- expect(slot.slot, `${DOC_KEYS[index]}:${slot.anchor}`).toBe("numeric-heading");
381
- }
382
- }
383
- });
384
-
385
- it("classifies the enum domain (status) and the graph rows as generator-truth", () => {
386
- for (const [index] of REGISTRIES.entries()) {
387
- const doc = skeletons[DOC_KEYS[index]];
388
- const status = doc.slots.find((slot) => slot.anchor === "status");
389
- if (status !== undefined) expect(status.slot).toBe("generator-truth");
390
- for (const anchor of ["Hard edge", "Graph legend"]) {
391
- const slot = doc.slots.find((s) => s.anchor === anchor);
392
- if (slot !== undefined) {
393
- expect(slot.slot, `${DOC_KEYS[index]}:${anchor}`).toBe("generator-truth");
394
- expect(slot.home).toBe("graph");
395
- }
396
- }
397
- }
398
- });
399
-
400
- it("classifies the version/date rows and the table tokens as scaffold", () => {
401
- for (const [index] of REGISTRIES.entries()) {
402
- const doc = skeletons[DOC_KEYS[index]];
403
- for (const anchor of [
404
- "version",
405
- "date",
406
- "Version token",
407
- "Change history date",
408
- "Phase id token",
409
- ]) {
410
- const slot = doc.slots.find((s) => s.anchor === anchor);
411
- if (slot !== undefined) expect(slot.slot, `${DOC_KEYS[index]}:${anchor}`).toBe("scaffold");
412
- }
413
- }
414
- });
415
-
416
- it("keeps the content slots free of fully-anchored enum and graph elements", () => {
417
- // the enum-domain + graph rows the generator-truth class owns — none of them
418
- // may ride the content class (a content slot is a free-text `:::fill` landing
419
- // position, never a judged enum/graph value). The anchors are the front-matter
420
- // keys (`status` · `doc-type`) plus the enum-typed table cells and the graph rows.
421
- const truthAnchors = [
422
- "status",
423
- "doc-type",
424
- "Issue ref cell",
425
- "Implementation plan cell",
426
- "Design spec cell",
427
- "Hard edge",
428
- "Graph legend",
429
- ];
430
- for (const [index] of REGISTRIES.entries()) {
431
- const doc = skeletons[DOC_KEYS[index]];
432
- for (const slot of doc.slots.filter((s) => s.slot === "content")) {
433
- expect(truthAnchors, `${DOC_KEYS[index]}:${slot.anchor}`).not.toContain(slot.anchor);
434
- }
435
- }
436
- });
437
- });
438
-
439
- describe("Projector.registries — the composed six-projection surface", () => {
440
- it("returns all six projections derived from the individual faces", () => {
441
- const projected = PROJECTOR.registries();
442
- expect(projected.shape).toEqual(PROJECTOR.shape());
443
- expect(projected.schema).toEqual(PROJECTOR.schema());
444
- expect(projected.slices).toEqual(PROJECTOR.slices());
445
- expect(projected.tokens).toEqual(PROJECTOR.tokens());
446
- expect(projected.reference).toEqual(PROJECTOR.reference());
447
- expect(projected.skeleton).toEqual(PROJECTOR.skeleton());
448
- });
449
-
450
- it("carries each doc type's declaration identity (docType field)", () => {
451
- const projected = PROJECTOR.registries();
452
- expect(projected.shape["overall-spec"].docType).toBe("overall-spec");
453
- expect(projected.schema.plan.docType).toBe("plan");
454
- expect(projected.tokens["phase-spec"].docType).toBe("phase-spec");
455
- expect(projected.skeleton["overall-spec"].docType).toBe("overall-spec");
456
- expect(projected.skeleton.plan.docType).toBe("plan");
457
- expect(projected.skeleton["phase-spec"].docType).toBe("phase-spec");
458
- expect(projected.skeleton["single-spec"].docType).toBe("single-spec");
459
- });
460
- });
@@ -1,186 +0,0 @@
1
- // packages/cdd-engine/src-next/contract/__tests__/structure-pin.test.ts
2
- // T9 — the spec §6 structure pin, one case carrying the three complementary
3
- // assertions (each catches a defect the other two would let through):
4
- // (a) retired literals — the seven line-anchored / hand-copied grammars the
5
- // front-matter + home-extractor migration deleted (task-block head,
6
- // task-field marker, task-step bullet, the markerValue payload slice, the
7
- // phase-id hand copy, the design group/item headings) are each zero-hit in
8
- // the parse face source;
9
- // (b) retained primitives — every census hit in contract/doc.ts belongs to
10
- // exactly one of the six preserved primitives, and the owning set equals
11
- // that six-primitive set (set equality over primitive identities, never a
12
- // line-number list — the valuePattern-application primitive has two
13
- // landing sites, so a count pin would drift with any rewrite). The census
14
- // vocabulary includes `.test(` and `.replace(` — the two keywords the
15
- // retired phase-id hand copy and the markerValue slice rode, without which
16
- // those two retirement classes would be invisible to the census;
17
- // (d) the registry side — every `home: "frontmatter"` anchor is a §3.3 key
18
- // (title / doc-type / version / date / status / author / spec /
19
- // parent-program / parent-version / depends-on / base / issues) and carries
20
- // no bullet/heading literal (a bullet-anchored header element would fail
21
- // the key-set membership); `Depends on ref` is zero-hit in the registry.
22
-
23
- import { readFileSync } from "node:fs";
24
- import path from "node:path";
25
- import { fileURLToPath } from "node:url";
26
- import { expect, test } from "vitest";
27
- import { declaredRegistries } from "../declare.ts";
28
-
29
- const HERE = path.dirname(fileURLToPath(import.meta.url));
30
- /** The parse face source — the file the retired/retained census walks. */
31
- const DOC_SRC = readFileSync(path.resolve(HERE, "../doc.ts"), "utf8");
32
- /** The registry source — the `Depends on ref` retirement pin's surface. */
33
- const DECLARE_SRC = readFileSync(path.resolve(HERE, "../declare.ts"), "utf8");
34
-
35
- /** The census vocabulary — every structural-regex / string-primitive hit the pin
36
- * sees. `.test(` and `.replace(` are REQUIRED members: the retired phase-id
37
- * hand copy (`:576`) rode `.test(` and the retired markerValue payload slice
38
- * (`:459`) rode `.replace(` — a vocabulary missing either is blind to that
39
- * retirement class (spec §6 (c)). */
40
- const CENSUS = /RegExp|\.match\(|\.matchAll\(|\.split\(|\.test\(|\.replace\(/;
41
-
42
- /** The six retained primitives — the identities every census hit must resolve
43
- * into (spec §6 (b); `#phaseId`'s valuePattern read is the second landing site
44
- * of the valuePattern-application primitive, per the same row). */
45
- const PRIMITIVES: readonly { id: string; owns: (line: string) => boolean }[] = [
46
- {
47
- id: "heading-rank",
48
- owns: (line) => line.includes("/^(#+)\\s/"),
49
- },
50
- {
51
- id: "table-split",
52
- owns: (line) =>
53
- line.includes('.split("|")') || (line.includes("/^\\|") && line.includes(".test(trimmed)")),
54
- },
55
- {
56
- id: "markdown-link",
57
- owns: (line) =>
58
- line.includes("matchAll(linkPattern)") || line.includes("\\[([^\\]]*)\\]\\(([^)]+)\\)"),
59
- },
60
- {
61
- id: "version-token",
62
- owns: (line) => line.includes("matchAll(tokenPattern)") || line.includes("/v\\d+\\.\\d+/g"),
63
- },
64
- {
65
- id: "graph-edge",
66
- owns: (line) =>
67
- line.includes("match(edgePattern)") || line.includes("P(\\d+(?:\\.\\d+)*)\\s*->"),
68
- },
69
- {
70
- id: "valuePattern-application",
71
- owns: (line) => line.includes(".valuePattern.test(") || line.includes("pattern?.test("),
72
- },
73
- ];
74
-
75
- /** The §3.3 header-key set — the key form a frontmatter-home anchor must take.
76
- * (a future keyed-header addition must extend this set with the registry,
77
- * never split the two declarations.) */
78
- const FRONTMATTER_KEYS = new Set([
79
- "title",
80
- "doc-type",
81
- "version",
82
- "date",
83
- "status",
84
- "author",
85
- "spec",
86
- "parent-program",
87
- "parent-version",
88
- "depends-on",
89
- "base",
90
- "issues",
91
- ]);
92
-
93
- test("spec §6 structure pin — retired grammars zero-hit · retained primitives set-equal · frontmatter-home anchors are keys", () => {
94
- // (a) the retired grammars — each absent from the parse face source.
95
- expect(CENSUS.test(".test("), "the census vocabulary must include `.test(`").toBe(true);
96
- expect(CENSUS.test(".replace("), "the census vocabulary must include `.replace(`").toBe(true);
97
-
98
- const retired = [
99
- ["task-block head grammar", /^### Task \(\d+\):/m],
100
- ["task-field marker grammar", /^-\s+\*\*([A-Za-z ]+)\*\*:\s*(.*)$/m],
101
- ["task-step bullet grammar", /^-\s+(.*)$/m],
102
- ["design group grammar", /^### (\d+)\.\s+(.*)$/m],
103
- ["design item grammar", /^#### (\d+)\.(\d+)\s+(.*)$/m],
104
- ] as const;
105
- for (const [id, pattern] of retired) {
106
- expect(pattern.test(DOC_SRC), `retired ${id} must be zero-hit in doc.ts`).toBe(false);
107
- }
108
- // the two hand-copied strings (spec §6 (a): the markerValue payload slice and
109
- // the `#phaseId` phase-token copy) — the exact retired literal text.
110
- expect(DOC_SRC, "retired markerValue payload slice must be zero-hit").not.toContain(
111
- ".replace(/^:\\s*/",
112
- );
113
- expect(DOC_SRC, "retired phase-id hand copy must be zero-hit").not.toContain(
114
- String.raw`/^P\d+(\.\d+)*$/`,
115
- );
116
-
117
- // (b) the retained primitives — every census hit resolves to exactly one of
118
- // the six, and the owning set equals the six identities.
119
- const hits = DOC_SRC.split("\n").filter((line) => CENSUS.test(line));
120
- const owners = hits.map((line) => {
121
- const matching = PRIMITIVES.filter((primitive) => primitive.owns(line));
122
- if (matching.length !== 1) {
123
- throw new Error(
124
- `census hit must belong to exactly one retained primitive: "${line}" (matches ${matching.length})`,
125
- );
126
- }
127
- return matching[0]!.id;
128
- });
129
- expect(
130
- new Set(owners),
131
- "the owning primitive set must equal the six retained primitives",
132
- ).toEqual(new Set(PRIMITIVES.map((primitive) => primitive.id)));
133
- // 6 primitives / 7 landing points / 7 census lines: the valuePattern-application
134
- // primitive has TWO landing sites (sectionConforms and the rewritten #phaseId —
135
- // the landing point moves from one site to two, spec §6 b), so the remaining
136
- // five primitives hold one census line each. The table-split primitive's
137
- // separator-row guard is no longer inline here — it is the TableExtractor's
138
- // hand-rolled `isSeparatorRow` (the table home's fixed structure rule), so the
139
- // table-split landing is the `split("|")` line alone.
140
- const hitsPerPrimitive = new Map<string, number>();
141
- for (const id of owners) hitsPerPrimitive.set(id, (hitsPerPrimitive.get(id) ?? 0) + 1);
142
- expect(hits.length, "the migrated census line count (6 primitives / 7 landing points)").toBe(7);
143
- // the double-landing primitive — valuePattern-application (sectionConforms +
144
- // the rewritten #phaseId). The remaining five primitives hold one census line
145
- // each.
146
- expect(hitsPerPrimitive.get("valuePattern-application")).toBe(2);
147
- for (const primitive of PRIMITIVES) {
148
- if (primitive.id === "valuePattern-application") continue;
149
- expect(hitsPerPrimitive.get(primitive.id), `${primitive.id} must own one census line`).toBe(1);
150
- }
151
-
152
- // (d) the registry side — the frontmatter-home anchor set is a key set.
153
- const registries = [
154
- declaredRegistries["overall-spec"],
155
- declaredRegistries.plan,
156
- declaredRegistries["phase-spec"],
157
- declaredRegistries["single-spec"],
158
- ];
159
- const frontmatterAnchors: string[] = [];
160
- for (const registry of registries) {
161
- for (const element of registry.elements) {
162
- if (element.home !== "frontmatter") continue;
163
- frontmatterAnchors.push(element.anchor);
164
- expect(
165
- FRONTMATTER_KEYS.has(element.anchor),
166
- `frontmatter-home anchor "${element.anchor}" must be a §3.3 key`,
167
- ).toBe(true);
168
- expect(
169
- element.anchor,
170
- `frontmatter-home anchor "${element.anchor}" must carry no bullet`,
171
- ).not.toMatch(/\*\*/);
172
- expect(
173
- element.anchor,
174
- `frontmatter-home anchor "${element.anchor}" must carry no heading prefix`,
175
- ).not.toMatch(/^#\s/);
176
- }
177
- }
178
- expect(
179
- frontmatterAnchors.length,
180
- "the frontmatter-home anchor set must be non-empty",
181
- ).toBeGreaterThan(0);
182
- // the `Depends on ref` retirement — the retired phase-id reference class (spec §3.3).
183
- expect(DECLARE_SRC, "retired `Depends on ref` must be zero-hit in the registry").not.toContain(
184
- "Depends on ref",
185
- );
186
- });