@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.
- package/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/{src-next/bin.ts → dist/bin.js} +18 -21
- package/dist/contract/declare.js +998 -0
- package/dist/contract/doc.js +565 -0
- package/dist/contract/frontmatter.js +209 -0
- package/dist/contract/home-extractors.js +379 -0
- package/dist/contract/invariants.js +1030 -0
- package/dist/contract/judge.js +109 -0
- package/dist/contract/lint.js +206 -0
- package/dist/contract/project.js +371 -0
- package/dist/contract/skill-anatomy.js +156 -0
- package/dist/contract/translate.js +85 -0
- package/dist/face/artifacts.js +189 -0
- package/dist/face/board-view.js +522 -0
- package/dist/face/capsule.js +141 -0
- package/dist/face/cli.js +891 -0
- package/dist/face/declare.js +241 -0
- package/dist/face/gate.js +158 -0
- package/dist/face/graph-view.js +66 -0
- package/dist/face/host.js +211 -0
- package/dist/face/lifecycle.js +603 -0
- package/dist/face/preview.js +136 -0
- package/dist/face/projection.js +259 -0
- package/dist/face/route-render.js +162 -0
- package/dist/face/termination.js +482 -0
- package/dist/face/words.js +220 -0
- package/{src-next/infra/config.ts → dist/infra/config.js} +19 -24
- package/dist/infra/doc-roots.js +19 -0
- package/dist/infra/git.js +37 -0
- package/dist/infra/process.js +22 -0
- package/dist/infra/root.js +62 -0
- package/dist/infra/runtime.js +85 -0
- package/dist/infra/workspace.js +276 -0
- package/dist/render/brief.js +82 -0
- package/dist/render/issue-body.js +129 -0
- package/dist/render/skeleton.js +434 -0
- package/dist/render/templates.js +520 -0
- package/dist/session/faces.js +38 -0
- package/dist/session/graph.js +309 -0
- package/dist/session/handoff-schema.js +295 -0
- package/dist/session/ledger.js +762 -0
- package/dist/session/next.js +211 -0
- package/dist/session/preflight.js +194 -0
- package/dist/session/round-naming.js +73 -0
- package/dist/session/run.js +441 -0
- package/dist/session/state.js +8 -0
- package/dist/session/wave.js +92 -0
- package/package.json +8 -7
- package/templates/report/issue-body.json +0 -46
- package/src-next/__tests__/bin.test.ts +0 -128
- package/src-next/__tests__/smoke.integration.test.ts +0 -202
- package/src-next/__tests__/zero-dep.test.ts +0 -134
- package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +0 -238
- package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +0 -153
- package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +0 -173
- package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +0 -89
- package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +0 -225
- package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +0 -155
- package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +0 -175
- package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +0 -85
- package/src-next/contract/__tests__/declare.test.ts +0 -242
- package/src-next/contract/__tests__/doc.test.ts +0 -358
- package/src-next/contract/__tests__/judge.test.ts +0 -873
- package/src-next/contract/__tests__/lint.test.ts +0 -314
- package/src-next/contract/__tests__/project.test.ts +0 -419
- package/src-next/contract/__tests__/translate.test.ts +0 -96
- package/src-next/contract/declare.ts +0 -983
- package/src-next/contract/doc.ts +0 -753
- package/src-next/contract/invariants.ts +0 -1268
- package/src-next/contract/judge.ts +0 -142
- package/src-next/contract/lint.ts +0 -275
- package/src-next/contract/project.ts +0 -596
- package/src-next/contract/skill-anatomy.ts +0 -273
- package/src-next/contract/translate.ts +0 -113
- package/src-next/face/__tests__/board-view.test.ts +0 -948
- package/src-next/face/__tests__/capsule.test.ts +0 -276
- package/src-next/face/__tests__/channel-closure.guard.test.ts +0 -102
- package/src-next/face/__tests__/cli.test.ts +0 -4643
- package/src-next/face/__tests__/face.test.ts +0 -289
- package/src-next/face/__tests__/graph-view.test.ts +0 -61
- package/src-next/face/__tests__/host.test.ts +0 -24
- package/src-next/face/__tests__/negation.ts +0 -6
- package/src-next/face/__tests__/projection.test.ts +0 -301
- package/src-next/face/__tests__/sync-runner.test.ts +0 -70
- package/src-next/face/__tests__/words.guard.test.ts +0 -93
- package/src-next/face/artifacts.ts +0 -195
- package/src-next/face/board-view.ts +0 -662
- package/src-next/face/capsule.ts +0 -149
- package/src-next/face/cli.ts +0 -819
- package/src-next/face/declare.ts +0 -326
- package/src-next/face/gate.ts +0 -170
- package/src-next/face/graph-view.ts +0 -74
- package/src-next/face/host.ts +0 -326
- package/src-next/face/lifecycle.ts +0 -700
- package/src-next/face/projection.ts +0 -282
- package/src-next/face/route-render.ts +0 -160
- package/src-next/face/words.ts +0 -296
- package/src-next/infra/__tests__/infra.test.ts +0 -287
- package/src-next/infra/git.ts +0 -39
- package/src-next/infra/process.ts +0 -34
- package/src-next/infra/runtime.ts +0 -185
- package/src-next/infra/workspace.ts +0 -232
- package/src-next/render/__tests__/render.test.ts +0 -499
- package/src-next/render/__tests__/skeleton.test.ts +0 -466
- package/src-next/render/brief.ts +0 -121
- package/src-next/render/issue-body.ts +0 -159
- package/src-next/render/skeleton.ts +0 -437
- package/src-next/render/templates.ts +0 -650
- package/src-next/session/__tests__/graph.test.ts +0 -270
- package/src-next/session/__tests__/handoff-plane.guard.test.ts +0 -48
- package/src-next/session/__tests__/handoff-schema.test.ts +0 -310
- package/src-next/session/__tests__/ledger.test.ts +0 -744
- package/src-next/session/__tests__/next.test.ts +0 -368
- package/src-next/session/__tests__/preflight.test.ts +0 -491
- package/src-next/session/__tests__/run.test.ts +0 -1014
- package/src-next/session/__tests__/wave-line-phase.guard.test.ts +0 -49
- package/src-next/session/__tests__/wave.test.ts +0 -469
- package/src-next/session/faces.ts +0 -110
- package/src-next/session/graph.ts +0 -411
- package/src-next/session/handoff-schema.ts +0 -373
- package/src-next/session/ledger.ts +0 -1004
- package/src-next/session/next.ts +0 -192
- package/src-next/session/preflight.ts +0 -240
- package/src-next/session/run.ts +0 -606
- package/src-next/session/state.ts +0 -30
- package/src-next/session/wave.ts +0 -139
|
@@ -1,4643 +0,0 @@
|
|
|
1
|
-
// packages/cdd-engine/src-next/face/__tests__/cli.test.ts
|
|
2
|
-
// T11 Cli + composition-root suite (design spec §3.3):
|
|
3
|
-
// · the command face — the seven steady subcommand words (implement / review / fix /
|
|
4
|
-
// schema / issue / base / board with their nested leaves) and the usage lines the
|
|
5
|
-
// consumers read (T20: the base command face — `cdd base set|get` — converges
|
|
6
|
-
// the command surface; T5 adds the board observability command);
|
|
7
|
-
// · parse — the commander-native parse pipeline (the projection's program): the
|
|
8
|
-
// value-domain validation (int-list tasks, enum type / source, sha base/head,
|
|
9
|
-
// int round) + the unknown-flag rejection (the
|
|
10
|
-
// acceptance's unknown-flag BLOCK) and the program scopes (--dry-run / --help)
|
|
11
|
-
// — the parse-level assertions ride runArgv (the retired tokenizer and its
|
|
12
|
-
// guard never return to the tree);
|
|
13
|
-
// · the work-command E2E (dry-run) — implement / review / fix compose the lifecycle,
|
|
14
|
-
// the capsule and the ledger in a hermetic temp repo, advance the requested phase
|
|
15
|
-
// and land the canonical artifacts (brief / handoffs / progress); the phase gate
|
|
16
|
-
// refuses an unreachable round without dispatching a phantom;
|
|
17
|
-
// · the pure-command E2E — schema get (the merged D19 single leaf: the shared
|
|
18
|
-
// schema-type vocabulary — the primary doc-key spellings — under the default
|
|
19
|
-
// --output json; the --output skeleton face
|
|
20
|
-
// rendering the derived doc skeleton DIRECTLY into the target document, the
|
|
21
|
-
// legacy phaseSpec alias normalized to the kebab key, §5.3), issue render
|
|
22
|
-
// (stdin body — the subcommand face; the
|
|
23
|
-
// renderer's own suite lives in render/__tests__/render.test.ts, its T19
|
|
24
|
-
// home), base set/get (the single → artifact);
|
|
25
|
-
// · the composition root + HarnessDispatch — host detection, the dispatch prompt
|
|
26
|
-
// (template data plane), the child return-block parse (block + JSON).
|
|
27
|
-
// Fixtures are hermetic mkdtemp repos (git-inited for the dry-run HEAD); the io is
|
|
28
|
-
// captured, never the process.
|
|
29
|
-
|
|
30
|
-
import { spawnSync } from "node:child_process";
|
|
31
|
-
import { createHash } from "node:crypto";
|
|
32
|
-
import {
|
|
33
|
-
existsSync,
|
|
34
|
-
mkdirSync,
|
|
35
|
-
mkdtempSync,
|
|
36
|
-
readdirSync,
|
|
37
|
-
readFileSync,
|
|
38
|
-
rmSync,
|
|
39
|
-
writeFileSync,
|
|
40
|
-
} from "node:fs";
|
|
41
|
-
import { tmpdir } from "node:os";
|
|
42
|
-
import path from "node:path";
|
|
43
|
-
import type { Command } from "commander";
|
|
44
|
-
import { describe, expect, it } from "vitest";
|
|
45
|
-
import { ConfigLoader } from "../../infra/config.ts";
|
|
46
|
-
import { Workspace, WorkspaceRoot } from "../../infra/workspace.ts";
|
|
47
|
-
import { BriefRenderer } from "../../render/brief.ts";
|
|
48
|
-
import type { RouteTarget } from "../../session/faces.ts";
|
|
49
|
-
import { Ledger } from "../../session/ledger.ts";
|
|
50
|
-
import type { Route } from "../../session/next.ts";
|
|
51
|
-
import { FIX_READBACK_SUFFIX } from "../../session/next.ts";
|
|
52
|
-
import type { OpenFrame } from "../../session/run.ts";
|
|
53
|
-
import { Capsule } from "../capsule.ts";
|
|
54
|
-
import type { CliIo, CliOptions, DispatchScene, SyncProcess } from "../cli.ts";
|
|
55
|
-
import { Cli, HarnessDispatch } from "../cli.ts";
|
|
56
|
-
import { CLI_COMMANDS, type CliVerb } from "../declare.ts";
|
|
57
|
-
import { CommandTreeBuilder } from "../projection.ts";
|
|
58
|
-
import { Words } from "../words.ts";
|
|
59
|
-
import { negatedOf } from "./negation.ts";
|
|
60
|
-
|
|
61
|
-
// The retired usage corpus — the pre-T2 usage product's bytes for the two verbs
|
|
62
|
-
// whose old rows still run as negative anchors (the survivors assert the old
|
|
63
|
-
// self-built face is gone from the commander-native output; the review/fix/
|
|
64
|
-
// schema/issue retired rows are deleted outright — no dead bytes stay pinned).
|
|
65
|
-
const RETIRED_USAGE = {
|
|
66
|
-
implement:
|
|
67
|
-
"usage: cdd implement --tasks <n|n,n,…> --plan <path> [--root <path>] — implement the plan wave's task group",
|
|
68
|
-
base: "usage: cdd base <set|get> --plan <path> [set: --base <branch> --source <source>] [--force] — read/write the base.json artifact",
|
|
69
|
-
} as const;
|
|
70
|
-
|
|
71
|
-
/** The engine's source planes — the destroy-list sweep's scan set (zero non-test
|
|
72
|
-
* residue is asserted across every plane and the src-next root, never a single
|
|
73
|
-
* file). */
|
|
74
|
-
const ENGINE_SOURCE_PLANES = ["contract", "face", "infra", "render", "session"] as const;
|
|
75
|
-
|
|
76
|
-
/** Every engine source file's (src-next-qualified name, text) — the plane enum +
|
|
77
|
-
* the src-next root's own .ts files (bin.ts — the shipped CLI entry, the engine's
|
|
78
|
-
* sole source file outside the planes). The .ts-suffix filter drops the __tests__
|
|
79
|
-
* dirs and the plane subdirectories (a directory never ends with .ts), so the
|
|
80
|
-
* swept set IS the engine's non-test source tree — the planes' root company
|
|
81
|
-
* included, the guard's closure over the 'zero residual across the engine source'
|
|
82
|
-
* claim. */
|
|
83
|
-
const engineSourceTexts = (): [string, string][] => {
|
|
84
|
-
return [
|
|
85
|
-
...ENGINE_SOURCE_PLANES.flatMap((plane) =>
|
|
86
|
-
readdirSync(new URL(`../../${plane}/`, import.meta.url))
|
|
87
|
-
.filter((name) => name.endsWith(".ts"))
|
|
88
|
-
.map(
|
|
89
|
-
(name) =>
|
|
90
|
-
[
|
|
91
|
-
`${plane}/${name}`,
|
|
92
|
-
readFileSync(new URL(`../../${plane}/${name}`, import.meta.url), "utf8"),
|
|
93
|
-
] as [string, string],
|
|
94
|
-
),
|
|
95
|
-
),
|
|
96
|
-
...readdirSync(new URL("../../", import.meta.url))
|
|
97
|
-
.filter((name) => name.endsWith(".ts"))
|
|
98
|
-
.map(
|
|
99
|
-
(name) =>
|
|
100
|
-
[name, readFileSync(new URL(`../../${name}`, import.meta.url), "utf8")] as [
|
|
101
|
-
string,
|
|
102
|
-
string,
|
|
103
|
-
],
|
|
104
|
-
),
|
|
105
|
-
];
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// ---------------------------------------------------------------------------
|
|
109
|
-
// fixtures
|
|
110
|
-
// ---------------------------------------------------------------------------
|
|
111
|
-
|
|
112
|
-
/** The captured io — the CLI's stdout/stderr seam (never the process). */
|
|
113
|
-
class CaptureIo implements CliIo {
|
|
114
|
-
stdoutText = "";
|
|
115
|
-
stderrText = "";
|
|
116
|
-
stdout(text: string): void {
|
|
117
|
-
this.stdoutText += text;
|
|
118
|
-
}
|
|
119
|
-
stderr(text: string): void {
|
|
120
|
-
this.stderrText += text;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
interface CliFixture {
|
|
125
|
-
command: Cli;
|
|
126
|
-
io: CaptureIo;
|
|
127
|
-
repoRoot: string;
|
|
128
|
-
cleanup: () => void;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** A hermetic CLI fixture — a fresh temp repo, the io captured, the root injected. */
|
|
132
|
-
const fixture = (opts: CliOptions = {}): CliFixture => {
|
|
133
|
-
const repoRoot = mkdtempSync(path.join(tmpdir(), "cli-"));
|
|
134
|
-
const io = new CaptureIo();
|
|
135
|
-
const command = Cli.create({ io, repoRoot, ...opts });
|
|
136
|
-
return {
|
|
137
|
-
command,
|
|
138
|
-
io,
|
|
139
|
-
repoRoot,
|
|
140
|
-
cleanup: () => rmSync(repoRoot, { recursive: true, force: true }),
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
/** Init a git repo with one commit — the dry-run's HEAD (the review `next:` base).
|
|
145
|
-
* The fixture .gitignore keeps the dispatch's own writes (the `.kairos` workspace)
|
|
146
|
-
* and the fixture's synthetic docs (`/docs/`) out of the tree — the working tree
|
|
147
|
-
* stays clean across multi-dispatch flows (the P4.1 clean-tree dispatch gate).
|
|
148
|
-
* Pass an explicit ignore content to shape it (the no-`.kairos`-ignore consumer
|
|
149
|
-
* regression). */
|
|
150
|
-
const gitInit = (repoRoot: string, ignore = ".kairos\n/docs/\n"): string => {
|
|
151
|
-
spawnSync("git", ["init", "-q"], { cwd: repoRoot });
|
|
152
|
-
spawnSync("git", ["config", "user.email", "cli@test"], { cwd: repoRoot });
|
|
153
|
-
spawnSync("git", ["config", "user.name", "cli-test"], { cwd: repoRoot });
|
|
154
|
-
writeFileSync(path.join(repoRoot, ".gitignore"), ignore, "utf8");
|
|
155
|
-
writeFileSync(path.join(repoRoot, "seed.txt"), "seed\n", "utf8");
|
|
156
|
-
spawnSync("git", ["add", "-A"], { cwd: repoRoot });
|
|
157
|
-
spawnSync("git", ["commit", "-q", "-m", "seed"], { cwd: repoRoot });
|
|
158
|
-
return spawnSync("git", ["rev-parse", "HEAD"], { cwd: repoRoot }).stdout.toString().trim();
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/** A plan document — the head + N task blocks (task 1 no-dep; loop tasks depend on task 1). */
|
|
162
|
-
const planFor = (repoRoot: string, count = 1, name = "p3.md"): string => {
|
|
163
|
-
const file = path.join(repoRoot, "docs", "kairos", "plans", name);
|
|
164
|
-
mkdirSync(path.dirname(file), { recursive: true });
|
|
165
|
-
const blocks: string[] = [];
|
|
166
|
-
for (let id = 1; id <= count; id += 1) {
|
|
167
|
-
blocks.push(
|
|
168
|
-
`### Task ${id}: task ${id}`,
|
|
169
|
-
"- **Objective**: objective",
|
|
170
|
-
"- **Files**: `a.ts`",
|
|
171
|
-
"- **Consumes**: x",
|
|
172
|
-
"- **Produces**: y",
|
|
173
|
-
"- **Steps**:",
|
|
174
|
-
" - step — checkable: green",
|
|
175
|
-
"- **Acceptance**: ok",
|
|
176
|
-
`- **DependsOn**: ${id === 1 ? "none" : "1"}`,
|
|
177
|
-
"",
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
writeFileSync(
|
|
181
|
-
file,
|
|
182
|
-
[
|
|
183
|
-
"# Test Plan",
|
|
184
|
-
"**Spec:** [p3-design.md](docs/kairos/specs/p3-design.md)",
|
|
185
|
-
"- **Parent program**: [p3-overall.md v1.0](docs/kairos/specs/p3-overall.md)",
|
|
186
|
-
"",
|
|
187
|
-
"## Constraints",
|
|
188
|
-
"",
|
|
189
|
-
"- delta",
|
|
190
|
-
"",
|
|
191
|
-
...blocks,
|
|
192
|
-
].join("\n"),
|
|
193
|
-
"utf8",
|
|
194
|
-
);
|
|
195
|
-
return file;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/** Read a JSON file (the workspace artifact assertions). */
|
|
199
|
-
const readJson = <T>(file: string): T => {
|
|
200
|
-
return JSON.parse(readFileSync(file, "utf8")) as T;
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
/** The D30 wave-line reviewed identity — the brief-revision ref a wave row binds:
|
|
204
|
-
* the plan it renders FROM + the RENDERED brief's sha1 (the wave gate binds the
|
|
205
|
-
* brief, never the whole plan). */
|
|
206
|
-
const briefRevision = (plan: string, tasks: string) => {
|
|
207
|
-
const brief = new BriefRenderer().render(
|
|
208
|
-
readFileSync(plan, "utf8"),
|
|
209
|
-
tasks.split(",").map(Number),
|
|
210
|
-
);
|
|
211
|
-
return {
|
|
212
|
-
kind: "brief-revision" as const,
|
|
213
|
-
plan,
|
|
214
|
-
brief_hash: createHash("sha1").update(brief).digest("hex"),
|
|
215
|
-
};
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
/** A doc-contract-clean plan — every registered plan element present (the header
|
|
219
|
-
* tuple + the version lineage + a Change-history table + the task fields), chain
|
|
220
|
-
* links resolving into existing same-family siblings. The P4.1 doc-contract
|
|
221
|
-
* dispatch gate (the spec/plan faces) requires it — a plain task-fixture plan is
|
|
222
|
-
* structurally defective and never dispatches a doc round. */
|
|
223
|
-
const conformingPlan = (repoRoot: string): string => {
|
|
224
|
-
const file = path.join(repoRoot, "docs", "kairos", "plans", "p3.md");
|
|
225
|
-
mkdirSync(path.dirname(file), { recursive: true });
|
|
226
|
-
writeFileSync(
|
|
227
|
-
file,
|
|
228
|
-
[
|
|
229
|
-
"# Test Plan",
|
|
230
|
-
"**Spec:** [p3-design.md](docs/kairos/specs/p3-design.md)",
|
|
231
|
-
"- **Parent program**: [p3-overall.md v1.0](docs/kairos/specs/p3-overall.md)",
|
|
232
|
-
"- **Version**: v1.0 · 2026-10-09",
|
|
233
|
-
"- **Doc type**: plan",
|
|
234
|
-
"- **Depends on**: P1",
|
|
235
|
-
"- **Base**: develop",
|
|
236
|
-
"",
|
|
237
|
-
"## Constraints",
|
|
238
|
-
"",
|
|
239
|
-
"- delta",
|
|
240
|
-
"",
|
|
241
|
-
"### Task 1:",
|
|
242
|
-
"- **Objective**: objective",
|
|
243
|
-
"- **Files**: a.ts",
|
|
244
|
-
"- **Consumes**: x",
|
|
245
|
-
"- **Produces**: y",
|
|
246
|
-
"- **Steps**:",
|
|
247
|
-
" - step — checkable: green",
|
|
248
|
-
"- **Acceptance**: ok",
|
|
249
|
-
"- **DependsOn**: none",
|
|
250
|
-
"",
|
|
251
|
-
"## Change history",
|
|
252
|
-
"",
|
|
253
|
-
"| Version | date | summary | author |",
|
|
254
|
-
"|---|---|---|---|",
|
|
255
|
-
"| v1.0 | 2026-10-09 | initial | [human] |",
|
|
256
|
-
].join("\n"),
|
|
257
|
-
"utf8",
|
|
258
|
-
);
|
|
259
|
-
for (const sibling of ["p3-design.md", "p3-overall.md"]) {
|
|
260
|
-
const siblingPath = path.join(repoRoot, "docs", "kairos", "specs", sibling);
|
|
261
|
-
mkdirSync(path.dirname(siblingPath), { recursive: true });
|
|
262
|
-
writeFileSync(siblingPath, `# ${sibling}\n`, "utf8");
|
|
263
|
-
}
|
|
264
|
-
return file;
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
/** A doc-contract-clean overall — every registered overall element present (the
|
|
268
|
-
* header tuple + the ten-element charter + the inventory tables), its chain links
|
|
269
|
-
* resolving into existing same-family siblings. The overall charter is the
|
|
270
|
-
* GOOD_OVERALL judge fixture shape (judge.test.ts:19-71) with the `o1-` names
|
|
271
|
-
* the temp repo actually holds — the review face's doc-contract gate must judge it
|
|
272
|
-
* under the overall-spec key (zero phase-spec misreport on the doc-key derivation). */
|
|
273
|
-
const conformingOverall = (repoRoot: string): string => {
|
|
274
|
-
const file = path.join(repoRoot, "docs", "kairos", "specs", "o1-overall.md");
|
|
275
|
-
mkdirSync(path.dirname(file), { recursive: true });
|
|
276
|
-
writeFileSync(
|
|
277
|
-
file,
|
|
278
|
-
[
|
|
279
|
-
"# Test Overall",
|
|
280
|
-
"- **Version**: v1.21 · 2026-10-07",
|
|
281
|
-
"- **Status**: Approved",
|
|
282
|
-
"- **Doc type**: overall-spec",
|
|
283
|
-
"- **Author**: [human]",
|
|
284
|
-
"- **Constraints**: all cross-cutting constraints apply",
|
|
285
|
-
"",
|
|
286
|
-
"## Document scope",
|
|
287
|
-
"scope prose",
|
|
288
|
-
"",
|
|
289
|
-
"## File paths",
|
|
290
|
-
"| Artifact | Path |",
|
|
291
|
-
"| --- | --- |",
|
|
292
|
-
"| overall-spec | docs/kairos/specs/o1-overall.md |",
|
|
293
|
-
"",
|
|
294
|
-
"## Program charter",
|
|
295
|
-
"### Goal",
|
|
296
|
-
"- goal text",
|
|
297
|
-
"",
|
|
298
|
-
"### Non-goals",
|
|
299
|
-
"- non-goal text",
|
|
300
|
-
"",
|
|
301
|
-
"### Cross-cutting",
|
|
302
|
-
"- cross text",
|
|
303
|
-
"",
|
|
304
|
-
"## Issue inventory",
|
|
305
|
-
"| Phase | Issue (ref) | Title summary |",
|
|
306
|
-
"| --- | --- | --- |",
|
|
307
|
-
"| P1 | #123 | issue one |",
|
|
308
|
-
"| P2 | none | issue two |",
|
|
309
|
-
"",
|
|
310
|
-
"## Phase inventory",
|
|
311
|
-
"| # | Phase | Scope | Design spec | Implementation plan | Acceptance criteria | Dependency |",
|
|
312
|
-
"| --- | --- | --- | --- | --- | --- | --- |",
|
|
313
|
-
"| P1 | doc-type derivation | scope a | [P1-design](docs/kairos/specs/o1-p1-design.md) | [P1 plan](docs/kairos/plans/o1-p1.md) | criteria a | |",
|
|
314
|
-
"| P2 | document surface | scope b | P2-design | [P2 plan](docs/kairos/plans/o1-p2.md) | criteria b | |",
|
|
315
|
-
"",
|
|
316
|
-
"## Dependency graph",
|
|
317
|
-
"P1 -> P2",
|
|
318
|
-
"- `->` = hard block",
|
|
319
|
-
"",
|
|
320
|
-
"## Boundary rules",
|
|
321
|
-
"- boundary rule",
|
|
322
|
-
"",
|
|
323
|
-
"## Maintenance",
|
|
324
|
-
"- maintenance note",
|
|
325
|
-
"",
|
|
326
|
-
"## Change history",
|
|
327
|
-
"| Version | Date | Summary |",
|
|
328
|
-
"| --- | --- | --- |",
|
|
329
|
-
"| v1.20 | 2026-10-06 | prior change |",
|
|
330
|
-
"| v1.21 | 2026-10-07 | merged change |",
|
|
331
|
-
].join("\n"),
|
|
332
|
-
"utf8",
|
|
333
|
-
);
|
|
334
|
-
for (const sibling of ["o1-p1-design.md", "o1-p2-design.md"]) {
|
|
335
|
-
const siblingPath = path.join(repoRoot, "docs", "kairos", "specs", sibling);
|
|
336
|
-
mkdirSync(path.dirname(siblingPath), { recursive: true });
|
|
337
|
-
writeFileSync(siblingPath, `# ${sibling}\n`, "utf8");
|
|
338
|
-
}
|
|
339
|
-
for (const sibling of ["o1-p1.md", "o1-p2.md"]) {
|
|
340
|
-
const siblingPath = path.join(repoRoot, "docs", "kairos", "plans", sibling);
|
|
341
|
-
mkdirSync(path.dirname(siblingPath), { recursive: true });
|
|
342
|
-
writeFileSync(siblingPath, `# ${sibling}\n`, "utf8");
|
|
343
|
-
}
|
|
344
|
-
return file;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
/** A plan with N independent tasks (no deps — a single root wave of N members). */
|
|
348
|
-
const independentPlan = (repoRoot: string, name: string, count: number): string => {
|
|
349
|
-
const file = path.join(repoRoot, "docs", "kairos", "plans", name);
|
|
350
|
-
mkdirSync(path.dirname(file), { recursive: true });
|
|
351
|
-
const blocks: string[] = [];
|
|
352
|
-
for (let id = 1; id <= count; id += 1) {
|
|
353
|
-
blocks.push(
|
|
354
|
-
`### Task ${id}: task ${id}`,
|
|
355
|
-
"- **Objective**: objective",
|
|
356
|
-
"- **Files**: `a.ts`",
|
|
357
|
-
"- **Consumes**: x",
|
|
358
|
-
"- **Produces**: y",
|
|
359
|
-
"- **Steps**:",
|
|
360
|
-
" - step — checkable: green",
|
|
361
|
-
"- **Acceptance**: ok",
|
|
362
|
-
"- **DependsOn**: none",
|
|
363
|
-
"",
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
writeFileSync(
|
|
367
|
-
file,
|
|
368
|
-
[
|
|
369
|
-
"# Test Plan",
|
|
370
|
-
"**Spec:** [p3-design.md](docs/kairos/specs/p3-design.md)",
|
|
371
|
-
"- **Parent program**: [p3-overall.md v1.0](docs/kairos/specs/p3-overall.md)",
|
|
372
|
-
"",
|
|
373
|
-
"## Constraints",
|
|
374
|
-
"",
|
|
375
|
-
"- delta",
|
|
376
|
-
"",
|
|
377
|
-
...blocks,
|
|
378
|
-
].join("\n"),
|
|
379
|
-
"utf8",
|
|
380
|
-
);
|
|
381
|
-
return file;
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
/** A doc-contract-clean phase-spec — every registered phase-spec element present
|
|
385
|
-
* (the header tuple + the version lineage + a Change-history table + the design
|
|
386
|
-
* skeleton), carrying the `- **Doc type**:` declaration line (spec §12 · D34) the
|
|
387
|
-
* capsule's doc-class discrimination reads (zero filename inference). */
|
|
388
|
-
const conformingSpec = (repoRoot: string, name = "s1-design.md"): string => {
|
|
389
|
-
const file = path.join(repoRoot, "docs", "kairos", "specs", name);
|
|
390
|
-
mkdirSync(path.dirname(file), { recursive: true });
|
|
391
|
-
writeFileSync(
|
|
392
|
-
file,
|
|
393
|
-
[
|
|
394
|
-
"# Test Spec",
|
|
395
|
-
"- **Version**: v1.0 · 2026-10-09",
|
|
396
|
-
"- **Status**: Draft",
|
|
397
|
-
"- **Doc type**: phase-spec",
|
|
398
|
-
"- **Author**: x",
|
|
399
|
-
"- **Parent program**: [x-overall.md v1.0](docs/kairos/specs/x-overall.md)",
|
|
400
|
-
"- **Depends on**: P1",
|
|
401
|
-
"",
|
|
402
|
-
"## Design",
|
|
403
|
-
"",
|
|
404
|
-
"Design intro — the double-layer skeleton semantics.",
|
|
405
|
-
"",
|
|
406
|
-
"### 1. Data plane",
|
|
407
|
-
"#### 1.1 Registry",
|
|
408
|
-
"- text",
|
|
409
|
-
"",
|
|
410
|
-
"### Acceptance criteria",
|
|
411
|
-
"",
|
|
412
|
-
"- `c`",
|
|
413
|
-
"",
|
|
414
|
-
"## Constraints",
|
|
415
|
-
"",
|
|
416
|
-
"- delta",
|
|
417
|
-
"",
|
|
418
|
-
"## Change history",
|
|
419
|
-
"",
|
|
420
|
-
"| Version | date | summary | author |",
|
|
421
|
-
"|---|---|---|---|",
|
|
422
|
-
"| v1.0 | 2026-10-09 | initial | [human] |",
|
|
423
|
-
].join("\n"),
|
|
424
|
-
"utf8",
|
|
425
|
-
);
|
|
426
|
-
// The chain sibling — the `**Parent program**` link resolves into the specs dir.
|
|
427
|
-
const sibling = path.join(repoRoot, "docs", "kairos", "specs", "x-overall.md");
|
|
428
|
-
mkdirSync(path.dirname(sibling), { recursive: true });
|
|
429
|
-
writeFileSync(sibling, "# x-overall\n", "utf8");
|
|
430
|
-
return file;
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
// ---------------------------------------------------------------------------
|
|
434
|
-
// the command face — the steady subcommand words
|
|
435
|
-
// ---------------------------------------------------------------------------
|
|
436
|
-
|
|
437
|
-
describe("the command face — the seven steady subcommand words", () => {
|
|
438
|
-
it("declares exactly the seven subcommands of the steady command face", () => {
|
|
439
|
-
expect(CLI_COMMANDS.map((command) => command.name)).toEqual([
|
|
440
|
-
"implement",
|
|
441
|
-
"review",
|
|
442
|
-
"fix",
|
|
443
|
-
"base",
|
|
444
|
-
"schema",
|
|
445
|
-
"issue",
|
|
446
|
-
"board",
|
|
447
|
-
]);
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
it("the retired usage corpus never returns to the declaration rows — the usage face is the commander-native projection (Task 2; the byte re-pins land at Task 5)", () => {
|
|
451
|
-
// The retired corpus is gone from the declaration surface — the command rows
|
|
452
|
-
// carry the description/keys/positionals/leaves face, never a usage corpus.
|
|
453
|
-
const declarationText = JSON.stringify(CLI_COMMANDS);
|
|
454
|
-
for (const line of Object.values(RETIRED_USAGE)) {
|
|
455
|
-
expect(declarationText, line).not.toContain(line);
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
it("declares the nested leaf surfaces — base set|get · schema get · issue render", () => {
|
|
460
|
-
const leavesOf = (verb: string) =>
|
|
461
|
-
CLI_COMMANDS.find((c) => c.name === verb)!.leaves!.map((l) => l.name);
|
|
462
|
-
expect(leavesOf("base")).toEqual(["set", "get"]);
|
|
463
|
-
// D19 — the schema leaf set is the single `get` leaf (gen merged into
|
|
464
|
-
// `get --output skeleton`).
|
|
465
|
-
expect(leavesOf("schema")).toEqual(["get"]);
|
|
466
|
-
expect(leavesOf("issue")).toEqual(["render"]);
|
|
467
|
-
});
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
// ---------------------------------------------------------------------------
|
|
471
|
-
// parse — the component-value validation + the unknown-flag guard (the safety
|
|
472
|
-
// semantics — value-domain rejection / unknown-flag narrowing / unknown command /
|
|
473
|
-
// pre-verb scope / help position — assert through command.runArgv, the public
|
|
474
|
-
// face `Cli#parse()` retired to at T3; the projection's parse PRODUCTS — the
|
|
475
|
-
// normalized values/positionals the thin shells consume — stay on the composed
|
|
476
|
-
// commander program, the same tree runArgv dispatches through)
|
|
477
|
-
|
|
478
|
-
describe("parse — the component-value validation + the unknown-flag guard", () => {
|
|
479
|
-
/** The composed parse gate — the projection's commander program (the same tree
|
|
480
|
-
* runArgv dispatches through); the parse-PRODUCT assertions only (the safety
|
|
481
|
-
* semantics ride the runArgv face below). */
|
|
482
|
-
const gate = new CommandTreeBuilder().program;
|
|
483
|
-
/** The parsed node of one verb — commander's parse() returns the PROGRAM; the
|
|
484
|
-
* parsed opts/arguments live on the dispatched subcommand node (the same read
|
|
485
|
-
* the runArgv thin shell consumes). */
|
|
486
|
-
function nodeOf(verb: CliVerb): Command {
|
|
487
|
-
const node = gate.commands.find((c) => c.name() === verb);
|
|
488
|
-
expect(node, `the ${verb} command node exists`).toBeDefined();
|
|
489
|
-
return node!;
|
|
490
|
-
}
|
|
491
|
-
/** The parsed leaf node of one parent command. */
|
|
492
|
-
function leafOf(parent: CliVerb, name: string): Command {
|
|
493
|
-
const node = nodeOf(parent).commands.find((c) => c.name() === name);
|
|
494
|
-
expect(node, `the ${parent}.${name} leaf exists`).toBeDefined();
|
|
495
|
-
return node!;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
it("parses implement with the normalized int-list tasks + the plan + the dry-run scope", () => {
|
|
499
|
-
const implement = nodeOf("implement");
|
|
500
|
-
gate.parse(["implement", "--tasks", "2,1,2", "--plan", "docs/x.md", "--dry-run"], {
|
|
501
|
-
from: "user",
|
|
502
|
-
});
|
|
503
|
-
expect(implement.opts().tasks).toBe("1,2");
|
|
504
|
-
expect(implement.opts().plan).toBe("docs/x.md");
|
|
505
|
-
expect((implement.optsWithGlobals() as Record<string, unknown>).dryRun).toBe(true);
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
it("rejects a non-integer --tasks token (the int-list value shape)", async () => {
|
|
509
|
-
const { command, io, cleanup } = fixture();
|
|
510
|
-
try {
|
|
511
|
-
const code = await command.runArgv(["implement", "--tasks", "1,x", "--plan", "x"]);
|
|
512
|
-
expect(code).toBe(2);
|
|
513
|
-
expect(io.stderrText).toContain(
|
|
514
|
-
"error: option '--tasks <n|n,n,…>' argument '1,x' is invalid",
|
|
515
|
-
);
|
|
516
|
-
expect(io.stderrText).toContain("must be comma-separated integers: x");
|
|
517
|
-
} finally {
|
|
518
|
-
cleanup();
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
it("rejects an out-of-enum --type and --source", async () => {
|
|
523
|
-
const { command, io, cleanup } = fixture();
|
|
524
|
-
try {
|
|
525
|
-
let code = await command.runArgv(["review", "--type", "bogus"]);
|
|
526
|
-
expect(code).toBe(2);
|
|
527
|
-
expect(io.stderrText).toContain(
|
|
528
|
-
"error: option '--type <wave|branch|spec|plan>' argument 'bogus' is invalid",
|
|
529
|
-
);
|
|
530
|
-
expect(io.stderrText).toContain("must be one of wave | branch | spec | plan");
|
|
531
|
-
io.stderrText = "";
|
|
532
|
-
code = await command.runArgv([
|
|
533
|
-
"base",
|
|
534
|
-
"set",
|
|
535
|
-
"--plan",
|
|
536
|
-
"p",
|
|
537
|
-
"--base",
|
|
538
|
-
"d",
|
|
539
|
-
"--source",
|
|
540
|
-
"nope",
|
|
541
|
-
]);
|
|
542
|
-
expect(code).toBe(2);
|
|
543
|
-
expect(io.stderrText).toContain(
|
|
544
|
-
"must be one of plan-field | branch-upstream | conversation-context | user-confirmed",
|
|
545
|
-
);
|
|
546
|
-
} finally {
|
|
547
|
-
cleanup();
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
it("rejects a non-integer --round (the sha value type retired with the commit-sha surface)", async () => {
|
|
552
|
-
const { command, io, cleanup } = fixture();
|
|
553
|
-
try {
|
|
554
|
-
const code = await command.runArgv([
|
|
555
|
-
"review",
|
|
556
|
-
"--type",
|
|
557
|
-
"plan",
|
|
558
|
-
"--plan",
|
|
559
|
-
"x",
|
|
560
|
-
"--round",
|
|
561
|
-
"x",
|
|
562
|
-
]);
|
|
563
|
-
expect(code).toBe(2);
|
|
564
|
-
expect(io.stderrText).toContain("must be an integer");
|
|
565
|
-
} finally {
|
|
566
|
-
cleanup();
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
it("the fix face declares NO branch refs — the review judges the live tree (no re-declared range)", () => {
|
|
571
|
-
// fix --type branch parses with --plan + --findings alone (no base/head)
|
|
572
|
-
const fix = nodeOf("fix");
|
|
573
|
-
gate.parse(
|
|
574
|
-
["fix", "--type", "branch", "--plan", "p.md", "--findings", "branch-review-x.json"],
|
|
575
|
-
{
|
|
576
|
-
from: "user",
|
|
577
|
-
},
|
|
578
|
-
);
|
|
579
|
-
expect((fix.opts() as Record<string, unknown>).base).toBeUndefined();
|
|
580
|
-
expect((fix.opts() as Record<string, unknown>).head).toBeUndefined();
|
|
581
|
-
// re-declaring the range on the fix CLI is rejected — the unknown-option
|
|
582
|
-
// face lands on the undeclared-flag runArgv test below
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
it("an undeclared flag is an unknown option — the unknown-flag semantics (a typo never runs a dispatch)", async () => {
|
|
586
|
-
const { command, io, cleanup } = fixture();
|
|
587
|
-
try {
|
|
588
|
-
// the required flags must be satisfied first — the missing-required check
|
|
589
|
-
// fires before the unknown-option scan (probe-verified)
|
|
590
|
-
let code = await command.runArgv(["implement", "--tasks", "1", "--plan", "x", "--taks"]);
|
|
591
|
-
expect(code).toBe(2);
|
|
592
|
-
expect(io.stderrText).toContain("error: unknown option '--taks'");
|
|
593
|
-
expect(io.stderrText).toContain("(Did you mean --tasks?)");
|
|
594
|
-
io.stderrText = "";
|
|
595
|
-
// the fix face re-declares no branch refs — --base/--head are unknown to fix
|
|
596
|
-
code = await command.runArgv([
|
|
597
|
-
"fix",
|
|
598
|
-
"--type",
|
|
599
|
-
"branch",
|
|
600
|
-
"--base",
|
|
601
|
-
"a".repeat(8),
|
|
602
|
-
"--head",
|
|
603
|
-
"b".repeat(8),
|
|
604
|
-
]);
|
|
605
|
-
expect(code).toBe(2);
|
|
606
|
-
expect(io.stderrText).toContain("error: unknown option '--base'");
|
|
607
|
-
io.stderrText = "";
|
|
608
|
-
// a typo with a required flag missing surfaces the required byte — the
|
|
609
|
-
// missing-required check wins over the unknown-option scan
|
|
610
|
-
code = await command.runArgv(["implement", "--taks", "1"]);
|
|
611
|
-
expect(code).toBe(2);
|
|
612
|
-
expect(io.stderrText).toContain("error: required option '--tasks <n|n,n,…>' not specified");
|
|
613
|
-
} finally {
|
|
614
|
-
cleanup();
|
|
615
|
-
}
|
|
616
|
-
});
|
|
617
|
-
|
|
618
|
-
it("rejects a non-program flag before the verb and an unknown command", async () => {
|
|
619
|
-
const { command, io, cleanup } = fixture();
|
|
620
|
-
try {
|
|
621
|
-
let code = await command.runArgv(["--root", "x", "implement"]);
|
|
622
|
-
expect(code).toBe(2);
|
|
623
|
-
expect(io.stderrText).toContain("error: unknown option '--root'");
|
|
624
|
-
io.stderrText = "";
|
|
625
|
-
// the unknown-command face carries commander's native name suggestion — the
|
|
626
|
-
// command-name near-miss never self-built before (the T5 new surface)
|
|
627
|
-
code = await command.runArgv(["implementt", "--tasks", "1"]);
|
|
628
|
-
expect(code).toBe(2);
|
|
629
|
-
expect(io.stderrText).toContain("error: unknown command 'implementt'");
|
|
630
|
-
expect(io.stderrText).toContain("(Did you mean implement?)");
|
|
631
|
-
} finally {
|
|
632
|
-
cleanup();
|
|
633
|
-
}
|
|
634
|
-
});
|
|
635
|
-
|
|
636
|
-
it("rejects a missing required flag", async () => {
|
|
637
|
-
const { command, io, cleanup } = fixture();
|
|
638
|
-
try {
|
|
639
|
-
let code = await command.runArgv(["implement", "--plan", "x"]);
|
|
640
|
-
expect(code).toBe(2);
|
|
641
|
-
expect(io.stderrText).toContain("error: required option '--tasks <n|n,n,…>' not specified");
|
|
642
|
-
io.stderrText = "";
|
|
643
|
-
code = await command.runArgv(["review", "--tasks", "1"]);
|
|
644
|
-
expect(code).toBe(2);
|
|
645
|
-
expect(io.stderrText).toContain(
|
|
646
|
-
"error: required option '--type <wave|branch|spec|plan>' not specified",
|
|
647
|
-
);
|
|
648
|
-
} finally {
|
|
649
|
-
cleanup();
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
it("parses the nested leaves — base set|get · schema get · issue render", () => {
|
|
654
|
-
gate.parse(["base", "set", "--plan", "p.md", "--base", "dev", "--source", "plan-field"], {
|
|
655
|
-
from: "user",
|
|
656
|
-
});
|
|
657
|
-
expect((leafOf("base", "set").opts() as Record<string, unknown>).base).toBe("dev");
|
|
658
|
-
gate.parse(
|
|
659
|
-
["base", "set", "--plan", "p.md", "--base", "dev", "--source", "plan-field", "--force"],
|
|
660
|
-
{ from: "user" },
|
|
661
|
-
);
|
|
662
|
-
expect((leafOf("base", "set").opts() as Record<string, unknown>).force).toBe(true);
|
|
663
|
-
gate.parse(["base", "get", "--plan", "p.md"], { from: "user" });
|
|
664
|
-
expect(leafOf("base", "get").args).toEqual([]);
|
|
665
|
-
gate.parse(["schema", "get", "plan"], { from: "user" });
|
|
666
|
-
// commander fills every declared positional — the missing optional <target>
|
|
667
|
-
// rides as undefined; the consumed <type> is the first slot
|
|
668
|
-
expect(leafOf("schema", "get").processedArgs[0]).toBe("plan");
|
|
669
|
-
leafOf("issue", "render");
|
|
670
|
-
expect(leafOf("issue", "render").name()).toBe("render");
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
it("rejects an unknown schema type against the shared schema-type vocabulary", async () => {
|
|
674
|
-
const { command, io, cleanup } = fixture();
|
|
675
|
-
try {
|
|
676
|
-
const code = await command.runArgv(["schema", "get", "bogus"]);
|
|
677
|
-
expect(code).toBe(2);
|
|
678
|
-
expect(io.stderrText).toContain(
|
|
679
|
-
"unknown schema type: bogus (available: overall-spec, plan, phase-spec, single-spec)",
|
|
680
|
-
);
|
|
681
|
-
} finally {
|
|
682
|
-
cleanup();
|
|
683
|
-
}
|
|
684
|
-
});
|
|
685
|
-
|
|
686
|
-
it("parses the merged get leaf — the shared vocabulary with the phaseSpec alias normalized to the kebab key + the optional <target> positional", () => {
|
|
687
|
-
const get = leafOf("schema", "get");
|
|
688
|
-
gate.parse(["schema", "get", "phase-spec"], { from: "user" });
|
|
689
|
-
expect(get.processedArgs[0]).toBe("phase-spec");
|
|
690
|
-
// the legacy camel alias normalizes to the same kebab key
|
|
691
|
-
gate.parse(["schema", "get", "phaseSpec"], { from: "user" });
|
|
692
|
-
expect(get.processedArgs[0]).toBe("phase-spec");
|
|
693
|
-
gate.parse(["schema", "get", "plan"], { from: "user" });
|
|
694
|
-
expect(get.processedArgs[0]).toBe("plan");
|
|
695
|
-
gate.parse(["schema", "get", "overall-spec"], { from: "user" });
|
|
696
|
-
expect(get.processedArgs[0]).toBe("overall-spec");
|
|
697
|
-
// D19 — the target positional rides the merged leaf (mandatory only under
|
|
698
|
-
// --output skeleton, an engine-declared parameter rather than a shell redirect)
|
|
699
|
-
gate.parse(["schema", "get", "phase-spec", "--output", "skeleton", "/tmp/demo.md"], {
|
|
700
|
-
from: "user",
|
|
701
|
-
});
|
|
702
|
-
expect(get.processedArgs).toEqual(["phase-spec", "/tmp/demo.md"]);
|
|
703
|
-
expect(get.opts().output).toBe("skeleton");
|
|
704
|
-
});
|
|
705
|
-
|
|
706
|
-
it("the skeleton render face — a missing <target> and a non-doc-key <type> exit 2 at the run face; a bogus --output rejects at parse", async () => {
|
|
707
|
-
const { command, io, cleanup } = fixture();
|
|
708
|
-
try {
|
|
709
|
-
// --output skeleton makes <target> conditionally required — the missing
|
|
710
|
-
// target surfaces at the domain run (exit 2 · the D19 conditional-required
|
|
711
|
-
// face — never a static commander requirement)
|
|
712
|
-
let code = await command.runArgv(["schema", "get", "phase-spec", "--output", "skeleton"]);
|
|
713
|
-
expect(code).toBe(2);
|
|
714
|
-
expect(io.stderrText).toContain("cdd schema get --output skeleton: missing <target>");
|
|
715
|
-
io.stderrText = "";
|
|
716
|
-
// a command word (board) is not a schema type — the schema vocabulary and
|
|
717
|
-
// the command vocabulary are separate; the unknown type exits 2 at the run
|
|
718
|
-
// face (the shared vocabulary's rejection face)
|
|
719
|
-
code = await command.runArgv([
|
|
720
|
-
"schema",
|
|
721
|
-
"get",
|
|
722
|
-
"board",
|
|
723
|
-
"--output",
|
|
724
|
-
"skeleton",
|
|
725
|
-
"/tmp/demo.md",
|
|
726
|
-
]);
|
|
727
|
-
expect(code).toBe(2);
|
|
728
|
-
expect(io.stderrText).toContain("unknown schema type: board");
|
|
729
|
-
io.stderrText = "";
|
|
730
|
-
// the --output enum rejects an out-of-domain value at parse
|
|
731
|
-
code = await command.runArgv(["schema", "get", "plan", "--output", "bogus"]);
|
|
732
|
-
expect(code).toBe(2);
|
|
733
|
-
expect(io.stderrText).toContain("must be one of json | skeleton");
|
|
734
|
-
} finally {
|
|
735
|
-
cleanup();
|
|
736
|
-
}
|
|
737
|
-
});
|
|
738
|
-
|
|
739
|
-
it("rejects a missing leaf, an unknown leaf and an extra positional", async () => {
|
|
740
|
-
const { command, io, cleanup } = fixture();
|
|
741
|
-
try {
|
|
742
|
-
// a missing subcommand shows the OWNING node's help (exit 2) — the base
|
|
743
|
-
// node's own set/get face, never the top-level program
|
|
744
|
-
let code = await command.runArgv(["base"]);
|
|
745
|
-
expect(code).toBe(2);
|
|
746
|
-
const out = io.stdoutText + io.stderrText;
|
|
747
|
-
expect(out).toContain("Usage: cdd base [options] [command]");
|
|
748
|
-
expect(out).toContain("set [options]");
|
|
749
|
-
expect(out).toContain("get [options]");
|
|
750
|
-
expect(out).not.toContain("Usage: cdd [options] [command]");
|
|
751
|
-
io.stdoutText = "";
|
|
752
|
-
io.stderrText = "";
|
|
753
|
-
// an unknown leaf carries commander's native subcommand suggestion
|
|
754
|
-
code = await command.runArgv(["base", "reset"]);
|
|
755
|
-
expect(code).toBe(2);
|
|
756
|
-
expect(io.stderrText).toContain("error: unknown command 'reset'");
|
|
757
|
-
expect(io.stderrText).toContain("(Did you mean set?)");
|
|
758
|
-
io.stderrText = "";
|
|
759
|
-
// a spurious target under the json render face rides the run-body usage —
|
|
760
|
-
// the target is the skeleton face's engine-declared parameter, never a
|
|
761
|
-
// shell-redirect slot (D19)
|
|
762
|
-
code = await command.runArgv(["schema", "get", "plan", "extra"]);
|
|
763
|
-
expect(code).toBe(2);
|
|
764
|
-
expect(io.stderrText).toContain(
|
|
765
|
-
"cdd schema get: unexpected <target> — the json render takes no target",
|
|
766
|
-
);
|
|
767
|
-
} finally {
|
|
768
|
-
cleanup();
|
|
769
|
-
}
|
|
770
|
-
});
|
|
771
|
-
|
|
772
|
-
it("accepts --help / -h and the dry-run scope at any position — the program scopes ride the runArgv face (exit 0)", async () => {
|
|
773
|
-
const { command, io, cleanup } = fixture();
|
|
774
|
-
try {
|
|
775
|
-
// --help anywhere pre-empts the scan — the helpDisplayed face (exit 0)
|
|
776
|
-
let code = await command.runArgv(["review", "--type", "wave", "--help"]);
|
|
777
|
-
expect(code).toBe(0);
|
|
778
|
-
expect(io.stdoutText).toContain("Usage: cdd review [options]");
|
|
779
|
-
io.stdoutText = "";
|
|
780
|
-
// -h before the verb resolves to the PROGRAM face, exit 0 (the pre-verb
|
|
781
|
-
// scope shows the top-level help, never the would-be command's)
|
|
782
|
-
code = await command.runArgv(["-h", "implement", "--tasks", "1"]);
|
|
783
|
-
expect(code).toBe(0);
|
|
784
|
-
expect(io.stdoutText).toContain("Usage: cdd [options] [command]");
|
|
785
|
-
} finally {
|
|
786
|
-
cleanup();
|
|
787
|
-
}
|
|
788
|
-
});
|
|
789
|
-
|
|
790
|
-
it("a pre-verb --dry-run dispatches through the program scope — the flag merges into the run (exit 0)", async () => {
|
|
791
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
792
|
-
try {
|
|
793
|
-
gitInit(repoRoot);
|
|
794
|
-
const plan = planFor(repoRoot);
|
|
795
|
-
const code = await command.runArgv([
|
|
796
|
-
"--dry-run",
|
|
797
|
-
"implement",
|
|
798
|
-
"--tasks",
|
|
799
|
-
"1",
|
|
800
|
-
"--plan",
|
|
801
|
-
plan,
|
|
802
|
-
"--root",
|
|
803
|
-
repoRoot,
|
|
804
|
-
]);
|
|
805
|
-
expect(code).toBe(0);
|
|
806
|
-
expect(io.stdoutText).toContain("status: APPROVED");
|
|
807
|
-
expect(
|
|
808
|
-
existsSync(path.join(repoRoot, ".kairos", "cdd", "p3", "tasks-1-implement.json")),
|
|
809
|
-
).toBe(true);
|
|
810
|
-
} finally {
|
|
811
|
-
cleanup();
|
|
812
|
-
}
|
|
813
|
-
});
|
|
814
|
-
|
|
815
|
-
it("a help flag on a leaf command pre-empts the required leaf word — base --help exits 0", async () => {
|
|
816
|
-
const { command, io, cleanup } = fixture();
|
|
817
|
-
try {
|
|
818
|
-
const code = await command.runArgv(["base", "--help"]);
|
|
819
|
-
expect(code).toBe(0);
|
|
820
|
-
expect(io.stdoutText).toContain("Usage: cdd base [options] [command]");
|
|
821
|
-
} finally {
|
|
822
|
-
cleanup();
|
|
823
|
-
}
|
|
824
|
-
});
|
|
825
|
-
|
|
826
|
-
it("the bool negation spellings are retired — a negated bool flag is an unknown option with the back-spelling hint", async () => {
|
|
827
|
-
const { command, io, cleanup } = fixture();
|
|
828
|
-
// the negated spellings are composed via the shared synthesizer — the
|
|
829
|
-
// literal tokens never appear in the tree (the zero-consumption pin)
|
|
830
|
-
const negatedDryRun = negatedOf("--dry-run");
|
|
831
|
-
const negatedForce = negatedOf("--force");
|
|
832
|
-
try {
|
|
833
|
-
// the hidden negations are never registered — commander's native near-miss
|
|
834
|
-
// still hints the real flag
|
|
835
|
-
let code = await command.runArgv(["implement", negatedDryRun, "--tasks", "1", "--plan", "x"]);
|
|
836
|
-
expect(code).toBe(2);
|
|
837
|
-
expect(io.stderrText).toContain(`error: unknown option '${negatedDryRun}'`);
|
|
838
|
-
expect(io.stderrText).toContain("(Did you mean --dry-run?)");
|
|
839
|
-
io.stderrText = "";
|
|
840
|
-
code = await command.runArgv([
|
|
841
|
-
"base",
|
|
842
|
-
"set",
|
|
843
|
-
"--plan",
|
|
844
|
-
"p",
|
|
845
|
-
"--base",
|
|
846
|
-
"d",
|
|
847
|
-
"--source",
|
|
848
|
-
"plan-field",
|
|
849
|
-
negatedForce,
|
|
850
|
-
]);
|
|
851
|
-
expect(code).toBe(2);
|
|
852
|
-
expect(io.stderrText).toContain(`error: unknown option '${negatedForce}'`);
|
|
853
|
-
expect(io.stderrText).toContain("(Did you mean --force?)");
|
|
854
|
-
} finally {
|
|
855
|
-
cleanup();
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
// ---------------------------------------------------------------------------
|
|
861
|
-
// the help/--help display face — the overview · the per-command native render ·
|
|
862
|
-
// the error-path bytes (T5 re-pin onto the commander-native surface; the old
|
|
863
|
-
// self-built rendering + smart-hint corpus retired with the T2 projection)
|
|
864
|
-
// ---------------------------------------------------------------------------
|
|
865
|
-
|
|
866
|
-
describe("the help/--help display face — the command overview", () => {
|
|
867
|
-
it("bare `cdd` renders the commander program face, exit 2 — no custom missing-command text (spec §3.3)", async () => {
|
|
868
|
-
const { command, io, cleanup } = fixture();
|
|
869
|
-
try {
|
|
870
|
-
const code = await command.runArgv([]);
|
|
871
|
-
expect(code).toBe(2);
|
|
872
|
-
// the bare run's help rides commander's error channel (exit 2 = the usage
|
|
873
|
-
// domain) — the native program face: Usage/Options/Commands + the help row.
|
|
874
|
-
const out = io.stdoutText + io.stderrText;
|
|
875
|
-
expect(out).toContain("Usage: cdd [options] [command]");
|
|
876
|
-
expect(out).toContain("Commands:");
|
|
877
|
-
// the seven-command table + the built-in help [command] row (native layout)
|
|
878
|
-
for (const name of ["implement", "review", "fix", "base", "schema", "issue", "board"]) {
|
|
879
|
-
expect(out).toContain(name);
|
|
880
|
-
}
|
|
881
|
-
expect(out).toContain("help [command]");
|
|
882
|
-
// the retired custom missing-command byte is gone — the bare run never
|
|
883
|
-
// renders a self-built message over the native face
|
|
884
|
-
expect(out).not.toContain("missing command");
|
|
885
|
-
expect(out).not.toContain(RETIRED_USAGE.implement);
|
|
886
|
-
} finally {
|
|
887
|
-
cleanup();
|
|
888
|
-
}
|
|
889
|
-
});
|
|
890
|
-
|
|
891
|
-
it("a verb-less --help renders the same native program face with the flip to exit 0 (§3.4)", async () => {
|
|
892
|
-
const { command, io, cleanup } = fixture();
|
|
893
|
-
try {
|
|
894
|
-
const code = await command.runArgv(["--help"]);
|
|
895
|
-
expect(code).toBe(0);
|
|
896
|
-
// the helpDisplayed face — the help lands on the stdout channel, exit 0
|
|
897
|
-
expect(io.stdoutText).toContain("Usage: cdd [options] [command]");
|
|
898
|
-
expect(io.stdoutText).toContain("Commands:");
|
|
899
|
-
expect(io.stdoutText).not.toContain("missing command");
|
|
900
|
-
expect(io.stderrText).toBe("");
|
|
901
|
-
} finally {
|
|
902
|
-
cleanup();
|
|
903
|
-
}
|
|
904
|
-
});
|
|
905
|
-
});
|
|
906
|
-
|
|
907
|
-
describe("the help/--help display face — the per-command render", () => {
|
|
908
|
-
it("cdd implement --help — the native command face: the flag tokens + value domains + the example, exit 0", async () => {
|
|
909
|
-
const { command, io, cleanup } = fixture();
|
|
910
|
-
try {
|
|
911
|
-
const code = await command.runArgv(["implement", "--help"]);
|
|
912
|
-
expect(code).toBe(0);
|
|
913
|
-
expect(io.stdoutText).toContain("Usage: cdd implement [options]");
|
|
914
|
-
expect(io.stdoutText).toContain("--tasks <n|n,n,…>");
|
|
915
|
-
expect(io.stdoutText).toContain("--plan <path>");
|
|
916
|
-
expect(io.stdoutText).toContain("--root <path>");
|
|
917
|
-
expect(io.stdoutText).toContain("the task ids of the wave group (comma-separated)");
|
|
918
|
-
expect(io.stdoutText).toContain("(required)");
|
|
919
|
-
expect(io.stdoutText).toContain("run the task implement phase");
|
|
920
|
-
expect(io.stdoutText).toContain("Examples:");
|
|
921
|
-
expect(io.stdoutText).toContain("cdd implement --tasks 1,2 --plan docs/kairos/plans/p3.md");
|
|
922
|
-
} finally {
|
|
923
|
-
cleanup();
|
|
924
|
-
}
|
|
925
|
-
});
|
|
926
|
-
|
|
927
|
-
it("cdd review --help — the --type enum + the per-flag value domains + the example, exit 0", async () => {
|
|
928
|
-
const { command, io, cleanup } = fixture();
|
|
929
|
-
try {
|
|
930
|
-
const code = await command.runArgv(["review", "--help"]);
|
|
931
|
-
expect(code).toBe(0);
|
|
932
|
-
expect(io.stdoutText).toContain("--type <wave|branch|spec|plan>");
|
|
933
|
-
expect(io.stdoutText).toContain("--tasks <n|n,n,…>");
|
|
934
|
-
expect(io.stdoutText).toContain("--round <n>");
|
|
935
|
-
expect(io.stdoutText).toContain("--spec <path>");
|
|
936
|
-
// the branch range flags retired with the commit-sha surface (P7)
|
|
937
|
-
expect(io.stdoutText).not.toContain("--base");
|
|
938
|
-
expect(io.stdoutText).not.toContain("--head");
|
|
939
|
-
expect(io.stdoutText).toContain("the target face of the round");
|
|
940
|
-
expect(io.stdoutText).toContain(
|
|
941
|
-
"cdd review --type spec --spec docs/kairos/specs/p3-design.md",
|
|
942
|
-
);
|
|
943
|
-
} finally {
|
|
944
|
-
cleanup();
|
|
945
|
-
}
|
|
946
|
-
});
|
|
947
|
-
|
|
948
|
-
it("cdd fix --help — the findings flag + the example, exit 0", async () => {
|
|
949
|
-
const { command, io, cleanup } = fixture();
|
|
950
|
-
try {
|
|
951
|
-
const code = await command.runArgv(["fix", "--help"]);
|
|
952
|
-
expect(code).toBe(0);
|
|
953
|
-
expect(io.stdoutText).toContain("--findings <path>");
|
|
954
|
-
expect(io.stdoutText).toContain("the source review handoff JSON path");
|
|
955
|
-
expect(io.stdoutText).toContain(
|
|
956
|
-
"cdd fix --type wave --tasks 1 --findings tasks-1-review-1.json",
|
|
957
|
-
);
|
|
958
|
-
} finally {
|
|
959
|
-
cleanup();
|
|
960
|
-
}
|
|
961
|
-
});
|
|
962
|
-
|
|
963
|
-
it("cdd base --help — the native sub-command table (set | get) without the leaf option tokens, exit 0", async () => {
|
|
964
|
-
const { command, io, cleanup } = fixture();
|
|
965
|
-
try {
|
|
966
|
-
const code = await command.runArgv(["base", "--help"]);
|
|
967
|
-
expect(code).toBe(0);
|
|
968
|
-
expect(io.stdoutText).toContain("Usage: cdd base [options] [command]");
|
|
969
|
-
expect(io.stdoutText).toContain("Commands:");
|
|
970
|
-
expect(io.stdoutText).toContain("set [options]");
|
|
971
|
-
expect(io.stdoutText).toContain("get [options]");
|
|
972
|
-
expect(io.stdoutText).toContain("write the base artifact");
|
|
973
|
-
expect(io.stdoutText).toContain("read the base artifact");
|
|
974
|
-
// the leaf option rows stay off the parent face — base set's --force (never
|
|
975
|
-
// mentioned on the parent) and the --source <…> row's token form (the written
|
|
976
|
-
// example sentence legitimately carries the bare `--source plan-field` value)
|
|
977
|
-
expect(io.stdoutText).not.toContain("--force");
|
|
978
|
-
expect(io.stdoutText).not.toContain("--source <");
|
|
979
|
-
expect(io.stdoutText).toContain(
|
|
980
|
-
"cdd base set --plan docs/kairos/plans/p3.md --base develop --source plan-field",
|
|
981
|
-
);
|
|
982
|
-
} finally {
|
|
983
|
-
cleanup();
|
|
984
|
-
}
|
|
985
|
-
});
|
|
986
|
-
|
|
987
|
-
it("cdd schema --help — the native Commands table (the merged get leaf) + the example, exit 0", async () => {
|
|
988
|
-
const { command, io, cleanup } = fixture();
|
|
989
|
-
try {
|
|
990
|
-
const code = await command.runArgv(["schema", "--help"]);
|
|
991
|
-
expect(code).toBe(0);
|
|
992
|
-
// whitespace-normalized — commander wraps the long description onto
|
|
993
|
-
// continuation lines; the assertion reads the token stream
|
|
994
|
-
const help = io.stdoutText.replace(/\s+/g, " ");
|
|
995
|
-
expect(help).toContain("Usage: cdd schema [options] [command]");
|
|
996
|
-
expect(help).toContain("Commands:");
|
|
997
|
-
expect(help).toContain("get [options] <type> [target]");
|
|
998
|
-
expect(help).toContain("print the derived doc-structure schema for <type>");
|
|
999
|
-
expect(help).toContain("or render the derived doc skeleton into <target>");
|
|
1000
|
-
// D19 — the gen leaf is gone; the single get leaf's rows ride the Commands table
|
|
1001
|
-
expect(help).not.toContain("gen [options]");
|
|
1002
|
-
expect(help).toContain("cdd schema get phase-spec");
|
|
1003
|
-
} finally {
|
|
1004
|
-
cleanup();
|
|
1005
|
-
}
|
|
1006
|
-
});
|
|
1007
|
-
|
|
1008
|
-
it("cdd issue --help — the native Commands table (render) + the example, exit 0", async () => {
|
|
1009
|
-
const { command, io, cleanup } = fixture();
|
|
1010
|
-
try {
|
|
1011
|
-
const code = await command.runArgv(["issue", "--help"]);
|
|
1012
|
-
expect(code).toBe(0);
|
|
1013
|
-
expect(io.stdoutText).toContain("Usage: cdd issue [options] [command]");
|
|
1014
|
-
expect(io.stdoutText).toContain("Commands:");
|
|
1015
|
-
expect(io.stdoutText).toContain("render [options]");
|
|
1016
|
-
expect(io.stdoutText).toContain("render the aggregate issue body");
|
|
1017
|
-
expect(io.stdoutText).toContain("cdd issue render < findings.json");
|
|
1018
|
-
} finally {
|
|
1019
|
-
cleanup();
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1022
|
-
|
|
1023
|
-
it("a help flag on a leaf command renders the LEAF's own face (base set --help), exit 0", async () => {
|
|
1024
|
-
const { command, io, cleanup } = fixture();
|
|
1025
|
-
try {
|
|
1026
|
-
const code = await command.runArgv(["base", "set", "--help"]);
|
|
1027
|
-
expect(code).toBe(0);
|
|
1028
|
-
// the leaf's own native help — its usage line + its own option rows (set's
|
|
1029
|
-
// --force face), never the parent base node's subcommand table
|
|
1030
|
-
expect(io.stdoutText).toContain("Usage: cdd base set [options]");
|
|
1031
|
-
expect(io.stdoutText).toContain("write the base artifact");
|
|
1032
|
-
expect(io.stdoutText).toContain("--force");
|
|
1033
|
-
expect(io.stdoutText).not.toContain("Commands:");
|
|
1034
|
-
} finally {
|
|
1035
|
-
cleanup();
|
|
1036
|
-
}
|
|
1037
|
-
});
|
|
1038
|
-
|
|
1039
|
-
it("every per-command --help carries the program-flag tail note (--dry-run alone)", async () => {
|
|
1040
|
-
const { command, io, cleanup } = fixture();
|
|
1041
|
-
try {
|
|
1042
|
-
for (const verb of ["implement", "review", "fix", "base", "schema", "issue", "board"]) {
|
|
1043
|
-
expect(await command.runArgv([verb, "--help"])).toBe(0);
|
|
1044
|
-
}
|
|
1045
|
-
// the tail note rides the commander afterAll surface — one line per help
|
|
1046
|
-
// face, listing --dry-run ALONE (the -h/--help redundant column unwritten)
|
|
1047
|
-
const legend = /program flags \(accepted at any position\): --dry-run/g;
|
|
1048
|
-
expect(io.stdoutText.match(legend) ?? []).toHaveLength(7);
|
|
1049
|
-
expect(io.stdoutText).not.toContain("· --help / -h");
|
|
1050
|
-
} finally {
|
|
1051
|
-
cleanup();
|
|
1052
|
-
}
|
|
1053
|
-
});
|
|
1054
|
-
});
|
|
1055
|
-
|
|
1056
|
-
describe("the T4 commander-native help acceptance — the projected help face (§5)", () => {
|
|
1057
|
-
/** Normalize the whitespace runs — commander wraps long texts onto a continuation
|
|
1058
|
-
* line with the table padding; the projection assertions read the description
|
|
1059
|
-
* token stream through single spaces, never a wrapped byte literal. */
|
|
1060
|
-
const norm = (text: string): string => text.replace(/\s+/g, " ");
|
|
1061
|
-
|
|
1062
|
-
it("cdd --help — the native program face: Usage · the seven-command table (short descriptions = the CLI_COMMANDS projection) · Examples heading · the --dry-run-only footer", async () => {
|
|
1063
|
-
const { command, io, cleanup } = fixture();
|
|
1064
|
-
try {
|
|
1065
|
-
const code = await command.runArgv(["--help"]);
|
|
1066
|
-
expect(code).toBe(0);
|
|
1067
|
-
const help = norm(io.stdoutText);
|
|
1068
|
-
// The commander-native layout — the Usage line + the capital-C section
|
|
1069
|
-
// headings (the §5.1 Usage/Options/Commands section heads).
|
|
1070
|
-
expect(help).toContain("Usage: cdd [options] [command]");
|
|
1071
|
-
expect(help).toContain("Commands:");
|
|
1072
|
-
expect(help).toContain("Options:");
|
|
1073
|
-
// The seven command rows — the command names + their short descriptions
|
|
1074
|
-
// SINGLE-SOURCED at the CLI_COMMANDS declaration rows (the projection test,
|
|
1075
|
-
// never a hand-typed byte list).
|
|
1076
|
-
for (const spec of CLI_COMMANDS) {
|
|
1077
|
-
expect(help).toContain(spec.name);
|
|
1078
|
-
expect(help).toContain(spec.description);
|
|
1079
|
-
}
|
|
1080
|
-
// The Examples section heading + a P1 example sentence in the stream.
|
|
1081
|
-
expect(help).toContain("Examples:");
|
|
1082
|
-
expect(help).toContain("cdd review --type spec --spec docs/kairos/specs/p3-design.md");
|
|
1083
|
-
// The program-flag tail note: --dry-run listed ALONE — the -h/--help
|
|
1084
|
-
// redundant column is not written (the built-in helpOption faces Options).
|
|
1085
|
-
const footer = io.stdoutText.split("\n").find((line) => line.startsWith("program flags"));
|
|
1086
|
-
expect(footer).toBe("program flags (accepted at any position): --dry-run");
|
|
1087
|
-
expect(footer).not.toContain("--help");
|
|
1088
|
-
expect(footer).not.toContain("-h");
|
|
1089
|
-
} finally {
|
|
1090
|
-
cleanup();
|
|
1091
|
-
}
|
|
1092
|
-
});
|
|
1093
|
-
|
|
1094
|
-
it("cdd review --help — the option descriptions carry the value-domain tokens, in the declared registration order (the §5.2 registration order)", async () => {
|
|
1095
|
-
const { command, io, cleanup } = fixture();
|
|
1096
|
-
try {
|
|
1097
|
-
const code = await command.runArgv(["review", "--help"]);
|
|
1098
|
-
expect(code).toBe(0);
|
|
1099
|
-
const help = norm(io.stdoutText);
|
|
1100
|
-
// The §5.2 value domains ride the option descriptions.
|
|
1101
|
-
expect(help).toContain("--type <wave|branch|spec|plan>");
|
|
1102
|
-
expect(help).toContain("--tasks <n|n,n,…>");
|
|
1103
|
-
expect(help).toContain("--plan <path>");
|
|
1104
|
-
// the branch range flags retired with the commit-sha surface (P7)
|
|
1105
|
-
expect(help).not.toContain("--base");
|
|
1106
|
-
expect(help).not.toContain("--head");
|
|
1107
|
-
// The description order = the ARGV_CHANNEL row order of the review node's
|
|
1108
|
-
// declared keys (the registration order never a sorted/derived one).
|
|
1109
|
-
expect(help.indexOf("--type")).toBeLessThan(help.indexOf("--tasks"));
|
|
1110
|
-
expect(help.indexOf("--plan")).toBeLessThan(help.indexOf("--spec"));
|
|
1111
|
-
expect(help.indexOf("--root")).toBeLessThan(help.indexOf("--dry-run"));
|
|
1112
|
-
} finally {
|
|
1113
|
-
cleanup();
|
|
1114
|
-
}
|
|
1115
|
-
});
|
|
1116
|
-
|
|
1117
|
-
it("cdd schema --help — the leaf subcommand table rides the native Commands face (the single get leaf)", async () => {
|
|
1118
|
-
const { command, io, cleanup } = fixture();
|
|
1119
|
-
try {
|
|
1120
|
-
const code = await command.runArgv(["schema", "--help"]);
|
|
1121
|
-
expect(code).toBe(0);
|
|
1122
|
-
const help = norm(io.stdoutText);
|
|
1123
|
-
expect(help).toContain("Commands:");
|
|
1124
|
-
expect(help).toContain("get [options] <type>");
|
|
1125
|
-
// D19 — the gen leaf is gone, so its Commands row never rides the face.
|
|
1126
|
-
expect(help).not.toContain("gen [options]");
|
|
1127
|
-
} finally {
|
|
1128
|
-
cleanup();
|
|
1129
|
-
}
|
|
1130
|
-
});
|
|
1131
|
-
|
|
1132
|
-
it("cdd base get --help — the leaf face binds its OWN keys: --plan present, set's --force NOT leaked (leaf granularity)", async () => {
|
|
1133
|
-
const { command, io, cleanup } = fixture();
|
|
1134
|
-
try {
|
|
1135
|
-
const code = await command.runArgv(["base", "get", "--help"]);
|
|
1136
|
-
expect(code).toBe(0);
|
|
1137
|
-
const help = norm(io.stdoutText);
|
|
1138
|
-
expect(help).toContain("--plan <path>");
|
|
1139
|
-
expect(help).not.toContain("--force");
|
|
1140
|
-
} finally {
|
|
1141
|
-
cleanup();
|
|
1142
|
-
}
|
|
1143
|
-
});
|
|
1144
|
-
});
|
|
1145
|
-
|
|
1146
|
-
describe("the error-path face — commander's native suggestion bytes (T5 re-pin)", () => {
|
|
1147
|
-
it("an unknown flag exits 2 with commander's unknown-option byte + the native did-you-mean", async () => {
|
|
1148
|
-
const { command, io, cleanup } = fixture();
|
|
1149
|
-
try {
|
|
1150
|
-
// the required flags must be satisfied first — commander's missing-required
|
|
1151
|
-
// check fires before the unknown-option scan (probe-verified)
|
|
1152
|
-
const code = await command.runArgv(["implement", "--tasks", "2", "--plan", "p.md", "--taks"]);
|
|
1153
|
-
expect(code).toBe(2);
|
|
1154
|
-
expect(io.stderrText).toContain("error: unknown option '--taks'");
|
|
1155
|
-
expect(io.stderrText).toContain("(Did you mean --tasks?)");
|
|
1156
|
-
// the self-built usage line + the suggestion hint never ride the error face
|
|
1157
|
-
expect(io.stderrText).not.toContain(RETIRED_USAGE.implement);
|
|
1158
|
-
} finally {
|
|
1159
|
-
cleanup();
|
|
1160
|
-
}
|
|
1161
|
-
});
|
|
1162
|
-
|
|
1163
|
-
it("an unknown flag never suggests a flag the same command also rejects", async () => {
|
|
1164
|
-
const { command, io, cleanup } = fixture();
|
|
1165
|
-
try {
|
|
1166
|
-
// `--spec` (the SPEL→SPEC near-miss) is a review/fix flag, not an
|
|
1167
|
-
// implement one — the did-you-mean candidates stay inside the errored
|
|
1168
|
-
// command's own declared flags, so a foreign flag the same verb would
|
|
1169
|
-
// reject is never suggested (the three-ID negative pin).
|
|
1170
|
-
const code = await command.runArgv(["implement", "--tasks", "2", "--plan", "p.md", "--spel"]);
|
|
1171
|
-
expect(code).toBe(2);
|
|
1172
|
-
expect(io.stderrText).toContain("error: unknown option '--spel'");
|
|
1173
|
-
expect(io.stderrText).not.toContain("(Did you mean --spec?)");
|
|
1174
|
-
expect(io.stderrText).not.toContain(RETIRED_USAGE.implement);
|
|
1175
|
-
} finally {
|
|
1176
|
-
cleanup();
|
|
1177
|
-
}
|
|
1178
|
-
});
|
|
1179
|
-
|
|
1180
|
-
it("a pre-verb unknown flag narrows to the program scopes — no command-flag suggestion (the §5.3 side-selection)", async () => {
|
|
1181
|
-
const { command, io, cleanup } = fixture();
|
|
1182
|
-
try {
|
|
1183
|
-
// `--taks` before the verb hits the PROGRAM node — its candidate set is the
|
|
1184
|
-
// program scopes alone (--dry-run/help), so the command-scoped `--tasks`
|
|
1185
|
-
// near-miss is never suggested (the program face never leaks a leaf flag).
|
|
1186
|
-
const code = await command.runArgv(["--taks", "implement"]);
|
|
1187
|
-
expect(code).toBe(2);
|
|
1188
|
-
expect(io.stderrText).toContain("error: unknown option '--taks'");
|
|
1189
|
-
expect(io.stderrText).not.toContain("(Did you mean --tasks?)");
|
|
1190
|
-
} finally {
|
|
1191
|
-
cleanup();
|
|
1192
|
-
}
|
|
1193
|
-
});
|
|
1194
|
-
|
|
1195
|
-
it("a leaf's unknown flag stays inside the leaf's own candidates (base get never suggests set's --force)", async () => {
|
|
1196
|
-
const { command, io, cleanup } = fixture();
|
|
1197
|
-
try {
|
|
1198
|
-
// --force / --source are set-only flags: the get leaf's candidate set is
|
|
1199
|
-
// its own declared options — `--forc` hints nothing (the three-ID pin).
|
|
1200
|
-
const code = await command.runArgv(["base", "get", "--forc", "--plan", "p.md"]);
|
|
1201
|
-
expect(code).toBe(2);
|
|
1202
|
-
expect(io.stderrText).toContain("error: unknown option '--forc'");
|
|
1203
|
-
expect(io.stderrText).not.toContain("(Did you mean");
|
|
1204
|
-
expect(io.stderrText).not.toContain(RETIRED_USAGE.base);
|
|
1205
|
-
} finally {
|
|
1206
|
-
cleanup();
|
|
1207
|
-
}
|
|
1208
|
-
});
|
|
1209
|
-
|
|
1210
|
-
it("the dead-end suggestion chain is gone — get hints nothing on set-only flags, set still hints its own", async () => {
|
|
1211
|
-
const { command, io, cleanup } = fixture();
|
|
1212
|
-
try {
|
|
1213
|
-
// Following an old-style hint (`base get --forc` → `--force`) would land on
|
|
1214
|
-
// another set-only flag the get face rejects — the get surface hints nothing.
|
|
1215
|
-
const dead = await command.runArgv(["base", "get", "--force", "--plan", "p.md"]);
|
|
1216
|
-
expect(dead).toBe(2);
|
|
1217
|
-
expect(io.stderrText).toContain("error: unknown option '--force'");
|
|
1218
|
-
expect(io.stderrText).not.toContain("(Did you mean");
|
|
1219
|
-
|
|
1220
|
-
// The native hint survives on the set surface — --force IS set-declared.
|
|
1221
|
-
const alive = await command.runArgv([
|
|
1222
|
-
"base",
|
|
1223
|
-
"set",
|
|
1224
|
-
"--forc",
|
|
1225
|
-
"--plan",
|
|
1226
|
-
"p.md",
|
|
1227
|
-
"--base",
|
|
1228
|
-
"develop",
|
|
1229
|
-
"--source",
|
|
1230
|
-
"plan-field",
|
|
1231
|
-
]);
|
|
1232
|
-
expect(alive).toBe(2);
|
|
1233
|
-
expect(io.stderrText).toContain("error: unknown option '--forc'");
|
|
1234
|
-
expect(io.stderrText).toContain("(Did you mean --force?)");
|
|
1235
|
-
} finally {
|
|
1236
|
-
cleanup();
|
|
1237
|
-
}
|
|
1238
|
-
});
|
|
1239
|
-
|
|
1240
|
-
it("a missing required flag exits 2 with the .requiredOption() byte (no suggestion)", async () => {
|
|
1241
|
-
const { command, io, cleanup } = fixture();
|
|
1242
|
-
try {
|
|
1243
|
-
const code = await command.runArgv(["implement", "--plan", "p.md"]);
|
|
1244
|
-
expect(code).toBe(2);
|
|
1245
|
-
expect(io.stderrText).toContain("error: required option '--tasks <n|n,n,…>' not specified");
|
|
1246
|
-
expect(io.stderrText).not.toContain(RETIRED_USAGE.implement);
|
|
1247
|
-
} finally {
|
|
1248
|
-
cleanup();
|
|
1249
|
-
}
|
|
1250
|
-
});
|
|
1251
|
-
|
|
1252
|
-
it("an unknown subcommand exits 2 with commander's unknown-command byte + the native subcommand suggestion", async () => {
|
|
1253
|
-
const { command, io, cleanup } = fixture();
|
|
1254
|
-
try {
|
|
1255
|
-
const code = await command.runArgv(["base", "reset"]);
|
|
1256
|
-
expect(code).toBe(2);
|
|
1257
|
-
expect(io.stderrText).toContain("error: unknown command 'reset'");
|
|
1258
|
-
expect(io.stderrText).toContain("(Did you mean set?)");
|
|
1259
|
-
expect(io.stderrText).not.toContain(RETIRED_USAGE.base);
|
|
1260
|
-
} finally {
|
|
1261
|
-
cleanup();
|
|
1262
|
-
}
|
|
1263
|
-
});
|
|
1264
|
-
|
|
1265
|
-
it("the D19 schema leaf merge — `schema g` exits 2 as an unknown command (the prefix resolves to the single get face, never a phantom dispatch)", async () => {
|
|
1266
|
-
const { command, io, cleanup } = fixture();
|
|
1267
|
-
try {
|
|
1268
|
-
// The `g` prefix's closest candidate is the single get leaf, but commander's
|
|
1269
|
-
// suggestion floor (similarity > 0.4) stays silent for a one-character guess —
|
|
1270
|
-
// the candidate set updated with the tree (gen gone); the leak face is exit 2,
|
|
1271
|
-
// never a dispatch.
|
|
1272
|
-
const code = await command.runArgv(["schema", "g"]);
|
|
1273
|
-
expect(code).toBe(2);
|
|
1274
|
-
expect(io.stderrText).toContain("error: unknown command 'g'");
|
|
1275
|
-
expect(io.stderrText).not.toContain("(Did you mean get?)");
|
|
1276
|
-
expect(io.stderrText).not.toContain("gen");
|
|
1277
|
-
} finally {
|
|
1278
|
-
cleanup();
|
|
1279
|
-
}
|
|
1280
|
-
});
|
|
1281
|
-
|
|
1282
|
-
it("the D19 --output option enters the get leaf's option candidates — a near-miss flags it", async () => {
|
|
1283
|
-
const { command, io, cleanup } = fixture();
|
|
1284
|
-
try {
|
|
1285
|
-
const code = await command.runArgv(["schema", "get", "--otput", "json", "phase-spec"]);
|
|
1286
|
-
expect(code).toBe(2);
|
|
1287
|
-
expect(io.stderrText).toContain("error: unknown option '--otput'");
|
|
1288
|
-
expect(io.stderrText).toContain("(Did you mean --output?)");
|
|
1289
|
-
} finally {
|
|
1290
|
-
cleanup();
|
|
1291
|
-
}
|
|
1292
|
-
});
|
|
1293
|
-
});
|
|
1294
|
-
|
|
1295
|
-
// ---------------------------------------------------------------------------
|
|
1296
|
-
// the work commands — the lifecycle/capsule/ledger composition (dry-run E2E)
|
|
1297
|
-
// ---------------------------------------------------------------------------
|
|
1298
|
-
|
|
1299
|
-
describe("the work commands run the lifecycle/capsule/ledger — dry-run E2E", () => {
|
|
1300
|
-
it("implement — one dispatch, the capsule face, the ledger record + the rendered brief", async () => {
|
|
1301
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1302
|
-
try {
|
|
1303
|
-
gitInit(repoRoot);
|
|
1304
|
-
const plan = planFor(repoRoot);
|
|
1305
|
-
const code = await command.runArgv([
|
|
1306
|
-
"implement",
|
|
1307
|
-
"--tasks",
|
|
1308
|
-
"1",
|
|
1309
|
-
"--plan",
|
|
1310
|
-
plan,
|
|
1311
|
-
"--dry-run",
|
|
1312
|
-
"--root",
|
|
1313
|
-
repoRoot,
|
|
1314
|
-
]);
|
|
1315
|
-
expect(code).toBe(0);
|
|
1316
|
-
expect(io.stdoutText).toContain("status: APPROVED · blocker: 0 · handoff: ");
|
|
1317
|
-
expect(io.stdoutText).toContain(`next: review --type wave --tasks 1`);
|
|
1318
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
1319
|
-
const progress = readJson<{ waves: unknown[] }>(path.join(workspace, "progress.json"));
|
|
1320
|
-
expect(progress.waves).toContainEqual({ wave: "1", rounds: { implement: [1] } });
|
|
1321
|
-
expect(existsSync(path.join(workspace, "tasks-1-implement.json"))).toBe(true);
|
|
1322
|
-
expect(existsSync(path.join(workspace, "tasks-1-brief.md"))).toBe(true);
|
|
1323
|
-
const brief = readFileSync(path.join(workspace, "tasks-1-brief.md"), "utf8");
|
|
1324
|
-
expect(brief).toContain("### Task 1:");
|
|
1325
|
-
expect(brief).not.toContain("WAVE_BASE:");
|
|
1326
|
-
} finally {
|
|
1327
|
-
cleanup();
|
|
1328
|
-
}
|
|
1329
|
-
});
|
|
1330
|
-
|
|
1331
|
-
it("every wave-face dispatch re-extracts the brief from the CURRENT plan — the complete plan mirror (task + Constraints), never an exists→reuse copy (§4.1/§5)", async () => {
|
|
1332
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1333
|
-
try {
|
|
1334
|
-
gitInit(repoRoot);
|
|
1335
|
-
const plan = planFor(repoRoot);
|
|
1336
|
-
const briefPath = path.join(repoRoot, ".kairos", "cdd", "p3", "tasks-1-brief.md");
|
|
1337
|
-
expect(
|
|
1338
|
-
await command.runArgv([
|
|
1339
|
-
"implement",
|
|
1340
|
-
"--tasks",
|
|
1341
|
-
"1",
|
|
1342
|
-
"--plan",
|
|
1343
|
-
plan,
|
|
1344
|
-
"--dry-run",
|
|
1345
|
-
"--root",
|
|
1346
|
-
repoRoot,
|
|
1347
|
-
]),
|
|
1348
|
-
).toBe(0);
|
|
1349
|
-
const firstBrief = readFileSync(briefPath, "utf8");
|
|
1350
|
-
// the complete plan mirror — the wave's task section AND the plan's
|
|
1351
|
-
// `## Constraints` section (both faces of the mirror, not the task block alone)
|
|
1352
|
-
expect(firstBrief).toContain("### Task 1:");
|
|
1353
|
-
expect(firstBrief).toContain("## Constraints");
|
|
1354
|
-
expect(firstBrief).toContain("- delta");
|
|
1355
|
-
// The plan's Constraints section moves between dispatches (the Plan Sole Writer
|
|
1356
|
-
// amends mid-run): the review dispatch re-extracts the brief from the CURRENT
|
|
1357
|
-
// plan — no "exists → leave it" reuse.
|
|
1358
|
-
writeFileSync(
|
|
1359
|
-
plan,
|
|
1360
|
-
readFileSync(plan, "utf8").replace("- delta", "- delta (amended)"),
|
|
1361
|
-
"utf8",
|
|
1362
|
-
);
|
|
1363
|
-
io.stdoutText = "";
|
|
1364
|
-
expect(
|
|
1365
|
-
await command.runArgv([
|
|
1366
|
-
"review",
|
|
1367
|
-
"--type",
|
|
1368
|
-
"wave",
|
|
1369
|
-
"--tasks",
|
|
1370
|
-
"1",
|
|
1371
|
-
"--plan",
|
|
1372
|
-
plan,
|
|
1373
|
-
"--dry-run",
|
|
1374
|
-
"--root",
|
|
1375
|
-
repoRoot,
|
|
1376
|
-
]),
|
|
1377
|
-
).toBe(0);
|
|
1378
|
-
const secondBrief = readFileSync(briefPath, "utf8");
|
|
1379
|
-
// the mirrored Constraints reflect the CURRENT plan (fresh-extracted at the
|
|
1380
|
-
// review dispatch), the task section still present
|
|
1381
|
-
expect(secondBrief).toContain("- delta (amended)");
|
|
1382
|
-
expect(secondBrief).toContain("### Task 1:");
|
|
1383
|
-
expect(secondBrief).not.toBe(firstBrief);
|
|
1384
|
-
} finally {
|
|
1385
|
-
cleanup();
|
|
1386
|
-
}
|
|
1387
|
-
});
|
|
1388
|
-
|
|
1389
|
-
it("implement — strict-wave dispatch: one derived wave per invocation (the C5 closure advances the wave)", async () => {
|
|
1390
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1391
|
-
try {
|
|
1392
|
-
gitInit(repoRoot);
|
|
1393
|
-
const plan = planFor(repoRoot, 2);
|
|
1394
|
-
// The root wave {1} first (task 2's dep sits in wave 1). Implementing task 1 does
|
|
1395
|
-
// NOT close it (implement rounds are never a closure — v1.20 closedWaves), so the
|
|
1396
|
-
// wave advances only through the review's C5 closure: review 1 must land before
|
|
1397
|
-
// task 2 becomes dispatchable.
|
|
1398
|
-
expect(
|
|
1399
|
-
await command.runArgv([
|
|
1400
|
-
"implement",
|
|
1401
|
-
"--tasks",
|
|
1402
|
-
"1",
|
|
1403
|
-
"--plan",
|
|
1404
|
-
plan,
|
|
1405
|
-
"--dry-run",
|
|
1406
|
-
"--root",
|
|
1407
|
-
repoRoot,
|
|
1408
|
-
]),
|
|
1409
|
-
).toBe(0);
|
|
1410
|
-
io.stdoutText = "";
|
|
1411
|
-
expect(
|
|
1412
|
-
await command.runArgv([
|
|
1413
|
-
"review",
|
|
1414
|
-
"--type",
|
|
1415
|
-
"wave",
|
|
1416
|
-
"--tasks",
|
|
1417
|
-
"1",
|
|
1418
|
-
"--plan",
|
|
1419
|
-
plan,
|
|
1420
|
-
"--dry-run",
|
|
1421
|
-
"--root",
|
|
1422
|
-
repoRoot,
|
|
1423
|
-
]),
|
|
1424
|
-
).toBe(0);
|
|
1425
|
-
io.stdoutText = "";
|
|
1426
|
-
const code = await command.runArgv([
|
|
1427
|
-
"implement",
|
|
1428
|
-
"--tasks",
|
|
1429
|
-
"2",
|
|
1430
|
-
"--plan",
|
|
1431
|
-
plan,
|
|
1432
|
-
"--dry-run",
|
|
1433
|
-
"--root",
|
|
1434
|
-
repoRoot,
|
|
1435
|
-
]);
|
|
1436
|
-
expect(code).toBe(0);
|
|
1437
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
1438
|
-
const progress = readJson<{ waves: unknown[] }>(path.join(workspace, "progress.json"));
|
|
1439
|
-
// the wave-1 row carries its D30 revision record — the completed wave review
|
|
1440
|
-
// bound the BRIEF it judged to ITS line (the row's reviewedRevision is a
|
|
1441
|
-
// brief-revision: the plan it renders from + the RENDERED brief's sha1 — the
|
|
1442
|
-
// wave-gate reopen basis: a plan edit outside this wave's tasks must not void it)
|
|
1443
|
-
expect(progress.waves).toContainEqual({
|
|
1444
|
-
wave: "1",
|
|
1445
|
-
rounds: { implement: [1], review: [1] },
|
|
1446
|
-
reviewedRevision: briefRevision(plan, "1"),
|
|
1447
|
-
});
|
|
1448
|
-
expect(progress.waves).toContainEqual({ wave: "2", rounds: { implement: [1] } });
|
|
1449
|
-
// the invocation's single stdout face — only the LAST step's capsule
|
|
1450
|
-
expect(io.stdoutText.split("status: APPROVED").length - 1).toBe(1);
|
|
1451
|
-
expect(existsSync(path.join(workspace, "tasks-2-implement.json"))).toBe(true);
|
|
1452
|
-
// the strict-wave gate (T24): a `--tasks` splitting the derived wave BLOCKs
|
|
1453
|
-
io.stderrText = "";
|
|
1454
|
-
const split = await command.runArgv([
|
|
1455
|
-
"implement",
|
|
1456
|
-
"--tasks",
|
|
1457
|
-
"1,2",
|
|
1458
|
-
"--plan",
|
|
1459
|
-
plan,
|
|
1460
|
-
"--dry-run",
|
|
1461
|
-
"--root",
|
|
1462
|
-
repoRoot,
|
|
1463
|
-
]);
|
|
1464
|
-
expect(split).toBe(1);
|
|
1465
|
-
expect(io.stderrText).toContain("derived wave");
|
|
1466
|
-
} finally {
|
|
1467
|
-
cleanup();
|
|
1468
|
-
}
|
|
1469
|
-
});
|
|
1470
|
-
|
|
1471
|
-
it("review — the phase derives from the ledger (implement then review), a clean review closes", async () => {
|
|
1472
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1473
|
-
try {
|
|
1474
|
-
gitInit(repoRoot);
|
|
1475
|
-
const plan = planFor(repoRoot);
|
|
1476
|
-
expect(
|
|
1477
|
-
await command.runArgv([
|
|
1478
|
-
"implement",
|
|
1479
|
-
"--tasks",
|
|
1480
|
-
"1",
|
|
1481
|
-
"--plan",
|
|
1482
|
-
plan,
|
|
1483
|
-
"--dry-run",
|
|
1484
|
-
"--root",
|
|
1485
|
-
repoRoot,
|
|
1486
|
-
]),
|
|
1487
|
-
).toBe(0);
|
|
1488
|
-
io.stdoutText = "";
|
|
1489
|
-
const code = await command.runArgv([
|
|
1490
|
-
"review",
|
|
1491
|
-
"--type",
|
|
1492
|
-
"wave",
|
|
1493
|
-
"--tasks",
|
|
1494
|
-
"1",
|
|
1495
|
-
"--plan",
|
|
1496
|
-
plan,
|
|
1497
|
-
"--dry-run",
|
|
1498
|
-
"--root",
|
|
1499
|
-
repoRoot,
|
|
1500
|
-
]);
|
|
1501
|
-
expect(code).toBe(0);
|
|
1502
|
-
expect(io.stdoutText).toContain("status: APPROVED · blocker: 0 · handoff: ");
|
|
1503
|
-
// T3 deliberate pin break (the constraints' registered next: break): the wave
|
|
1504
|
-
// closure renders the wave→branch wiring literal (PIPELINE_NEXT.wave), never
|
|
1505
|
-
// the bare terminal word.
|
|
1506
|
-
expect(io.stdoutText).toContain("next: review --type branch --plan ");
|
|
1507
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
1508
|
-
expect(existsSync(path.join(workspace, "tasks-1-review-1.json"))).toBe(true);
|
|
1509
|
-
} finally {
|
|
1510
|
-
cleanup();
|
|
1511
|
-
}
|
|
1512
|
-
});
|
|
1513
|
-
|
|
1514
|
-
it("review with findings — the fix-route next: line carries the readback suffix", async () => {
|
|
1515
|
-
const { command, io, repoRoot, cleanup } = fixture({
|
|
1516
|
-
dispatch: (frame: OpenFrame) =>
|
|
1517
|
-
frame.phase === "review"
|
|
1518
|
-
? {
|
|
1519
|
-
status: "CHANGES_REQUESTED",
|
|
1520
|
-
findings: [{ severity: "blocker", summary: "drift" }],
|
|
1521
|
-
}
|
|
1522
|
-
: { status: "APPROVED" },
|
|
1523
|
-
});
|
|
1524
|
-
try {
|
|
1525
|
-
gitInit(repoRoot);
|
|
1526
|
-
const plan = planFor(repoRoot);
|
|
1527
|
-
expect(
|
|
1528
|
-
await command.runArgv([
|
|
1529
|
-
"implement",
|
|
1530
|
-
"--tasks",
|
|
1531
|
-
"1",
|
|
1532
|
-
"--plan",
|
|
1533
|
-
plan,
|
|
1534
|
-
"--dry-run",
|
|
1535
|
-
"--root",
|
|
1536
|
-
repoRoot,
|
|
1537
|
-
]),
|
|
1538
|
-
).toBe(0);
|
|
1539
|
-
io.stdoutText = "";
|
|
1540
|
-
const code = await command.runArgv([
|
|
1541
|
-
"review",
|
|
1542
|
-
"--type",
|
|
1543
|
-
"wave",
|
|
1544
|
-
"--tasks",
|
|
1545
|
-
"1",
|
|
1546
|
-
"--plan",
|
|
1547
|
-
plan,
|
|
1548
|
-
"--dry-run",
|
|
1549
|
-
"--root",
|
|
1550
|
-
repoRoot,
|
|
1551
|
-
]);
|
|
1552
|
-
expect(code).toBe(0);
|
|
1553
|
-
// the review's findings route the one-way fix hop — the capsule next: line
|
|
1554
|
-
// names the review handoff (the resolved workspace path) and rides the
|
|
1555
|
-
// readback suffix (the cli face checkable)
|
|
1556
|
-
expect(io.stdoutText).toContain("status: CHANGES_REQUESTED · blocker: 1 · handoff: ");
|
|
1557
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
1558
|
-
expect(io.stdoutText).toContain(
|
|
1559
|
-
`next: fix --type wave --tasks 1 --plan ${plan} --findings ${path.join(workspace, "tasks-1-review-1.json")} ${FIX_READBACK_SUFFIX}`,
|
|
1560
|
-
);
|
|
1561
|
-
} finally {
|
|
1562
|
-
cleanup();
|
|
1563
|
-
}
|
|
1564
|
-
});
|
|
1565
|
-
|
|
1566
|
-
it("fix — the source review's blocker findings drive the re-review next (C5-1)", async () => {
|
|
1567
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1568
|
-
try {
|
|
1569
|
-
gitInit(repoRoot);
|
|
1570
|
-
const plan = planFor(repoRoot);
|
|
1571
|
-
// Seed the implement + a blocker review round (the fix's C5-1 input).
|
|
1572
|
-
const workspace = new Workspace(new WorkspaceRoot(repoRoot, ".kairos/cdd"), "p3").ensure();
|
|
1573
|
-
const ledger = new Ledger(workspace, new ConfigLoader());
|
|
1574
|
-
ledger.recordRound(1, "implement");
|
|
1575
|
-
ledger.persistHandoff(
|
|
1576
|
-
"review",
|
|
1577
|
-
"wave",
|
|
1578
|
-
{ tasks: "1", round: 1 },
|
|
1579
|
-
{
|
|
1580
|
-
tasks: [1],
|
|
1581
|
-
phase: "review",
|
|
1582
|
-
findings: [{ severity: "blocker", summary: "drift" }],
|
|
1583
|
-
},
|
|
1584
|
-
);
|
|
1585
|
-
ledger.recordRound(1, "review");
|
|
1586
|
-
const code = await command.runArgv([
|
|
1587
|
-
"fix",
|
|
1588
|
-
"--type",
|
|
1589
|
-
"wave",
|
|
1590
|
-
"--tasks",
|
|
1591
|
-
"1",
|
|
1592
|
-
"--plan",
|
|
1593
|
-
plan,
|
|
1594
|
-
"--dry-run",
|
|
1595
|
-
"--root",
|
|
1596
|
-
repoRoot,
|
|
1597
|
-
]);
|
|
1598
|
-
expect(code).toBe(0);
|
|
1599
|
-
expect(io.stdoutText).toContain("status: APPROVED · blocker: 0 · handoff: ");
|
|
1600
|
-
expect(io.stdoutText).toContain(`next: review --type wave --tasks 1`);
|
|
1601
|
-
expect(existsSync(path.join(workspace.path, "tasks-1-fix-1.json"))).toBe(true);
|
|
1602
|
-
} finally {
|
|
1603
|
-
cleanup();
|
|
1604
|
-
}
|
|
1605
|
-
});
|
|
1606
|
-
|
|
1607
|
-
it("fix — the branch re-review next: carries the workspace --plan and re-dispatches through the runtime gate (find #8/#9)", async () => {
|
|
1608
|
-
const { command, io, repoRoot, cleanup } = fixture({
|
|
1609
|
-
dispatch: (frame: OpenFrame) =>
|
|
1610
|
-
frame.phase === "fix" ? { status: "APPROVED" } : { status: "APPROVED", findings: [] },
|
|
1611
|
-
});
|
|
1612
|
-
try {
|
|
1613
|
-
gitInit(repoRoot);
|
|
1614
|
-
const plan = conformingPlan(repoRoot);
|
|
1615
|
-
// Seed the branch line: a blocker branch-review round (the fix's C5-1 input)
|
|
1616
|
-
// whose handoff carries the reviewed findings (the fix's --findings single
|
|
1617
|
-
// carrier).
|
|
1618
|
-
// find #9 — the branch line's workspace is the plan-slug (the fix dispatch's
|
|
1619
|
-
// --plan); the handoff file is the spine name `branch-review-{round}.json`.
|
|
1620
|
-
const workspace = new Workspace(
|
|
1621
|
-
new WorkspaceRoot(repoRoot, ".kairos/cdd"),
|
|
1622
|
-
Workspace.slugFromDoc(plan),
|
|
1623
|
-
).ensure();
|
|
1624
|
-
const ledger = new Ledger(workspace, new ConfigLoader());
|
|
1625
|
-
const params = { round: 1 };
|
|
1626
|
-
ledger.persistHandoff("review", "branch", params, {
|
|
1627
|
-
phase: "branch-review",
|
|
1628
|
-
findings: [{ severity: "blocker", summary: "drift" }],
|
|
1629
|
-
});
|
|
1630
|
-
// find #9 — the line key is the stable "branch" (round accumulates across
|
|
1631
|
-
// re-reviews; the old range-short key reset to 1 on every head move).
|
|
1632
|
-
ledger.recordRound("branch", "branch-review");
|
|
1633
|
-
const findingsPath = workspace.resolve("branch-review-1.json");
|
|
1634
|
-
const code = await command.runArgv([
|
|
1635
|
-
"fix",
|
|
1636
|
-
"--type",
|
|
1637
|
-
"branch",
|
|
1638
|
-
"--plan",
|
|
1639
|
-
plan,
|
|
1640
|
-
"--findings",
|
|
1641
|
-
findingsPath,
|
|
1642
|
-
"--dry-run",
|
|
1643
|
-
"--root",
|
|
1644
|
-
repoRoot,
|
|
1645
|
-
]);
|
|
1646
|
-
expect(code).toBe(0);
|
|
1647
|
-
// the re-review literal carries the workspace --plan only — the review judges
|
|
1648
|
-
// the live tree (the scope anchor BASE_BRANCH is engine-injected at dispatch)
|
|
1649
|
-
expect(io.stdoutText).toContain(`next: review --type branch --plan ${plan}`);
|
|
1650
|
-
// the runtime gate, not parse-only: re-feeding the literal's argv through the CLI
|
|
1651
|
-
// dispatches a real branch review — exit 0, never a missing-refs refusal
|
|
1652
|
-
const reExit = await command.runArgv([
|
|
1653
|
-
"review",
|
|
1654
|
-
"--type",
|
|
1655
|
-
"branch",
|
|
1656
|
-
"--plan",
|
|
1657
|
-
plan,
|
|
1658
|
-
"--dry-run",
|
|
1659
|
-
"--root",
|
|
1660
|
-
repoRoot,
|
|
1661
|
-
]);
|
|
1662
|
-
expect(reExit).toBe(0);
|
|
1663
|
-
} finally {
|
|
1664
|
-
cleanup();
|
|
1665
|
-
}
|
|
1666
|
-
});
|
|
1667
|
-
|
|
1668
|
-
it("review --type branch — the live-tree branch face", async () => {
|
|
1669
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1670
|
-
try {
|
|
1671
|
-
gitInit(repoRoot);
|
|
1672
|
-
const plan = conformingPlan(repoRoot);
|
|
1673
|
-
const code = await command.runArgv([
|
|
1674
|
-
"review",
|
|
1675
|
-
"--type",
|
|
1676
|
-
"branch",
|
|
1677
|
-
"--plan",
|
|
1678
|
-
plan,
|
|
1679
|
-
"--dry-run",
|
|
1680
|
-
"--root",
|
|
1681
|
-
repoRoot,
|
|
1682
|
-
]);
|
|
1683
|
-
expect(code).toBe(0);
|
|
1684
|
-
expect(io.stdoutText).toContain("status: APPROVED · blocker: 0 ·");
|
|
1685
|
-
// T3 deliberate pin break: the branch closure routes the cdd-close ref
|
|
1686
|
-
// (PIPELINE_NEXT.branch through REFS[ref][host]).
|
|
1687
|
-
expect(io.stdoutText).toContain("next: /kairos:cdd-close");
|
|
1688
|
-
// the branch line's workspace is the plan-slug (the fix dispatch's --plan) and
|
|
1689
|
-
// the handoff is the spine `branch-review-1.json` (no range token in the name)
|
|
1690
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", Workspace.slugFromDoc(plan));
|
|
1691
|
-
expect(existsSync(path.join(workspace, "branch-review-1.json"))).toBe(true);
|
|
1692
|
-
} finally {
|
|
1693
|
-
cleanup();
|
|
1694
|
-
}
|
|
1695
|
-
});
|
|
1696
|
-
|
|
1697
|
-
it("review --type branch — the CLI injects the base artifact's branch as BASE_BRANCH (the scope anchor value source)", async () => {
|
|
1698
|
-
const sync = new FakeSync();
|
|
1699
|
-
sync.stdout = "status: APPROVED\n";
|
|
1700
|
-
const { command, repoRoot, cleanup } = fixture({ sync });
|
|
1701
|
-
try {
|
|
1702
|
-
gitInit(repoRoot);
|
|
1703
|
-
const plan = conformingPlan(repoRoot);
|
|
1704
|
-
// the base artifact the CLI reads (the same `base set` write-through source);
|
|
1705
|
-
// the leaf carries no --root — the fixture's injected repoRoot is the root.
|
|
1706
|
-
expect(
|
|
1707
|
-
await command.runArgv([
|
|
1708
|
-
"base",
|
|
1709
|
-
"set",
|
|
1710
|
-
"--plan",
|
|
1711
|
-
plan,
|
|
1712
|
-
"--base",
|
|
1713
|
-
"develop",
|
|
1714
|
-
"--source",
|
|
1715
|
-
"plan-field",
|
|
1716
|
-
]),
|
|
1717
|
-
).toBe(0);
|
|
1718
|
-
// A REAL branch-review dispatch (not --dry-run — the dry-run synthetic approval
|
|
1719
|
-
// never reaches the lifecycle). The host is injected ambiently (the CLI's
|
|
1720
|
-
// production dispatch reads process.env), so mark it and restore it.
|
|
1721
|
-
const saved = process.env.CLAUDE_CODE_SESSION_ID;
|
|
1722
|
-
process.env.CLAUDE_CODE_SESSION_ID = "s";
|
|
1723
|
-
let code: number;
|
|
1724
|
-
try {
|
|
1725
|
-
code = await command.runArgv([
|
|
1726
|
-
"review",
|
|
1727
|
-
"--type",
|
|
1728
|
-
"branch",
|
|
1729
|
-
"--plan",
|
|
1730
|
-
plan,
|
|
1731
|
-
"--root",
|
|
1732
|
-
repoRoot,
|
|
1733
|
-
]);
|
|
1734
|
-
} finally {
|
|
1735
|
-
if (saved === undefined) delete process.env.CLAUDE_CODE_SESSION_ID;
|
|
1736
|
-
else process.env.CLAUDE_CODE_SESSION_ID = saved;
|
|
1737
|
-
}
|
|
1738
|
-
// the child is a fake (no draft written → the round reads back BLOCKED), but the
|
|
1739
|
-
// dispatch itself ran — the prompt is the assertion surface
|
|
1740
|
-
expect(code).toBe(1);
|
|
1741
|
-
const prompt = sync.calls[0]!.args[sync.calls[0]!.args.length - 1];
|
|
1742
|
-
// the base artifact's branch name rides the round context — the wave/branch
|
|
1743
|
-
// review's scope anchor resolves (never an empty, dropped slot)
|
|
1744
|
-
expect(prompt).toContain("- `BASE_BRANCH`: develop");
|
|
1745
|
-
} finally {
|
|
1746
|
-
cleanup();
|
|
1747
|
-
}
|
|
1748
|
-
});
|
|
1749
|
-
|
|
1750
|
-
it("BASE_BRANCH injection — the wave/branch tree-review faces carry the anchor; the spec/plan doc faces never do (§3.2)", async () => {
|
|
1751
|
-
const sync = new FakeSync();
|
|
1752
|
-
sync.stdout = "status: APPROVED\n";
|
|
1753
|
-
const { command, repoRoot, cleanup } = fixture({ sync });
|
|
1754
|
-
try {
|
|
1755
|
-
gitInit(repoRoot);
|
|
1756
|
-
const plan = conformingPlan(repoRoot);
|
|
1757
|
-
// the base artifact the CLI reads back at dispatch (the scope anchor source) —
|
|
1758
|
-
// the same `base set` write-through the wave/branch faces resolve.
|
|
1759
|
-
expect(
|
|
1760
|
-
await command.runArgv([
|
|
1761
|
-
"base",
|
|
1762
|
-
"set",
|
|
1763
|
-
"--plan",
|
|
1764
|
-
plan,
|
|
1765
|
-
"--base",
|
|
1766
|
-
"develop",
|
|
1767
|
-
"--source",
|
|
1768
|
-
"plan-field",
|
|
1769
|
-
]),
|
|
1770
|
-
).toBe(0);
|
|
1771
|
-
// seed the wave's implement round so the review face is dispatchable (the wave
|
|
1772
|
-
// line advances implement → review as ONE train)
|
|
1773
|
-
const workspace = new Workspace(new WorkspaceRoot(repoRoot, ".kairos/cdd"), "p3").ensure();
|
|
1774
|
-
const ledger = new Ledger(workspace, new ConfigLoader());
|
|
1775
|
-
ledger.recordRound("1", "implement");
|
|
1776
|
-
ledger.persistHandoff(
|
|
1777
|
-
"implement",
|
|
1778
|
-
"wave",
|
|
1779
|
-
{ tasks: "1" },
|
|
1780
|
-
{
|
|
1781
|
-
status: "APPROVED",
|
|
1782
|
-
artifacts: {},
|
|
1783
|
-
},
|
|
1784
|
-
);
|
|
1785
|
-
// A REAL dispatch (not --dry-run — the synthetic approval never reaches the
|
|
1786
|
-
// lifecycle). The host is injected ambiently (the CLI's production dispatch
|
|
1787
|
-
// reads process.env), so mark it and restore it.
|
|
1788
|
-
const saved = process.env.CLAUDE_CODE_SESSION_ID;
|
|
1789
|
-
process.env.CLAUDE_CODE_SESSION_ID = "s";
|
|
1790
|
-
const promptOf = async (argv: readonly string[]): Promise<string> => {
|
|
1791
|
-
await command.runArgv([...argv, "--root", repoRoot]);
|
|
1792
|
-
const call = sync.calls[sync.calls.length - 1]!;
|
|
1793
|
-
return call.args[call.args.length - 1];
|
|
1794
|
-
};
|
|
1795
|
-
try {
|
|
1796
|
-
// the wave tree-review face carries the anchor
|
|
1797
|
-
const wave = await promptOf(["review", "--type", "wave", "--tasks", "1", "--plan", plan]);
|
|
1798
|
-
expect(wave).toContain("- `BASE_BRANCH`: develop");
|
|
1799
|
-
// the branch tree-review face carries the anchor
|
|
1800
|
-
const branch = await promptOf(["review", "--type", "branch", "--plan", plan]);
|
|
1801
|
-
expect(branch).toContain("- `BASE_BRANCH`: develop");
|
|
1802
|
-
// the spec + plan doc faces never carry the anchor (the slot stays empty and
|
|
1803
|
-
// the assembler drops it — only the tree-review faces resolve a scope axis)
|
|
1804
|
-
const spec = await promptOf([
|
|
1805
|
-
"review",
|
|
1806
|
-
"--type",
|
|
1807
|
-
"spec",
|
|
1808
|
-
"--spec",
|
|
1809
|
-
path.join(repoRoot, "docs", "kairos", "specs", "s1-design.md"),
|
|
1810
|
-
]);
|
|
1811
|
-
expect(spec).not.toContain("BASE_BRANCH");
|
|
1812
|
-
const planReview = await promptOf(["review", "--type", "plan", "--plan", plan]);
|
|
1813
|
-
expect(planReview).not.toContain("BASE_BRANCH");
|
|
1814
|
-
} finally {
|
|
1815
|
-
if (saved === undefined) delete process.env.CLAUDE_CODE_SESSION_ID;
|
|
1816
|
-
else process.env.CLAUDE_CODE_SESSION_ID = saved;
|
|
1817
|
-
}
|
|
1818
|
-
} finally {
|
|
1819
|
-
cleanup();
|
|
1820
|
-
}
|
|
1821
|
-
});
|
|
1822
|
-
|
|
1823
|
-
it("review --type spec/plan — the doc-path face (the doc-derived workspace slug)", async () => {
|
|
1824
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1825
|
-
try {
|
|
1826
|
-
gitInit(repoRoot);
|
|
1827
|
-
// The declared, contract-clean spec doc — the `- **Doc type**:` header
|
|
1828
|
-
// declaration (spec §12 · D34) the capsule's doc-class discrimination reads
|
|
1829
|
-
// (zero filename inference).
|
|
1830
|
-
const spec = conformingSpec(repoRoot);
|
|
1831
|
-
const specCode = await command.runArgv([
|
|
1832
|
-
"review",
|
|
1833
|
-
"--type",
|
|
1834
|
-
"spec",
|
|
1835
|
-
"--spec",
|
|
1836
|
-
spec,
|
|
1837
|
-
"--dry-run",
|
|
1838
|
-
"--root",
|
|
1839
|
-
repoRoot,
|
|
1840
|
-
]);
|
|
1841
|
-
expect(specCode).toBe(0);
|
|
1842
|
-
// T3 deliberate pin break: the phase-spec closure routes the cdd-plan ref (PIPELINE_NEXT.phase-spec).
|
|
1843
|
-
expect(io.stdoutText).toContain("next: /kairos:cdd-plan");
|
|
1844
|
-
expect(existsSync(path.join(repoRoot, ".kairos", "cdd", "s1", "spec-review-1.json"))).toBe(
|
|
1845
|
-
true,
|
|
1846
|
-
);
|
|
1847
|
-
io.stdoutText = "";
|
|
1848
|
-
// The plan face is doc-contract-gated (P4.1 T1): a contract-clean plan (the
|
|
1849
|
-
// header tuple + version lineage + Change-history table + the chain siblings)
|
|
1850
|
-
// dispatches its review round.
|
|
1851
|
-
const plan = conformingPlan(repoRoot);
|
|
1852
|
-
const planCode = await command.runArgv([
|
|
1853
|
-
"review",
|
|
1854
|
-
"--type",
|
|
1855
|
-
"plan",
|
|
1856
|
-
"--plan",
|
|
1857
|
-
plan,
|
|
1858
|
-
"--dry-run",
|
|
1859
|
-
"--root",
|
|
1860
|
-
repoRoot,
|
|
1861
|
-
]);
|
|
1862
|
-
expect(planCode).toBe(0);
|
|
1863
|
-
expect(existsSync(path.join(repoRoot, ".kairos", "cdd", "p3", "plan-review-1.json"))).toBe(
|
|
1864
|
-
true,
|
|
1865
|
-
);
|
|
1866
|
-
} finally {
|
|
1867
|
-
cleanup();
|
|
1868
|
-
}
|
|
1869
|
-
});
|
|
1870
|
-
|
|
1871
|
-
it("review --type plan on a declaration-less plan BLOCKs — the plan face reads the declaration, zero command-type carve-out (spec §12 · D34)", async () => {
|
|
1872
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1873
|
-
try {
|
|
1874
|
-
gitInit(repoRoot);
|
|
1875
|
-
// A structurally contract-clean plan with its `- **Doc type**:` line stripped:
|
|
1876
|
-
// the plan face keys the doc-contract target by the DECLARED type alone, never
|
|
1877
|
-
// by the command verb — a missing declaration reads null and the seam BLOCKs.
|
|
1878
|
-
const plan = conformingPlan(repoRoot);
|
|
1879
|
-
const stripped = readFileSync(plan, "utf8").replace("- **Doc type**: plan\n", "");
|
|
1880
|
-
writeFileSync(plan, stripped, "utf8");
|
|
1881
|
-
const code = await command.runArgv([
|
|
1882
|
-
"review",
|
|
1883
|
-
"--type",
|
|
1884
|
-
"plan",
|
|
1885
|
-
"--plan",
|
|
1886
|
-
plan,
|
|
1887
|
-
"--dry-run",
|
|
1888
|
-
"--root",
|
|
1889
|
-
repoRoot,
|
|
1890
|
-
]);
|
|
1891
|
-
expect(code).toBe(1);
|
|
1892
|
-
expect(io.stderrText).toContain("CDD_BLOCKED");
|
|
1893
|
-
expect(io.stderrText).toContain("the doc declares no `- **Doc type**:` line");
|
|
1894
|
-
// no phantom round lands — the BLOCK precedes any child dispatch
|
|
1895
|
-
expect(existsSync(path.join(repoRoot, ".kairos", "cdd", "p3", "plan-review-1.json"))).toBe(
|
|
1896
|
-
false,
|
|
1897
|
-
);
|
|
1898
|
-
} finally {
|
|
1899
|
-
cleanup();
|
|
1900
|
-
}
|
|
1901
|
-
});
|
|
1902
|
-
|
|
1903
|
-
it("review --type spec of an -overall.md — the overall-spec doc-key face (zero phase-spec misreport)", async () => {
|
|
1904
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1905
|
-
try {
|
|
1906
|
-
gitInit(repoRoot);
|
|
1907
|
-
const overall = conformingOverall(repoRoot);
|
|
1908
|
-
const overallCode = await command.runArgv([
|
|
1909
|
-
"review",
|
|
1910
|
-
"--type",
|
|
1911
|
-
"spec",
|
|
1912
|
-
"--spec",
|
|
1913
|
-
overall,
|
|
1914
|
-
"--dry-run",
|
|
1915
|
-
"--root",
|
|
1916
|
-
repoRoot,
|
|
1917
|
-
]);
|
|
1918
|
-
expect(overallCode).toBe(0);
|
|
1919
|
-
expect(io.stdoutText).toContain("next: done");
|
|
1920
|
-
// The overall was judged under the overall-spec key (its declared
|
|
1921
|
-
// `- **Doc type**:` line, spec §12 · D34) — a phase-spec misjudge would trip
|
|
1922
|
-
// the doc-contract gate: the charter fails the phase-spec face, the pre-flight
|
|
1923
|
-
// refuses over CDD_BLOCKED and no round lands. The exit 0 + round +
|
|
1924
|
-
// empty-findings carrier pin the zero misreport; the stderr stays free of the
|
|
1925
|
-
// blocked channel.
|
|
1926
|
-
const round = path.join(repoRoot, ".kairos", "cdd", "o1-overall", "spec-review-1.json");
|
|
1927
|
-
expect(existsSync(round)).toBe(true);
|
|
1928
|
-
expect(io.stderrText).not.toContain("CDD_BLOCKED");
|
|
1929
|
-
expect(readJson<{ findings: unknown[] }>(round).findings).toEqual([]);
|
|
1930
|
-
} finally {
|
|
1931
|
-
cleanup();
|
|
1932
|
-
}
|
|
1933
|
-
});
|
|
1934
|
-
|
|
1935
|
-
it("a closed doc line REOPENS on doc-revision drift — the identity-aware line gate (T7)", async () => {
|
|
1936
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1937
|
-
try {
|
|
1938
|
-
gitInit(repoRoot);
|
|
1939
|
-
const plan = conformingPlan(repoRoot);
|
|
1940
|
-
// Round 1: the initial clean review closes the doc line AND records the
|
|
1941
|
-
// reviewed doc revision (the line's identity — the T7 write-back at bookkeep).
|
|
1942
|
-
expect(
|
|
1943
|
-
await command.runArgv([
|
|
1944
|
-
"review",
|
|
1945
|
-
"--type",
|
|
1946
|
-
"plan",
|
|
1947
|
-
"--plan",
|
|
1948
|
-
plan,
|
|
1949
|
-
"--dry-run",
|
|
1950
|
-
"--root",
|
|
1951
|
-
repoRoot,
|
|
1952
|
-
]),
|
|
1953
|
-
).toBe(0);
|
|
1954
|
-
// T3 deliberate pin break: the plan closure routes the cdd-dev ref (PIPELINE_NEXT.plan).
|
|
1955
|
-
expect(io.stdoutText).toContain("next: /kairos:cdd-dev");
|
|
1956
|
-
// The target doc then DRIFTS (a backfill edits the plan — the pre-T7 flow
|
|
1957
|
-
// froze the closed doc at "reviewed" with no reopen entry: the line held no
|
|
1958
|
-
// open round). The target identity moved — review is the requested phase and
|
|
1959
|
-
// the drifted doc reopens the line (round continuation, no flag).
|
|
1960
|
-
const driftedSource = readFileSync(plan, "utf8").replace(
|
|
1961
|
-
"- **Acceptance**: ok",
|
|
1962
|
-
"- **Acceptance**: ok (drifted)",
|
|
1963
|
-
);
|
|
1964
|
-
writeFileSync(plan, driftedSource, "utf8");
|
|
1965
|
-
io.stdoutText = "";
|
|
1966
|
-
const reopen = await command.runArgv([
|
|
1967
|
-
"review",
|
|
1968
|
-
"--type",
|
|
1969
|
-
"plan",
|
|
1970
|
-
"--plan",
|
|
1971
|
-
plan,
|
|
1972
|
-
"--dry-run",
|
|
1973
|
-
"--root",
|
|
1974
|
-
repoRoot,
|
|
1975
|
-
]);
|
|
1976
|
-
expect(reopen).toBe(0);
|
|
1977
|
-
expect(existsSync(path.join(repoRoot, ".kairos", "cdd", "p3", "plan-review-2.json"))).toBe(
|
|
1978
|
-
true,
|
|
1979
|
-
);
|
|
1980
|
-
} finally {
|
|
1981
|
-
cleanup();
|
|
1982
|
-
}
|
|
1983
|
-
});
|
|
1984
|
-
|
|
1985
|
-
it("an UNCHANGED closed doc line stays blocked — the revision-aware BLOCK message (T7)", async () => {
|
|
1986
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
1987
|
-
try {
|
|
1988
|
-
gitInit(repoRoot);
|
|
1989
|
-
const plan = conformingPlan(repoRoot);
|
|
1990
|
-
expect(
|
|
1991
|
-
await command.runArgv([
|
|
1992
|
-
"review",
|
|
1993
|
-
"--type",
|
|
1994
|
-
"plan",
|
|
1995
|
-
"--plan",
|
|
1996
|
-
plan,
|
|
1997
|
-
"--dry-run",
|
|
1998
|
-
"--root",
|
|
1999
|
-
repoRoot,
|
|
2000
|
-
]),
|
|
2001
|
-
).toBe(0);
|
|
2002
|
-
expect(io.stdoutText).toContain("next: /kairos:cdd-dev");
|
|
2003
|
-
// The doc did NOT move — the line gate compares the current revision to the
|
|
2004
|
-
// reviewed one and BLOCKs with the identity-aware message (the old "no open
|
|
2005
|
-
// round" text retires on the doc face).
|
|
2006
|
-
io.stderrText = "";
|
|
2007
|
-
const unchanged = await command.runArgv([
|
|
2008
|
-
"review",
|
|
2009
|
-
"--type",
|
|
2010
|
-
"plan",
|
|
2011
|
-
"--plan",
|
|
2012
|
-
plan,
|
|
2013
|
-
"--dry-run",
|
|
2014
|
-
"--root",
|
|
2015
|
-
repoRoot,
|
|
2016
|
-
]);
|
|
2017
|
-
expect(unchanged).toBe(1);
|
|
2018
|
-
expect(io.stderrText).toContain("already reviewed at v1.0");
|
|
2019
|
-
expect(io.stderrText).toContain("target revision unchanged");
|
|
2020
|
-
// no phantom round files land on the unchanged line
|
|
2021
|
-
expect(existsSync(path.join(repoRoot, ".kairos", "cdd", "p3", "plan-review-2.json"))).toBe(
|
|
2022
|
-
false,
|
|
2023
|
-
);
|
|
2024
|
-
} finally {
|
|
2025
|
-
cleanup();
|
|
2026
|
-
}
|
|
2027
|
-
});
|
|
2028
|
-
|
|
2029
|
-
it("a closed doc line with an UNREADABLE target keeps the generic BLOCK — the null-verdict face (T7)", async () => {
|
|
2030
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
2031
|
-
try {
|
|
2032
|
-
gitInit(repoRoot);
|
|
2033
|
-
const specPath = path.join(repoRoot, "docs", "kairos", "specs", "s1-design.md");
|
|
2034
|
-
// Seed a CLOSED spec line: a clean completed review round keyed under the
|
|
2035
|
-
// line-type constant (§3.7), zero reviewed revision bound. The line's identity
|
|
2036
|
-
// is the line type, never the argv path.
|
|
2037
|
-
const workspace = new Workspace(new WorkspaceRoot(repoRoot, ".kairos/cdd"), "s1").ensure();
|
|
2038
|
-
const ledger = new Ledger(workspace, new ConfigLoader());
|
|
2039
|
-
ledger.persistHandoff("review", "spec", { round: 1 }, { phase: "review", findings: [] });
|
|
2040
|
-
ledger.recordRound("spec", "review");
|
|
2041
|
-
// The target doc is unreadable (never written) — the doc-contract gate skips
|
|
2042
|
-
// an absent doc and the ledger verdict is null, not "same": the "target
|
|
2043
|
-
// revision unchanged" claim would be fabricated (only present facts land).
|
|
2044
|
-
// The gate keeps the generic closed-line message.
|
|
2045
|
-
io.stderrText = "";
|
|
2046
|
-
const blocked = await command.runArgv([
|
|
2047
|
-
"review",
|
|
2048
|
-
"--type",
|
|
2049
|
-
"spec",
|
|
2050
|
-
"--spec",
|
|
2051
|
-
specPath,
|
|
2052
|
-
"--dry-run",
|
|
2053
|
-
"--root",
|
|
2054
|
-
repoRoot,
|
|
2055
|
-
]);
|
|
2056
|
-
expect(blocked).toBe(1);
|
|
2057
|
-
expect(io.stderrText).toContain("the line holds no open round");
|
|
2058
|
-
expect(io.stderrText).not.toContain("target revision unchanged");
|
|
2059
|
-
// no phantom round files land on the null-verdict line
|
|
2060
|
-
expect(existsSync(path.join(repoRoot, ".kairos", "cdd", "s1", "spec-review-2.json"))).toBe(
|
|
2061
|
-
false,
|
|
2062
|
-
);
|
|
2063
|
-
} finally {
|
|
2064
|
-
cleanup();
|
|
2065
|
-
}
|
|
2066
|
-
});
|
|
2067
|
-
|
|
2068
|
-
it("T8 — after an ABORTED fix the drifted doc re-reviews directly — the doc revision is the gate's primary criterion (judgment order = doc revision first)", async () => {
|
|
2069
|
-
const { command, io, repoRoot, cleanup } = fixture({
|
|
2070
|
-
dispatch: (frame: OpenFrame) =>
|
|
2071
|
-
frame.phase === "fix"
|
|
2072
|
-
? { status: "BLOCKED" } // the aborted fix — its round never records
|
|
2073
|
-
: {
|
|
2074
|
-
status: "CHANGES_REQUESTED",
|
|
2075
|
-
findings: [{ severity: "blocker", summary: "drift" }],
|
|
2076
|
-
},
|
|
2077
|
-
});
|
|
2078
|
-
try {
|
|
2079
|
-
gitInit(repoRoot);
|
|
2080
|
-
const plan = conformingPlan(repoRoot);
|
|
2081
|
-
// Review round 1 with blockers — the line awaits its fix (fixes < reviews:
|
|
2082
|
-
// the pre-T8 gate read the fix-awaited route and froze the re-review at
|
|
2083
|
-
// "the next round is fix" even after the doc moved).
|
|
2084
|
-
expect(
|
|
2085
|
-
await command.runArgv([
|
|
2086
|
-
"review",
|
|
2087
|
-
"--type",
|
|
2088
|
-
"plan",
|
|
2089
|
-
"--plan",
|
|
2090
|
-
plan,
|
|
2091
|
-
"--dry-run",
|
|
2092
|
-
"--root",
|
|
2093
|
-
repoRoot,
|
|
2094
|
-
]),
|
|
2095
|
-
).toBe(0);
|
|
2096
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
2097
|
-
expect(existsSync(path.join(workspace, "plan-review-1.json"))).toBe(true);
|
|
2098
|
-
// The aborted fix — the pre-T8 stuck path's origin: the fix attempt BLOCKS,
|
|
2099
|
-
// records no fix round, and the line stays fix-awaited with the OLD review's
|
|
2100
|
-
// findings binding the reviewed doc revision.
|
|
2101
|
-
io.stdoutText = "";
|
|
2102
|
-
io.stderrText = "";
|
|
2103
|
-
expect(
|
|
2104
|
-
await command.runArgv([
|
|
2105
|
-
"fix",
|
|
2106
|
-
"--type",
|
|
2107
|
-
"plan",
|
|
2108
|
-
"--plan",
|
|
2109
|
-
plan,
|
|
2110
|
-
"--dry-run",
|
|
2111
|
-
"--root",
|
|
2112
|
-
repoRoot,
|
|
2113
|
-
]),
|
|
2114
|
-
).toBe(1);
|
|
2115
|
-
// The doc then moves (fix applied · backfill · user decision are the SAME
|
|
2116
|
-
// case — the doc revision is the gate's primary criterion): the review runs
|
|
2117
|
-
// directly, whatever the fix-awaited round state says, and the old findings
|
|
2118
|
-
// are auto-invalid (bound to the superseded doc revision).
|
|
2119
|
-
const driftedSource = readFileSync(plan, "utf8").replace(
|
|
2120
|
-
"- **Acceptance**: ok",
|
|
2121
|
-
"- **Acceptance**: ok (drifted)",
|
|
2122
|
-
);
|
|
2123
|
-
writeFileSync(plan, driftedSource, "utf8");
|
|
2124
|
-
io.stderrText = "";
|
|
2125
|
-
io.stdoutText = "";
|
|
2126
|
-
const reopen = await command.runArgv([
|
|
2127
|
-
"review",
|
|
2128
|
-
"--type",
|
|
2129
|
-
"plan",
|
|
2130
|
-
"--plan",
|
|
2131
|
-
plan,
|
|
2132
|
-
"--dry-run",
|
|
2133
|
-
"--root",
|
|
2134
|
-
repoRoot,
|
|
2135
|
-
]);
|
|
2136
|
-
expect(reopen).toBe(0);
|
|
2137
|
-
expect(io.stderrText).not.toContain("cannot dispatch");
|
|
2138
|
-
expect(io.stderrText).not.toContain("the next round is fix");
|
|
2139
|
-
expect(existsSync(path.join(workspace, "plan-review-2.json"))).toBe(true);
|
|
2140
|
-
// The completion counts stay preserved (the re-review books the next round
|
|
2141
|
-
// increment) and the progress row's key set carries zero new fields (the
|
|
2142
|
-
// pending fix is derived, never a stored state).
|
|
2143
|
-
const progress = readJson<{
|
|
2144
|
-
waves: Array<{ wave: string; rounds?: Record<string, number[]> }>;
|
|
2145
|
-
}>(path.join(workspace, "progress.json"));
|
|
2146
|
-
// §3.7 — the doc line keys by its line-type constant, never the argv path
|
|
2147
|
-
const row = progress.waves.find((entry) => entry.wave === "plan");
|
|
2148
|
-
expect(row?.rounds?.review).toEqual([1, 2]);
|
|
2149
|
-
expect(row?.rounds?.fix).toBeUndefined();
|
|
2150
|
-
expect(JSON.stringify(progress)).not.toContain("pending");
|
|
2151
|
-
} finally {
|
|
2152
|
-
cleanup();
|
|
2153
|
-
}
|
|
2154
|
-
});
|
|
2155
|
-
|
|
2156
|
-
it("dogfood §3.7 — the same doc via an ABSOLUTE then a RELATIVE argv path lands ONE ledger line (the doc line keys by its line-type constant, never the argv string)", async () => {
|
|
2157
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
2158
|
-
const savedCwd = process.cwd();
|
|
2159
|
-
try {
|
|
2160
|
-
gitInit(repoRoot);
|
|
2161
|
-
const plan = conformingPlan(repoRoot);
|
|
2162
|
-
// the RELATIVE spelling `docs/kairos/plans/p3.md` (readText resolves it against
|
|
2163
|
-
// the process cwd — the same file the absolute path names)
|
|
2164
|
-
const relativePlan = path.relative(repoRoot, plan);
|
|
2165
|
-
expect(
|
|
2166
|
-
await command.runArgv([
|
|
2167
|
-
"review",
|
|
2168
|
-
"--type",
|
|
2169
|
-
"plan",
|
|
2170
|
-
"--plan",
|
|
2171
|
-
plan, // the ABSOLUTE argv spelling
|
|
2172
|
-
"--dry-run",
|
|
2173
|
-
"--root",
|
|
2174
|
-
repoRoot,
|
|
2175
|
-
]),
|
|
2176
|
-
).toBe(0);
|
|
2177
|
-
expect(io.stdoutText).toContain("next: /kairos:cdd-dev");
|
|
2178
|
-
// The doc DRIFTS (a backfill edits the plan) so the second review reopens the
|
|
2179
|
-
// line at the NEXT round rather than being refused as an unchanged doc.
|
|
2180
|
-
writeFileSync(
|
|
2181
|
-
plan,
|
|
2182
|
-
readFileSync(plan, "utf8").replace("- delta", "- delta (drifted)"),
|
|
2183
|
-
"utf8",
|
|
2184
|
-
);
|
|
2185
|
-
process.chdir(repoRoot); // the relative argv path resolves to the same file
|
|
2186
|
-
io.stdoutText = "";
|
|
2187
|
-
io.stderrText = "";
|
|
2188
|
-
const relative = await command.runArgv([
|
|
2189
|
-
"review",
|
|
2190
|
-
"--type",
|
|
2191
|
-
"plan",
|
|
2192
|
-
"--plan",
|
|
2193
|
-
relativePlan, // the RELATIVE argv spelling — the same file
|
|
2194
|
-
"--dry-run",
|
|
2195
|
-
"--root",
|
|
2196
|
-
repoRoot,
|
|
2197
|
-
]);
|
|
2198
|
-
expect(relative).toBe(0);
|
|
2199
|
-
expect(io.stdoutText).toContain("next: /kairos:cdd-dev");
|
|
2200
|
-
// ONE line under the line-type key `"plan"` — the two argv spellings did NOT
|
|
2201
|
-
// fork a second row keyed by the other spelling; the round CONTINUED (2), it
|
|
2202
|
-
// did not reset to 1 (the §3.7 dogfood fix)
|
|
2203
|
-
const progress = readJson<{
|
|
2204
|
-
waves: Array<{ wave: string; rounds?: Record<string, number> }>;
|
|
2205
|
-
}>(path.join(repoRoot, ".kairos", "cdd", "p3", "progress.json"));
|
|
2206
|
-
const planRows = progress.waves.filter((row) => row.wave.startsWith("plan"));
|
|
2207
|
-
expect(planRows).toHaveLength(1);
|
|
2208
|
-
expect(planRows[0]!.wave).toBe("plan");
|
|
2209
|
-
expect(planRows[0]!.rounds?.review).toEqual([1, 2]);
|
|
2210
|
-
} finally {
|
|
2211
|
-
process.chdir(savedCwd);
|
|
2212
|
-
cleanup();
|
|
2213
|
-
}
|
|
2214
|
-
});
|
|
2215
|
-
|
|
2216
|
-
it("T8 — an UNCHANGED fix-awaited doc stays rejected — the pending fix is derived (doc same + not APPROVED), never an independent field", async () => {
|
|
2217
|
-
const { command, io, repoRoot, cleanup } = fixture({
|
|
2218
|
-
dispatch: (frame: OpenFrame) =>
|
|
2219
|
-
frame.phase === "review"
|
|
2220
|
-
? {
|
|
2221
|
-
status: "CHANGES_REQUESTED",
|
|
2222
|
-
findings: [{ severity: "blocker", summary: "drift" }],
|
|
2223
|
-
}
|
|
2224
|
-
: { status: "APPROVED" },
|
|
2225
|
-
});
|
|
2226
|
-
try {
|
|
2227
|
-
gitInit(repoRoot);
|
|
2228
|
-
const plan = conformingPlan(repoRoot);
|
|
2229
|
-
expect(
|
|
2230
|
-
await command.runArgv([
|
|
2231
|
-
"review",
|
|
2232
|
-
"--type",
|
|
2233
|
-
"plan",
|
|
2234
|
-
"--plan",
|
|
2235
|
-
plan,
|
|
2236
|
-
"--dry-run",
|
|
2237
|
-
"--root",
|
|
2238
|
-
repoRoot,
|
|
2239
|
-
]),
|
|
2240
|
-
).toBe(0);
|
|
2241
|
-
// The SAME doc (no drift) — the repeat review stays REFUSED (Review
|
|
2242
|
-
// Convergence anti-spin): the pending fix derives from the doc-same +
|
|
2243
|
-
// non-APPROVED face (the review's own fix is still outstanding), and the
|
|
2244
|
-
// message names the derived hop.
|
|
2245
|
-
io.stderrText = "";
|
|
2246
|
-
const repeat = await command.runArgv([
|
|
2247
|
-
"review",
|
|
2248
|
-
"--type",
|
|
2249
|
-
"plan",
|
|
2250
|
-
"--plan",
|
|
2251
|
-
plan,
|
|
2252
|
-
"--dry-run",
|
|
2253
|
-
"--root",
|
|
2254
|
-
repoRoot,
|
|
2255
|
-
]);
|
|
2256
|
-
expect(repeat).toBe(1);
|
|
2257
|
-
expect(io.stderrText).toContain("the pending fix applies to the unchanged doc");
|
|
2258
|
-
expect(io.stderrText).toContain("— run cdd fix first");
|
|
2259
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
2260
|
-
// no phantom re-review lands on the unchanged line
|
|
2261
|
-
expect(existsSync(path.join(workspace, "plan-review-2.json"))).toBe(false);
|
|
2262
|
-
} finally {
|
|
2263
|
-
cleanup();
|
|
2264
|
-
}
|
|
2265
|
-
});
|
|
2266
|
-
|
|
2267
|
-
it("T8 — a COMPLETED fix on an UNCHANGED doc reopens the review through its C5-1 route — the doc-same face keeps the legacy rounds/routes judgment (the gate and the frame agree)", async () => {
|
|
2268
|
-
const { command, io, repoRoot, cleanup } = fixture({
|
|
2269
|
-
dispatch: (frame: OpenFrame) =>
|
|
2270
|
-
frame.phase === "fix"
|
|
2271
|
-
? { status: "APPROVED" }
|
|
2272
|
-
: {
|
|
2273
|
-
status: "CHANGES_REQUESTED",
|
|
2274
|
-
findings: [{ severity: "blocker", summary: "drift" }],
|
|
2275
|
-
},
|
|
2276
|
-
});
|
|
2277
|
-
try {
|
|
2278
|
-
gitInit(repoRoot);
|
|
2279
|
-
const plan = conformingPlan(repoRoot);
|
|
2280
|
-
// Review round 1 with blockers, then the fix round COMPLETES on the SAME doc
|
|
2281
|
-
// (fixes === reviews). The unchanged doc's "same" verdict carries NO pending
|
|
2282
|
-
// fix — the no-pending face falls back to the legacy rounds/routes judgment,
|
|
2283
|
-
// and the fix round's C5-1 route (blockers → re-review the fix delta) opens
|
|
2284
|
-
// the review lead. The lifecycle already dispatches this face; the CLI gate
|
|
2285
|
-
// must agree (an open gate and a dispatchable frame — the run.ts JSDoc
|
|
2286
|
-
// invariant) instead of the revision-aware "amend body/version" rejection.
|
|
2287
|
-
expect(
|
|
2288
|
-
await command.runArgv([
|
|
2289
|
-
"review",
|
|
2290
|
-
"--type",
|
|
2291
|
-
"plan",
|
|
2292
|
-
"--plan",
|
|
2293
|
-
plan,
|
|
2294
|
-
"--dry-run",
|
|
2295
|
-
"--root",
|
|
2296
|
-
repoRoot,
|
|
2297
|
-
]),
|
|
2298
|
-
).toBe(0);
|
|
2299
|
-
io.stdoutText = "";
|
|
2300
|
-
io.stderrText = "";
|
|
2301
|
-
expect(
|
|
2302
|
-
await command.runArgv([
|
|
2303
|
-
"fix",
|
|
2304
|
-
"--type",
|
|
2305
|
-
"plan",
|
|
2306
|
-
"--plan",
|
|
2307
|
-
plan,
|
|
2308
|
-
"--dry-run",
|
|
2309
|
-
"--root",
|
|
2310
|
-
repoRoot,
|
|
2311
|
-
]),
|
|
2312
|
-
).toBe(0);
|
|
2313
|
-
io.stdoutText = "";
|
|
2314
|
-
io.stderrText = "";
|
|
2315
|
-
const reopen = await command.runArgv([
|
|
2316
|
-
"review",
|
|
2317
|
-
"--type",
|
|
2318
|
-
"plan",
|
|
2319
|
-
"--plan",
|
|
2320
|
-
plan,
|
|
2321
|
-
"--dry-run",
|
|
2322
|
-
"--root",
|
|
2323
|
-
repoRoot,
|
|
2324
|
-
]);
|
|
2325
|
-
expect(reopen).toBe(0);
|
|
2326
|
-
// no revision-aware rejection on the completed-fix face — the delta has moved
|
|
2327
|
-
expect(io.stderrText).not.toContain("already reviewed");
|
|
2328
|
-
expect(io.stderrText).not.toContain("cannot dispatch");
|
|
2329
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
2330
|
-
expect(existsSync(path.join(workspace, "plan-review-2.json"))).toBe(true);
|
|
2331
|
-
} finally {
|
|
2332
|
-
cleanup();
|
|
2333
|
-
}
|
|
2334
|
-
});
|
|
2335
|
-
|
|
2336
|
-
it("the phase gate refuses an unreachable round without dispatching a phantom", async () => {
|
|
2337
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
2338
|
-
try {
|
|
2339
|
-
gitInit(repoRoot);
|
|
2340
|
-
const plan = planFor(repoRoot);
|
|
2341
|
-
const code = await command.runArgv([
|
|
2342
|
-
"review",
|
|
2343
|
-
"--type",
|
|
2344
|
-
"wave",
|
|
2345
|
-
"--tasks",
|
|
2346
|
-
"1",
|
|
2347
|
-
"--plan",
|
|
2348
|
-
plan,
|
|
2349
|
-
"--dry-run",
|
|
2350
|
-
"--root",
|
|
2351
|
-
repoRoot,
|
|
2352
|
-
]);
|
|
2353
|
-
expect(code).toBe(1);
|
|
2354
|
-
expect(io.stderrText).toContain("the open wave is at implement");
|
|
2355
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
2356
|
-
expect(existsSync(path.join(workspace, "tasks-1-implement.json"))).toBe(false);
|
|
2357
|
-
expect(existsSync(path.join(workspace, "progress.json"))).toBe(false);
|
|
2358
|
-
} finally {
|
|
2359
|
-
cleanup();
|
|
2360
|
-
}
|
|
2361
|
-
});
|
|
2362
|
-
|
|
2363
|
-
it("a BLOCKED dispatch exits 1 with the capsule (the round outcome rides the face)", async () => {
|
|
2364
|
-
const { command, io, repoRoot, cleanup } = fixture({ dispatch: () => ({ status: "BLOCKED" }) });
|
|
2365
|
-
try {
|
|
2366
|
-
gitInit(repoRoot);
|
|
2367
|
-
const plan = planFor(repoRoot);
|
|
2368
|
-
const code = await command.runArgv([
|
|
2369
|
-
"implement",
|
|
2370
|
-
"--tasks",
|
|
2371
|
-
"1",
|
|
2372
|
-
"--plan",
|
|
2373
|
-
plan,
|
|
2374
|
-
"--dry-run",
|
|
2375
|
-
"--root",
|
|
2376
|
-
repoRoot,
|
|
2377
|
-
]);
|
|
2378
|
-
expect(code).toBe(1);
|
|
2379
|
-
expect(io.stdoutText).toContain("status: BLOCKED");
|
|
2380
|
-
} finally {
|
|
2381
|
-
cleanup();
|
|
2382
|
-
}
|
|
2383
|
-
});
|
|
2384
|
-
|
|
2385
|
-
it("dogfood §2.8 — a rejected fix round with a leftover APPROVED draft renders NO next: line (the verdict is single-sourced; a stale draft is never read back)", async () => {
|
|
2386
|
-
// The round-verdict single-source pin: the child's fix write is REJECTED (the
|
|
2387
|
-
// round stays BLOCKED and unrecorded), yet a stale APPROVED draft sits on disk
|
|
2388
|
-
// at the fix path. The pre-fix engine re-read that draft from disk and rendered
|
|
2389
|
-
// the self-contradictory `status: BLOCKED · next: done`; the gated round-read
|
|
2390
|
-
// (§2.8) returns null for the unrecorded round → no next: line.
|
|
2391
|
-
const { command, io, repoRoot, cleanup } = fixture({
|
|
2392
|
-
dispatch: () => ({ status: "BLOCKED" }),
|
|
2393
|
-
});
|
|
2394
|
-
try {
|
|
2395
|
-
gitInit(repoRoot);
|
|
2396
|
-
const plan = planFor(repoRoot);
|
|
2397
|
-
const workspace = new Workspace(new WorkspaceRoot(repoRoot, ".kairos/cdd"), "p3").ensure();
|
|
2398
|
-
const ledger = new Ledger(workspace, new ConfigLoader());
|
|
2399
|
-
// a recorded implement + blocker review round → the line awaits its fix
|
|
2400
|
-
ledger.recordRound(1, "implement");
|
|
2401
|
-
ledger.persistHandoff(
|
|
2402
|
-
"review",
|
|
2403
|
-
"wave",
|
|
2404
|
-
{ tasks: "1", round: 1 },
|
|
2405
|
-
{
|
|
2406
|
-
tasks: [1],
|
|
2407
|
-
phase: "review",
|
|
2408
|
-
findings: [{ severity: "blocker", summary: "drift" }],
|
|
2409
|
-
},
|
|
2410
|
-
);
|
|
2411
|
-
ledger.recordRound(1, "review");
|
|
2412
|
-
// the stale "successful-looking" fix draft the rejected child left behind — it
|
|
2413
|
-
// must NOT be read back as the round's verdict
|
|
2414
|
-
writeFileSync(
|
|
2415
|
-
path.join(workspace.path, "tasks-1-fix-1.json"),
|
|
2416
|
-
JSON.stringify({ status: "APPROVED", findings: [] }),
|
|
2417
|
-
"utf8",
|
|
2418
|
-
);
|
|
2419
|
-
const code = await command.runArgv([
|
|
2420
|
-
"fix",
|
|
2421
|
-
"--type",
|
|
2422
|
-
"wave",
|
|
2423
|
-
"--tasks",
|
|
2424
|
-
"1",
|
|
2425
|
-
"--plan",
|
|
2426
|
-
plan,
|
|
2427
|
-
"--dry-run",
|
|
2428
|
-
"--root",
|
|
2429
|
-
repoRoot,
|
|
2430
|
-
]);
|
|
2431
|
-
expect(code).toBe(1);
|
|
2432
|
-
expect(io.stdoutText).toContain("status: BLOCKED");
|
|
2433
|
-
// the verdict single-source face — zero next: line (the unrecorded round holds
|
|
2434
|
-
// no route; the stale draft is never consulted)
|
|
2435
|
-
expect(io.stdoutText).not.toContain("next: done");
|
|
2436
|
-
expect(io.stdoutText).not.toMatch(/^next:/m);
|
|
2437
|
-
} finally {
|
|
2438
|
-
cleanup();
|
|
2439
|
-
}
|
|
2440
|
-
});
|
|
2441
|
-
|
|
2442
|
-
it("the WaveGate blocks the three verbs against a split/subset request (v1.21)", async () => {
|
|
2443
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
2444
|
-
try {
|
|
2445
|
-
gitInit(repoRoot);
|
|
2446
|
-
// Two no-dependency tasks open the single root wave {1,2} — a half-wave request
|
|
2447
|
-
// (review 1 alone / fix 2 alone) is the structural subset the gate refuses.
|
|
2448
|
-
const planPath = independentPlan(repoRoot, "two.md", 2);
|
|
2449
|
-
io.stderrText = "";
|
|
2450
|
-
// review of a subset {1} while the wave sits at {1,2} → the split BLOCK (review is
|
|
2451
|
-
// gated like implement — the half-wave review is structurally refused)
|
|
2452
|
-
expect(
|
|
2453
|
-
await command.runArgv([
|
|
2454
|
-
"review",
|
|
2455
|
-
"--type",
|
|
2456
|
-
"wave",
|
|
2457
|
-
"--tasks",
|
|
2458
|
-
"1",
|
|
2459
|
-
"--plan",
|
|
2460
|
-
planPath,
|
|
2461
|
-
"--dry-run",
|
|
2462
|
-
"--root",
|
|
2463
|
-
repoRoot,
|
|
2464
|
-
]),
|
|
2465
|
-
).toBe(1);
|
|
2466
|
-
expect(io.stderrText).toContain("splits/mismatches the derived wave");
|
|
2467
|
-
io.stderrText = "";
|
|
2468
|
-
// fix of a subset {2} before its implement → the split BLOCK (fix shares the gate)
|
|
2469
|
-
expect(
|
|
2470
|
-
await command.runArgv([
|
|
2471
|
-
"fix",
|
|
2472
|
-
"--type",
|
|
2473
|
-
"wave",
|
|
2474
|
-
"--tasks",
|
|
2475
|
-
"2",
|
|
2476
|
-
"--plan",
|
|
2477
|
-
planPath,
|
|
2478
|
-
"--dry-run",
|
|
2479
|
-
"--root",
|
|
2480
|
-
repoRoot,
|
|
2481
|
-
]),
|
|
2482
|
-
).toBe(1);
|
|
2483
|
-
expect(io.stderrText).toContain("splits/mismatches the derived wave");
|
|
2484
|
-
} finally {
|
|
2485
|
-
cleanup();
|
|
2486
|
-
}
|
|
2487
|
-
});
|
|
2488
|
-
|
|
2489
|
-
it("a multi-task wave's phase reads the WAVE row — review passes, re-implement wrong-phases (v1.28)", async () => {
|
|
2490
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
2491
|
-
try {
|
|
2492
|
-
gitInit(repoRoot);
|
|
2493
|
-
const planPath = independentPlan(repoRoot, "two.md", 2);
|
|
2494
|
-
// the WAVE row carries the implement round — review is the open phase for the whole
|
|
2495
|
-
// wave (the retired per-task build could never hold a mixed-phase wave-unitary row).
|
|
2496
|
-
const workspace = new Workspace(new WorkspaceRoot(repoRoot, ".kairos/cdd"), "two").ensure();
|
|
2497
|
-
new Ledger(workspace, new ConfigLoader()).recordRound("1,2", "implement");
|
|
2498
|
-
io.stderrText = "";
|
|
2499
|
-
// review on the implemented multi-task wave passes the gate (dispatch proceeds).
|
|
2500
|
-
expect(
|
|
2501
|
-
await command.runArgv([
|
|
2502
|
-
"review",
|
|
2503
|
-
"--tasks",
|
|
2504
|
-
"1,2",
|
|
2505
|
-
"--plan",
|
|
2506
|
-
planPath,
|
|
2507
|
-
"--dry-run",
|
|
2508
|
-
"--root",
|
|
2509
|
-
repoRoot,
|
|
2510
|
-
]),
|
|
2511
|
-
).not.toBe(1);
|
|
2512
|
-
// a re-implement on the at-review wave is the wrong-phase BLOCK, not a silent split.
|
|
2513
|
-
io.stderrText = "";
|
|
2514
|
-
expect(
|
|
2515
|
-
await command.runArgv([
|
|
2516
|
-
"implement",
|
|
2517
|
-
"--tasks",
|
|
2518
|
-
"1,2",
|
|
2519
|
-
"--plan",
|
|
2520
|
-
planPath,
|
|
2521
|
-
"--dry-run",
|
|
2522
|
-
"--root",
|
|
2523
|
-
repoRoot,
|
|
2524
|
-
]),
|
|
2525
|
-
).toBe(1);
|
|
2526
|
-
expect(io.stderrText).toContain("at review");
|
|
2527
|
-
} finally {
|
|
2528
|
-
cleanup();
|
|
2529
|
-
}
|
|
2530
|
-
});
|
|
2531
|
-
|
|
2532
|
-
it("an approved implement round routes its review hop — no commit identity gates the next: line", async () => {
|
|
2533
|
-
// The sha era gated the implement→review route on the round's commits (`commits?.base
|
|
2534
|
-
// === undefined → null`), so an approved-without-commits round produced a null route
|
|
2535
|
-
// and tripped the v1.20 no-next hard error. The commit carrier is retired (spec §2.6):
|
|
2536
|
-
// implement now ALWAYS routes `{ kind: "review" }` — the live tree needs no sha — so
|
|
2537
|
-
// the same approved round yields its review hop, exit 0.
|
|
2538
|
-
const { command, io, repoRoot, cleanup } = fixture({
|
|
2539
|
-
dispatch: () => ({ status: "APPROVED" }),
|
|
2540
|
-
});
|
|
2541
|
-
try {
|
|
2542
|
-
gitInit(repoRoot);
|
|
2543
|
-
const plan = planFor(repoRoot);
|
|
2544
|
-
const code = await command.runArgv([
|
|
2545
|
-
"implement",
|
|
2546
|
-
"--tasks",
|
|
2547
|
-
"1",
|
|
2548
|
-
"--plan",
|
|
2549
|
-
plan,
|
|
2550
|
-
"--dry-run",
|
|
2551
|
-
"--root",
|
|
2552
|
-
repoRoot,
|
|
2553
|
-
]);
|
|
2554
|
-
expect(code).toBe(0);
|
|
2555
|
-
expect(io.stdoutText).toContain("status: APPROVED");
|
|
2556
|
-
expect(io.stdoutText).toContain(`next: review --type wave --tasks 1 --plan ${plan}`);
|
|
2557
|
-
expect(io.stderrText).not.toContain("CDD_BLOCKED:");
|
|
2558
|
-
} finally {
|
|
2559
|
-
cleanup();
|
|
2560
|
-
}
|
|
2561
|
-
});
|
|
2562
|
-
|
|
2563
|
-
it("the clean-tree gate blocks the three verbs on a dirty tree — CDD_BLOCKED · guidance · child zero (P4.1 T1)", async () => {
|
|
2564
|
-
const { command, io, repoRoot, cleanup } = fixture({
|
|
2565
|
-
dispatch: () => ({ status: "APPROVED" }), // a spy — must never run on a dirty tree
|
|
2566
|
-
});
|
|
2567
|
-
try {
|
|
2568
|
-
gitInit(repoRoot);
|
|
2569
|
-
const plan = planFor(repoRoot);
|
|
2570
|
-
// Dirty the fixture tree — a tracked change + an untracked file.
|
|
2571
|
-
writeFileSync(path.join(repoRoot, "seed.txt"), "modified\n", "utf8");
|
|
2572
|
-
for (const verb of ["implement", "review", "fix"] as const) {
|
|
2573
|
-
io.stderrText = "";
|
|
2574
|
-
io.stdoutText = "";
|
|
2575
|
-
const args =
|
|
2576
|
-
verb === "implement"
|
|
2577
|
-
? ["implement", "--tasks", "1", "--plan", plan]
|
|
2578
|
-
: verb === "review"
|
|
2579
|
-
? ["review", "--type", "wave", "--tasks", "1", "--plan", plan]
|
|
2580
|
-
: ["fix", "--type", "wave", "--tasks", "1", "--plan", plan];
|
|
2581
|
-
const code = await command.runArgv([...args, "--dry-run", "--root", repoRoot]);
|
|
2582
|
-
expect(code).toBe(1);
|
|
2583
|
-
// the CDD_BLOCKED channel + the commit/discard guidance
|
|
2584
|
-
expect(io.stderrText).toContain("CDD_BLOCKED:");
|
|
2585
|
-
expect(io.stderrText).toContain("commit or discard");
|
|
2586
|
-
// child zero dispatch — no round artifacts ever land
|
|
2587
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
2588
|
-
expect(existsSync(path.join(workspace, "progress.json"))).toBe(false);
|
|
2589
|
-
expect(existsSync(path.join(workspace, "tasks-1-brief.md"))).toBe(false);
|
|
2590
|
-
}
|
|
2591
|
-
} finally {
|
|
2592
|
-
cleanup();
|
|
2593
|
-
}
|
|
2594
|
-
});
|
|
2595
|
-
|
|
2596
|
-
it("a consumer repo WITHOUT a .kairos gitignore — the engine workspace does not self-BLOCK the clean-tree gate across dispatches (P4.1 F1 regression)", async () => {
|
|
2597
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
2598
|
-
try {
|
|
2599
|
-
// The consumer-repo shape: no `.kairos` entry in the fixture .gitignore — the
|
|
2600
|
-
// workspace ensure self-publishes `.kairos/cdd/.gitignore` (content `*`)
|
|
2601
|
-
// BEFORE the gate reads the tree, so the first dispatch's own writes (the
|
|
2602
|
-
// scene's workspace ensure + the round artifacts) land under the engine's own
|
|
2603
|
-
// keep-out marker — git's judgment stays clean, and the gate refuses only
|
|
2604
|
-
// genuinely dirty user work (never the engine's own outputs).
|
|
2605
|
-
gitInit(repoRoot, "/docs/\n");
|
|
2606
|
-
const plan = conformingPlan(repoRoot);
|
|
2607
|
-
const implement = await command.runArgv([
|
|
2608
|
-
"implement",
|
|
2609
|
-
"--tasks",
|
|
2610
|
-
"1",
|
|
2611
|
-
"--plan",
|
|
2612
|
-
plan,
|
|
2613
|
-
"--dry-run",
|
|
2614
|
-
"--root",
|
|
2615
|
-
repoRoot,
|
|
2616
|
-
]);
|
|
2617
|
-
expect(implement).toBe(0);
|
|
2618
|
-
// the first dispatch landed the engine workspace + its self-published keep-out
|
|
2619
|
-
expect(existsSync(path.join(repoRoot, ".kairos", "cdd", "p3"))).toBe(true);
|
|
2620
|
-
expect(readFileSync(path.join(repoRoot, ".kairos", ".gitignore"), "utf8")).toBe("*\n");
|
|
2621
|
-
io.stderrText = "";
|
|
2622
|
-
// the SECOND dispatch must not self-BLOCK on the engine's own artifacts
|
|
2623
|
-
const review = await command.runArgv([
|
|
2624
|
-
"review",
|
|
2625
|
-
"--type",
|
|
2626
|
-
"wave",
|
|
2627
|
-
"--tasks",
|
|
2628
|
-
"1",
|
|
2629
|
-
"--plan",
|
|
2630
|
-
plan,
|
|
2631
|
-
"--dry-run",
|
|
2632
|
-
"--root",
|
|
2633
|
-
repoRoot,
|
|
2634
|
-
]);
|
|
2635
|
-
expect(review).toBe(0);
|
|
2636
|
-
expect(io.stderrText).not.toContain("CDD_BLOCKED:");
|
|
2637
|
-
} finally {
|
|
2638
|
-
cleanup();
|
|
2639
|
-
}
|
|
2640
|
-
});
|
|
2641
|
-
|
|
2642
|
-
it("the materialized implement carrier on disk carries zero findings keys — the work face's zero-findings write path (T2)", async () => {
|
|
2643
|
-
const { command, repoRoot, cleanup } = fixture();
|
|
2644
|
-
try {
|
|
2645
|
-
gitInit(repoRoot);
|
|
2646
|
-
const plan = planFor(repoRoot);
|
|
2647
|
-
const code = await command.runArgv([
|
|
2648
|
-
"implement",
|
|
2649
|
-
"--tasks",
|
|
2650
|
-
"1",
|
|
2651
|
-
"--plan",
|
|
2652
|
-
plan,
|
|
2653
|
-
"--dry-run",
|
|
2654
|
-
"--root",
|
|
2655
|
-
repoRoot,
|
|
2656
|
-
]);
|
|
2657
|
-
expect(code).toBe(0);
|
|
2658
|
-
const carrier = JSON.parse(
|
|
2659
|
-
readFileSync(path.join(repoRoot, ".kairos", "cdd", "p3", "tasks-1-implement.json"), "utf8"),
|
|
2660
|
-
) as Record<string, unknown>;
|
|
2661
|
-
expect("findings" in carrier).toBe(false);
|
|
2662
|
-
expect(Object.keys(carrier)).not.toContain("findings");
|
|
2663
|
-
} finally {
|
|
2664
|
-
cleanup();
|
|
2665
|
-
}
|
|
2666
|
-
});
|
|
2667
|
-
|
|
2668
|
-
it("T6 — probe A: the end-to-end dry-run implement + fix final carriers carry zero findings keys — both work-face materialization legs (implement + wave fix)", async () => {
|
|
2669
|
-
const { command, repoRoot, cleanup } = fixture();
|
|
2670
|
-
try {
|
|
2671
|
-
gitInit(repoRoot);
|
|
2672
|
-
const plan = planFor(repoRoot);
|
|
2673
|
-
// the implement leg — the dry-run dispatch persists the work-face final carrier
|
|
2674
|
-
expect(
|
|
2675
|
-
await command.runArgv([
|
|
2676
|
-
"implement",
|
|
2677
|
-
"--tasks",
|
|
2678
|
-
"1",
|
|
2679
|
-
"--plan",
|
|
2680
|
-
plan,
|
|
2681
|
-
"--dry-run",
|
|
2682
|
-
"--root",
|
|
2683
|
-
repoRoot,
|
|
2684
|
-
]),
|
|
2685
|
-
).toBe(0);
|
|
2686
|
-
const implementCarrier = JSON.parse(
|
|
2687
|
-
readFileSync(path.join(repoRoot, ".kairos", "cdd", "p3", "tasks-1-implement.json"), "utf8"),
|
|
2688
|
-
) as Record<string, unknown>;
|
|
2689
|
-
expect("findings" in implementCarrier).toBe(false);
|
|
2690
|
-
expect(Object.keys(implementCarrier)).not.toContain("findings");
|
|
2691
|
-
// the fix leg — seed the blocker source review (the C5-1 fix input) so the fix
|
|
2692
|
-
// dispatch reads a finding-bearing review carrier back and still lands its
|
|
2693
|
-
// final carrier on the work face (the fix-will-not-mirror-findings probe)
|
|
2694
|
-
const workspace = new Workspace(new WorkspaceRoot(repoRoot, ".kairos/cdd"), "p3").ensure();
|
|
2695
|
-
const ledger = new Ledger(workspace, new ConfigLoader());
|
|
2696
|
-
ledger.persistHandoff(
|
|
2697
|
-
"review",
|
|
2698
|
-
"wave",
|
|
2699
|
-
{ tasks: "1", round: 1 },
|
|
2700
|
-
{
|
|
2701
|
-
tasks: [1],
|
|
2702
|
-
phase: "review",
|
|
2703
|
-
findings: [{ severity: "blocker", summary: "drift" }],
|
|
2704
|
-
},
|
|
2705
|
-
);
|
|
2706
|
-
ledger.recordRound(1, "review");
|
|
2707
|
-
expect(
|
|
2708
|
-
await command.runArgv([
|
|
2709
|
-
"fix",
|
|
2710
|
-
"--type",
|
|
2711
|
-
"wave",
|
|
2712
|
-
"--tasks",
|
|
2713
|
-
"1",
|
|
2714
|
-
"--plan",
|
|
2715
|
-
plan,
|
|
2716
|
-
"--dry-run",
|
|
2717
|
-
"--root",
|
|
2718
|
-
repoRoot,
|
|
2719
|
-
]),
|
|
2720
|
-
).toBe(0);
|
|
2721
|
-
const fixCarrier = JSON.parse(
|
|
2722
|
-
readFileSync(path.join(repoRoot, ".kairos", "cdd", "p3", "tasks-1-fix-1.json"), "utf8"),
|
|
2723
|
-
) as Record<string, unknown>;
|
|
2724
|
-
expect("findings" in fixCarrier).toBe(false);
|
|
2725
|
-
expect(Object.keys(fixCarrier)).not.toContain("findings");
|
|
2726
|
-
} finally {
|
|
2727
|
-
cleanup();
|
|
2728
|
-
}
|
|
2729
|
-
});
|
|
2730
|
-
|
|
2731
|
-
it("a command word is not a schema type — `schema get board` carries no route and no vocabulary row", async () => {
|
|
2732
|
-
const { command, io, cleanup } = fixture();
|
|
2733
|
-
try {
|
|
2734
|
-
const code = await command.runArgv(["schema", "get", "board"]);
|
|
2735
|
-
expect(code).toBe(2);
|
|
2736
|
-
expect(io.stderrText).toContain("unknown schema type: board");
|
|
2737
|
-
} finally {
|
|
2738
|
-
cleanup();
|
|
2739
|
-
}
|
|
2740
|
-
});
|
|
2741
|
-
});
|
|
2742
|
-
|
|
2743
|
-
// ---------------------------------------------------------------------------
|
|
2744
|
-
// P4.1 T4 — the complete executable next literal (v1.39 semantic reversal):
|
|
2745
|
-
// the `next:` line IS the dispatch (zero-error second parse · done never fed to parse ·
|
|
2746
|
-
// routeWords sync · implement without --type)
|
|
2747
|
-
// ---------------------------------------------------------------------------
|
|
2748
|
-
|
|
2749
|
-
describe("P4.1 T4 — the next literal is a complete executable command (zero-error second parse)", () => {
|
|
2750
|
-
/** The next text of a capsule emit (the second line, station prefix stripped). */
|
|
2751
|
-
function literalOf(route: Route, target?: RouteTarget): string {
|
|
2752
|
-
const lines = new Capsule(new Words()).emit("APPROVED", "0", "/h.json", route, target);
|
|
2753
|
-
return lines[1]!.slice("next: ".length);
|
|
2754
|
-
}
|
|
2755
|
-
|
|
2756
|
-
/** The parseable argv of a literal — the fix readback suffix is prompt prose,
|
|
2757
|
-
* never argv (the parse gate strips the declared suffix before feeding). */
|
|
2758
|
-
function argvOf(literal: string): string[] {
|
|
2759
|
-
return literal
|
|
2760
|
-
.replace(new RegExp(`\\s*\\(${FIX_READBACK_SUFFIX.slice(1, -1)}\\)$`), "")
|
|
2761
|
-
.split(/\s+/);
|
|
2762
|
-
}
|
|
2763
|
-
|
|
2764
|
-
/** The secondary-parse gate — the literal's argv must parse with zero errors
|
|
2765
|
-
* (the same commander program the runArgv dispatch reads; `Cli#parse()`
|
|
2766
|
-
* retired at T3). */
|
|
2767
|
-
function parses(literal: string): void {
|
|
2768
|
-
expect(() =>
|
|
2769
|
-
new CommandTreeBuilder().program.parse(argvOf(literal), { from: "user" }),
|
|
2770
|
-
).not.toThrow();
|
|
2771
|
-
}
|
|
2772
|
-
|
|
2773
|
-
const wave = { type: "wave", id: "1,2", plan: "docs/kairos/plans/p3.md" } as const;
|
|
2774
|
-
const spec = { type: "spec", id: "docs/kairos/specs/p3-design.md" } as const;
|
|
2775
|
-
const planT = { type: "plan", id: "docs/kairos/plans/p3.md" } as const;
|
|
2776
|
-
// the branch target carries the workspace --plan only — the review judges the
|
|
2777
|
-
// live tree, so no range rides the command (spec §2.3/§2.6)
|
|
2778
|
-
const branch = {
|
|
2779
|
-
type: "branch",
|
|
2780
|
-
id: "branch",
|
|
2781
|
-
plan: "docs/kairos/plans/p3.md",
|
|
2782
|
-
} as const;
|
|
2783
|
-
|
|
2784
|
-
it("implement — the literal is `implement --plan <path> --tasks <n>` with NO --type", () => {
|
|
2785
|
-
const literal = literalOf({ kind: "next-wave", tasks: "1,2" }, wave);
|
|
2786
|
-
expect(literal).toBe("implement --plan docs/kairos/plans/p3.md --tasks 1,2");
|
|
2787
|
-
expect(literal).not.toContain("--type");
|
|
2788
|
-
parses(literal);
|
|
2789
|
-
// the declaration needs no new `--type` key — the default-type semantics stand
|
|
2790
|
-
const specOf = CLI_COMMANDS.find((command) => command.name === "implement")!;
|
|
2791
|
-
expect(specOf.keys.some((key) => key.key === "type")).toBe(false);
|
|
2792
|
-
});
|
|
2793
|
-
|
|
2794
|
-
it("review × 4 types — `review --type <type> <type-arg>` parses", () => {
|
|
2795
|
-
// find #7 (P4.1 T7): the wave review literal carries its runtime-required `--plan`
|
|
2796
|
-
// (the W3 dispatch gap — `review --type wave --tasks 5` parsed green yet refused
|
|
2797
|
-
// at run time with `required option '--plan <path>' not specified`); the full
|
|
2798
|
-
// coverage table lives in capsule.test.ts (the design §5.6 parse-green ⇒ full
|
|
2799
|
-
// required-flag coverage rule).
|
|
2800
|
-
const waveLiteral = literalOf({ kind: "review" }, wave);
|
|
2801
|
-
expect(waveLiteral).toBe("review --type wave --tasks 1,2 --plan docs/kairos/plans/p3.md");
|
|
2802
|
-
parses(waveLiteral);
|
|
2803
|
-
const specLiteral = literalOf({ kind: "review" }, spec);
|
|
2804
|
-
expect(specLiteral).toBe("review --type spec --spec docs/kairos/specs/p3-design.md");
|
|
2805
|
-
parses(specLiteral);
|
|
2806
|
-
const planLiteral = literalOf({ kind: "review" }, planT);
|
|
2807
|
-
expect(planLiteral).toBe("review --type plan --plan docs/kairos/plans/p3.md");
|
|
2808
|
-
parses(planLiteral);
|
|
2809
|
-
const branchLiteral = literalOf({ kind: "review" }, branch);
|
|
2810
|
-
// the branch review literal carries the workspace --plan only — the live tree
|
|
2811
|
-
// needs no SHA range (spec §2.3/§2.6)
|
|
2812
|
-
expect(branchLiteral).toBe("review --type branch --plan docs/kairos/plans/p3.md");
|
|
2813
|
-
parses(branchLiteral);
|
|
2814
|
-
});
|
|
2815
|
-
|
|
2816
|
-
it("fix × 4 types — `fix --type <type> <type-arg> --findings <handoff>` parses", () => {
|
|
2817
|
-
const waveLiteral = literalOf({ kind: "fix", findings: "tasks-1-review-1.json" }, wave);
|
|
2818
|
-
expect(waveLiteral).toBe(
|
|
2819
|
-
"fix --type wave --tasks 1,2 --plan docs/kairos/plans/p3.md --findings tasks-1-review-1.json " +
|
|
2820
|
-
FIX_READBACK_SUFFIX,
|
|
2821
|
-
);
|
|
2822
|
-
parses(waveLiteral);
|
|
2823
|
-
const specLiteral = literalOf({ kind: "fix", findings: "s1-review-1.json" }, spec);
|
|
2824
|
-
expect(specLiteral).toBe(
|
|
2825
|
-
"fix --type spec --spec docs/kairos/specs/p3-design.md --findings s1-review-1.json " +
|
|
2826
|
-
FIX_READBACK_SUFFIX,
|
|
2827
|
-
);
|
|
2828
|
-
parses(specLiteral);
|
|
2829
|
-
const planLiteral = literalOf({ kind: "fix", findings: "p1-review-1.json" }, planT);
|
|
2830
|
-
expect(planLiteral).toBe(
|
|
2831
|
-
`fix --type plan --plan docs/kairos/plans/p3.md --findings p1-review-1.json ${FIX_READBACK_SUFFIX}`,
|
|
2832
|
-
);
|
|
2833
|
-
parses(planLiteral);
|
|
2834
|
-
const branchLiteral = literalOf({ kind: "fix", findings: "br1-review-1.json" }, branch);
|
|
2835
|
-
// find #8 F1b — the branch fix literal carries the workspace --plan
|
|
2836
|
-
// (user-decided; the orchestrator provides zero fallback · spec §5.7 fix (2))
|
|
2837
|
-
expect(branchLiteral).toBe(
|
|
2838
|
-
`fix --type branch --plan docs/kairos/plans/p3.md --findings br1-review-1.json ${FIX_READBACK_SUFFIX}`,
|
|
2839
|
-
);
|
|
2840
|
-
parses(branchLiteral);
|
|
2841
|
-
});
|
|
2842
|
-
|
|
2843
|
-
it("done — the bare terminal word, never fed to parse (a bare `done` is not a command)", async () => {
|
|
2844
|
-
expect(literalOf({ kind: "done" })).toBe("done");
|
|
2845
|
-
const { command, io, cleanup } = fixture();
|
|
2846
|
-
try {
|
|
2847
|
-
const code = await command.runArgv(["done"]);
|
|
2848
|
-
expect(code).toBe(2);
|
|
2849
|
-
expect(io.stderrText).toContain("error: unknown command 'done'");
|
|
2850
|
-
} finally {
|
|
2851
|
-
cleanup();
|
|
2852
|
-
}
|
|
2853
|
-
});
|
|
2854
|
-
|
|
2855
|
-
it("routeWords sync — the four literal verbs ARE the four route classifier words", () => {
|
|
2856
|
-
const words = new Words();
|
|
2857
|
-
expect(literalOf({ kind: "next-wave", tasks: "1" }, wave)).toMatch(
|
|
2858
|
-
new RegExp(`^${words.routeWord("implement")} `),
|
|
2859
|
-
);
|
|
2860
|
-
expect(literalOf({ kind: "review" }, wave)).toMatch(
|
|
2861
|
-
new RegExp(`^${words.routeWord("review")} `),
|
|
2862
|
-
);
|
|
2863
|
-
expect(literalOf({ kind: "fix", findings: "f.json" }, wave)).toMatch(
|
|
2864
|
-
new RegExp(`^${words.routeWord("fix")} `),
|
|
2865
|
-
);
|
|
2866
|
-
expect(literalOf({ kind: "done" })).toBe(words.routeWord("done"));
|
|
2867
|
-
});
|
|
2868
|
-
});
|
|
2869
|
-
|
|
2870
|
-
describe("P4.1 T4 — the dry-run real chain: next literals dispatch the next round (rev1→implement wave 2 · rev2→done)", () => {
|
|
2871
|
-
it("implement→review(fix)→fix(closure)→implement wave 2→review→done — every next literal re-dispatches", async () => {
|
|
2872
|
-
const { command, io, repoRoot, cleanup } = fixture({
|
|
2873
|
-
dispatch: (frame: OpenFrame) => {
|
|
2874
|
-
// the first review finds a warn (one-way fix hop); everything else approves
|
|
2875
|
-
return frame.phase === "review" && frame.params.tasks === "1"
|
|
2876
|
-
? {
|
|
2877
|
-
status: "CHANGES_REQUESTED",
|
|
2878
|
-
findings: [{ severity: "warn", summary: "drift" }],
|
|
2879
|
-
}
|
|
2880
|
-
: { status: "APPROVED" };
|
|
2881
|
-
},
|
|
2882
|
-
});
|
|
2883
|
-
try {
|
|
2884
|
-
gitInit(repoRoot);
|
|
2885
|
-
const plan = planFor(repoRoot, 2);
|
|
2886
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
2887
|
-
const nextOf = (): string | null => {
|
|
2888
|
-
const m = io.stdoutText.match(/^next: (.+)$/m);
|
|
2889
|
-
return m === null ? null : m[1]!;
|
|
2890
|
-
};
|
|
2891
|
-
|
|
2892
|
-
// rev 1 — implement wave 1 → the review literal
|
|
2893
|
-
expect(
|
|
2894
|
-
await command.runArgv([
|
|
2895
|
-
"implement",
|
|
2896
|
-
"--tasks",
|
|
2897
|
-
"1",
|
|
2898
|
-
"--plan",
|
|
2899
|
-
plan,
|
|
2900
|
-
"--dry-run",
|
|
2901
|
-
"--root",
|
|
2902
|
-
repoRoot,
|
|
2903
|
-
]),
|
|
2904
|
-
).toBe(0);
|
|
2905
|
-
expect(nextOf()).toBe(`review --type wave --tasks 1 --plan ${plan}`);
|
|
2906
|
-
io.stdoutText = "";
|
|
2907
|
-
|
|
2908
|
-
// the review finds a warn → the fix literal
|
|
2909
|
-
expect(
|
|
2910
|
-
await command.runArgv([
|
|
2911
|
-
"review",
|
|
2912
|
-
"--type",
|
|
2913
|
-
"wave",
|
|
2914
|
-
"--tasks",
|
|
2915
|
-
"1",
|
|
2916
|
-
"--plan",
|
|
2917
|
-
plan,
|
|
2918
|
-
"--dry-run",
|
|
2919
|
-
"--root",
|
|
2920
|
-
repoRoot,
|
|
2921
|
-
]),
|
|
2922
|
-
).toBe(0);
|
|
2923
|
-
expect(nextOf()).toBe(
|
|
2924
|
-
`fix --type wave --tasks 1 --plan ${plan} --findings ${path.join(workspace, "tasks-1-review-1.json")} ${FIX_READBACK_SUFFIX}`,
|
|
2925
|
-
);
|
|
2926
|
-
io.stdoutText = "";
|
|
2927
|
-
|
|
2928
|
-
// the fix closes (warn-only input) → rev1 lands on the NEXT WAVE's implement literal
|
|
2929
|
-
expect(
|
|
2930
|
-
await command.runArgv([
|
|
2931
|
-
"fix",
|
|
2932
|
-
"--type",
|
|
2933
|
-
"wave",
|
|
2934
|
-
"--tasks",
|
|
2935
|
-
"1",
|
|
2936
|
-
"--plan",
|
|
2937
|
-
plan,
|
|
2938
|
-
"--dry-run",
|
|
2939
|
-
"--root",
|
|
2940
|
-
repoRoot,
|
|
2941
|
-
]),
|
|
2942
|
-
).toBe(0);
|
|
2943
|
-
expect(nextOf()).toBe(`implement --plan ${plan} --tasks 2`);
|
|
2944
|
-
io.stdoutText = "";
|
|
2945
|
-
|
|
2946
|
-
// rev 2 — implement wave 2 → the review literal
|
|
2947
|
-
expect(
|
|
2948
|
-
await command.runArgv([
|
|
2949
|
-
"implement",
|
|
2950
|
-
"--tasks",
|
|
2951
|
-
"2",
|
|
2952
|
-
"--plan",
|
|
2953
|
-
plan,
|
|
2954
|
-
"--dry-run",
|
|
2955
|
-
"--root",
|
|
2956
|
-
repoRoot,
|
|
2957
|
-
]),
|
|
2958
|
-
).toBe(0);
|
|
2959
|
-
expect(nextOf()).toBe(`review --type wave --tasks 2 --plan ${plan}`);
|
|
2960
|
-
io.stdoutText = "";
|
|
2961
|
-
|
|
2962
|
-
// the final review closes the run → rev2 lands on the wave→branch wiring
|
|
2963
|
-
// literal (T3 deliberate pin break — the PIPELINE_NEXT.wave route)
|
|
2964
|
-
expect(
|
|
2965
|
-
await command.runArgv([
|
|
2966
|
-
"review",
|
|
2967
|
-
"--type",
|
|
2968
|
-
"wave",
|
|
2969
|
-
"--tasks",
|
|
2970
|
-
"2",
|
|
2971
|
-
"--plan",
|
|
2972
|
-
plan,
|
|
2973
|
-
"--dry-run",
|
|
2974
|
-
"--root",
|
|
2975
|
-
repoRoot,
|
|
2976
|
-
]),
|
|
2977
|
-
).toBe(0);
|
|
2978
|
-
expect(nextOf()).toBe(`review --type branch --plan ${plan}`);
|
|
2979
|
-
|
|
2980
|
-
const progress = readJson<{ waves: unknown[] }>(path.join(workspace, "progress.json"));
|
|
2981
|
-
// the wave-2 row carries its own D30 revision record — the final APPROVED
|
|
2982
|
-
// review bound wave 2's BRIEF to its line (the same brief-revision write-back)
|
|
2983
|
-
expect(progress.waves).toContainEqual({
|
|
2984
|
-
wave: "2",
|
|
2985
|
-
rounds: { implement: [1], review: [1] },
|
|
2986
|
-
reviewedRevision: briefRevision(plan, "2"),
|
|
2987
|
-
});
|
|
2988
|
-
} finally {
|
|
2989
|
-
cleanup();
|
|
2990
|
-
}
|
|
2991
|
-
});
|
|
2992
|
-
});
|
|
2993
|
-
|
|
2994
|
-
// ---------------------------------------------------------------------------
|
|
2995
|
-
// the pure commands — schema / issue / base (the dry-run E2E surface)
|
|
2996
|
-
// ---------------------------------------------------------------------------
|
|
2997
|
-
|
|
2998
|
-
describe("the pure commands — schema / issue / base", () => {
|
|
2999
|
-
it("schema get <plan> — the derived doc-structure schema to stdout", async () => {
|
|
3000
|
-
const { command, io, cleanup } = fixture();
|
|
3001
|
-
try {
|
|
3002
|
-
const code = await command.runArgv(["schema", "get", "plan"]);
|
|
3003
|
-
expect(code).toBe(0);
|
|
3004
|
-
const schema = JSON.parse(io.stdoutText) as {
|
|
3005
|
-
docType: string;
|
|
3006
|
-
properties: Record<string, unknown>;
|
|
3007
|
-
required: string[];
|
|
3008
|
-
};
|
|
3009
|
-
expect(schema.docType).toBe("plan");
|
|
3010
|
-
expect(schema.properties["### Task N:"]).toBeDefined();
|
|
3011
|
-
expect(schema.required).toContain("### Task N:");
|
|
3012
|
-
expect(schema.required.length).toBeGreaterThan(0);
|
|
3013
|
-
} finally {
|
|
3014
|
-
cleanup();
|
|
3015
|
-
}
|
|
3016
|
-
});
|
|
3017
|
-
|
|
3018
|
-
it("schema get — an unknown type exits 2 with the derived vocabulary", async () => {
|
|
3019
|
-
const { command, io, cleanup } = fixture();
|
|
3020
|
-
try {
|
|
3021
|
-
const code = await command.runArgv(["schema", "get", "bogus"]);
|
|
3022
|
-
expect(code).toBe(2);
|
|
3023
|
-
expect(io.stderrText).toContain(
|
|
3024
|
-
"unknown schema type: bogus (available: overall-spec, plan, phase-spec, single-spec)",
|
|
3025
|
-
);
|
|
3026
|
-
} finally {
|
|
3027
|
-
cleanup();
|
|
3028
|
-
}
|
|
3029
|
-
});
|
|
3030
|
-
|
|
3031
|
-
it("schema get phase-spec --output skeleton <target> — the derived doc skeleton written directly into the target document", async () => {
|
|
3032
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
3033
|
-
try {
|
|
3034
|
-
const target = path.join(repoRoot, "docs", "skeleton.md");
|
|
3035
|
-
mkdirSync(path.dirname(target), { recursive: true });
|
|
3036
|
-
const code = await command.runArgv([
|
|
3037
|
-
"schema",
|
|
3038
|
-
"get",
|
|
3039
|
-
"phase-spec",
|
|
3040
|
-
"--output",
|
|
3041
|
-
"skeleton",
|
|
3042
|
-
target,
|
|
3043
|
-
]);
|
|
3044
|
-
expect(code).toBe(0);
|
|
3045
|
-
// the D19 in-place scaffold — the target doc carries the structural bytes
|
|
3046
|
-
// (headings, numeric truths, fills, the version row, the change-history
|
|
3047
|
-
// first row) the old stdout face emitted, and the path prints to stdout
|
|
3048
|
-
const text = readFileSync(target, "utf8");
|
|
3049
|
-
expect(text).toContain("## Design");
|
|
3050
|
-
expect(text).toContain("### 1. :::fill group-title");
|
|
3051
|
-
expect(text).toContain("- `:::fill acceptance-entry`");
|
|
3052
|
-
expect(text).toContain("- **Version**: v0.1 · ");
|
|
3053
|
-
expect(text).toContain("| v0.1 | ");
|
|
3054
|
-
// the written doc ends with exactly one newline — the EOF rule (render()
|
|
3055
|
-
// never appends; the D19 write path appends the single `\n`)
|
|
3056
|
-
expect(text.endsWith("\n")).toBe(true);
|
|
3057
|
-
expect(text.endsWith("\n\n")).toBe(false);
|
|
3058
|
-
expect(io.stdoutText.trim()).toBe(target);
|
|
3059
|
-
} finally {
|
|
3060
|
-
cleanup();
|
|
3061
|
-
}
|
|
3062
|
-
});
|
|
3063
|
-
|
|
3064
|
-
it("schema get single-spec — the fourth doc-type channel: the json render without a target, the skeleton render into a required target", async () => {
|
|
3065
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
3066
|
-
try {
|
|
3067
|
-
// the json render face — the derived single-spec declaration, no target
|
|
3068
|
-
let code = await command.runArgv(["schema", "get", "single-spec"]);
|
|
3069
|
-
expect(code).toBe(0);
|
|
3070
|
-
expect(io.stdoutText).toContain('"docType": "single-spec"');
|
|
3071
|
-
expect(io.stdoutText).toContain('"## Background & root cause"');
|
|
3072
|
-
io.stdoutText = "";
|
|
3073
|
-
// the skeleton render face — the lightweight scaffold written DIRECTLY into
|
|
3074
|
-
// the target (the P5 conditional-required target mechanism)
|
|
3075
|
-
const target = path.join(repoRoot, "docs", "single-spec-skeleton.md");
|
|
3076
|
-
mkdirSync(path.dirname(target), { recursive: true });
|
|
3077
|
-
code = await command.runArgv([
|
|
3078
|
-
"schema",
|
|
3079
|
-
"get",
|
|
3080
|
-
"single-spec",
|
|
3081
|
-
"--output",
|
|
3082
|
-
"skeleton",
|
|
3083
|
-
target,
|
|
3084
|
-
]);
|
|
3085
|
-
expect(code).toBe(0);
|
|
3086
|
-
const text = readFileSync(target, "utf8");
|
|
3087
|
-
// the header five-tuple without the phase-spec's Parent program
|
|
3088
|
-
expect(text).toContain("- **Version**: v0.1 · ");
|
|
3089
|
-
expect(text).toContain("- **Status**: Draft");
|
|
3090
|
-
expect(text).toContain("- **Author**: :::fill author");
|
|
3091
|
-
expect(text).toContain("- **Depends on**: :::fill depends-on");
|
|
3092
|
-
expect(text).not.toContain("**Parent program**");
|
|
3093
|
-
// the prose `:::fill` body + the change-history lineage — no `### N.` outline
|
|
3094
|
-
expect(text).toContain("## Background & root cause");
|
|
3095
|
-
expect(text).toContain(":::fill background-root-cause");
|
|
3096
|
-
expect(text).toContain("## Design decisions");
|
|
3097
|
-
expect(text).toContain("## Acceptance");
|
|
3098
|
-
expect(text).toContain("## Constraints");
|
|
3099
|
-
expect(text).not.toContain("### N.");
|
|
3100
|
-
expect(text).toContain("## Change history");
|
|
3101
|
-
expect(text).toContain("| v0.1 | ");
|
|
3102
|
-
// the written doc ends with exactly one newline — the EOF rule
|
|
3103
|
-
expect(text.endsWith("\n")).toBe(true);
|
|
3104
|
-
expect(text.endsWith("\n\n")).toBe(false);
|
|
3105
|
-
expect(io.stdoutText.trim()).toBe(target);
|
|
3106
|
-
// a missing <target> under --output skeleton exits 2 with the conditional-required byte
|
|
3107
|
-
io.stderrText = "";
|
|
3108
|
-
code = await command.runArgv(["schema", "get", "single-spec", "--output", "skeleton"]);
|
|
3109
|
-
expect(code).toBe(2);
|
|
3110
|
-
expect(io.stderrText).toContain("cdd schema get --output skeleton: missing <target>");
|
|
3111
|
-
} finally {
|
|
3112
|
-
cleanup();
|
|
3113
|
-
}
|
|
3114
|
-
});
|
|
3115
|
-
|
|
3116
|
-
it("schema get --output skeleton — the phaseSpec alias renders byte-identical to the DocType literal", async () => {
|
|
3117
|
-
const dash = fixture();
|
|
3118
|
-
const camel = fixture();
|
|
3119
|
-
try {
|
|
3120
|
-
const dashTarget = path.join(dash.repoRoot, "dash.md");
|
|
3121
|
-
const camelTarget = path.join(camel.repoRoot, "camel.md");
|
|
3122
|
-
expect(
|
|
3123
|
-
await dash.command.runArgv([
|
|
3124
|
-
"schema",
|
|
3125
|
-
"get",
|
|
3126
|
-
"phase-spec",
|
|
3127
|
-
"--output",
|
|
3128
|
-
"skeleton",
|
|
3129
|
-
dashTarget,
|
|
3130
|
-
]),
|
|
3131
|
-
).toBe(0);
|
|
3132
|
-
expect(
|
|
3133
|
-
await camel.command.runArgv([
|
|
3134
|
-
"schema",
|
|
3135
|
-
"get",
|
|
3136
|
-
"phaseSpec",
|
|
3137
|
-
"--output",
|
|
3138
|
-
"skeleton",
|
|
3139
|
-
camelTarget,
|
|
3140
|
-
]),
|
|
3141
|
-
).toBe(0);
|
|
3142
|
-
expect(readFileSync(camelTarget, "utf8")).toBe(readFileSync(dashTarget, "utf8"));
|
|
3143
|
-
} finally {
|
|
3144
|
-
dash.cleanup();
|
|
3145
|
-
camel.cleanup();
|
|
3146
|
-
}
|
|
3147
|
-
});
|
|
3148
|
-
|
|
3149
|
-
it("schema get — the bare call keeps its missing-type byte; the kebab spelling and the legacy alias render the same derived JSON; the default --output is json", async () => {
|
|
3150
|
-
const bare = fixture();
|
|
3151
|
-
expect(await bare.command.runArgv(["schema", "get"])).toBe(2);
|
|
3152
|
-
// the get leaf's missing-type byte is unchanged — the parse-level required
|
|
3153
|
-
// positional face (commander's native missing-required-argument error)
|
|
3154
|
-
expect(bare.io.stderrText).toContain("error: missing required argument 'type'");
|
|
3155
|
-
bare.cleanup();
|
|
3156
|
-
const literal = fixture();
|
|
3157
|
-
expect(await literal.command.runArgv(["schema", "get", "phase-spec"])).toBe(0);
|
|
3158
|
-
expect(JSON.parse(literal.io.stdoutText).docType).toBe("phase-spec");
|
|
3159
|
-
// the legacy alias normalizes to the same kebab key — byte-identical output
|
|
3160
|
-
const alias = fixture();
|
|
3161
|
-
expect(await alias.command.runArgv(["schema", "get", "phaseSpec"])).toBe(0);
|
|
3162
|
-
expect(alias.io.stdoutText).toBe(literal.io.stdoutText);
|
|
3163
|
-
alias.cleanup();
|
|
3164
|
-
// D19 — the --output default is json: a bare `schema get <type>` (no --output)
|
|
3165
|
-
// stays legal and byte-identical to the explicit json render face
|
|
3166
|
-
const json = fixture();
|
|
3167
|
-
expect(await json.command.runArgv(["schema", "get", "phase-spec", "--output", "json"])).toBe(0);
|
|
3168
|
-
expect(json.io.stdoutText).toBe(literal.io.stdoutText);
|
|
3169
|
-
json.cleanup();
|
|
3170
|
-
literal.cleanup();
|
|
3171
|
-
});
|
|
3172
|
-
|
|
3173
|
-
it("issue render — stdin findings JSON → the aggregate body on stdout (the subcommand face)", async () => {
|
|
3174
|
-
const input = {
|
|
3175
|
-
harness: "claude",
|
|
3176
|
-
findings: [
|
|
3177
|
-
{
|
|
3178
|
-
type: "bug",
|
|
3179
|
-
lang: "en",
|
|
3180
|
-
context: "c",
|
|
3181
|
-
problem: "p",
|
|
3182
|
-
impact: "i",
|
|
3183
|
-
suggestedFix: "f",
|
|
3184
|
-
meta: { skill: "cdd-dev", step: "implement" },
|
|
3185
|
-
},
|
|
3186
|
-
],
|
|
3187
|
-
related: {
|
|
3188
|
-
open: [{ issue: 1, component: "cdd", reason: "dup" }],
|
|
3189
|
-
closed: [{ issue: 9 }],
|
|
3190
|
-
program: { issue: 2 },
|
|
3191
|
-
},
|
|
3192
|
-
};
|
|
3193
|
-
const { command, io, cleanup } = fixture({ stdinRead: () => JSON.stringify(input) });
|
|
3194
|
-
try {
|
|
3195
|
-
const code = await command.runArgv(["issue", "render"]);
|
|
3196
|
-
expect(code).toBe(0);
|
|
3197
|
-
// the subcommand face — the body and a label land on stdout (the renderer's
|
|
3198
|
-
// own deep suite — labels/langs/dedup — lives in render/__tests__/render.test.ts)
|
|
3199
|
-
expect(io.stdoutText).toContain("# CDD aggregate issue");
|
|
3200
|
-
expect(io.stdoutText).toContain("- Harness: claude");
|
|
3201
|
-
expect(io.stdoutText).toContain("## Context\n\nc");
|
|
3202
|
-
} finally {
|
|
3203
|
-
cleanup();
|
|
3204
|
-
}
|
|
3205
|
-
});
|
|
3206
|
-
|
|
3207
|
-
it("issue render — malformed / invalid input exits 1 with the field path", async () => {
|
|
3208
|
-
const bad = fixture({ stdinRead: () => "not-json" });
|
|
3209
|
-
expect(await bad.command.runArgv(["issue", "render"])).toBe(1);
|
|
3210
|
-
expect(bad.io.stderrText).toContain("invalid input JSON");
|
|
3211
|
-
bad.cleanup();
|
|
3212
|
-
const invalid = fixture({
|
|
3213
|
-
stdinRead: () => JSON.stringify({ harness: "claude", findings: [] }),
|
|
3214
|
-
});
|
|
3215
|
-
expect(await invalid.command.runArgv(["issue", "render"])).toBe(1);
|
|
3216
|
-
expect(invalid.io.stderrText).toContain("findings");
|
|
3217
|
-
invalid.cleanup();
|
|
3218
|
-
});
|
|
3219
|
-
|
|
3220
|
-
it("base set/get — the single --plan artifact write-through + the force gate (T20 face)", async () => {
|
|
3221
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
3222
|
-
try {
|
|
3223
|
-
const plan = planFor(repoRoot);
|
|
3224
|
-
const setCode = await command.runArgv([
|
|
3225
|
-
"base",
|
|
3226
|
-
"set",
|
|
3227
|
-
"--plan",
|
|
3228
|
-
plan,
|
|
3229
|
-
"--base",
|
|
3230
|
-
"develop",
|
|
3231
|
-
"--source",
|
|
3232
|
-
"plan-field",
|
|
3233
|
-
]);
|
|
3234
|
-
expect(setCode).toBe(0);
|
|
3235
|
-
expect(io.stdoutText).toContain("base.json");
|
|
3236
|
-
const workspace = path.join(repoRoot, ".kairos", "cdd", "p3");
|
|
3237
|
-
const artifact = readJson<{ base: string; source: string }>(
|
|
3238
|
-
path.join(workspace, "base.json"),
|
|
3239
|
-
);
|
|
3240
|
-
expect(artifact.base).toBe("develop");
|
|
3241
|
-
expect(artifact.source).toBe("plan-field");
|
|
3242
|
-
io.stdoutText = "";
|
|
3243
|
-
const getCode = await command.runArgv(["base", "get", "--plan", plan]);
|
|
3244
|
-
expect(getCode).toBe(0);
|
|
3245
|
-
expect(io.stdoutText).toContain('"base": "develop"');
|
|
3246
|
-
const conflict = await command.runArgv([
|
|
3247
|
-
"base",
|
|
3248
|
-
"set",
|
|
3249
|
-
"--plan",
|
|
3250
|
-
plan,
|
|
3251
|
-
"--base",
|
|
3252
|
-
"main",
|
|
3253
|
-
"--source",
|
|
3254
|
-
"plan-field",
|
|
3255
|
-
]);
|
|
3256
|
-
expect(conflict).toBe(2);
|
|
3257
|
-
expect(io.stderrText).toContain("--force");
|
|
3258
|
-
io.stderrText = "";
|
|
3259
|
-
const forced = await command.runArgv([
|
|
3260
|
-
"base",
|
|
3261
|
-
"set",
|
|
3262
|
-
"--plan",
|
|
3263
|
-
plan,
|
|
3264
|
-
"--base",
|
|
3265
|
-
"main",
|
|
3266
|
-
"--source",
|
|
3267
|
-
"user-confirmed",
|
|
3268
|
-
"--force",
|
|
3269
|
-
]);
|
|
3270
|
-
expect(forced).toBe(0);
|
|
3271
|
-
const getMissing = await command.runArgv([
|
|
3272
|
-
"base",
|
|
3273
|
-
"get",
|
|
3274
|
-
"--plan",
|
|
3275
|
-
"docs/kairos/plans/missing.md",
|
|
3276
|
-
]);
|
|
3277
|
-
expect(getMissing).toBe(2);
|
|
3278
|
-
} finally {
|
|
3279
|
-
cleanup();
|
|
3280
|
-
}
|
|
3281
|
-
});
|
|
3282
|
-
});
|
|
3283
|
-
|
|
3284
|
-
describe("T9 — the composition-root entry is the Cli.create static factory (deliberate pin)", () => {
|
|
3285
|
-
it("the module's composition root is the class static factory — zero bare-function entry", () => {
|
|
3286
|
-
// The P5 zero-bare-function closure locked the composition root's class form:
|
|
3287
|
-
// the sole entry is the Cli.create static factory, never a module-level `cli`
|
|
3288
|
-
// function (a regression trips this source-level pin — the deliberate T9 break).
|
|
3289
|
-
const src = readFileSync(new URL("../cli.ts", import.meta.url), "utf8");
|
|
3290
|
-
expect(src).toContain("static create(opts: CliOptions = {}): Cli");
|
|
3291
|
-
expect(src).not.toContain("export function cli");
|
|
3292
|
-
expect(src).not.toMatch(/^(export )?(async )?function /m);
|
|
3293
|
-
});
|
|
3294
|
-
|
|
3295
|
-
it("Cli.create is a live factory — the default construction resolves a working Cli", async () => {
|
|
3296
|
-
const command = Cli.create();
|
|
3297
|
-
const exit = await command.runArgv([]);
|
|
3298
|
-
expect(exit).toBe(2);
|
|
3299
|
-
});
|
|
3300
|
-
});
|
|
3301
|
-
|
|
3302
|
-
// ---------------------------------------------------------------------------
|
|
3303
|
-
// T5 — `cdd board <slug>`: the pure-read observability command (no preflight
|
|
3304
|
-
// gate, zero side effects; missing slug → usage exit 2 · a ghost slug → exit 2 ·
|
|
3305
|
-
// a valid slug → the board to stdout, exit 0).
|
|
3306
|
-
// ---------------------------------------------------------------------------
|
|
3307
|
-
|
|
3308
|
-
describe("T5 — cdd board <slug>: the pure-read board command", () => {
|
|
3309
|
-
/** Seed a minimal phase's docs + overall (declared doc-types) in a fixture repo. */
|
|
3310
|
-
const seedPhaseDocs = (repoRoot: string, program: string): void => {
|
|
3311
|
-
mkdirSync(path.join(repoRoot, "docs/kairos/specs"), { recursive: true });
|
|
3312
|
-
mkdirSync(path.join(repoRoot, "docs/kairos/plans"), { recursive: true });
|
|
3313
|
-
writeFileSync(
|
|
3314
|
-
path.join(repoRoot, `docs/kairos/specs/${program}-overall.md`),
|
|
3315
|
-
"# O\n\n- **Doc type**: overall-spec\n",
|
|
3316
|
-
"utf8",
|
|
3317
|
-
);
|
|
3318
|
-
writeFileSync(
|
|
3319
|
-
path.join(repoRoot, `docs/kairos/specs/${program}-p1-design.md`),
|
|
3320
|
-
"# S\n\n- **Doc type**: phase-spec\n",
|
|
3321
|
-
"utf8",
|
|
3322
|
-
);
|
|
3323
|
-
writeFileSync(
|
|
3324
|
-
path.join(repoRoot, `docs/kairos/plans/${program}-p1.md`),
|
|
3325
|
-
"# Plan\n\n- **Doc type**: plan\n",
|
|
3326
|
-
"utf8",
|
|
3327
|
-
);
|
|
3328
|
-
};
|
|
3329
|
-
|
|
3330
|
-
it("a valid slug renders the board to stdout and exits 0", async () => {
|
|
3331
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
3332
|
-
try {
|
|
3333
|
-
seedPhaseDocs(repoRoot, "prog");
|
|
3334
|
-
const code = await command.runArgv(["board", "prog-p1"]);
|
|
3335
|
-
expect(code).toBe(0);
|
|
3336
|
-
expect(io.stdoutText).toContain("cdd board: prog-p1");
|
|
3337
|
-
expect(io.stdoutText.split("\n").at(-2)).toBe("progress: ✔ done · ▶ current · ○ pending");
|
|
3338
|
-
} finally {
|
|
3339
|
-
cleanup();
|
|
3340
|
-
}
|
|
3341
|
-
});
|
|
3342
|
-
|
|
3343
|
-
it("a missing slug is a usage error — exit 2 (commander's required positional)", async () => {
|
|
3344
|
-
const { command, io, cleanup } = fixture();
|
|
3345
|
-
try {
|
|
3346
|
-
const code = await command.runArgv(["board"]);
|
|
3347
|
-
expect(code).toBe(2);
|
|
3348
|
-
expect(io.stderrText).toContain("missing required argument 'slug'");
|
|
3349
|
-
} finally {
|
|
3350
|
-
cleanup();
|
|
3351
|
-
}
|
|
3352
|
-
});
|
|
3353
|
-
|
|
3354
|
-
it("a ghost slug matches nothing on disk — exit 2, no wall", async () => {
|
|
3355
|
-
const { command, io, cleanup } = fixture();
|
|
3356
|
-
try {
|
|
3357
|
-
const code = await command.runArgv(["board", "nonexistent-slug"]);
|
|
3358
|
-
expect(code).toBe(2);
|
|
3359
|
-
expect(io.stderrText).toContain("no docs match slug nonexistent-slug");
|
|
3360
|
-
} finally {
|
|
3361
|
-
cleanup();
|
|
3362
|
-
}
|
|
3363
|
-
});
|
|
3364
|
-
});
|
|
3365
|
-
|
|
3366
|
-
// ---------------------------------------------------------------------------
|
|
3367
|
-
// T3 — the commander-native composition root (behavior probes): runArgv parses
|
|
3368
|
-
// through the projection's commander program (face/projection.ts), the domain-run
|
|
3369
|
-
// thin shells dispatch the parsed commands, and the exit-code discriminator maps
|
|
3370
|
-
// the CommanderError surface (§3.1: `commander.help` + exit 0 → 0 · non-zero →
|
|
3371
|
-
// 2 · `commander.helpDisplayed` → 0 · usage-class codes → 2). Every probe below
|
|
3372
|
-
// pins commander's own bytes (probe-verified — the discrimination face, never a
|
|
3373
|
-
// self-built rerender).
|
|
3374
|
-
// ---------------------------------------------------------------------------
|
|
3375
|
-
|
|
3376
|
-
describe("T3 — the commander-native composition root: program parse + .action shells + the exit-code discriminator", () => {
|
|
3377
|
-
it("bare `cdd` → commander program help + exit 2, no custom missing-command text (§3.3)", async () => {
|
|
3378
|
-
const { command, io, cleanup } = fixture();
|
|
3379
|
-
try {
|
|
3380
|
-
const code = await command.runArgv([]);
|
|
3381
|
-
expect(code).toBe(2);
|
|
3382
|
-
// the commander program face — Usage/Options/Commands (the error-context
|
|
3383
|
-
// help lands on the io stderr channel, commander's own byte choice)
|
|
3384
|
-
const out = io.stdoutText + io.stderrText;
|
|
3385
|
-
expect(out).toContain("Usage: cdd [options] [command]");
|
|
3386
|
-
expect(out).toContain("implement");
|
|
3387
|
-
expect(out).toContain("review");
|
|
3388
|
-
expect(out).not.toContain("missing command");
|
|
3389
|
-
} finally {
|
|
3390
|
-
cleanup();
|
|
3391
|
-
}
|
|
3392
|
-
});
|
|
3393
|
-
|
|
3394
|
-
it("a missing subcommand shows the OWNING node's help, exit 2 (base set/get, never the top program face)", async () => {
|
|
3395
|
-
const { command, io, cleanup } = fixture();
|
|
3396
|
-
try {
|
|
3397
|
-
const code = await command.runArgv(["base"]);
|
|
3398
|
-
expect(code).toBe(2);
|
|
3399
|
-
const out = io.stdoutText + io.stderrText;
|
|
3400
|
-
// the base node's own helpInformation — its subcommand table, not the
|
|
3401
|
-
// top-level program face
|
|
3402
|
-
expect(out).toContain("Usage: cdd base [options] [command]");
|
|
3403
|
-
expect(out).toContain("set [options]");
|
|
3404
|
-
expect(out).toContain("get [options]");
|
|
3405
|
-
expect(out).not.toContain("Usage: cdd [options] [command]");
|
|
3406
|
-
} finally {
|
|
3407
|
-
cleanup();
|
|
3408
|
-
}
|
|
3409
|
-
});
|
|
3410
|
-
|
|
3411
|
-
it("the built-in help [command] reuse — `cdd help` and `cdd base help` exit 0 with the owning face (v0.9)", async () => {
|
|
3412
|
-
const program = fixture();
|
|
3413
|
-
const base = fixture();
|
|
3414
|
-
try {
|
|
3415
|
-
const programCode = await program.command.runArgv(["help"]);
|
|
3416
|
-
expect(programCode).toBe(0);
|
|
3417
|
-
expect(program.io.stdoutText).toContain("Usage: cdd [options] [command]");
|
|
3418
|
-
const baseCode = await base.command.runArgv(["base", "help"]);
|
|
3419
|
-
expect(baseCode).toBe(0);
|
|
3420
|
-
expect(base.io.stdoutText).toContain("Usage: cdd base [options] [command]");
|
|
3421
|
-
} finally {
|
|
3422
|
-
program.cleanup();
|
|
3423
|
-
base.cleanup();
|
|
3424
|
-
}
|
|
3425
|
-
});
|
|
3426
|
-
|
|
3427
|
-
it("a leaf's help positional → the excess-arguments usage face, exit 2 (`implement help`)", async () => {
|
|
3428
|
-
const { command, io, cleanup } = fixture();
|
|
3429
|
-
try {
|
|
3430
|
-
// bare `implement help` — commander's required-option check fires first
|
|
3431
|
-
// (implement requires --tasks/--plan), still the usage face → 2
|
|
3432
|
-
expect(await command.runArgv(["implement", "help"])).toBe(2);
|
|
3433
|
-
io.stderrText = "";
|
|
3434
|
-
// with the required options present the excess-arguments byte surfaces
|
|
3435
|
-
const code = await command.runArgv(["implement", "--tasks", "1", "--plan", "p", "help"]);
|
|
3436
|
-
expect(code).toBe(2);
|
|
3437
|
-
expect(io.stderrText).toContain("too many arguments for 'implement'");
|
|
3438
|
-
expect(io.stderrText).toContain("Expected 0 arguments but got 1: help");
|
|
3439
|
-
} finally {
|
|
3440
|
-
cleanup();
|
|
3441
|
-
}
|
|
3442
|
-
});
|
|
3443
|
-
|
|
3444
|
-
it("`cdd help <bogus>` → the program help + exit 2 (invalid target, exit 1 → 2)", async () => {
|
|
3445
|
-
const { command, io, cleanup } = fixture();
|
|
3446
|
-
try {
|
|
3447
|
-
const code = await command.runArgv(["help", "bogus"]);
|
|
3448
|
-
expect(code).toBe(2);
|
|
3449
|
-
expect(io.stdoutText + io.stderrText).toContain("Usage: cdd [options] [command]");
|
|
3450
|
-
} finally {
|
|
3451
|
-
cleanup();
|
|
3452
|
-
}
|
|
3453
|
-
});
|
|
3454
|
-
|
|
3455
|
-
it("verb-less `--help` flips to exit 0 (§3.4) — the helpDisplayed face", async () => {
|
|
3456
|
-
const { command, io, cleanup } = fixture();
|
|
3457
|
-
try {
|
|
3458
|
-
const code = await command.runArgv(["--help"]);
|
|
3459
|
-
expect(code).toBe(0);
|
|
3460
|
-
expect(io.stdoutText).toContain("Usage: cdd [options] [command]");
|
|
3461
|
-
expect(io.stdoutText).toContain("Commands:");
|
|
3462
|
-
} finally {
|
|
3463
|
-
cleanup();
|
|
3464
|
-
}
|
|
3465
|
-
});
|
|
3466
|
-
|
|
3467
|
-
it("a commander-native value-domain rejection exits 2 with commander's own bytes", async () => {
|
|
3468
|
-
const { command, io, cleanup } = fixture();
|
|
3469
|
-
try {
|
|
3470
|
-
const code = await command.runArgv(["review", "--type", "bogus"]);
|
|
3471
|
-
expect(code).toBe(2);
|
|
3472
|
-
expect(io.stderrText).toContain(
|
|
3473
|
-
"error: option '--type <wave|branch|spec|plan>' argument 'bogus' is invalid",
|
|
3474
|
-
);
|
|
3475
|
-
} finally {
|
|
3476
|
-
cleanup();
|
|
3477
|
-
}
|
|
3478
|
-
});
|
|
3479
|
-
|
|
3480
|
-
it("the preAction conditional-required group exits 2 with the group message (§4.2)", async () => {
|
|
3481
|
-
const { command, io, cleanup } = fixture();
|
|
3482
|
-
try {
|
|
3483
|
-
const code = await command.runArgv(["review", "--type", "wave"]);
|
|
3484
|
-
expect(code).toBe(2);
|
|
3485
|
-
// the REQUIRED_GROUPS InvalidArgumentError rides the same commander pipeline
|
|
3486
|
-
expect(io.stderrText).toContain("--plan required when --type wave");
|
|
3487
|
-
} finally {
|
|
3488
|
-
cleanup();
|
|
3489
|
-
}
|
|
3490
|
-
});
|
|
3491
|
-
|
|
3492
|
-
it("the schema <type> vocabulary rejects an unknown type through the argument parseArg", async () => {
|
|
3493
|
-
const { command, io, cleanup } = fixture();
|
|
3494
|
-
try {
|
|
3495
|
-
const code = await command.runArgv(["schema", "get", "bogus"]);
|
|
3496
|
-
expect(code).toBe(2);
|
|
3497
|
-
expect(io.stderrText).toContain(
|
|
3498
|
-
"unknown schema type: bogus (available: overall-spec, plan, phase-spec, single-spec)",
|
|
3499
|
-
);
|
|
3500
|
-
} finally {
|
|
3501
|
-
cleanup();
|
|
3502
|
-
}
|
|
3503
|
-
});
|
|
3504
|
-
|
|
3505
|
-
it("the schema get <type> domain read — a valid type exits 0 with the derived schema", async () => {
|
|
3506
|
-
const { command, io, cleanup } = fixture();
|
|
3507
|
-
try {
|
|
3508
|
-
const code = await command.runArgv(["schema", "get", "phase-spec"]);
|
|
3509
|
-
expect(code).toBe(0);
|
|
3510
|
-
expect(io.stdoutText).toContain('"docType": "phase-spec"');
|
|
3511
|
-
} finally {
|
|
3512
|
-
cleanup();
|
|
3513
|
-
}
|
|
3514
|
-
});
|
|
3515
|
-
|
|
3516
|
-
it("the domain-run usage faces surface the owning node's commander-native usage line before the error byte (Task 3)", async () => {
|
|
3517
|
-
const { command, io, cleanup } = fixture();
|
|
3518
|
-
try {
|
|
3519
|
-
// a run-body usage rejection emits the owning node's helpInformation() first
|
|
3520
|
-
// line — the commander-native usage byte — then the error byte (review's
|
|
3521
|
-
// preAction passes --plan; the run body refuses the missing --tasks)
|
|
3522
|
-
expect(await command.runArgv(["review", "--type", "wave", "--plan", "p"])).toBe(2);
|
|
3523
|
-
expect(io.stderrText).toContain("Usage: cdd review [options]");
|
|
3524
|
-
expect(io.stderrText).toContain(
|
|
3525
|
-
"error: cdd review --type wave: missing required --tasks <n|n,n,…>",
|
|
3526
|
-
);
|
|
3527
|
-
io.stderrText = "";
|
|
3528
|
-
// the schema face — the --output skeleton missing-target byte rides its own
|
|
3529
|
-
// commander-native usage line
|
|
3530
|
-
expect(await command.runArgv(["schema", "get", "phase-spec", "--output", "skeleton"])).toBe(
|
|
3531
|
-
2,
|
|
3532
|
-
);
|
|
3533
|
-
expect(io.stderrText).toContain("Usage: cdd schema get [options] <type>");
|
|
3534
|
-
expect(io.stderrText).toContain("cdd schema get --output skeleton: missing <target>");
|
|
3535
|
-
} finally {
|
|
3536
|
-
cleanup();
|
|
3537
|
-
}
|
|
3538
|
-
});
|
|
3539
|
-
|
|
3540
|
-
it("the shared text-read's unreadable-file refusal rides the work face's native usage line", async () => {
|
|
3541
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
3542
|
-
try {
|
|
3543
|
-
// The text-read face the work commands share (readText) — its unreadable-file
|
|
3544
|
-
// refusal surfaces through the wave face's --plan read (the same artifacts
|
|
3545
|
-
// face; the owning node's usage line).
|
|
3546
|
-
const missing = path.join(repoRoot, "no-such-plan.md");
|
|
3547
|
-
const code = await command.runArgv([
|
|
3548
|
-
"implement",
|
|
3549
|
-
"--tasks",
|
|
3550
|
-
"1",
|
|
3551
|
-
"--plan",
|
|
3552
|
-
missing,
|
|
3553
|
-
"--root",
|
|
3554
|
-
repoRoot,
|
|
3555
|
-
]);
|
|
3556
|
-
expect(code).toBe(2);
|
|
3557
|
-
expect(io.stderrText).toContain("Usage: cdd implement [options]");
|
|
3558
|
-
expect(io.stderrText).toContain(`error: cannot read file: ${missing}`);
|
|
3559
|
-
} finally {
|
|
3560
|
-
cleanup();
|
|
3561
|
-
}
|
|
3562
|
-
});
|
|
3563
|
-
|
|
3564
|
-
it("the base get domain read — a set artifact exits 0 over the write-through path", async () => {
|
|
3565
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
3566
|
-
try {
|
|
3567
|
-
const plan = planFor(repoRoot);
|
|
3568
|
-
expect(
|
|
3569
|
-
await command.runArgv([
|
|
3570
|
-
"base",
|
|
3571
|
-
"set",
|
|
3572
|
-
"--plan",
|
|
3573
|
-
plan,
|
|
3574
|
-
"--base",
|
|
3575
|
-
"develop",
|
|
3576
|
-
"--source",
|
|
3577
|
-
"plan-field",
|
|
3578
|
-
]),
|
|
3579
|
-
).toBe(0);
|
|
3580
|
-
io.stdoutText = "";
|
|
3581
|
-
const code = await command.runArgv(["base", "get", "--plan", plan]);
|
|
3582
|
-
expect(code).toBe(0);
|
|
3583
|
-
expect(io.stdoutText).toContain('"base": "develop"');
|
|
3584
|
-
} finally {
|
|
3585
|
-
cleanup();
|
|
3586
|
-
}
|
|
3587
|
-
});
|
|
3588
|
-
|
|
3589
|
-
it("review --type spec --dry-run — the thin-shell domain run synthesizes the approval", async () => {
|
|
3590
|
-
const { command, io, repoRoot, cleanup } = fixture();
|
|
3591
|
-
try {
|
|
3592
|
-
gitInit(repoRoot);
|
|
3593
|
-
// The declared, contract-clean spec doc — the `- **Doc type**:` header
|
|
3594
|
-
// declaration (spec §12 · D34) the capsule's doc-class discrimination reads
|
|
3595
|
-
// (zero filename inference).
|
|
3596
|
-
const spec = conformingSpec(repoRoot);
|
|
3597
|
-
const code = await command.runArgv([
|
|
3598
|
-
"review",
|
|
3599
|
-
"--type",
|
|
3600
|
-
"spec",
|
|
3601
|
-
"--spec",
|
|
3602
|
-
spec,
|
|
3603
|
-
"--dry-run",
|
|
3604
|
-
"--root",
|
|
3605
|
-
repoRoot,
|
|
3606
|
-
]);
|
|
3607
|
-
expect(code).toBe(0);
|
|
3608
|
-
expect(io.stdoutText).toContain("next: /kairos:cdd-plan");
|
|
3609
|
-
} finally {
|
|
3610
|
-
cleanup();
|
|
3611
|
-
}
|
|
3612
|
-
});
|
|
3613
|
-
});
|
|
3614
|
-
|
|
3615
|
-
// ---------------------------------------------------------------------------
|
|
3616
|
-
// the HarnessDispatch — host detection · the template prompt · the return read-back
|
|
3617
|
-
// ---------------------------------------------------------------------------
|
|
3618
|
-
|
|
3619
|
-
describe("the HarnessDispatch — the production dispatch default", () => {
|
|
3620
|
-
/** A hermetic harness scene (workspace + ledger) for frame dispatch tests. */
|
|
3621
|
-
function harnessScene(repoRoot: string, slug = "p3"): DispatchScene {
|
|
3622
|
-
const workspace = new Workspace(new WorkspaceRoot(repoRoot, ".kairos/cdd"), slug).ensure();
|
|
3623
|
-
const ledger = new Ledger(workspace, new ConfigLoader());
|
|
3624
|
-
return { workspace, ledger, planPath: null, briefPath: null };
|
|
3625
|
-
}
|
|
3626
|
-
|
|
3627
|
-
const implementFrame: OpenFrame = {
|
|
3628
|
-
type: "wave",
|
|
3629
|
-
phase: "implement",
|
|
3630
|
-
round: 1,
|
|
3631
|
-
target: { kind: "wave", tasks: [1] },
|
|
3632
|
-
params: { tasks: "1" },
|
|
3633
|
-
key: "1",
|
|
3634
|
-
};
|
|
3635
|
-
|
|
3636
|
-
const specReviewFrame: OpenFrame = {
|
|
3637
|
-
type: "spec",
|
|
3638
|
-
phase: "review",
|
|
3639
|
-
round: 1,
|
|
3640
|
-
target: { kind: "doc", doc: "docs/kairos/specs/s1-design.md" },
|
|
3641
|
-
params: { round: 1 },
|
|
3642
|
-
key: "docs/kairos/specs/s1-design.md",
|
|
3643
|
-
};
|
|
3644
|
-
|
|
3645
|
-
const taskReviewFrame: OpenFrame = {
|
|
3646
|
-
type: "wave",
|
|
3647
|
-
phase: "review",
|
|
3648
|
-
round: 1,
|
|
3649
|
-
target: { kind: "wave", tasks: [1] },
|
|
3650
|
-
params: { tasks: "1", round: 1 },
|
|
3651
|
-
key: "1",
|
|
3652
|
-
};
|
|
3653
|
-
|
|
3654
|
-
const fixFrame: OpenFrame = {
|
|
3655
|
-
type: "wave",
|
|
3656
|
-
phase: "fix",
|
|
3657
|
-
round: 1,
|
|
3658
|
-
target: { kind: "wave", tasks: [1] },
|
|
3659
|
-
params: { tasks: "1", round: 1 },
|
|
3660
|
-
key: "1",
|
|
3661
|
-
};
|
|
3662
|
-
|
|
3663
|
-
it("detects the host from the harness-contract detect markers (claude > cursor > pi)", () => {
|
|
3664
|
-
const { repoRoot, cleanup } = fixture();
|
|
3665
|
-
try {
|
|
3666
|
-
const scene = harnessScene(repoRoot);
|
|
3667
|
-
const io = new CaptureIo();
|
|
3668
|
-
const dispatch = new HarnessDispatch({ scene, io, env: {} });
|
|
3669
|
-
expect(dispatch.detectHost({})).toBe("");
|
|
3670
|
-
expect(dispatch.detectHost({ CLAUDE_CODE_SESSION_ID: "s" })).toBe("claude");
|
|
3671
|
-
expect(dispatch.detectHost({ CURSOR_TRACE_ID: "t" })).toBe("cursor");
|
|
3672
|
-
expect(dispatch.detectHost({ AI_AGENT: "pi" })).toBe("pi");
|
|
3673
|
-
expect(dispatch.detectHost({ AI_AGENT: "claude-code" })).toBe("claude");
|
|
3674
|
-
expect(dispatch.detectHost({ CLAUDE_CODE_SESSION_ID: "s", CURSOR_TRACE_ID: "t" })).toBe(
|
|
3675
|
-
"claude",
|
|
3676
|
-
);
|
|
3677
|
-
} finally {
|
|
3678
|
-
cleanup();
|
|
3679
|
-
}
|
|
3680
|
-
});
|
|
3681
|
-
|
|
3682
|
-
it("dispatches through the harness rows — the skill-ref slash form + the prompt, the draft read back into the outcome", () => {
|
|
3683
|
-
const { repoRoot, cleanup } = fixture();
|
|
3684
|
-
try {
|
|
3685
|
-
const scene = harnessScene(repoRoot);
|
|
3686
|
-
const io = new CaptureIo();
|
|
3687
|
-
const sync = new FakeSync();
|
|
3688
|
-
// the child's block-return is the two-line contract (status + artifacts — the
|
|
3689
|
-
// commit carrier is retired · spec §2.4)
|
|
3690
|
-
sync.stdout = "status: APPROVED\nartifacts: brief=/b report=/r test_evidence=/t\n";
|
|
3691
|
-
// The child's write-back: the implement draft at OUTPUT_HANDOFF per the injected
|
|
3692
|
-
// `work` schema + the canonical test-evidence file (the v1.9 read-back inputs).
|
|
3693
|
-
const draft = path.join(scene.workspace.path, "tasks-1-implement.json");
|
|
3694
|
-
// The compliant child follows the prescribed OUTPUT_* names (find #5): the
|
|
3695
|
-
// artifacts it declares are the canonical {family}-{key}-{artifact} paths (the
|
|
3696
|
-
// report at tasks-1-implement-report.md · the evidence at
|
|
3697
|
-
// tasks-1-test-evidence.json); a free-named deviation is corrected in the
|
|
3698
|
-
// reconstruct (the path-deviation test below).
|
|
3699
|
-
writeFileSync(
|
|
3700
|
-
draft,
|
|
3701
|
-
JSON.stringify({
|
|
3702
|
-
status: "APPROVED",
|
|
3703
|
-
artifacts: {
|
|
3704
|
-
brief: "/b",
|
|
3705
|
-
report: path.join(scene.workspace.path, "tasks-1-implement-report.md"),
|
|
3706
|
-
test_evidence: path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
3707
|
-
},
|
|
3708
|
-
}),
|
|
3709
|
-
"utf8",
|
|
3710
|
-
);
|
|
3711
|
-
writeFileSync(
|
|
3712
|
-
path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
3713
|
-
JSON.stringify({
|
|
3714
|
-
command: "npx vitest run",
|
|
3715
|
-
exit_code: 0,
|
|
3716
|
-
passed: true,
|
|
3717
|
-
warnings_count: 0,
|
|
3718
|
-
typecheck: { command: "tsc --noEmit", exit_code: 0, passed: true },
|
|
3719
|
-
}),
|
|
3720
|
-
"utf8",
|
|
3721
|
-
);
|
|
3722
|
-
const dispatch = new HarnessDispatch({
|
|
3723
|
-
scene,
|
|
3724
|
-
io,
|
|
3725
|
-
sync,
|
|
3726
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
3727
|
-
});
|
|
3728
|
-
const outcome = dispatch.step()(implementFrame);
|
|
3729
|
-
expect(sync.calls.length).toBe(1);
|
|
3730
|
-
const call = sync.calls[0];
|
|
3731
|
-
expect(call.command).toBe("claude");
|
|
3732
|
-
expect(call.args).toContain("-p");
|
|
3733
|
-
// The skill ref is NOT a standalone positional (the harness CLI consumes the
|
|
3734
|
-
// first positional as the whole prompt — a split prompt loses everything after
|
|
3735
|
-
// the ref). It prefixes the single prompt argument instead.
|
|
3736
|
-
expect(call.args).not.toContain("/mattpocock-skills:implement");
|
|
3737
|
-
const prompt = call.args[call.args.length - 1];
|
|
3738
|
-
expect(prompt.startsWith("/mattpocock-skills:implement ")).toBe(true);
|
|
3739
|
-
// v1.8 — the mode dispatch table + the normalized naming grammar (ROLE/WAVE · INPUT_/OUTPUT_/WORKSPACE_)
|
|
3740
|
-
expect(prompt).toContain("- `ROLE`: implement");
|
|
3741
|
-
expect(prompt).toContain("- `WAVE`: 1");
|
|
3742
|
-
expect(prompt).toContain(`- \`WORKSPACE_DIR\`: ${scene.workspace.path}`);
|
|
3743
|
-
expect(prompt).toContain(
|
|
3744
|
-
`- \`OUTPUT_HANDOFF\`: ${path.join(scene.workspace.path, "tasks-1-implement.json")}`,
|
|
3745
|
-
);
|
|
3746
|
-
// find #4 — INPUT_RULES is gone: the implement child reads the plan's
|
|
3747
|
-
// `## Constraints` through the wave brief mirror (zero materialized rules file,
|
|
3748
|
-
// zero dead pointer — the round context carries no rules channel).
|
|
3749
|
-
expect(prompt).not.toContain("INPUT_RULES");
|
|
3750
|
-
// find #5 — the artifact write paths are prescribed (OUTPUT_* · {family}-{key}-
|
|
3751
|
-
// prefix): the brief is a pure read input (INPUT_WAVE_BRIEF) with no write slot
|
|
3752
|
-
// (only present facts ride the prompt), while report + evidence are prescribed.
|
|
3753
|
-
expect(prompt).not.toContain("OUTPUT_BRIEF");
|
|
3754
|
-
expect(prompt).toContain(
|
|
3755
|
-
`- \`OUTPUT_REPORT\`: ${path.join(scene.workspace.path, "tasks-1-implement-report.md")}`,
|
|
3756
|
-
);
|
|
3757
|
-
expect(prompt).toContain(
|
|
3758
|
-
`- \`OUTPUT_EVIDENCE\`: ${path.join(scene.workspace.path, "tasks-1-test-evidence.json")}`,
|
|
3759
|
-
);
|
|
3760
|
-
// the per-mode trimming: this scene carries no brief (briefPath null) — the empty
|
|
3761
|
-
// INPUT_TASK key is NOT emitted (empty keys are never emitted)
|
|
3762
|
-
expect(prompt).not.toContain("- `INPUT_TASK`");
|
|
3763
|
-
// v1.9 — the injected writable-subset schema rides the shell's fixed tail (the
|
|
3764
|
-
// ```json fence + the evidence fence — the task-family work round's two files)
|
|
3765
|
-
expect(prompt).toContain("## Handoff schema");
|
|
3766
|
-
expect(prompt).toContain("```json");
|
|
3767
|
-
expect(prompt).toContain("The evidence file");
|
|
3768
|
-
expect(prompt).not.toContain("HANDOFF_WRITE_GATE");
|
|
3769
|
-
// the read-back reconstruct — the final carrier (the schema's declared fields
|
|
3770
|
-
// only: identity rides the file name, never phase/tasks inline — v1.30) rides
|
|
3771
|
-
// the outcome, the block's two lines the pointer
|
|
3772
|
-
expect(outcome.status).toBe("APPROVED");
|
|
3773
|
-
expect(outcome.carrier).toEqual({
|
|
3774
|
-
artifacts: {
|
|
3775
|
-
brief: "/b",
|
|
3776
|
-
report: path.join(scene.workspace.path, "tasks-1-implement-report.md"),
|
|
3777
|
-
test_evidence: path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
3778
|
-
},
|
|
3779
|
-
status: "APPROVED",
|
|
3780
|
-
});
|
|
3781
|
-
// T2 — the materialized work carrier is the work face: zero findings key (the
|
|
3782
|
-
// face-aware write path never injects the work-carrier findings byte bridge)
|
|
3783
|
-
expect("findings" in outcome.carrier!).toBe(false);
|
|
3784
|
-
} finally {
|
|
3785
|
-
cleanup();
|
|
3786
|
-
}
|
|
3787
|
-
});
|
|
3788
|
-
|
|
3789
|
-
it("prescribes the implement artifact paths — REPORT/EVIDENCE carry the canonical {family}-{key}- names (find #5)", () => {
|
|
3790
|
-
const { repoRoot, cleanup } = fixture();
|
|
3791
|
-
try {
|
|
3792
|
-
const workspace = new Workspace(new WorkspaceRoot(repoRoot, ".kairos/cdd"), "p3").ensure();
|
|
3793
|
-
const ledger = new Ledger(workspace, new ConfigLoader());
|
|
3794
|
-
const scene: DispatchScene = {
|
|
3795
|
-
workspace,
|
|
3796
|
-
ledger,
|
|
3797
|
-
planPath: null,
|
|
3798
|
-
briefPath: path.join(workspace.path, "tasks-1-brief.md"),
|
|
3799
|
-
};
|
|
3800
|
-
const io = new CaptureIo();
|
|
3801
|
-
const sync = new FakeSync();
|
|
3802
|
-
sync.stdout = "status: APPROVED\n";
|
|
3803
|
-
const dispatch = new HarnessDispatch({
|
|
3804
|
-
scene,
|
|
3805
|
-
io,
|
|
3806
|
-
sync,
|
|
3807
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
3808
|
-
});
|
|
3809
|
-
dispatch.step()(implementFrame);
|
|
3810
|
-
const prompt = sync.calls[0]!.args[sync.calls[0]!.args.length - 1];
|
|
3811
|
-
// the brief is a pure read input (INPUT_WAVE_BRIEF — no OUTPUT_BRIEF · spec §4.2);
|
|
3812
|
-
// the prescribed write paths ride the round context (report + evidence = the
|
|
3813
|
-
// report/verify write paths — zero free naming, cross-round zero overwrite).
|
|
3814
|
-
expect(prompt).toContain(
|
|
3815
|
-
`- \`INPUT_WAVE_BRIEF\`: ${path.join(workspace.path, "tasks-1-brief.md")}`,
|
|
3816
|
-
);
|
|
3817
|
-
expect(prompt).not.toContain("OUTPUT_BRIEF");
|
|
3818
|
-
expect(prompt).toContain(
|
|
3819
|
-
`- \`OUTPUT_REPORT\`: ${path.join(workspace.path, "tasks-1-implement-report.md")}`,
|
|
3820
|
-
);
|
|
3821
|
-
expect(prompt).toContain(
|
|
3822
|
-
`- \`OUTPUT_EVIDENCE\`: ${path.join(workspace.path, "tasks-1-test-evidence.json")}`,
|
|
3823
|
-
);
|
|
3824
|
-
} finally {
|
|
3825
|
-
cleanup();
|
|
3826
|
-
}
|
|
3827
|
-
});
|
|
3828
|
-
|
|
3829
|
-
it("§4.2 — every wave frame (implement/review/fix) carries the scene's brief as INPUT_WAVE_BRIEF, never a disk-existence read", () => {
|
|
3830
|
-
const { repoRoot, cleanup } = fixture();
|
|
3831
|
-
try {
|
|
3832
|
-
const workspace = new Workspace(new WorkspaceRoot(repoRoot, ".kairos/cdd"), "p3").ensure();
|
|
3833
|
-
const ledger = new Ledger(workspace, new ConfigLoader());
|
|
3834
|
-
const briefPath = path.join(workspace.path, "tasks-1-brief.md");
|
|
3835
|
-
// The scene carries the brief path but NO brief file is written to disk — the
|
|
3836
|
-
// read is the scene's fact, not the filesystem's (the retired existsSync guard).
|
|
3837
|
-
const scene: DispatchScene = {
|
|
3838
|
-
workspace,
|
|
3839
|
-
ledger,
|
|
3840
|
-
planPath: null,
|
|
3841
|
-
briefPath,
|
|
3842
|
-
};
|
|
3843
|
-
const io = new CaptureIo();
|
|
3844
|
-
const sync = new FakeSync();
|
|
3845
|
-
sync.stdout = "status: APPROVED\n";
|
|
3846
|
-
const dispatch = new HarnessDispatch({
|
|
3847
|
-
scene,
|
|
3848
|
-
io,
|
|
3849
|
-
sync,
|
|
3850
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
3851
|
-
});
|
|
3852
|
-
// the review + fix frames both carry the ONE scene brief (not implement-only)
|
|
3853
|
-
dispatch.step()(taskReviewFrame);
|
|
3854
|
-
dispatch.step()(fixFrame);
|
|
3855
|
-
for (const call of sync.calls) {
|
|
3856
|
-
const prompt = call.args[call.args.length - 1];
|
|
3857
|
-
expect(prompt).toContain(`- \`INPUT_WAVE_BRIEF\`: ${briefPath}`);
|
|
3858
|
-
}
|
|
3859
|
-
} finally {
|
|
3860
|
-
cleanup();
|
|
3861
|
-
}
|
|
3862
|
-
});
|
|
3863
|
-
|
|
3864
|
-
it("the doc-family artifacts are round-keyed — a second review round prescribes a different report path, never an overwrite (find #5)", () => {
|
|
3865
|
-
const { repoRoot, cleanup } = fixture();
|
|
3866
|
-
try {
|
|
3867
|
-
const workspace = new Workspace(new WorkspaceRoot(repoRoot, ".kairos/cdd"), "p3").ensure();
|
|
3868
|
-
const ledger = new Ledger(workspace, new ConfigLoader());
|
|
3869
|
-
const scene: DispatchScene = {
|
|
3870
|
-
workspace,
|
|
3871
|
-
ledger,
|
|
3872
|
-
planPath: null,
|
|
3873
|
-
briefPath: null,
|
|
3874
|
-
};
|
|
3875
|
-
const io = new CaptureIo();
|
|
3876
|
-
const sync = new FakeSync();
|
|
3877
|
-
sync.stdout = "status: APPROVED\n";
|
|
3878
|
-
const dispatch = new HarnessDispatch({
|
|
3879
|
-
scene,
|
|
3880
|
-
io,
|
|
3881
|
-
sync,
|
|
3882
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
3883
|
-
});
|
|
3884
|
-
dispatch.step()(specReviewFrame);
|
|
3885
|
-
const first = sync.calls[0]!.args[sync.calls[0]!.args.length - 1];
|
|
3886
|
-
dispatch.step()({ ...specReviewFrame, round: 2, params: { round: 2 } });
|
|
3887
|
-
const second = sync.calls[1]!.args[sync.calls[1]!.args.length - 1];
|
|
3888
|
-
expect(first).toContain(
|
|
3889
|
-
`- \`OUTPUT_REPORT\`: ${path.join(workspace.path, "spec-review-1-report.md")}`,
|
|
3890
|
-
);
|
|
3891
|
-
expect(second).toContain(
|
|
3892
|
-
`- \`OUTPUT_REPORT\`: ${path.join(workspace.path, "spec-review-2-report.md")}`,
|
|
3893
|
-
);
|
|
3894
|
-
// the round-keyed names never collide — a re-review cannot overwrite its predecessor
|
|
3895
|
-
expect(path.join(workspace.path, "spec-review-1-report.md")).not.toBe(
|
|
3896
|
-
path.join(workspace.path, "spec-review-2-report.md"),
|
|
3897
|
-
);
|
|
3898
|
-
} finally {
|
|
3899
|
-
cleanup();
|
|
3900
|
-
}
|
|
3901
|
-
});
|
|
3902
|
-
|
|
3903
|
-
it("a free-named declared artifact path is corrected to the canonical OUTPUT_* path + surfaced on the notes (find #5 self-derivation)", () => {
|
|
3904
|
-
const { repoRoot, cleanup } = fixture();
|
|
3905
|
-
try {
|
|
3906
|
-
const scene = harnessScene(repoRoot);
|
|
3907
|
-
const io = new CaptureIo();
|
|
3908
|
-
const sync = new FakeSync();
|
|
3909
|
-
sync.stdout = "status: APPROVED\n";
|
|
3910
|
-
const draftPath = path.join(scene.workspace.path, "tasks-1-implement.json");
|
|
3911
|
-
writeFileSync(
|
|
3912
|
-
draftPath,
|
|
3913
|
-
JSON.stringify({
|
|
3914
|
-
status: "APPROVED",
|
|
3915
|
-
artifacts: { report: "/r", test_evidence: "/t" },
|
|
3916
|
-
}),
|
|
3917
|
-
"utf8",
|
|
3918
|
-
);
|
|
3919
|
-
// the evidence file at the canonical name makes the evidence gate pass — this
|
|
3920
|
-
// test isolates the artifact-path correction from the evidence read-back
|
|
3921
|
-
writeFileSync(
|
|
3922
|
-
path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
3923
|
-
JSON.stringify({
|
|
3924
|
-
command: "npx vitest run",
|
|
3925
|
-
exit_code: 0,
|
|
3926
|
-
passed: true,
|
|
3927
|
-
warnings_count: 0,
|
|
3928
|
-
typecheck: { command: "tsc --noEmit", exit_code: 0, passed: true },
|
|
3929
|
-
}),
|
|
3930
|
-
"utf8",
|
|
3931
|
-
);
|
|
3932
|
-
const dispatch = new HarnessDispatch({
|
|
3933
|
-
scene,
|
|
3934
|
-
io,
|
|
3935
|
-
sync,
|
|
3936
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
3937
|
-
});
|
|
3938
|
-
const outcome = dispatch.step()(implementFrame);
|
|
3939
|
-
expect(outcome.status).toBe("APPROVED");
|
|
3940
|
-
// the engine books the canonical names — a child-reported free path never lands;
|
|
3941
|
-
// both deviations ride the carrier's notes (the review scope axis reads them)
|
|
3942
|
-
expect(outcome.carrier).toEqual({
|
|
3943
|
-
artifacts: {
|
|
3944
|
-
report: path.join(scene.workspace.path, "tasks-1-implement-report.md"),
|
|
3945
|
-
test_evidence: path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
3946
|
-
},
|
|
3947
|
-
status: "APPROVED",
|
|
3948
|
-
notes: [
|
|
3949
|
-
expect.stringContaining("artifact report"),
|
|
3950
|
-
expect.stringContaining("artifact test_evidence"),
|
|
3951
|
-
],
|
|
3952
|
-
});
|
|
3953
|
-
// T2 — the materialized work carrier is the work face: zero findings key
|
|
3954
|
-
expect("findings" in outcome.carrier!).toBe(false);
|
|
3955
|
-
} finally {
|
|
3956
|
-
cleanup();
|
|
3957
|
-
}
|
|
3958
|
-
});
|
|
3959
|
-
|
|
3960
|
-
it("D39 — a trailing-comma draft reconstructs cleanly (the lenient read face; the round is not voided)", () => {
|
|
3961
|
-
const { repoRoot, cleanup } = fixture();
|
|
3962
|
-
try {
|
|
3963
|
-
const scene = harnessScene(repoRoot);
|
|
3964
|
-
const io = new CaptureIo();
|
|
3965
|
-
const sync = new FakeSync();
|
|
3966
|
-
sync.stdout = "status: APPROVED\n";
|
|
3967
|
-
// The child LLM writes a draft with a routine slip — a trailing comma in the
|
|
3968
|
-
// notes array (the W3 {5,11} block shape). The reconstruct's draft read is the
|
|
3969
|
-
// LENIENT face (D39): the slip must not void the whole round.
|
|
3970
|
-
const draftPath = path.join(scene.workspace.path, "tasks-1-implement.json");
|
|
3971
|
-
writeFileSync(
|
|
3972
|
-
draftPath,
|
|
3973
|
-
'{\n "status": "APPROVED",\n "artifacts": {\n "report": "' +
|
|
3974
|
-
path.join(scene.workspace.path, "tasks-1-implement-report.md") +
|
|
3975
|
-
'",\n "test_evidence": "' +
|
|
3976
|
-
path.join(scene.workspace.path, "tasks-1-test-evidence.json") +
|
|
3977
|
-
'"\n },\n "notes": [\n "a",\n "b",\n ]\n}\n',
|
|
3978
|
-
"utf8",
|
|
3979
|
-
);
|
|
3980
|
-
writeFileSync(
|
|
3981
|
-
path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
3982
|
-
JSON.stringify({
|
|
3983
|
-
command: "npx vitest run",
|
|
3984
|
-
exit_code: 0,
|
|
3985
|
-
passed: true,
|
|
3986
|
-
warnings_count: 0,
|
|
3987
|
-
typecheck: { command: "tsc --noEmit", exit_code: 0, passed: true },
|
|
3988
|
-
}),
|
|
3989
|
-
"utf8",
|
|
3990
|
-
);
|
|
3991
|
-
const dispatch = new HarnessDispatch({
|
|
3992
|
-
scene,
|
|
3993
|
-
io,
|
|
3994
|
-
sync,
|
|
3995
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
3996
|
-
});
|
|
3997
|
-
const outcome = dispatch.step()(implementFrame);
|
|
3998
|
-
// The trailing comma is tolerated — the round lands APPROVED, never a malformed
|
|
3999
|
-
// reject; the notes the child wrote survive into the carrier.
|
|
4000
|
-
expect(outcome.status).toBe("APPROVED");
|
|
4001
|
-
expect(io.stderrText).toBe("");
|
|
4002
|
-
expect((outcome.carrier as { notes?: string[] }).notes).toEqual(["a", "b"]);
|
|
4003
|
-
} finally {
|
|
4004
|
-
cleanup();
|
|
4005
|
-
}
|
|
4006
|
-
});
|
|
4007
|
-
|
|
4008
|
-
it("§8.7 — a non-declared / engine-reserved draft field is dropped with a single WARN, never a BLOCK (materialize and the validator judge the same way)", () => {
|
|
4009
|
-
const { repoRoot, cleanup } = fixture();
|
|
4010
|
-
try {
|
|
4011
|
-
const scene = harnessScene(repoRoot);
|
|
4012
|
-
const io = new CaptureIo();
|
|
4013
|
-
const sync = new FakeSync();
|
|
4014
|
-
sync.stdout = "status: APPROVED\n";
|
|
4015
|
-
// A work draft carrying engine-reserved keys (commits — retired) + a child extra
|
|
4016
|
-
// (phase). The read-back validator drops them (never a refusal); materialize
|
|
4017
|
-
// drops them from the carrier and books ONE WARN on the notes.
|
|
4018
|
-
writeFileSync(
|
|
4019
|
-
path.join(scene.workspace.path, "tasks-1-implement.json"),
|
|
4020
|
-
JSON.stringify({
|
|
4021
|
-
status: "APPROVED",
|
|
4022
|
-
artifacts: {
|
|
4023
|
-
report: path.join(scene.workspace.path, "tasks-1-implement-report.md"),
|
|
4024
|
-
test_evidence: path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
4025
|
-
},
|
|
4026
|
-
commits: { base: "a".repeat(8), head: "b".repeat(8) },
|
|
4027
|
-
phase: "implement",
|
|
4028
|
-
}),
|
|
4029
|
-
"utf8",
|
|
4030
|
-
);
|
|
4031
|
-
writeFileSync(
|
|
4032
|
-
path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
4033
|
-
JSON.stringify({
|
|
4034
|
-
command: "npx vitest run",
|
|
4035
|
-
exit_code: 0,
|
|
4036
|
-
passed: true,
|
|
4037
|
-
warnings_count: 0,
|
|
4038
|
-
typecheck: { command: "tsc --noEmit", exit_code: 0, passed: true },
|
|
4039
|
-
}),
|
|
4040
|
-
"utf8",
|
|
4041
|
-
);
|
|
4042
|
-
const dispatch = new HarnessDispatch({
|
|
4043
|
-
scene,
|
|
4044
|
-
io,
|
|
4045
|
-
sync,
|
|
4046
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4047
|
-
});
|
|
4048
|
-
const outcome = dispatch.step()(implementFrame);
|
|
4049
|
-
// the round is NOT blocked (a non-declared extra field is not a semantic error)
|
|
4050
|
-
expect(outcome.status).toBe("APPROVED");
|
|
4051
|
-
expect(io.stderrText).toBe("");
|
|
4052
|
-
const carrier = outcome.carrier as Record<string, unknown>;
|
|
4053
|
-
// the non-declared keys never land on the carrier
|
|
4054
|
-
expect("commits" in carrier).toBe(false);
|
|
4055
|
-
expect("phase" in carrier).toBe(false);
|
|
4056
|
-
// exactly ONE WARN names the dropped keys (sorted-stable order is not required,
|
|
4057
|
-
// only that both keys are surfaced in a single note)
|
|
4058
|
-
const notes = carrier.notes as string[];
|
|
4059
|
-
expect(notes).toHaveLength(1);
|
|
4060
|
-
expect(notes[0]).toContain("dropped non-declared draft field(s)");
|
|
4061
|
-
expect(notes[0]).toContain("commits");
|
|
4062
|
-
expect(notes[0]).toContain("phase");
|
|
4063
|
-
} finally {
|
|
4064
|
-
cleanup();
|
|
4065
|
-
}
|
|
4066
|
-
});
|
|
4067
|
-
|
|
4068
|
-
it("§8.7 — a findings-face draft carrying a stray `status` (+ another key) is dropped with a single WARN, never a BLOCK (the exact dogfood crash face)", () => {
|
|
4069
|
-
const { repoRoot, cleanup } = fixture();
|
|
4070
|
-
try {
|
|
4071
|
-
const scene = harnessScene(repoRoot);
|
|
4072
|
-
const io = new CaptureIo();
|
|
4073
|
-
const sync = new FakeSync();
|
|
4074
|
-
// The §2.8/§8.7 dogfood crash face: a child-authored `status` (non-declared on
|
|
4075
|
-
// the findings face — the finding carrier holds no status; the conclusion derives
|
|
4076
|
-
// at judgment time) on a review draft, plus a stray extra key. The read-back
|
|
4077
|
-
// validator drops both (never a refusal); materialize drops them from the carrier
|
|
4078
|
-
// and books ONE WARN on the notes.
|
|
4079
|
-
sync.stdout = "status: APPROVED\n";
|
|
4080
|
-
writeFileSync(
|
|
4081
|
-
path.join(scene.workspace.path, "spec-review-1.json"),
|
|
4082
|
-
JSON.stringify({
|
|
4083
|
-
findings: [{ severity: "nit", lens: "spec", summary: "drift" }],
|
|
4084
|
-
status: "APPROVED",
|
|
4085
|
-
phase: "review",
|
|
4086
|
-
}),
|
|
4087
|
-
"utf8",
|
|
4088
|
-
);
|
|
4089
|
-
const dispatch = new HarnessDispatch({
|
|
4090
|
-
scene,
|
|
4091
|
-
io,
|
|
4092
|
-
sync,
|
|
4093
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4094
|
-
});
|
|
4095
|
-
const outcome = dispatch.step()(specReviewFrame);
|
|
4096
|
-
// the round is NOT blocked (a non-declared field is not a semantic error) — the
|
|
4097
|
-
// conclusion derives from the draft's findings (nit → REVIEW_FIX), never the
|
|
4098
|
-
// dropped child status
|
|
4099
|
-
expect(outcome.status).toBe("REVIEW_FIX");
|
|
4100
|
-
expect(io.stderrText).toBe("");
|
|
4101
|
-
const carrier = outcome.carrier as Record<string, unknown>;
|
|
4102
|
-
// the findings carrier holds NO status field (the conclusion is derived, never
|
|
4103
|
-
// persisted on the findings plane · D27); the dropped keys never land either
|
|
4104
|
-
expect("phase" in carrier).toBe(false);
|
|
4105
|
-
expect("status" in carrier).toBe(false);
|
|
4106
|
-
// exactly ONE WARN names both dropped keys
|
|
4107
|
-
const notes = carrier.notes as string[];
|
|
4108
|
-
expect(notes).toHaveLength(1);
|
|
4109
|
-
expect(notes[0]).toContain("dropped non-declared draft field(s)");
|
|
4110
|
-
expect(notes[0]).toContain("status");
|
|
4111
|
-
expect(notes[0]).toContain("phase");
|
|
4112
|
-
} finally {
|
|
4113
|
-
cleanup();
|
|
4114
|
-
}
|
|
4115
|
-
});
|
|
4116
|
-
|
|
4117
|
-
it("the docs review — the block + draft face: findings flow back from the file, the status rolls up", () => {
|
|
4118
|
-
const { repoRoot, cleanup } = fixture();
|
|
4119
|
-
try {
|
|
4120
|
-
const scene = harnessScene(repoRoot);
|
|
4121
|
-
const io = new CaptureIo();
|
|
4122
|
-
const sync = new FakeSync();
|
|
4123
|
-
// The review child states `status: APPROVED` in the block (its conclusion is the
|
|
4124
|
-
// draft's findings — never printed); the engine derives the capsule status.
|
|
4125
|
-
sync.stdout = "status: APPROVED\n";
|
|
4126
|
-
writeFileSync(
|
|
4127
|
-
path.join(scene.workspace.path, "spec-review-1.json"),
|
|
4128
|
-
JSON.stringify({
|
|
4129
|
-
findings: [{ severity: "blocker", lens: "spec", summary: "drift" }],
|
|
4130
|
-
}),
|
|
4131
|
-
"utf8",
|
|
4132
|
-
);
|
|
4133
|
-
const dispatch = new HarnessDispatch({
|
|
4134
|
-
scene,
|
|
4135
|
-
io,
|
|
4136
|
-
sync,
|
|
4137
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4138
|
-
});
|
|
4139
|
-
const outcome = dispatch.step()(specReviewFrame);
|
|
4140
|
-
// the rollup (v1.9: a review never declares its own status) + the findings from
|
|
4141
|
-
// the FILE — the read-back is the fix loop's only content channel
|
|
4142
|
-
expect(outcome.status).toBe("CHANGES_REQUESTED");
|
|
4143
|
-
expect(outcome.findings).toEqual([{ severity: "blocker", summary: "drift" }]);
|
|
4144
|
-
// the persisted findings carrier holds NO status field (D27 — the conclusion is
|
|
4145
|
-
// derived at judgment time, never stored on the findings plane); the conclusion
|
|
4146
|
-
// still rides the outcome.status above, derived from the findings
|
|
4147
|
-
expect(outcome.carrier).toEqual({
|
|
4148
|
-
artifacts: {},
|
|
4149
|
-
findings: [{ severity: "blocker", lens: "spec", summary: "drift" }],
|
|
4150
|
-
});
|
|
4151
|
-
expect("status" in (outcome.carrier as Record<string, unknown>)).toBe(false);
|
|
4152
|
-
// the URC criteria ride the review prompt's fixed prefix (the spec review has
|
|
4153
|
-
// no slash ref) — the criteria/lens are folded in, never round-context values
|
|
4154
|
-
const call = sync.calls[0];
|
|
4155
|
-
expect(call.args).not.toContain("/mattpocock-skills:code-review");
|
|
4156
|
-
const prompt = call.args[call.args.length - 1];
|
|
4157
|
-
expect(prompt).toContain("Follow URC:");
|
|
4158
|
-
expect(prompt).toContain("- `ROLE`: review");
|
|
4159
|
-
expect(prompt).toContain("- `INPUT_DOC`: docs/kairos/specs/s1-design.md");
|
|
4160
|
-
// the v1.8 per-mode trimming: a review context carries no fix/work keys
|
|
4161
|
-
expect(prompt).not.toContain("- `INPUT_FINDINGS`");
|
|
4162
|
-
expect(prompt).not.toContain("- `INPUT_CRITERIA`");
|
|
4163
|
-
} finally {
|
|
4164
|
-
cleanup();
|
|
4165
|
-
}
|
|
4166
|
-
});
|
|
4167
|
-
|
|
4168
|
-
it("a task review appends the review skill ref — the object {ref} row's slash form", () => {
|
|
4169
|
-
const { repoRoot, cleanup } = fixture();
|
|
4170
|
-
try {
|
|
4171
|
-
const scene = harnessScene(repoRoot);
|
|
4172
|
-
const io = new CaptureIo();
|
|
4173
|
-
const sync = new FakeSync();
|
|
4174
|
-
sync.stdout = "status: APPROVED\n";
|
|
4175
|
-
writeFileSync(
|
|
4176
|
-
path.join(scene.workspace.path, "tasks-1-review-1.json"),
|
|
4177
|
-
JSON.stringify({
|
|
4178
|
-
findings: [{ severity: "warn", lens: "buildability", summary: "dual evidence" }],
|
|
4179
|
-
}),
|
|
4180
|
-
"utf8",
|
|
4181
|
-
);
|
|
4182
|
-
const dispatch = new HarnessDispatch({
|
|
4183
|
-
scene,
|
|
4184
|
-
io,
|
|
4185
|
-
sync,
|
|
4186
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4187
|
-
});
|
|
4188
|
-
const outcome = dispatch.step()(taskReviewFrame);
|
|
4189
|
-
// the finding flows back from the FILE; the status rolls up from its severity
|
|
4190
|
-
// (blocker → CHANGES_REQUESTED · warn/nit → REVIEW_FIX · none → APPROVED) — a
|
|
4191
|
-
// review never declares its own status, so the block's `status: APPROVED` is
|
|
4192
|
-
// not what the round concludes
|
|
4193
|
-
expect(outcome.status).toBe("REVIEW_FIX");
|
|
4194
|
-
expect(outcome.findings).toEqual([{ severity: "warn", summary: "dual evidence" }]);
|
|
4195
|
-
const call = sync.calls[0];
|
|
4196
|
-
// the task/branch review rows are object-shaped {ref} (the P5 note deletion) — the
|
|
4197
|
-
// slash form prefixes the single prompt argument (not a standalone positional —
|
|
4198
|
-
// the harness CLI consumes the first positional as the whole prompt), and the
|
|
4199
|
-
// task variant's fixed prefix carries the typed axes guide inside the same prompt
|
|
4200
|
-
expect(call.args).not.toContain("/mattpocock-skills:code-review");
|
|
4201
|
-
const prompt = call.args[call.args.length - 1];
|
|
4202
|
-
expect(prompt.startsWith("/mattpocock-skills:code-review ")).toBe(true);
|
|
4203
|
-
expect(prompt).toContain("Standards axis");
|
|
4204
|
-
expect(prompt).toContain("dual evidence");
|
|
4205
|
-
expect(prompt).not.toContain("parallel sub-agents");
|
|
4206
|
-
} finally {
|
|
4207
|
-
cleanup();
|
|
4208
|
-
}
|
|
4209
|
-
});
|
|
4210
|
-
|
|
4211
|
-
it("the fix face carries no skill ref — the prompt opens with the template header, never a slash ref (T1)", () => {
|
|
4212
|
-
const { repoRoot, cleanup } = fixture();
|
|
4213
|
-
try {
|
|
4214
|
-
const scene = harnessScene(repoRoot);
|
|
4215
|
-
const io = new CaptureIo();
|
|
4216
|
-
const sync = new FakeSync();
|
|
4217
|
-
sync.stdout = "status: APPROVED\n";
|
|
4218
|
-
writeFileSync(
|
|
4219
|
-
path.join(scene.workspace.path, "tasks-1-fix-1.json"),
|
|
4220
|
-
JSON.stringify({
|
|
4221
|
-
status: "APPROVED",
|
|
4222
|
-
artifacts: {
|
|
4223
|
-
report: path.join(scene.workspace.path, "tasks-1-fix-1-report.md"),
|
|
4224
|
-
test_evidence: path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
4225
|
-
},
|
|
4226
|
-
}),
|
|
4227
|
-
"utf8",
|
|
4228
|
-
);
|
|
4229
|
-
writeFileSync(
|
|
4230
|
-
path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
4231
|
-
JSON.stringify({
|
|
4232
|
-
command: "npx vitest run",
|
|
4233
|
-
exit_code: 0,
|
|
4234
|
-
passed: true,
|
|
4235
|
-
warnings_count: 0,
|
|
4236
|
-
typecheck: { command: "tsc --noEmit", exit_code: 0, passed: true },
|
|
4237
|
-
}),
|
|
4238
|
-
"utf8",
|
|
4239
|
-
);
|
|
4240
|
-
const dispatch = new HarnessDispatch({
|
|
4241
|
-
scene,
|
|
4242
|
-
io,
|
|
4243
|
-
sync,
|
|
4244
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4245
|
-
});
|
|
4246
|
-
const outcome = dispatch.step()(fixFrame);
|
|
4247
|
-
expect(outcome.status).toBe("APPROVED");
|
|
4248
|
-
const call = sync.calls[0];
|
|
4249
|
-
const prompt = call.args[call.args.length - 1];
|
|
4250
|
-
// the fix face resolves NO skill ref (the reference-less doc faces' face) —
|
|
4251
|
-
// the single prompt argument opens with the template header, never a slash form
|
|
4252
|
-
expect(prompt.startsWith("/mattpocock-skills:")).toBe(false);
|
|
4253
|
-
expect(prompt.startsWith("# CDD dispatch — fix round")).toBe(true);
|
|
4254
|
-
} finally {
|
|
4255
|
-
cleanup();
|
|
4256
|
-
}
|
|
4257
|
-
});
|
|
4258
|
-
|
|
4259
|
-
it("T6 — probe B: the fix dispatch prompt carries the strict-schema single sentence — the declaration is the field source, zero extra keys (the child-facing fix shell)", () => {
|
|
4260
|
-
const { repoRoot, cleanup } = fixture();
|
|
4261
|
-
try {
|
|
4262
|
-
const scene = harnessScene(repoRoot);
|
|
4263
|
-
const io = new CaptureIo();
|
|
4264
|
-
const sync = new FakeSync();
|
|
4265
|
-
sync.stdout = "status: APPROVED\n";
|
|
4266
|
-
writeFileSync(
|
|
4267
|
-
path.join(scene.workspace.path, "tasks-1-fix-1.json"),
|
|
4268
|
-
JSON.stringify({
|
|
4269
|
-
status: "APPROVED",
|
|
4270
|
-
artifacts: {
|
|
4271
|
-
report: path.join(scene.workspace.path, "tasks-1-fix-1-report.md"),
|
|
4272
|
-
test_evidence: path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
4273
|
-
},
|
|
4274
|
-
}),
|
|
4275
|
-
"utf8",
|
|
4276
|
-
);
|
|
4277
|
-
writeFileSync(
|
|
4278
|
-
path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
4279
|
-
JSON.stringify({
|
|
4280
|
-
command: "npx vitest run",
|
|
4281
|
-
exit_code: 0,
|
|
4282
|
-
passed: true,
|
|
4283
|
-
warnings_count: 0,
|
|
4284
|
-
typecheck: { command: "tsc --noEmit", exit_code: 0, passed: true },
|
|
4285
|
-
}),
|
|
4286
|
-
"utf8",
|
|
4287
|
-
);
|
|
4288
|
-
const dispatch = new HarnessDispatch({
|
|
4289
|
-
scene,
|
|
4290
|
-
io,
|
|
4291
|
-
sync,
|
|
4292
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4293
|
-
});
|
|
4294
|
-
const outcome = dispatch.step()(fixFrame);
|
|
4295
|
-
expect(outcome.status).toBe("APPROVED");
|
|
4296
|
-
const call = sync.calls[0];
|
|
4297
|
-
const prompt = call.args[call.args.length - 1];
|
|
4298
|
-
// the ONE strict-schema sentence lands in the child-facing fix shell — the
|
|
4299
|
-
// declared properties are the draft's single field source (the T5 bytes riding
|
|
4300
|
-
// the rendered prompt; probe B's checkable)
|
|
4301
|
-
expect(prompt).toContain(
|
|
4302
|
-
"every top-level field of the draft comes from the `## Handoff schema` declared `properties`",
|
|
4303
|
-
);
|
|
4304
|
-
expect(prompt).toContain("zero extra keys");
|
|
4305
|
-
} finally {
|
|
4306
|
-
cleanup();
|
|
4307
|
-
}
|
|
4308
|
-
});
|
|
4309
|
-
|
|
4310
|
-
it("no host harness → BLOCKED over the CDD_BLOCKED channel; a broken child → BLOCKED too", () => {
|
|
4311
|
-
const { repoRoot, cleanup } = fixture();
|
|
4312
|
-
try {
|
|
4313
|
-
const scene = harnessScene(repoRoot);
|
|
4314
|
-
const io = new CaptureIo();
|
|
4315
|
-
const noHost = new HarnessDispatch({ scene, io, env: {} });
|
|
4316
|
-
expect(noHost.step()(implementFrame)).toEqual({ status: "BLOCKED" });
|
|
4317
|
-
expect(io.stderrText).toContain("CDD_BLOCKED: no host harness detected");
|
|
4318
|
-
const failed = new HarnessDispatch({
|
|
4319
|
-
scene,
|
|
4320
|
-
io,
|
|
4321
|
-
sync: { run: () => ({ code: 1, stdout: "", stderr: "boom" }) },
|
|
4322
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4323
|
-
});
|
|
4324
|
-
expect(failed.step()(implementFrame)).toEqual({ status: "BLOCKED" });
|
|
4325
|
-
expect(io.stderrText).toContain("child");
|
|
4326
|
-
} finally {
|
|
4327
|
-
cleanup();
|
|
4328
|
-
}
|
|
4329
|
-
});
|
|
4330
|
-
|
|
4331
|
-
it("a child that exits 0 without the handoff → BLOCKED + CDD_BLOCKED + crash record (nothing clobbered)", () => {
|
|
4332
|
-
const { repoRoot, cleanup } = fixture();
|
|
4333
|
-
try {
|
|
4334
|
-
const scene = harnessScene(repoRoot);
|
|
4335
|
-
const io = new CaptureIo();
|
|
4336
|
-
const sync = new FakeSync();
|
|
4337
|
-
sync.stdout = "status: APPROVED\n";
|
|
4338
|
-
const dispatch = new HarnessDispatch({
|
|
4339
|
-
scene,
|
|
4340
|
-
io,
|
|
4341
|
-
sync,
|
|
4342
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4343
|
-
});
|
|
4344
|
-
const outcome = dispatch.step()(implementFrame);
|
|
4345
|
-
// no carrier → the bookkeep persists nothing: the read-back rejection face
|
|
4346
|
-
expect(outcome).toEqual({ status: "BLOCKED" });
|
|
4347
|
-
expect(io.stderrText).toContain("CDD_BLOCKED: the handoff draft was not written");
|
|
4348
|
-
// the crash record — the same-command resume's decision source
|
|
4349
|
-
const crash = readJson<{ attemptedHandoff: string; next: string; cause: string }>(
|
|
4350
|
-
path.join(scene.workspace.path, "crash-implement.wave-1.json"),
|
|
4351
|
-
);
|
|
4352
|
-
expect(crash.attemptedHandoff).toBe(
|
|
4353
|
-
path.join(scene.workspace.path, "tasks-1-implement.json"),
|
|
4354
|
-
);
|
|
4355
|
-
expect(crash.next).toBe("cdd implement --tasks 1 --plan <plan>");
|
|
4356
|
-
expect(crash.cause).toBe("contract-violation");
|
|
4357
|
-
} finally {
|
|
4358
|
-
cleanup();
|
|
4359
|
-
}
|
|
4360
|
-
});
|
|
4361
|
-
|
|
4362
|
-
it("a MALFORMED draft → BLOCKED reporting the true cause (malformed JSON), never the misleading 'not written' (D27)", () => {
|
|
4363
|
-
const { repoRoot, cleanup } = fixture();
|
|
4364
|
-
try {
|
|
4365
|
-
const scene = harnessScene(repoRoot);
|
|
4366
|
-
const io = new CaptureIo();
|
|
4367
|
-
const sync = new FakeSync();
|
|
4368
|
-
sync.stdout = "status: APPROVED\n";
|
|
4369
|
-
// the child wrote an unparseable draft at OUTPUT_HANDOFF — present but corrupt.
|
|
4370
|
-
// The tri-state read reports the true cause; a corrupt draft is never misreported
|
|
4371
|
-
// as absent (the "not written" path would hide the real defect).
|
|
4372
|
-
writeFileSync(
|
|
4373
|
-
path.join(scene.workspace.path, "tasks-1-implement.json"),
|
|
4374
|
-
"{ not json",
|
|
4375
|
-
"utf8",
|
|
4376
|
-
);
|
|
4377
|
-
const dispatch = new HarnessDispatch({
|
|
4378
|
-
scene,
|
|
4379
|
-
io,
|
|
4380
|
-
sync,
|
|
4381
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4382
|
-
});
|
|
4383
|
-
const outcome = dispatch.step()(implementFrame);
|
|
4384
|
-
expect(outcome).toEqual({ status: "BLOCKED" });
|
|
4385
|
-
expect(io.stderrText).toContain("CDD_BLOCKED: the handoff draft at");
|
|
4386
|
-
expect(io.stderrText).toContain("is malformed JSON");
|
|
4387
|
-
expect(io.stderrText).not.toContain("was not written");
|
|
4388
|
-
} finally {
|
|
4389
|
-
cleanup();
|
|
4390
|
-
}
|
|
4391
|
-
});
|
|
4392
|
-
|
|
4393
|
-
it("a schema-violating draft → BLOCKED with the draft preserved untouched (no-overwrite on failure)", () => {
|
|
4394
|
-
const { repoRoot, cleanup } = fixture();
|
|
4395
|
-
try {
|
|
4396
|
-
const scene = harnessScene(repoRoot);
|
|
4397
|
-
const io = new CaptureIo();
|
|
4398
|
-
const sync = new FakeSync();
|
|
4399
|
-
sync.stdout = "status: APPROVED\n";
|
|
4400
|
-
// the child wrote a draft MISSING the required `status` — the `work` subset's
|
|
4401
|
-
// read-back refuses it
|
|
4402
|
-
const draftPath = path.join(scene.workspace.path, "tasks-1-implement.json");
|
|
4403
|
-
writeFileSync(draftPath, JSON.stringify({ artifacts: { report: "/r" } }), "utf8");
|
|
4404
|
-
const dispatch = new HarnessDispatch({
|
|
4405
|
-
scene,
|
|
4406
|
-
io,
|
|
4407
|
-
sync,
|
|
4408
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4409
|
-
});
|
|
4410
|
-
const outcome = dispatch.step()(implementFrame);
|
|
4411
|
-
expect(outcome).toEqual({ status: "BLOCKED" });
|
|
4412
|
-
expect(io.stderrText).toContain("violates the work schema");
|
|
4413
|
-
expect(io.stderrText).toContain("status: required");
|
|
4414
|
-
// the draft is preserved byte-identically — the engine never clobbers the
|
|
4415
|
-
// child's work; the resume re-runs the same command and the child rewrites it
|
|
4416
|
-
expect(readJson<{ artifacts: { report: string } }>(draftPath)).toEqual({
|
|
4417
|
-
artifacts: { report: "/r" },
|
|
4418
|
-
});
|
|
4419
|
-
} finally {
|
|
4420
|
-
cleanup();
|
|
4421
|
-
}
|
|
4422
|
-
});
|
|
4423
|
-
|
|
4424
|
-
it("a missing/violating test-evidence file rewrites the draft to BLOCKED (the evidence read-back)", () => {
|
|
4425
|
-
const { repoRoot, cleanup } = fixture();
|
|
4426
|
-
try {
|
|
4427
|
-
const scene = harnessScene(repoRoot);
|
|
4428
|
-
const io = new CaptureIo();
|
|
4429
|
-
const sync = new FakeSync();
|
|
4430
|
-
sync.stdout = "status: APPROVED\n";
|
|
4431
|
-
// the implement draft is valid, but NO evidence file was written — the evidence
|
|
4432
|
-
// gate (v1.9) turns the round BLOCKED with the carrier preserved
|
|
4433
|
-
writeFileSync(
|
|
4434
|
-
path.join(scene.workspace.path, "tasks-1-implement.json"),
|
|
4435
|
-
JSON.stringify({
|
|
4436
|
-
status: "APPROVED",
|
|
4437
|
-
artifacts: { brief: "/b", report: "/r", test_evidence: "/t" },
|
|
4438
|
-
}),
|
|
4439
|
-
"utf8",
|
|
4440
|
-
);
|
|
4441
|
-
const dispatch = new HarnessDispatch({
|
|
4442
|
-
scene,
|
|
4443
|
-
io,
|
|
4444
|
-
sync,
|
|
4445
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4446
|
-
});
|
|
4447
|
-
const outcome = dispatch.step()(implementFrame);
|
|
4448
|
-
expect(outcome.status).toBe("BLOCKED");
|
|
4449
|
-
// the carrier is materialized (the child's work preserved) but rewritten BLOCKED.
|
|
4450
|
-
// The free-named declared paths are corrected to the canonical OUTPUT_* names
|
|
4451
|
-
// (find #5 — the engine derives, never books a child-reported path): the report
|
|
4452
|
-
// and evidence book their canonical tasks-1- names with the deviations surfaced.
|
|
4453
|
-
expect(outcome.carrier).toEqual({
|
|
4454
|
-
artifacts: {
|
|
4455
|
-
brief: "/b",
|
|
4456
|
-
report: path.join(scene.workspace.path, "tasks-1-implement-report.md"),
|
|
4457
|
-
test_evidence: path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
4458
|
-
},
|
|
4459
|
-
status: "BLOCKED",
|
|
4460
|
-
failure_category: "evidence-contract",
|
|
4461
|
-
notes: [
|
|
4462
|
-
expect.stringContaining("artifact report"),
|
|
4463
|
-
expect.stringContaining("artifact test_evidence"),
|
|
4464
|
-
expect.stringContaining("the test evidence at"),
|
|
4465
|
-
],
|
|
4466
|
-
});
|
|
4467
|
-
// T2 — the materialized work carrier is the work face: zero findings key (the
|
|
4468
|
-
// evidence-contract rewrite never re-injects the work-carrier findings bridge)
|
|
4469
|
-
expect("findings" in outcome.carrier!).toBe(false);
|
|
4470
|
-
} finally {
|
|
4471
|
-
cleanup();
|
|
4472
|
-
}
|
|
4473
|
-
});
|
|
4474
|
-
|
|
4475
|
-
it("a MALFORMED test-evidence file → BLOCKED reporting the true cause (malformed JSON), never the misleading 'missing' (D27)", () => {
|
|
4476
|
-
const { repoRoot, cleanup } = fixture();
|
|
4477
|
-
try {
|
|
4478
|
-
const scene = harnessScene(repoRoot);
|
|
4479
|
-
const io = new CaptureIo();
|
|
4480
|
-
const sync = new FakeSync();
|
|
4481
|
-
sync.stdout = "status: APPROVED\n";
|
|
4482
|
-
// a VALID draft + a PRESENT-but-corrupt evidence file — the tri-state read
|
|
4483
|
-
// reports the true cause; a corrupt file is never misreported as absent
|
|
4484
|
-
// (the "missing" path would hide the real defect on the evidence leg, the
|
|
4485
|
-
// exact true-cause misreport D27 exists to eliminate).
|
|
4486
|
-
writeFileSync(
|
|
4487
|
-
path.join(scene.workspace.path, "tasks-1-implement.json"),
|
|
4488
|
-
JSON.stringify({
|
|
4489
|
-
status: "APPROVED",
|
|
4490
|
-
artifacts: { brief: "/b", report: "/r", test_evidence: "/t" },
|
|
4491
|
-
}),
|
|
4492
|
-
"utf8",
|
|
4493
|
-
);
|
|
4494
|
-
writeFileSync(
|
|
4495
|
-
path.join(scene.workspace.path, "tasks-1-test-evidence.json"),
|
|
4496
|
-
"{ not json",
|
|
4497
|
-
"utf8",
|
|
4498
|
-
);
|
|
4499
|
-
const dispatch = new HarnessDispatch({
|
|
4500
|
-
scene,
|
|
4501
|
-
io,
|
|
4502
|
-
sync,
|
|
4503
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4504
|
-
});
|
|
4505
|
-
const outcome = dispatch.step()(implementFrame);
|
|
4506
|
-
expect(outcome.status).toBe("BLOCKED");
|
|
4507
|
-
expect(outcome.carrier?.failure_category).toBe("evidence-contract");
|
|
4508
|
-
const notes = (outcome.carrier?.notes ?? []) as string[];
|
|
4509
|
-
expect(notes.join("\n")).toContain("is malformed JSON");
|
|
4510
|
-
// the true cause, never the misleading "missing" the collapsed read produced
|
|
4511
|
-
expect(notes.join("\n")).not.toContain("the evidence file is missing");
|
|
4512
|
-
} finally {
|
|
4513
|
-
cleanup();
|
|
4514
|
-
}
|
|
4515
|
-
});
|
|
4516
|
-
|
|
4517
|
-
it("find #9 — the branch fix's OUTPUT_* artifacts are the line-keyed names (report `branch-fix-{round}-report.md` · evidence `branch-test-evidence.json`), never the range", () => {
|
|
4518
|
-
const { repoRoot, cleanup } = fixture();
|
|
4519
|
-
try {
|
|
4520
|
-
const scene = harnessScene(repoRoot);
|
|
4521
|
-
const io = new CaptureIo();
|
|
4522
|
-
const sync = new FakeSync();
|
|
4523
|
-
sync.stdout = "status: APPROVED\nartifacts: report=/r test_evidence=/t\n";
|
|
4524
|
-
writeFileSync(
|
|
4525
|
-
path.join(scene.workspace.path, "branch-fix-1.json"),
|
|
4526
|
-
JSON.stringify({
|
|
4527
|
-
status: "APPROVED",
|
|
4528
|
-
artifacts: {
|
|
4529
|
-
brief: "/b",
|
|
4530
|
-
report: path.join(scene.workspace.path, "branch-fix-1-report.md"),
|
|
4531
|
-
test_evidence: path.join(scene.workspace.path, "branch-test-evidence.json"),
|
|
4532
|
-
},
|
|
4533
|
-
}),
|
|
4534
|
-
"utf8",
|
|
4535
|
-
);
|
|
4536
|
-
writeFileSync(
|
|
4537
|
-
path.join(scene.workspace.path, "branch-test-evidence.json"),
|
|
4538
|
-
JSON.stringify({
|
|
4539
|
-
command: "npx vitest run",
|
|
4540
|
-
exit_code: 0,
|
|
4541
|
-
passed: true,
|
|
4542
|
-
warnings_count: 0,
|
|
4543
|
-
typecheck: { command: "tsc --noEmit", exit_code: 0, passed: true },
|
|
4544
|
-
}),
|
|
4545
|
-
"utf8",
|
|
4546
|
-
);
|
|
4547
|
-
const dispatch = new HarnessDispatch({
|
|
4548
|
-
scene,
|
|
4549
|
-
io,
|
|
4550
|
-
sync,
|
|
4551
|
-
env: { CLAUDE_CODE_SESSION_ID: "s" },
|
|
4552
|
-
});
|
|
4553
|
-
const frame: OpenFrame = {
|
|
4554
|
-
type: "branch",
|
|
4555
|
-
phase: "fix",
|
|
4556
|
-
round: 1,
|
|
4557
|
-
// the branch target carries no commit identity — the artifact names are
|
|
4558
|
-
// line-keyed (the spine wins · find #9)
|
|
4559
|
-
target: { kind: "branch" },
|
|
4560
|
-
params: { round: 1 },
|
|
4561
|
-
key: "branch",
|
|
4562
|
-
};
|
|
4563
|
-
const outcome = dispatch.step()(frame);
|
|
4564
|
-
expect(io.stderrText).toBe("");
|
|
4565
|
-
expect(outcome.status).toBe("APPROVED");
|
|
4566
|
-
const prompt = sync.calls[0]!.args[sync.calls[0]!.args.length - 1];
|
|
4567
|
-
// find #9 — the prescribed artifact names are line-keyed: the round rides the
|
|
4568
|
-
// name (branch-fix-1-report.md), the evidence is the line's single file
|
|
4569
|
-
// (branch-test-evidence.json); the range token appears NOWHERE in the paths
|
|
4570
|
-
expect(prompt).toContain(
|
|
4571
|
-
`- \`OUTPUT_REPORT\`: ${path.join(scene.workspace.path, "branch-fix-1-report.md")}`,
|
|
4572
|
-
);
|
|
4573
|
-
expect(prompt).toContain(
|
|
4574
|
-
`- \`OUTPUT_EVIDENCE\`: ${path.join(scene.workspace.path, "branch-test-evidence.json")}`,
|
|
4575
|
-
);
|
|
4576
|
-
expect(prompt).not.toContain("aaaaaaaa..bbbbbbbb");
|
|
4577
|
-
} finally {
|
|
4578
|
-
cleanup();
|
|
4579
|
-
}
|
|
4580
|
-
});
|
|
4581
|
-
});
|
|
4582
|
-
|
|
4583
|
-
describe("T9 — the destroy-list zero-residual sweep (spec §6.3 cross-reference)", () => {
|
|
4584
|
-
it("the hand-written parse monoliths + the destroyed write-plane table carry zero residual across the engine source", () => {
|
|
4585
|
-
// The destroy list (spec §6.3 + the T3 parallel-table destroy): the four
|
|
4586
|
-
// hand-written value-domain monoliths (destroyed at T7 — the rules live in
|
|
4587
|
-
// declare.ts VALUE_SHAPES) and the HANDOFF_WRITE_PLANE parallel table
|
|
4588
|
-
// (destroyed at T3 — the write plane derives from the declared properties).
|
|
4589
|
-
// The retained pair (#parseTypeKey/SCHEMA_TYPE_KEYS — the schema <type>
|
|
4590
|
-
// doc-key vocabulary, orthogonal to the value-shape table) is NOT swept here —
|
|
4591
|
-
// its retention is pinned in projection.test.ts.
|
|
4592
|
-
const destroyed = [
|
|
4593
|
-
"#parseEnum",
|
|
4594
|
-
"#parseInts",
|
|
4595
|
-
"#parseSha8",
|
|
4596
|
-
"#parseInt",
|
|
4597
|
-
"HANDOFF_WRITE_PLANE",
|
|
4598
|
-
] as const;
|
|
4599
|
-
for (const [file, text] of engineSourceTexts()) {
|
|
4600
|
-
for (const name of destroyed) {
|
|
4601
|
-
expect(text, `${name} must not survive in ${file}`).not.toContain(name);
|
|
4602
|
-
}
|
|
4603
|
-
}
|
|
4604
|
-
});
|
|
4605
|
-
|
|
4606
|
-
it("the retired commit-sha vocabulary carries zero residual across the engine source (spec §7.4)", () => {
|
|
4607
|
-
// The sha surface retired engine-wide (§2): no source file names the retired
|
|
4608
|
-
// scope tokens (WAVE_BASE / FIX_BASE / INPUT_RANGE / INPUT_PLAN) or the
|
|
4609
|
-
// retired git/BranchRef members (revParseHead / BranchRef) — the GitClient
|
|
4610
|
-
// holds only topLevel + isClean, the review carries the single doc anchor
|
|
4611
|
-
// (INPUT_DOC), and the branch scope rides the base artifact's BASE_BRANCH.
|
|
4612
|
-
// The pin is construction-establishment-level: it fails if any retired name
|
|
4613
|
-
// resurfaces in a non-test source file.
|
|
4614
|
-
const retiredShaVocab = [
|
|
4615
|
-
"WAVE_BASE",
|
|
4616
|
-
"FIX_BASE",
|
|
4617
|
-
"INPUT_RANGE",
|
|
4618
|
-
"INPUT_PLAN",
|
|
4619
|
-
"revParseHead",
|
|
4620
|
-
"BranchRef",
|
|
4621
|
-
] as const;
|
|
4622
|
-
for (const [file, text] of engineSourceTexts()) {
|
|
4623
|
-
for (const name of retiredShaVocab) {
|
|
4624
|
-
expect(text, `${name} must not survive in ${file}`).not.toContain(name);
|
|
4625
|
-
}
|
|
4626
|
-
}
|
|
4627
|
-
});
|
|
4628
|
-
});
|
|
4629
|
-
|
|
4630
|
-
/** The fake child-process seam — records every invocation, ans answers a canned stdout. */
|
|
4631
|
-
class FakeSync implements SyncProcess {
|
|
4632
|
-
calls: { command: string; args: string[]; cwd: string }[] = [];
|
|
4633
|
-
stdout = "";
|
|
4634
|
-
|
|
4635
|
-
run(
|
|
4636
|
-
command: string,
|
|
4637
|
-
args: readonly string[],
|
|
4638
|
-
cwd: string,
|
|
4639
|
-
): { code: number; stdout: string; stderr: string } {
|
|
4640
|
-
this.calls.push({ command, args: [...args], cwd });
|
|
4641
|
-
return { code: 0, stdout: this.stdout, stderr: "" };
|
|
4642
|
-
}
|
|
4643
|
-
}
|