@oscaner-skills/cdd-engine 2.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 (127) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +2 -2
  3. package/{src-next/bin.ts → dist/bin.js} +18 -21
  4. package/dist/contract/declare.js +998 -0
  5. package/dist/contract/doc.js +565 -0
  6. package/dist/contract/frontmatter.js +209 -0
  7. package/dist/contract/home-extractors.js +379 -0
  8. package/dist/contract/invariants.js +1030 -0
  9. package/dist/contract/judge.js +109 -0
  10. package/dist/contract/lint.js +206 -0
  11. package/dist/contract/project.js +371 -0
  12. package/dist/contract/skill-anatomy.js +156 -0
  13. package/dist/contract/translate.js +85 -0
  14. package/dist/face/artifacts.js +189 -0
  15. package/dist/face/board-view.js +522 -0
  16. package/dist/face/capsule.js +141 -0
  17. package/dist/face/cli.js +891 -0
  18. package/dist/face/declare.js +241 -0
  19. package/dist/face/gate.js +158 -0
  20. package/dist/face/graph-view.js +66 -0
  21. package/dist/face/host.js +211 -0
  22. package/dist/face/lifecycle.js +603 -0
  23. package/dist/face/preview.js +136 -0
  24. package/dist/face/projection.js +259 -0
  25. package/dist/face/route-render.js +162 -0
  26. package/dist/face/termination.js +482 -0
  27. package/dist/face/words.js +220 -0
  28. package/{src-next/infra/config.ts → dist/infra/config.js} +19 -24
  29. package/dist/infra/doc-roots.js +19 -0
  30. package/dist/infra/git.js +37 -0
  31. package/dist/infra/process.js +22 -0
  32. package/dist/infra/root.js +62 -0
  33. package/dist/infra/runtime.js +85 -0
  34. package/dist/infra/workspace.js +276 -0
  35. package/dist/render/brief.js +82 -0
  36. package/dist/render/issue-body.js +129 -0
  37. package/dist/render/skeleton.js +434 -0
  38. package/dist/render/templates.js +520 -0
  39. package/dist/session/faces.js +38 -0
  40. package/dist/session/graph.js +309 -0
  41. package/dist/session/handoff-schema.js +295 -0
  42. package/dist/session/ledger.js +762 -0
  43. package/dist/session/next.js +211 -0
  44. package/dist/session/preflight.js +194 -0
  45. package/dist/session/round-naming.js +73 -0
  46. package/dist/session/run.js +441 -0
  47. package/dist/session/state.js +8 -0
  48. package/dist/session/wave.js +92 -0
  49. package/package.json +8 -7
  50. package/templates/report/issue-body.json +0 -46
  51. package/src-next/__tests__/bin.test.ts +0 -128
  52. package/src-next/__tests__/smoke.integration.test.ts +0 -202
  53. package/src-next/__tests__/zero-dep.test.ts +0 -134
  54. package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +0 -238
  55. package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +0 -153
  56. package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +0 -173
  57. package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +0 -89
  58. package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +0 -225
  59. package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +0 -155
  60. package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +0 -175
  61. package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +0 -85
  62. package/src-next/contract/__tests__/declare.test.ts +0 -242
  63. package/src-next/contract/__tests__/doc.test.ts +0 -358
  64. package/src-next/contract/__tests__/judge.test.ts +0 -873
  65. package/src-next/contract/__tests__/lint.test.ts +0 -314
  66. package/src-next/contract/__tests__/project.test.ts +0 -419
  67. package/src-next/contract/__tests__/translate.test.ts +0 -96
  68. package/src-next/contract/declare.ts +0 -983
  69. package/src-next/contract/doc.ts +0 -753
  70. package/src-next/contract/invariants.ts +0 -1268
  71. package/src-next/contract/judge.ts +0 -142
  72. package/src-next/contract/lint.ts +0 -275
  73. package/src-next/contract/project.ts +0 -596
  74. package/src-next/contract/skill-anatomy.ts +0 -273
  75. package/src-next/contract/translate.ts +0 -113
  76. package/src-next/face/__tests__/board-view.test.ts +0 -948
  77. package/src-next/face/__tests__/capsule.test.ts +0 -276
  78. package/src-next/face/__tests__/channel-closure.guard.test.ts +0 -102
  79. package/src-next/face/__tests__/cli.test.ts +0 -4643
  80. package/src-next/face/__tests__/face.test.ts +0 -289
  81. package/src-next/face/__tests__/graph-view.test.ts +0 -61
  82. package/src-next/face/__tests__/host.test.ts +0 -24
  83. package/src-next/face/__tests__/negation.ts +0 -6
  84. package/src-next/face/__tests__/projection.test.ts +0 -301
  85. package/src-next/face/__tests__/sync-runner.test.ts +0 -70
  86. package/src-next/face/__tests__/words.guard.test.ts +0 -93
  87. package/src-next/face/artifacts.ts +0 -195
  88. package/src-next/face/board-view.ts +0 -662
  89. package/src-next/face/capsule.ts +0 -149
  90. package/src-next/face/cli.ts +0 -819
  91. package/src-next/face/declare.ts +0 -326
  92. package/src-next/face/gate.ts +0 -170
  93. package/src-next/face/graph-view.ts +0 -74
  94. package/src-next/face/host.ts +0 -326
  95. package/src-next/face/lifecycle.ts +0 -700
  96. package/src-next/face/projection.ts +0 -282
  97. package/src-next/face/route-render.ts +0 -160
  98. package/src-next/face/words.ts +0 -296
  99. package/src-next/infra/__tests__/infra.test.ts +0 -287
  100. package/src-next/infra/git.ts +0 -39
  101. package/src-next/infra/process.ts +0 -34
  102. package/src-next/infra/runtime.ts +0 -185
  103. package/src-next/infra/workspace.ts +0 -232
  104. package/src-next/render/__tests__/render.test.ts +0 -499
  105. package/src-next/render/__tests__/skeleton.test.ts +0 -466
  106. package/src-next/render/brief.ts +0 -121
  107. package/src-next/render/issue-body.ts +0 -159
  108. package/src-next/render/skeleton.ts +0 -437
  109. package/src-next/render/templates.ts +0 -650
  110. package/src-next/session/__tests__/graph.test.ts +0 -270
  111. package/src-next/session/__tests__/handoff-plane.guard.test.ts +0 -48
  112. package/src-next/session/__tests__/handoff-schema.test.ts +0 -310
  113. package/src-next/session/__tests__/ledger.test.ts +0 -744
  114. package/src-next/session/__tests__/next.test.ts +0 -368
  115. package/src-next/session/__tests__/preflight.test.ts +0 -491
  116. package/src-next/session/__tests__/run.test.ts +0 -1014
  117. package/src-next/session/__tests__/wave-line-phase.guard.test.ts +0 -49
  118. package/src-next/session/__tests__/wave.test.ts +0 -469
  119. package/src-next/session/faces.ts +0 -110
  120. package/src-next/session/graph.ts +0 -411
  121. package/src-next/session/handoff-schema.ts +0 -373
  122. package/src-next/session/ledger.ts +0 -1004
  123. package/src-next/session/next.ts +0 -192
  124. package/src-next/session/preflight.ts +0 -240
  125. package/src-next/session/run.ts +0 -606
  126. package/src-next/session/state.ts +0 -30
  127. package/src-next/session/wave.ts +0 -139
@@ -1,419 +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 declared element's slice parses its own anchor;
14
- // · Projector.tokens / Projector.reference — both surfaces correspond 1:1
15
- // with the registered elements.
16
- // Every projection is derived: the registered declaration and known-good anchor
17
- // literals (never module output) are the independent sources of truth, so a
18
- // hand-written copy or a derivation drift fails a byte or equality assertion.
19
-
20
- import { describe, expect, it } from "vitest";
21
- import type { ElementRegistry } from "../declare.ts";
22
- import { declaredRegistries } from "../declare.ts";
23
- import { Projector } from "../project.ts";
24
-
25
- const DOC_KEYS = ["overall-spec", "plan", "phase-spec", "single-spec"] as const;
26
- const REGISTRIES = [
27
- declaredRegistries["overall-spec"],
28
- declaredRegistries.plan,
29
- declaredRegistries["phase-spec"],
30
- declaredRegistries["single-spec"],
31
- ] as const satisfies readonly ElementRegistry[];
32
-
33
- /** The shared projection carrier the suite derives every surface from. */
34
- const PROJECTOR = new Projector(declaredRegistries);
35
-
36
- // The exact serialization the snapshots pin: projection JSON with two-space
37
- // indentation and exactly one trailing newline (the package's EOF-newline rule).
38
- const serialize = (value: unknown): string => `${JSON.stringify(value, null, 2)}\n`;
39
-
40
- const REF_KINDS = new Set([
41
- "none",
42
- "version-lineage",
43
- "markdown-link",
44
- "phase-id",
45
- "issue-ref",
46
- "spec-ref",
47
- "parent-program",
48
- "task-id",
49
- ]);
50
-
51
- describe("schema projection (Projector.schema)", () => {
52
- const schemas = PROJECTOR.schema();
53
-
54
- it("emits a JSON-stringify-able schema per doc type that round-trips byte-identically", () => {
55
- for (const [index, registry] of REGISTRIES.entries()) {
56
- const doc = schemas[DOC_KEYS[index]];
57
- expect(() => JSON.stringify(doc), `${registry.docType} stringify`).not.toThrow();
58
- expect(JSON.parse(serialize(doc))).toEqual(doc);
59
- }
60
- });
61
-
62
- it("keys its properties one-per-declared-element, in registry order", () => {
63
- for (const [index, registry] of REGISTRIES.entries()) {
64
- const doc = schemas[DOC_KEYS[index]];
65
- expect(Object.keys(doc.properties)).toEqual(
66
- registry.elements.map((element) => element.anchor),
67
- );
68
- }
69
- });
70
-
71
- it("carries the property description (presence · home · ref) and the declared value pattern", () => {
72
- for (const [index, registry] of REGISTRIES.entries()) {
73
- const doc = schemas[DOC_KEYS[index]];
74
- for (const element of registry.elements) {
75
- const property = doc.properties[element.anchor];
76
- expect(property.description).toBe(
77
- `presence: ${element.presence} · home: ${element.home} · ref: ${element.refKind}`,
78
- );
79
- expect(property.pattern).toBe(element.valuePattern);
80
- }
81
- }
82
- });
83
-
84
- it("derives the required set from the required-presence elements, in registry order", () => {
85
- for (const [index, registry] of REGISTRIES.entries()) {
86
- const doc = schemas[DOC_KEYS[index]];
87
- expect(doc.required).toEqual(
88
- registry.elements
89
- .filter((element) => element.presence === "required")
90
- .map((element) => element.anchor),
91
- );
92
- }
93
- });
94
-
95
- it("pins the schema bytes from the first version (byte snapshots)", async () => {
96
- for (const key of DOC_KEYS) {
97
- await expect(serialize(schemas[key])).toMatchFileSnapshot(
98
- `__snapshots__/project.schema.${key}.snap`,
99
- );
100
- }
101
- });
102
- });
103
-
104
- describe("shape projection (Projector.shape)", () => {
105
- const shapes = PROJECTOR.shape();
106
-
107
- it("corresponds 1:1 with the registered elements (a bijection over the registry rows)", () => {
108
- for (const [index, registry] of REGISTRIES.entries()) {
109
- const doc = shapes[DOC_KEYS[index]];
110
- const flat = doc.structure.flatMap((group) => group.elements);
111
- // One shape element per registered element.
112
- expect(flat).toHaveLength(registry.elements.length);
113
- const byAnchor = new Map(flat.map((element) => [element.anchor, element]));
114
- for (const element of registry.elements) {
115
- const projected = byAnchor.get(element.anchor);
116
- expect(projected, `${registry.docType}:${element.anchor}`).toBeDefined();
117
- expect(projected!.presence).toBe(element.presence);
118
- expect(projected!.refKind).toBe(element.refKind);
119
- }
120
- // The shape carries exactly the registry's anchors — no extra, none missing.
121
- expect(flat.map((element) => element.anchor).sort()).toEqual(
122
- registry.elements.map((element) => element.anchor).sort(),
123
- );
124
- }
125
- });
126
-
127
- it("reads as the section skeleton: non-empty groups in first home-occurrence order", () => {
128
- for (const [index, registry] of REGISTRIES.entries()) {
129
- const doc = shapes[DOC_KEYS[index]];
130
- const expectedGroups: string[] = [];
131
- const seen = new Set<string>();
132
- for (const element of registry.elements) {
133
- if (!seen.has(element.home)) {
134
- seen.add(element.home);
135
- expectedGroups.push(element.home);
136
- }
137
- }
138
- expect(doc.structure.map((group) => group.home)).toEqual(expectedGroups);
139
- expect(doc.structure).toHaveLength(seen.size);
140
- for (const group of doc.structure) {
141
- expect(group.elements.length, `${group.home} group`).toBeGreaterThan(0);
142
- // Each group collects its home's rows in registry order.
143
- expect(group.elements.map((element) => element.anchor)).toEqual(
144
- registry.elements
145
- .filter((element) => element.home === group.home)
146
- .map((element) => element.anchor),
147
- );
148
- }
149
- }
150
- });
151
-
152
- it("pins the shape bytes from the first version (byte snapshots)", async () => {
153
- for (const key of DOC_KEYS) {
154
- await expect(serialize(shapes[key])).toMatchFileSnapshot(
155
- `__snapshots__/project.shape.${key}.snap`,
156
- );
157
- }
158
- });
159
- });
160
-
161
- describe("slices projection (Projector.slices)", () => {
162
- const slices = PROJECTOR.slices();
163
-
164
- it("gives every declared element a slice that parses its own anchor", () => {
165
- for (const [index, registry] of REGISTRIES.entries()) {
166
- const doc = slices[DOC_KEYS[index]];
167
- expect(doc.slices).toHaveLength(registry.elements.length);
168
- for (let i = 0; i < registry.elements.length; i++) {
169
- const element = registry.elements[i];
170
- const slice = doc.slices[i];
171
- expect(slice.anchor).toBe(element.anchor);
172
- expect(slice.anchorPattern, `${registry.docType}:${element.anchor}`).toBeInstanceOf(RegExp);
173
- // The slice parses its anchor — the escaped anchor literal matches the anchor itself.
174
- expect(
175
- slice.anchorPattern.test(element.anchor),
176
- `${registry.docType}:${element.anchor} anchorPattern`,
177
- ).toBe(true);
178
- }
179
- }
180
- });
181
-
182
- it("derives the anchor pattern from the anchor literal (known-good escapes)", () => {
183
- const overall = slices["overall-spec"];
184
- // No metacharacters: the anchor is its own pattern.
185
- expect(overall.slices[0].anchorPattern.source).toBe("# Title");
186
- // `**Version**` — every `*` escaped.
187
- expect(overall.slices[1].anchorPattern.source).toBe("\\*\\*Version\\*\\*");
188
- // `#### [MFRBEN] group` — brackets escaped (the anchor is the English canonical;
189
- // the legacy zh leaf matches through the judge's canonicalize view, never here).
190
- const mfrben = overall.slices.find((slice) => slice.anchor === "#### [MFRBEN] group")!;
191
- expect(mfrben.anchorPattern.source).toBe("#### \\[MFRBEN\\] group");
192
- });
193
-
194
- it("derives the value slice from the declared value pattern", () => {
195
- for (const [index, registry] of REGISTRIES.entries()) {
196
- const doc = slices[DOC_KEYS[index]];
197
- for (let i = 0; i < registry.elements.length; i++) {
198
- const element = registry.elements[i];
199
- const slice = doc.slices[i];
200
- expect(slice.valuePattern, `${registry.docType}:${element.anchor}`).toBeInstanceOf(RegExp);
201
- if (element.valuePattern !== undefined) {
202
- expect(slice.valuePattern?.source).toBe(element.valuePattern);
203
- }
204
- }
205
- }
206
- });
207
- });
208
-
209
- describe("tokens projection (Projector.tokens)", () => {
210
- const tokens = PROJECTOR.tokens();
211
-
212
- it("corresponds 1:1 with the registered elements", () => {
213
- for (const [index, registry] of REGISTRIES.entries()) {
214
- const doc = tokens[DOC_KEYS[index]];
215
- expect(doc.tokens).toHaveLength(registry.elements.length);
216
- for (let i = 0; i < registry.elements.length; i++) {
217
- const element = registry.elements[i];
218
- const token = doc.tokens[i];
219
- expect(token.anchor).toBe(element.anchor);
220
- expect(token.presence).toBe(element.presence);
221
- expect(token.home).toBe(element.home);
222
- expect(token.refKind).toBe(element.refKind);
223
- }
224
- }
225
- });
226
-
227
- it("keeps the vocabulary exactly the registry's anchor set", () => {
228
- for (const [index, registry] of REGISTRIES.entries()) {
229
- const doc = tokens[DOC_KEYS[index]];
230
- const anchors = doc.tokens.map((token) => token.anchor);
231
- expect(new Set(anchors).size).toBe(anchors.length);
232
- expect(new Set(anchors)).toEqual(new Set(registry.elements.map((element) => element.anchor)));
233
- }
234
- });
235
- });
236
-
237
- describe("reference projection (Projector.reference)", () => {
238
- const reference = PROJECTOR.reference();
239
-
240
- it("corresponds 1:1 with the registered elements, carrying refKind and value pattern", () => {
241
- for (const [index, registry] of REGISTRIES.entries()) {
242
- const doc = reference[DOC_KEYS[index]];
243
- expect(doc.entries).toHaveLength(registry.elements.length);
244
- for (let i = 0; i < registry.elements.length; i++) {
245
- const element = registry.elements[i];
246
- const entry = doc.entries[i];
247
- expect(entry.anchor).toBe(element.anchor);
248
- expect(entry.refKind).toBe(element.refKind);
249
- if (element.valuePattern !== undefined) {
250
- expect(entry.valuePattern).toBe(element.valuePattern);
251
- }
252
- }
253
- }
254
- });
255
-
256
- it("keeps the reference vocabulary inside the declared ref kinds", () => {
257
- for (const [index, registry] of REGISTRIES.entries()) {
258
- const doc = reference[DOC_KEYS[index]];
259
- for (const entry of doc.entries) {
260
- expect(REF_KINDS.has(entry.refKind), `${registry.docType}:${entry.anchor}`).toBe(true);
261
- }
262
- }
263
- });
264
- });
265
-
266
- describe("skeleton projection (Projector.skeleton)", () => {
267
- const skeletons = PROJECTOR.skeleton();
268
-
269
- it("keys the projection record by the DocKey domain and carries each doc's type identity", () => {
270
- // The skeleton record rides the projection DocKey domain (overall-spec | plan |
271
- // phase-spec | single-spec) — the same single spelling as the DocType literals (spec §5.2).
272
- expect(Object.keys(skeletons)).toEqual([...DOC_KEYS]);
273
- expect(skeletons["overall-spec"].docType).toBe("overall-spec");
274
- expect(skeletons.plan.docType).toBe("plan");
275
- expect(skeletons["phase-spec"].docType).toBe("phase-spec");
276
- expect(skeletons["single-spec"].docType).toBe("single-spec");
277
- });
278
-
279
- it("projects exactly the required elements — optional/conditional generate zero slots", () => {
280
- for (const [index, registry] of REGISTRIES.entries()) {
281
- const doc = skeletons[DOC_KEYS[index]];
282
- // The projected slot SET equals the required element set of the live
283
- // registry (the shape's home-group order, not the flat registry order,
284
- // is the projection's sequence — asserted separately below).
285
- expect(new Set(doc.slots.map((slot) => slot.anchor))).toEqual(
286
- new Set(
287
- registry.elements
288
- .filter((element) => element.presence === "required")
289
- .map((element) => element.anchor),
290
- ),
291
- );
292
- expect(doc.slots.length).toBe(
293
- registry.elements.filter((element) => element.presence === "required").length,
294
- );
295
- for (const slot of doc.slots) expect(slot.presence).toBe("required");
296
- }
297
- });
298
-
299
- it("keeps the shape home-group order — the slot homes run the shape's group sequence", () => {
300
- for (const [index] of REGISTRIES.entries()) {
301
- const doc = skeletons[DOC_KEYS[index]];
302
- const shape = PROJECTOR.shape()[DOC_KEYS[index]];
303
- const expectedHomes = shape.structure.flatMap((group) =>
304
- group.elements.filter((element) => element.presence === "required").map(() => group.home),
305
- );
306
- expect(doc.slots.map((slot) => slot.home)).toEqual(expectedHomes);
307
- }
308
- });
309
-
310
- it("classifies the parent-program / spec-ref link anchors as link slots", () => {
311
- for (const [index, registry] of REGISTRIES.entries()) {
312
- const doc = skeletons[DOC_KEYS[index]];
313
- const linkSlots = doc.slots.filter((slot) => slot.slot === "link");
314
- for (const slot of linkSlots) {
315
- const element = registry.elements.find((e) => e.anchor === slot.anchor);
316
- // the link class is exactly the header parent-program / spec-ref anchors
317
- // (never the enum-typed table cells that also mention spec/ref)
318
- expect(element?.home).toBe("header");
319
- expect(["parent-program", "spec-ref"]).toContain(slot.refKind);
320
- }
321
- }
322
- expect(skeletons.plan.slots.find((s) => s.anchor === "**Spec:**")?.slot).toBe("link");
323
- expect(skeletons.plan.slots.find((s) => s.anchor === "**Parent program**")?.slot).toBe("link");
324
- expect(skeletons["phase-spec"].slots.find((s) => s.anchor === "**Parent program**")?.slot).toBe(
325
- "link",
326
- );
327
- });
328
-
329
- it("classifies the digit-family headings of the task-block / design-body surfaces as numeric-heading", () => {
330
- for (const [index] of REGISTRIES.entries()) {
331
- const doc = skeletons[DOC_KEYS[index]];
332
- for (const slot of doc.slots) {
333
- if (
334
- ![
335
- "### Task N:",
336
- "Task id token",
337
- "### N. group heading",
338
- "#### N.M item heading",
339
- ].includes(slot.anchor)
340
- )
341
- continue;
342
- expect(slot.slot, `${DOC_KEYS[index]}:${slot.anchor}`).toBe("numeric-heading");
343
- }
344
- }
345
- });
346
-
347
- it("classifies the enum domain (**Status**) and the graph rows as generator-truth", () => {
348
- for (const [index] of REGISTRIES.entries()) {
349
- const doc = skeletons[DOC_KEYS[index]];
350
- const status = doc.slots.find((slot) => slot.anchor === "**Status**");
351
- if (status !== undefined) expect(status.slot).toBe("generator-truth");
352
- for (const anchor of ["Hard edge", "Graph legend"]) {
353
- const slot = doc.slots.find((s) => s.anchor === anchor);
354
- if (slot !== undefined) {
355
- expect(slot.slot, `${DOC_KEYS[index]}:${anchor}`).toBe("generator-truth");
356
- expect(slot.home).toBe("graph");
357
- }
358
- }
359
- }
360
- });
361
-
362
- it("classifies the version/date rows and the table tokens as scaffold", () => {
363
- for (const [index] of REGISTRIES.entries()) {
364
- const doc = skeletons[DOC_KEYS[index]];
365
- for (const anchor of [
366
- "**Version**",
367
- "Version token",
368
- "Change history date",
369
- "Phase id token",
370
- ]) {
371
- const slot = doc.slots.find((s) => s.anchor === anchor);
372
- if (slot !== undefined) expect(slot.slot, `${DOC_KEYS[index]}:${anchor}`).toBe("scaffold");
373
- }
374
- }
375
- });
376
-
377
- it("keeps the content slots free of fully-anchored enum and graph elements", () => {
378
- // the enum-domain + graph rows the generator-truth class owns — none of them
379
- // may ride the content class (a content slot is a free-text `:::fill` landing
380
- // position, never a judged enum/graph value)
381
- const truthAnchors = [
382
- "**Status**",
383
- "Issue ref cell",
384
- "Implementation plan cell",
385
- "Design spec cell",
386
- "Hard edge",
387
- "Graph legend",
388
- ];
389
- for (const [index] of REGISTRIES.entries()) {
390
- const doc = skeletons[DOC_KEYS[index]];
391
- for (const slot of doc.slots.filter((s) => s.slot === "content")) {
392
- expect(truthAnchors, `${DOC_KEYS[index]}:${slot.anchor}`).not.toContain(slot.anchor);
393
- }
394
- }
395
- });
396
- });
397
-
398
- describe("Projector.registries — the composed six-projection surface", () => {
399
- it("returns all six projections derived from the individual faces", () => {
400
- const projected = PROJECTOR.registries();
401
- expect(projected.shape).toEqual(PROJECTOR.shape());
402
- expect(projected.schema).toEqual(PROJECTOR.schema());
403
- expect(projected.slices).toEqual(PROJECTOR.slices());
404
- expect(projected.tokens).toEqual(PROJECTOR.tokens());
405
- expect(projected.reference).toEqual(PROJECTOR.reference());
406
- expect(projected.skeleton).toEqual(PROJECTOR.skeleton());
407
- });
408
-
409
- it("carries each doc type's declaration identity (docType field)", () => {
410
- const projected = PROJECTOR.registries();
411
- expect(projected.shape["overall-spec"].docType).toBe("overall-spec");
412
- expect(projected.schema.plan.docType).toBe("plan");
413
- expect(projected.tokens["phase-spec"].docType).toBe("phase-spec");
414
- expect(projected.skeleton["overall-spec"].docType).toBe("overall-spec");
415
- expect(projected.skeleton.plan.docType).toBe("plan");
416
- expect(projected.skeleton["phase-spec"].docType).toBe("phase-spec");
417
- expect(projected.skeleton["single-spec"].docType).toBe("single-spec");
418
- });
419
- });
@@ -1,96 +0,0 @@
1
- // packages/cdd-engine/src-next/contract/__tests__/translate.test.ts
2
- // T19 Translator suite — the P7 bidirectional translation layer (design spec §1.2
3
- // locale face):
4
- // · canonicalize — the recognition face: every registered Chinese alias span maps
5
- // to its canonical English form (a full-line alias is the single-token case), an
6
- // already-canonical / unregistered line passes through unchanged (identity) — the
7
- // positive + identity + negative cases, the P7 charter rows, and the
8
- // compound-word boundary;
9
- // · localize — the rendering face: the canonical token renders at the requested
10
- // locale (en = identity · zh = the row's alias), an unknown token / locale / a
11
- // row without the locale's alias is null;
12
- // · the bidirectional property — canonicalize(localize(token, zh)) recovers the
13
- // canonical token, over every row of the word table;
14
- // · the machine-face immunity — the capsule machine words (status · next: ·
15
- // CDD_BLOCKED:) are NOT locale rows: canonicalize passes them through unchanged
16
- // and localize cannot render them (the machine surface is English-constant,
17
- // never localized).
18
- // The data all rides the word table (Words — the single source); the translator
19
- // itself holds zero literal word data.
20
-
21
- import { describe, expect, it } from "vitest";
22
- import { Words } from "../../face/words.ts";
23
- import { Translator } from "../translate.ts";
24
-
25
- const words = new Words();
26
- const translator = new Translator(words);
27
-
28
- describe("Translator — the bidirectional translation layer", () => {
29
- it("canonicalize — a Chinese alias span maps to the canonical English token (the recognition face)", () => {
30
- expect(translator.canonicalize("## 场景")).toBe("## Context");
31
- expect(translator.canonicalize("## 问题")).toBe("## Problem");
32
- expect(translator.canonicalize("## 差距")).toBe("## Gap");
33
- expect(translator.canonicalize("## 建议方向")).toBe("## Suggested direction");
34
- expect(translator.canonicalize("## 建议修复")).toBe("## Suggested fix");
35
- });
36
-
37
- it("canonicalize — the charter rows: a registered Chinese marker maps to its canonical form", () => {
38
- expect(translator.canonicalize("M 组")).toBe("M group");
39
- expect(translator.canonicalize("#### 上游先例背书")).toBe("#### Upstream Endorsements");
40
- });
41
-
42
- it("canonicalize — an already-canonical line passes through (identity)", () => {
43
- expect(translator.canonicalize("## Context")).toBe("## Context");
44
- expect(translator.canonicalize("## Suggested fix")).toBe("## Suggested fix");
45
- });
46
-
47
- it("canonicalize — unregistered text passes through unchanged (no null face)", () => {
48
- expect(translator.canonicalize("## 未知")).toBe("## 未知");
49
- expect(translator.canonicalize("bogus")).toBe("bogus");
50
- expect(translator.canonicalize("")).toBe("");
51
- });
52
-
53
- it("canonicalize — the compound boundary: only the registered span is replaced, neighbors untouched", () => {
54
- // 件 is unregistered — the single-character 组 alias replaces only its own span
55
- expect(translator.canonicalize("组件")).toBe("group件");
56
- // trailing unregistered prose (the parenthetical) passes through verbatim
57
- expect(translator.canonicalize("M 组(skill-ref 映射,M1–M4 全关)")).toBe(
58
- "M group(skill-ref 映射,M1–M4 全关)",
59
- );
60
- });
61
-
62
- it("localize — the canonical token renders at the requested locale (en identity · zh alias)", () => {
63
- expect(translator.localize("## Context", "en")).toBe("## Context");
64
- expect(translator.localize("## Problem", "zh")).toBe("## 问题");
65
- expect(translator.localize("## Impact", "zh")).toBe("## 影响");
66
- expect(translator.localize("## Suggested direction", "zh")).toBe("## 建议方向");
67
- });
68
-
69
- it("localize — an unknown token / locale is null (the negative face)", () => {
70
- expect(translator.localize("bogus", "zh")).toBeNull();
71
- expect(translator.localize("## Context", "fr")).toBeNull();
72
- expect(translator.localize("", "zh")).toBeNull();
73
- });
74
-
75
- it("the round trip — canonicalize(localize(token, zh)) recovers the canonical token over every row", () => {
76
- for (const row of words.localeRows()) {
77
- const localized = translator.localize(row.en, "zh");
78
- expect(localized).not.toBeNull();
79
- expect(translator.canonicalize(localized!)).toBe(row.en);
80
- }
81
- });
82
-
83
- it("the machine face is not the translation surface — the capsule words carry zero aliases", () => {
84
- // status / next: / CDD_BLOCKED: / the status vocabulary are the capsule machine
85
- // channel words — English-constant, never human-readable rendering words. The
86
- // Translator over the word table holds no alias for them — canonicalize passes
87
- // them through unchanged, localize cannot render them.
88
- expect(translator.canonicalize(words.station("next"))).toBe("next:");
89
- expect(translator.canonicalize(words.station("blocked"))).toBe("CDD_BLOCKED:");
90
- expect(translator.canonicalize(words.station("warn"))).toBe("CDD_WARN:");
91
- expect(translator.localize(words.station("next"), "zh")).toBeNull();
92
- expect(translator.localize("status", "zh")).toBeNull();
93
- expect(translator.localize(words.statusVocab()[0], "zh")).toBeNull();
94
- expect(translator.localize(words.statusVocab()[1], "zh")).toBeNull();
95
- });
96
- });