@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,301 +0,0 @@
1
- // packages/cdd-engine/src-next/face/__tests__/projection.test.ts
2
- // T2 — the CommandTreeBuilder projection suite (spec §2.1/§4): the constructor
3
- // assembles the whole command tree from the declare single surface — the six
4
- // commands + the nested leaves, the binding rules (command keys → .option() /
5
- // .requiredOption() · positionals → .argument() · bool rows single-spelling · the
6
- // program scope merged into every node · the built-in help row un-projected), the
7
- // value-domain validation through the commander pipeline (parseArg →
8
- // commander.invalidArgument · §4.1) and the conditional-required preAction hook
9
- // (REQUIRED_GROUPS · §4.2). Instance-level assertions — the projections are read
10
- // off the assembled program, never a re-declared expectation list.
11
-
12
- import { readFileSync } from "node:fs";
13
- import type { Command } from "commander";
14
- import { describe, expect, it } from "vitest";
15
-
16
- import type { ChannelArgRow } from "../declare.ts";
17
- import { VALUE_SHAPES } from "../declare.ts";
18
- import { CommandTreeBuilder } from "../projection.ts";
19
- import { negatedOf } from "./negation.ts";
20
-
21
- /** The command node of one verb. */
22
- const commandOf = (program: Command, verb: string): Command => {
23
- const node = program.commands.find((command) => command.name() === verb);
24
- expect(node, `the ${verb} command node exists`).toBeDefined();
25
- return node!;
26
- };
27
-
28
- /** The leaf node of one parent command. */
29
- const leafOf = (parent: Command, name: string): Command => {
30
- const node = parent.commands.find((command) => command.name() === name);
31
- expect(node, `the ${name} leaf exists`).toBeDefined();
32
- return node!;
33
- };
34
-
35
- /** The code + message of the commander error `fn` rejects with (the builder's
36
- * program carries the throwing exitOverride — the composed parse rejects, never
37
- * process.exit). */
38
- const commanderError = (fn: () => void): { code: string; message: string } => {
39
- let raw: unknown = null;
40
- try {
41
- fn();
42
- } catch (caught) {
43
- raw = caught;
44
- }
45
- const error = raw as { code?: unknown; message?: unknown };
46
- expect(error, "expected the commander pipeline to reject").toBeTruthy();
47
- expect(typeof error.code, "the rejection carries a commander error code").toBe("string");
48
- return {
49
- code: error.code as string,
50
- message: typeof error.message === "string" ? error.message : "",
51
- };
52
- };
53
-
54
- describe("CommandTreeBuilder — the declaration projection (the constructor is the assembly)", () => {
55
- it("assembles the seven subcommand nodes from the CLI_COMMANDS rows, in the declared order", () => {
56
- const { program } = new CommandTreeBuilder();
57
- expect(program.commands.map((command) => command.name())).toEqual([
58
- "implement",
59
- "review",
60
- "fix",
61
- "base",
62
- "schema",
63
- "issue",
64
- "board",
65
- ]);
66
- });
67
-
68
- it("projects the review surface — every declared key option, --type as a requiredOption", () => {
69
- const { program } = new CommandTreeBuilder();
70
- const review = commandOf(program, "review");
71
- for (const key of ["--type", "--tasks", "--plan", "--spec", "--round", "--root"]) {
72
- expect(
73
- review.options.some((option) => option.flags.startsWith(key)),
74
- `review declares ${key}`,
75
- ).toBe(true);
76
- }
77
- // the branch range flags retired with the commit-sha surface (P7)
78
- expect(review.options.some((option) => option.flags.startsWith("--base"))).toBe(false);
79
- expect(review.options.some((option) => option.flags.startsWith("--head"))).toBe(false);
80
- const typeOption = review.options.find((option) => option.attributeName() === "type");
81
- expect(typeOption?.mandatory, "--type rides .requiredOption()").toBe(true);
82
- const tasksOption = review.options.find((option) => option.attributeName() === "tasks");
83
- expect(tasksOption?.mandatory, "--tasks stays a plain .option()").toBe(false);
84
- });
85
-
86
- it("registers the program scope --dry-run on the program and on every node — the positive spelling only (the negated form is never registered)", () => {
87
- const { program } = new CommandTreeBuilder();
88
- // the retired negated spelling is composed via the shared synthesizer —
89
- // the literal token never appears in the tree (the zero-consumption pin)
90
- expect(program.options.some((option) => option.flags === "--dry-run")).toBe(true);
91
- expect(program.options.some((option) => option.flags === negatedOf("--dry-run"))).toBe(false);
92
- const nodes = [program, ...program.commands, ...program.commands.flatMap((c) => c.commands)];
93
- for (const node of nodes) {
94
- expect(
95
- node.options.some((option) => option.flags === "--dry-run"),
96
- `the ${node.name()} node is usable with --dry-run`,
97
- ).toBe(true);
98
- }
99
- });
100
-
101
- it("never re-registers the built-in -h/--help (the help channel row is not projected)", () => {
102
- const { program } = new CommandTreeBuilder();
103
- const nodes = [program, ...program.commands, ...program.commands.flatMap((c) => c.commands)];
104
- for (const node of nodes) {
105
- for (const option of node.options) {
106
- // The built-in helpOption's flags string — the only spelling that would
107
- // indicate a duplicated help option (the --plan option is not a help flag).
108
- expect(option.flags, `the ${node.name()} node duplicates no help flag`).not.toContain(
109
- "-h, --help",
110
- );
111
- }
112
- }
113
- });
114
-
115
- it("nests base set|get — each leaf holds its own declared keys (set --force, get without)", () => {
116
- const { program } = new CommandTreeBuilder();
117
- const base = commandOf(program, "base");
118
- expect(base.commands.map((command) => command.name())).toEqual(["set", "get"]);
119
- const set = leafOf(base, "set");
120
- const get = leafOf(base, "get");
121
- expect(set.options.some((option) => option.flags.startsWith("--force"))).toBe(true);
122
- expect(get.options.some((option) => option.flags.startsWith("--force"))).toBe(false);
123
- expect(get.options.some((option) => option.flags.startsWith("--plan"))).toBe(true);
124
- // base set's --base carries the branch override domain — the base artifact
125
- // branch name (the "sha" value type retired with the commit-sha surface · P7).
126
- const baseOption = set.options.find((option) => option.flags.startsWith("--base"));
127
- expect(baseOption?.flags).toBe("--base <branch>");
128
- expect(baseOption?.description).toBe("the base branch name (required)");
129
- });
130
-
131
- it("nests schema get and issue render", () => {
132
- const { program } = new CommandTreeBuilder();
133
- const schema = commandOf(program, "schema");
134
- // D19 — the schema leaf set is the single `get` leaf (gen merged into
135
- // `get --output skeleton`); the get leaf holds the `--output` json|skeleton
136
- // option + the conditional `<target>` positional.
137
- expect(schema.commands.map((command) => command.name())).toEqual(["get"]);
138
- const get = leafOf(schema, "get");
139
- expect(get.options.some((option) => option.flags.startsWith("--output"))).toBe(true);
140
- const issue = commandOf(program, "issue");
141
- expect(issue.commands.map((command) => command.name())).toEqual(["render"]);
142
- });
143
-
144
- it("projects the positionals — schema get requires <type>, the <target> rides optional and conditional on the skeleton render", () => {
145
- const { program } = new CommandTreeBuilder();
146
- const schema = commandOf(program, "schema");
147
- const get = leafOf(schema, "get");
148
- expect(get.registeredArguments[0]?.required).toBe(true);
149
- // D19 — the merged leaf's target positional stays optional at parse (the
150
- // conditional-required judgment — only `--output skeleton` demands it — is
151
- // the run body's usage rejection, never a static commander requirement).
152
- expect(get.registeredArguments[1]?.required).toBe(false);
153
- });
154
- });
155
-
156
- describe("the commander pipeline — parseArg value-domain rejection + the normalized value (§4.1)", () => {
157
- it("rejects a non-integer --tasks token with commander.invalidArgument — the domain and the raw value in the message", () => {
158
- const { program } = new CommandTreeBuilder();
159
- const { code, message } = commanderError(() =>
160
- program.parse(["review", "--tasks", "abc"], { from: "user" }),
161
- );
162
- expect(code).toBe("commander.invalidArgument");
163
- expect(message).toContain("--tasks <n|n,n,…>");
164
- expect(message).toContain("abc");
165
- });
166
-
167
- it("normalizes --tasks to the sorted deduped comma string (2,1,1 → 1,2)", () => {
168
- const { program } = new CommandTreeBuilder();
169
- const review = commandOf(program, "review");
170
- program.parse(["review", "--type", "wave", "--tasks", "2,1,1", "--plan", "docs/x.md"], {
171
- from: "user",
172
- });
173
- expect(review.getOptionValue("tasks")).toBe("1,2");
174
- });
175
-
176
- it("rejects an out-of-enum --type and a bogus schema <type>", () => {
177
- const program = new CommandTreeBuilder().program;
178
- expect(
179
- commanderError(() => program.parse(["review", "--type", "bogus"], { from: "user" })).code,
180
- ).toBe("commander.invalidArgument");
181
- expect(
182
- commanderError(() => program.parse(["schema", "get", "bogus"], { from: "user" })).code,
183
- ).toBe("commander.invalidArgument");
184
- });
185
-
186
- it("accepts the schema <type> vocabulary — the phaseSpec alias normalizes, a command word rejects", () => {
187
- const schemaProgram = new CommandTreeBuilder();
188
- const get = leafOf(commandOf(schemaProgram.program, "schema"), "get");
189
- schemaProgram.program.parse(["schema", "get", "phaseSpec"], { from: "user" });
190
- expect(get.processedArgs[0]).toBe("phase-spec");
191
- const rejectedProgram = new CommandTreeBuilder();
192
- expect(() =>
193
- rejectedProgram.program.parse(["schema", "get", "board"], { from: "user" }),
194
- ).toThrow();
195
- });
196
- });
197
-
198
- describe("the preAction conditional-required groups (§4.2 · REQUIRED_GROUPS)", () => {
199
- it("rejects review --type wave without --plan, accepts it with both --plan and --spec (non-exclusive)", () => {
200
- const { program } = new CommandTreeBuilder();
201
- // commander's preAction fires only for commands with an action handler — the
202
- // T3 composition root wires the .action thin shells; the test attaches a
203
- // no-op action to observe the hook the way the root will.
204
- commandOf(program, "review").action(() => undefined);
205
- const { code, message } = commanderError(() =>
206
- program.parse(["review", "--type", "wave"], { from: "user" }),
207
- );
208
- expect(code).toBe("commander.invalidArgument");
209
- expect(message).toContain("--plan required when --type wave");
210
- expect(() =>
211
- program.parse(["review", "--type", "wave", "--plan", "docs/x.md", "--spec", "docs/y.md"], {
212
- from: "user",
213
- }),
214
- ).not.toThrow();
215
- });
216
-
217
- it("rejects fix --type branch without --findings (the fix branch face)", () => {
218
- const { program } = new CommandTreeBuilder();
219
- commandOf(program, "fix").action(() => undefined);
220
- const { code, message } = commanderError(() =>
221
- program.parse(["fix", "--type", "branch"], { from: "user" }),
222
- );
223
- expect(code).toBe("commander.invalidArgument");
224
- // the branch fix carries both its findings carrier and the --plan workspace
225
- // identity (BranchRef retired — the plan is the branch line's identity · §2.3)
226
- expect(message).toContain("--findings --plan required when --type branch");
227
- });
228
-
229
- it("rejects review --type branch without --plan (the branch review face)", () => {
230
- const { program } = new CommandTreeBuilder();
231
- commandOf(program, "review").action(() => undefined);
232
- const { code, message } = commanderError(() =>
233
- program.parse(["review", "--type", "branch"], { from: "user" }),
234
- );
235
- expect(code).toBe("commander.invalidArgument");
236
- // the branch review's sole required flag is the --plan workspace identity — the
237
- // commit range is retired (the review judges the live tree · §2.3)
238
- expect(message).toContain("--plan required when --type branch");
239
- });
240
- });
241
-
242
- describe("the value-domain table declaration — VALUE_SHAPES (T7)", () => {
243
- it("the shaped-channel key set — the validated types, and only those (the table-source pin)", () => {
244
- // The value-domain shape derives from the declaration table, never a second
245
- // hand-written list: the key set is exactly the validated subset of the
246
- // channel type vocabulary (string/path/bool faces carry no parser — the
247
- // shaped-channel record face excludes them by construction). The `sha` shape
248
- // retired with the commit-sha surface (P7).
249
- expect(Object.keys(VALUE_SHAPES)).toEqual(["enum", "int-list", "int"]);
250
- for (const key of Object.keys(VALUE_SHAPES)) {
251
- expect(typeof VALUE_SHAPES[key as keyof typeof VALUE_SHAPES].parse).toBe("function");
252
- }
253
- });
254
-
255
- it("the enum domain reads the row's declared values — an out-of-domain raw rejects", () => {
256
- const row: ChannelArgRow = { flag: "--type", type: "enum", values: ["wave", "branch"] };
257
- expect(VALUE_SHAPES.enum.parse("wave", row)).toBe("wave");
258
- const { code, message } = commanderError(() => VALUE_SHAPES.enum.parse("plan", row));
259
- expect(code).toBe("commander.invalidArgument");
260
- expect(message).toBe("must be one of wave | branch");
261
- });
262
-
263
- it("the int-list normalizes to the sorted deduped comma string and rejects non-integers", () => {
264
- const row: ChannelArgRow = { flag: "--tasks", type: "int-list" };
265
- expect(VALUE_SHAPES["int-list"].parse("3,1,3,2", row)).toBe("1,2,3");
266
- const { code, message } = commanderError(() => VALUE_SHAPES["int-list"].parse("1,x", row));
267
- expect(code).toBe("commander.invalidArgument");
268
- expect(message).toBe("--tasks <n|n,n,…> — must be comma-separated integers: x");
269
- });
270
-
271
- it("the int face rejects a non-conforming raw with the pinned byte message", () => {
272
- const intRow: ChannelArgRow = { flag: "--round", type: "int" };
273
- expect(VALUE_SHAPES.int.parse("7", intRow)).toBe("7");
274
- const { code, message } = commanderError(() => VALUE_SHAPES.int.parse("-1", intRow));
275
- expect(code).toBe("commander.invalidArgument");
276
- expect(message).toBe("must be an integer");
277
- });
278
-
279
- it("the hand-written replication is destroyed — the four #parse* methods are gone from the projection (the grep pin)", () => {
280
- const source = readFileSync(new URL("../projection.ts", import.meta.url), "utf8");
281
- for (const method of ["#parseEnum", "#parseInts", "#parseSha8", "#parseInt"] as const) {
282
- expect(
283
- source.includes(method),
284
- `${method} must not survive the table migration (the value-domain rules live in VALUE_SHAPES)`,
285
- ).toBe(false);
286
- }
287
- });
288
-
289
- it("the schema <type> vocabulary is retained — #parseTypeKey + SCHEMA_TYPE_KEYS stay out of the destroy list (T9)", () => {
290
- const projection = readFileSync(new URL("../projection.ts", import.meta.url), "utf8");
291
- const declare = readFileSync(new URL("../declare.ts", import.meta.url), "utf8");
292
- // The retention disposition (plan T7 — the spec §6.3 cross-reference): the pair
293
- // is §6.3-listed but T7 records it as RETAINED, never on the destroy list —
294
- // SCHEMA_TYPE_KEYS is the schema get <type> doc-key vocabulary, orthogonal
295
- // to the ChannelValueType value-shape table (merging it into VALUE_SHAPES does
296
- // not fit); #parseTypeKey derives through it.
297
- expect(projection).toContain("#parseTypeKey");
298
- expect(projection).toContain("SCHEMA_TYPE_KEYS");
299
- expect(declare).toContain("SCHEMA_TYPE_KEYS");
300
- });
301
- });
@@ -1,70 +0,0 @@
1
- // packages/cdd-engine/src-next/face/__tests__/sync-runner.test.ts
2
- // The SyncRunner colocated pins (spec §14 · D36 — the host-channel integrity):
3
- // the sync child-process face collects UNBOUNDED output (the retired fixed 1 MiB
4
- // output-buffer cap — the W1 truncation class — is gone: execa's sync face
5
- // buffers without bound by default):
6
- // · >1 MiB output (exactly the retired default-ceiling byte count + 1) arrives
7
- // whole — the tail block the read-back gate parses is intact;
8
- // · a `status: APPROVED` RETURN_STDOUT_BLOCK tail survives the biggest pipe —
9
- // the W1 failure class (tail truncation losing the status line) is dead;
10
- // · stderr aggregates by the same face;
11
- // · the fail-open semantics hold — a non-zero child rides its code, a broken
12
- // command never throws.
13
- // The child is a real hermetic shell process (no network, no repo writes).
14
-
15
- import { describe, expect, it } from "vitest";
16
- import { SyncRunner } from "../lifecycle.ts";
17
-
18
- describe("SyncRunner — the unbounded sync child-channel collection (spec §14 · D36)", () => {
19
- const runner = new SyncRunner();
20
-
21
- it("collects >1 MiB stdout whole — exactly the retired default ceiling + 1 byte", () => {
22
- // 1 MiB + 1 byte of 'x' — the byte count that trips the retired default
23
- // output-buffer cap; every byte must arrive.
24
- const result = runner.run(
25
- "sh",
26
- ["-c", "head -c 1048577 /dev/zero | tr '\\0' x"],
27
- process.cwd(),
28
- );
29
- expect(result.code).toBe(0);
30
- expect(result.stdout.length).toBe(1048577);
31
- });
32
-
33
- it("keeps the `status: APPROVED` tail block intact behind a huge narrative — the W1 truncation class is dead", () => {
34
- // A big narrative stdout followed by the canonical return block — the exact
35
- // W1 incident shape (work fine, tail block lost). The status line MUST reach.
36
- const result = runner.run(
37
- "sh",
38
- [
39
- "-c",
40
- "head -c 2000000 /dev/zero | tr '\\0' x; printf '\\nstatus: APPROVED\\nartifacts: report=/tmp/r.md\\n'",
41
- ],
42
- process.cwd(),
43
- );
44
- expect(result.code).toBe(0);
45
- expect(result.stdout.length).toBeGreaterThan(2000000);
46
- expect(result.stdout).toMatch(/^status: APPROVED$/m);
47
- expect(result.stdout).toMatch(/^artifacts: report=\/tmp\/r\.md$/m);
48
- });
49
-
50
- it("aggregates stderr by the same streaming face", () => {
51
- const result = runner.run(
52
- "sh",
53
- ["-c", "head -c 1100000 /dev/zero | tr '\\0' e >&2"],
54
- process.cwd(),
55
- );
56
- expect(result.code).toBe(0);
57
- expect(result.stderr.length).toBe(1100000);
58
- expect(result.stderr).toMatch(/^e+$/);
59
- });
60
-
61
- it("stays fail-open — a non-zero child rides its code, a broken command never throws", () => {
62
- const nonZero = runner.run("sh", ["-c", "echo partial; exit 7"], process.cwd());
63
- expect(nonZero.code).toBe(7);
64
- expect(nonZero.stdout).toBe("partial\n");
65
- const broken = runner.run("cdd-no-such-binary-xyz", [], process.cwd());
66
- expect(broken.code).toBe(1);
67
- expect(broken.stdout).toBe("");
68
- expect(broken.stderr.length).toBeGreaterThan(0);
69
- });
70
- });
@@ -1,93 +0,0 @@
1
- // packages/cdd-engine/src-next/face/__tests__/words.guard.test.ts
2
- // P5 — the engine-literal half of the word-face audit, colocated after the
3
- // D17 six-premise ownership-migration (the root guard's checkWords split: the skill-text half
4
- // re-homes to the kairos test plane, the engine-literal half lands HERE — the
5
- // surfaces this tree owns must carry zero of its own retired vocabulary). The
6
- // token set is the exported ban-table data (`guard.ts` GUARD_BAN_WORDS), never a
7
- // hand-written list; the scan release-masks the ban-round's own data homes
8
- // (`face/words.ts` · `face/host.ts` — their quoted rows ARE the release form,
9
- // where the guard-ban vocabulary legitimately lives as declared data).
10
- //
11
- // The stale + gate families are the retired-mechanism tokens the engine's live
12
- // faces must stay clean of; the shape family is the consumer-skill surface's
13
- // concern (the kairos plane) and rides no source-face scan here.
14
- //
15
- // Zero module-level bare functions — the walk/scan helpers are `const` (the P5
16
- // zero-`function`-declaration discipline).
17
-
18
- import { readdirSync, readFileSync } from "node:fs";
19
- import path from "node:path";
20
- import { fileURLToPath } from "node:url";
21
- import { describe, expect, it } from "vitest";
22
-
23
- import { GUARD_BAN_WORDS } from "../words.ts";
24
-
25
- /** The src-next plane root — the engine's own source face (the scan set). */
26
- const FACE_ROOT = fileURLToPath(new URL("../../", import.meta.url));
27
-
28
- /** The ban vocabulary's data homes — the files whose quoted rows are the release
29
- * form (a live face never carries the lexeme outside these homes). */
30
- const RELEASE_FILES = new Set(["face/words.ts", "face/host.ts"]);
31
-
32
- /** Walk the src-next tree collecting `.ts` files (bounded — the explicit plane root). */
33
- const collectTsFiles = (dir: string, out: string[]): void => {
34
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
35
- const full = path.join(dir, entry.name);
36
- if (entry.isDirectory()) collectTsFiles(full, out);
37
- else if (entry.name.endsWith(".ts")) out.push(full);
38
- }
39
- };
40
-
41
- /** Whether a line carries the token only inside quoted strings (the release-row
42
- * form — a data-home line that lists the value, never restates it bare). */
43
- const isQuotedDataRow = (line: string, token: string): boolean =>
44
- !line.replace(/"[^"]*"/g, "").includes(token);
45
-
46
- /** One token's scanned hits over the src-next tree (the relative file + line). */
47
- const scanHits = (token: string): string[] => {
48
- const files: string[] = [];
49
- collectTsFiles(FACE_ROOT, files);
50
- const hits: string[] = [];
51
- for (const file of files) {
52
- const relative = path.relative(FACE_ROOT, file);
53
- const release = RELEASE_FILES.has(relative);
54
- const lines = readFileSync(file, "utf8").split("\n");
55
- for (let index = 0; index < lines.length; index += 1) {
56
- const text = lines[index]!;
57
- if (!text.includes(token)) continue;
58
- if (release && isQuotedDataRow(text, token)) continue;
59
- hits.push(`${relative}:${index + 1}`);
60
- }
61
- }
62
- return hits;
63
- };
64
-
65
- describe("the engine-literal word-face audit — the guard-ban vocabulary on the engine source face", () => {
66
- it("the src-next face carries zero stale-family ban tokens (release-masked at the data homes)", () => {
67
- const tokens = GUARD_BAN_WORDS.stale.map((row) => row.token);
68
- for (const token of tokens) {
69
- const hits = scanHits(token);
70
- expect(hits, `the engine source face carries the ban token "${token}"`).toEqual([]);
71
- }
72
- });
73
-
74
- it("the src-next face carries zero gate-family ban tokens (release-masked at the data homes)", () => {
75
- const tokens = GUARD_BAN_WORDS.gate.map((row) => row.token);
76
- for (const token of tokens) {
77
- const hits = scanHits(token);
78
- expect(hits, `the engine source face carries the ban token "${token}"`).toEqual([]);
79
- }
80
- });
81
-
82
- it("the release homes do carry their declared rows — the mask is the release form, never a blind skip", () => {
83
- // The mask must NOT be vacuous: the two data homes hold every stale + gate
84
- // row as a quoted data value — the release-masked scan stands down only for
85
- // those exact rows (a non-quoted restatement would build a hit).
86
- const tokens = [...GUARD_BAN_WORDS.stale, ...GUARD_BAN_WORDS.gate].map((row) => row.token);
87
- const homes = [...RELEASE_FILES].map((relative) => path.join(FACE_ROOT, relative));
88
- const all = readFileSync(homes[0]!, "utf8") + readFileSync(homes[1]!, "utf8");
89
- for (const token of tokens) {
90
- expect(all.includes(token), `the data home carries its declared row "${token}"`).toBe(true);
91
- }
92
- });
93
- });
@@ -1,195 +0,0 @@
1
- // packages/cdd-engine/src-next/face/artifacts.ts
2
- // T8 — the split contract's artifacts face (§6.2: face/artifacts.ts — the pure-command
3
- // domain). The pure artifact surfaces run through this class: the schema skeleton
4
- // (#runSchemaSkeleton/#today), the issue render (#runIssue) and the base artifact
5
- // read/write (#baseSet/#baseGet/#readBase) plus the doc read/usage face (#readText).
6
- // The method bodies are the pre-split Cli members moved verbatim — behavior bytes
7
- // identical; the root Cli holds the artifacts instance and composes through it via its
8
- // .action thin shells. The root's commander usage throw (#usage — the composition-
9
- // root exit face, never re-implemented here) is injected as the usage seam; the BaseArtifact
10
- // row (the CDD --plan target's read/write face) is declared here and re-exported by
11
- // face/cli.ts so the public surface never drifts.
12
-
13
- import { readFileSync, writeFileSync } from "node:fs";
14
- import process from "node:process";
15
- import type { Command } from "commander";
16
- import { declaredRegistries } from "../contract/declare.ts";
17
- import type { DocKey } from "../contract/project.ts";
18
- import { Projector } from "../contract/project.ts";
19
- import type { IssueBodyRenderer, IssueReportInput } from "../render/issue-body.ts";
20
- import { SkeletonAssembler } from "../render/skeleton.ts";
21
- import type { RunInput } from "./cli.ts";
22
- import type { CliIo } from "./lifecycle.ts";
23
-
24
- // ---------------------------------------------------------------------------
25
- // the pure artifact surfaces — the base artifact + the issue body
26
- // ---------------------------------------------------------------------------
27
-
28
- /** The base artifact schema — the sole CDD --plan target's read/write row (the
29
- * artifact file carries the `base` face: the base branch the plan's line rides). */
30
- export interface BaseArtifact {
31
- /** The base branch name. */
32
- base: string;
33
- /** The base's source channel (the engine-config source enum). */
34
- source: string;
35
- /** The plan path the artifact serves. */
36
- plan: string;
37
- /** The ISO write timestamp. */
38
- recordedAt: string;
39
- }
40
-
41
- /**
42
- * CliArtifacts — the pure-command domain (the split contract's artifacts face): the
43
- * schema/issue/base run bodies. The instance holds the pure-domain renderers + the
44
- * root-injected seam faces (io / the usage throw); the root composes the command
45
- * scenes and delegates the pure runs here.
46
- */
47
- export class CliArtifacts {
48
- readonly #io: CliIo;
49
- readonly #projector: Projector;
50
- readonly #issue: IssueBodyRenderer;
51
- readonly #stdinRead: () => string;
52
- /** The composition-root usage throw — commander's OWN CommanderError (the root's
53
- * exit-normalization face; the split never re-implements the usage byte). */
54
- readonly #usage: (node: Command, message: string) => never;
55
-
56
- constructor(opts: {
57
- io?: CliIo;
58
- projector?: Projector;
59
- issue: IssueBodyRenderer;
60
- stdinRead: () => string;
61
- usage: (node: Command, message: string) => never;
62
- }) {
63
- this.#io = opts.io ?? {
64
- stdout: (t) => process.stdout.write(t),
65
- stderr: (t) => process.stderr.write(t),
66
- };
67
- this.#projector = opts.projector ?? new Projector(declaredRegistries);
68
- this.#issue = opts.issue;
69
- this.#stdinRead = opts.stdinRead;
70
- this.#usage = opts.usage;
71
- }
72
-
73
- /** `cdd schema get <type> --output skeleton <target>` — the derived doc skeleton
74
- * rendered DIRECTLY into the target document (the D19 merged leaf's skeleton
75
- * face): the normalized DocType key → the projector's skeleton projection → the
76
- * SkeletonAssembler bytes → the single appended newline written to <target>
77
- * (the assembler never appends one — the written doc ends with exactly one
78
- * `\n`). The target is the engine-declared parameter of the skeleton render
79
- * face — the authoring scaffold lands in place, zero shell-redirection
80
- * indirection (the D19 `<path>` zero-constraint fix). The written path prints
81
- * to stdout. */
82
- runSchemaSkeleton(node: Command, type: string, target: string): number {
83
- const projection = this.#projector.skeleton()[type as DocKey];
84
- const date = this.#today();
85
- const file = `${new SkeletonAssembler(projection, date).render()}\n`;
86
- try {
87
- writeFileSync(target, file, "utf8");
88
- } catch {
89
- this.#usage(node, `cannot write file: ${target}`);
90
- }
91
- this.#io.stdout(`${target}\n`);
92
- return 0;
93
- }
94
-
95
- /** `cdd issue render` — stdin findings JSON → the aggregate body → stdout (the
96
- * renderer's only CLI entry; a bare call, no flags). */
97
- runIssue(): number {
98
- let input: unknown;
99
- try {
100
- input = JSON.parse(this.#stdinRead());
101
- } catch (err) {
102
- this.#io.stderr(
103
- `cdd issue render: invalid input JSON — ${err instanceof Error ? err.message : String(err)}\n`,
104
- );
105
- return 1;
106
- }
107
- const violations = this.#issue.validateInput(input);
108
- if (violations.length > 0) {
109
- this.#io.stderr(
110
- `cdd issue render: invalid input:\n${violations.map((v) => ` ${v}`).join("\n")}\n`,
111
- );
112
- return 1;
113
- }
114
- this.#io.stdout(`${this.#issue.renderBody(input as IssueReportInput)}\n`);
115
- return 0;
116
- }
117
-
118
- /** The `set` body — base/source required, a different existing base refuses without
119
- * --force (the write-through artifact single-author). */
120
- baseSet(node: Command, parsed: RunInput, planPath: string, path: string): number {
121
- const base = parsed.args.base;
122
- const source = parsed.args.source;
123
- if (base === undefined || source === undefined) {
124
- this.#usage(node, "cdd base set: required --base <branch> and --source <source>");
125
- }
126
- const existing = this.#readBase(path);
127
- if (existing !== null && existing.base !== base && parsed.args.force !== "true") {
128
- this.#usage(
129
- node,
130
- `cdd base set: base already set to ${existing.base} — pass --force to override`,
131
- );
132
- }
133
- const artifact: BaseArtifact = {
134
- base,
135
- source,
136
- plan: planPath,
137
- recordedAt: new Date().toISOString(),
138
- };
139
- writeFileSync(path, `${JSON.stringify(artifact, null, 2)}\n`, "utf8");
140
- this.#io.stdout(`${path}\n`);
141
- return 0;
142
- }
143
-
144
- /** The `get` body — read + validate + print the artifact JSON (exit 2 when the
145
- * artifact is missing or corrupt — the orchestrator's inference-chain input). */
146
- baseGet(path: string): number {
147
- const artifact = this.#readBase(path);
148
- if (artifact === null) {
149
- this.#io.stderr(`cdd base get: missing or corrupt base artifact at ${path}\n`);
150
- return 2;
151
- }
152
- this.#io.stdout(`${JSON.stringify(artifact, null, 2)}\n`);
153
- return 0;
154
- }
155
-
156
- /** Read a text file through the caller's command face; a missing/unreadable file is
157
- * the usage error of that face (the owning node's commander-native usage line). */
158
- readText(node: Command, file: string): string {
159
- try {
160
- return readFileSync(file, "utf8");
161
- } catch {
162
- this.#usage(node, `cannot read file: ${file}`);
163
- }
164
- }
165
-
166
- /** The run date in `YYYY-MM-DD` — the skeleton's version-row date truth (the
167
- * local day; the skeleton carries no date parameter face). */
168
- #today(): string {
169
- const now = new Date();
170
- const month = String(now.getMonth() + 1).padStart(2, "0");
171
- const day = String(now.getDate()).padStart(2, "0");
172
- return `${now.getFullYear()}-${month}-${day}`;
173
- }
174
-
175
- /** Read + validate the base artifact; null when missing or malformed. */
176
- #readBase(path: string): BaseArtifact | null {
177
- try {
178
- const parsed = JSON.parse(readFileSync(path, "utf8")) as Record<string, unknown>;
179
- if (
180
- typeof parsed.base !== "string" ||
181
- typeof parsed.source !== "string" ||
182
- typeof parsed.plan !== "string"
183
- )
184
- return null;
185
- return {
186
- base: parsed.base,
187
- source: parsed.source,
188
- plan: parsed.plan,
189
- recordedAt: typeof parsed.recordedAt === "string" ? parsed.recordedAt : "",
190
- };
191
- } catch {
192
- return null;
193
- }
194
- }
195
- }