@oscaner-skills/cdd-engine 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +9 -8
  2. package/README.zh-CN.md +9 -8
  3. package/package.json +15 -22
  4. package/src-next/__tests__/bin.test.ts +128 -0
  5. package/src-next/__tests__/smoke.integration.test.ts +202 -0
  6. package/src-next/__tests__/zero-dep.test.ts +134 -0
  7. package/src-next/bin.ts +61 -0
  8. package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +238 -0
  9. package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +153 -0
  10. package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +173 -0
  11. package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +89 -0
  12. package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +225 -0
  13. package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +155 -0
  14. package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +175 -0
  15. package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +85 -0
  16. package/src-next/contract/__tests__/declare.test.ts +242 -0
  17. package/src-next/contract/__tests__/doc.test.ts +358 -0
  18. package/src-next/contract/__tests__/judge.test.ts +873 -0
  19. package/src-next/contract/__tests__/lint.test.ts +314 -0
  20. package/src-next/contract/__tests__/project.test.ts +419 -0
  21. package/src-next/contract/__tests__/translate.test.ts +96 -0
  22. package/src-next/contract/declare.ts +983 -0
  23. package/src-next/contract/doc.ts +753 -0
  24. package/src-next/contract/invariants.ts +1268 -0
  25. package/src-next/contract/judge.ts +142 -0
  26. package/src-next/contract/lint.ts +275 -0
  27. package/src-next/contract/project.ts +596 -0
  28. package/src-next/contract/skill-anatomy.ts +273 -0
  29. package/src-next/contract/translate.ts +113 -0
  30. package/src-next/face/__tests__/board-view.test.ts +948 -0
  31. package/src-next/face/__tests__/capsule.test.ts +276 -0
  32. package/src-next/face/__tests__/channel-closure.guard.test.ts +102 -0
  33. package/src-next/face/__tests__/cli.test.ts +4643 -0
  34. package/src-next/face/__tests__/face.test.ts +289 -0
  35. package/src-next/face/__tests__/graph-view.test.ts +61 -0
  36. package/src-next/face/__tests__/host.test.ts +24 -0
  37. package/src-next/face/__tests__/negation.ts +6 -0
  38. package/src-next/face/__tests__/projection.test.ts +301 -0
  39. package/src-next/face/__tests__/sync-runner.test.ts +70 -0
  40. package/src-next/face/__tests__/words.guard.test.ts +93 -0
  41. package/src-next/face/artifacts.ts +195 -0
  42. package/src-next/face/board-view.ts +662 -0
  43. package/src-next/face/capsule.ts +149 -0
  44. package/src-next/face/cli.ts +819 -0
  45. package/src-next/face/declare.ts +326 -0
  46. package/src-next/face/gate.ts +170 -0
  47. package/src-next/face/graph-view.ts +74 -0
  48. package/src-next/face/host.ts +326 -0
  49. package/src-next/face/lifecycle.ts +700 -0
  50. package/src-next/face/projection.ts +282 -0
  51. package/src-next/face/route-render.ts +160 -0
  52. package/src-next/face/words.ts +296 -0
  53. package/src-next/infra/__tests__/infra.test.ts +287 -0
  54. package/src-next/infra/config.ts +42 -0
  55. package/src-next/infra/git.ts +39 -0
  56. package/src-next/infra/process.ts +34 -0
  57. package/src-next/infra/runtime.ts +185 -0
  58. package/src-next/infra/workspace.ts +232 -0
  59. package/src-next/render/__tests__/render.test.ts +499 -0
  60. package/src-next/render/__tests__/skeleton.test.ts +466 -0
  61. package/src-next/render/brief.ts +121 -0
  62. package/src-next/render/issue-body.ts +159 -0
  63. package/src-next/render/skeleton.ts +437 -0
  64. package/src-next/render/templates.ts +650 -0
  65. package/src-next/session/__tests__/graph.test.ts +270 -0
  66. package/src-next/session/__tests__/handoff-plane.guard.test.ts +48 -0
  67. package/src-next/session/__tests__/handoff-schema.test.ts +310 -0
  68. package/src-next/session/__tests__/ledger.test.ts +744 -0
  69. package/src-next/session/__tests__/next.test.ts +368 -0
  70. package/src-next/session/__tests__/preflight.test.ts +491 -0
  71. package/src-next/session/__tests__/run.test.ts +1014 -0
  72. package/src-next/session/__tests__/wave-line-phase.guard.test.ts +49 -0
  73. package/src-next/session/__tests__/wave.test.ts +469 -0
  74. package/src-next/session/faces.ts +110 -0
  75. package/src-next/session/graph.ts +411 -0
  76. package/src-next/session/handoff-schema.ts +373 -0
  77. package/src-next/session/ledger.ts +1004 -0
  78. package/src-next/session/next.ts +192 -0
  79. package/src-next/session/preflight.ts +240 -0
  80. package/src-next/session/run.ts +606 -0
  81. package/src-next/session/state.ts +30 -0
  82. package/src-next/session/wave.ts +139 -0
  83. package/templates/report/issue-body.json +18 -20
  84. package/dist/chunks/branch.mjs +0 -480
  85. package/dist/chunks/docs.mjs +0 -253
  86. package/dist/chunks/task.mjs +0 -913
  87. package/dist/cli.mjs +0 -5457
  88. package/dist/documents/schema/add-phase-protocol.json +0 -126
  89. package/dist/documents/schema/overall.json +0 -361
  90. package/dist/documents/schema/phase-spec.json +0 -145
  91. package/dist/documents/schema/plan.json +0 -191
  92. package/dist/documents/schema/skill-anatomy.json +0 -233
  93. package/dist/resources/harness-registry.json +0 -49
  94. package/dist/shared/cdd-engine.liioziig.mjs +0 -184
  95. package/templates/engine-config.json +0 -302
  96. package/templates/schema/cache-profile-schema.json +0 -23
  97. package/templates/schema/docs-handoff-schema.json +0 -129
  98. package/templates/schema/task-handoff-schema.json +0 -332
  99. package/templates/template-contract.json +0 -231
@@ -0,0 +1,419 @@
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
+ });
@@ -0,0 +1,96 @@
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
+ });