@psimona/darkf 0.5.0 → 0.7.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/docs/concepts/failure-modes.md +177 -0
- package/docs/concepts/handoff.md +91 -0
- package/docs/concepts/journal.md +92 -0
- package/docs/concepts/node-types.md +177 -0
- package/docs/guides/pick-an-agent-runner.md +57 -0
- package/docs/guides/plan-with-a-task-queue.md +411 -0
- package/docs/guides/render-to-mermaid.md +22 -0
- package/docs/guides/run-detached-and-monitor.md +76 -0
- package/docs/guides/test-your-workflow.md +20 -0
- package/docs/guides/write-your-first-workflow.md +101 -0
- package/docs/index.mdx +68 -0
- package/docs/reference/cli-commands.md +105 -0
- package/docs/reference/core-types.md +128 -0
- package/docs/reference/package-map.md +39 -0
- package/docs/start-here/install.md +71 -0
- package/docs/start-here/quickstart.md +248 -0
- package/package.json +15 -2
- package/skills/darkf-usage/SKILL.md +92 -0
- package/skills/darkf-writing-workflows/SKILL.md +213 -0
- package/src/cli/doctor.test.ts +338 -0
- package/src/cli/index.ts +139 -15
- package/src/cli/setup.test.ts +384 -0
- package/src/cli/setup.ts +281 -0
- package/src/cli/state-file.ts +14 -0
- package/src/cli/tarball.test.ts +127 -0
- package/src/cli/update.test.ts +82 -0
- package/src/cli/update.ts +24 -9
- package/src/core/tasks.ts +1 -1
- package/src/core/types.test.ts +52 -0
- package/src/core/types.ts +33 -16
- package/src/engine/run.test.ts +462 -3
- package/src/engine/run.ts +114 -8
- package/src/exports.ts +4 -0
- package/src/kit/agents/claude-code.ts +4 -34
- package/src/kit/agents/handoff.test.ts +12 -0
- package/src/kit/agents/handoff.ts +32 -8
- package/src/kit/agents/opencode.test.ts +232 -2
- package/src/kit/agents/opencode.ts +80 -31
- package/src/kit/specs.test.ts +247 -0
- package/src/kit/specs.ts +344 -0
- package/src/kit/status.test.ts +67 -0
- package/src/kit/status.ts +29 -4
- package/src/kit/validation/zod.test.ts +42 -0
- package/src/kit/validation/zod.ts +20 -0
- package/workflows/dev-loop/scripts/begin.ts +9 -6
- package/workflows/dev-loop/scripts/dispatch.ts +50 -0
- package/workflows/dev-loop/scripts/finish.ts +26 -21
- package/workflows/dev-loop/scripts/mark-done.ts +22 -0
- package/workflows/dev-loop/scripts/validate-plan.ts +30 -0
- package/workflows/dev-loop/workflow.ts +171 -64
- package/bunfig.toml +0 -13
- package/examples/article-classifier/data/articles.ts +0 -38
- package/examples/article-classifier/scripts/next.ts +0 -7
- package/examples/article-classifier/scripts/queue.ts +0 -33
- package/examples/article-classifier/scripts/record.ts +0 -9
- package/examples/article-classifier/workflow.ts +0 -44
- package/examples/haiku-commit/scripts/check.ts +0 -24
- package/examples/haiku-commit/workflow.ts +0 -28
- package/examples/haiku-readme/scripts/test.ts +0 -13
- package/examples/haiku-readme/scripts/write.ts +0 -10
- package/examples/haiku-readme/workflow.ts +0 -41
- package/examples/task-queue/scripts/next.ts +0 -20
- package/examples/task-queue/scripts/record.ts +0 -20
- package/examples/task-queue/supervise.ts +0 -57
- package/examples/task-queue/workflow.ts +0 -33
- package/feedback/2026-10-30-self-update.md +0 -29
- package/feedback/2026-10-31-task-list-json.md +0 -26
- package/tsconfig.json +0 -4
- /package/workflows/dev-loop/scripts/{check.ts → test.ts} +0 -0
|
@@ -5,36 +5,22 @@ import {
|
|
|
5
5
|
AgentFailure,
|
|
6
6
|
type AgentProgress,
|
|
7
7
|
type AgentRunner,
|
|
8
|
-
type AgentStateDef,
|
|
9
8
|
type DispatchInfo,
|
|
10
9
|
type NodeResult,
|
|
11
10
|
} from "../../core/index.ts";
|
|
12
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
buildPrompt,
|
|
13
|
+
handoffContractText,
|
|
14
|
+
handoffPath,
|
|
15
|
+
nudgeMessage,
|
|
16
|
+
readHandoff,
|
|
17
|
+
} from "./handoff.ts";
|
|
13
18
|
|
|
14
19
|
// Mirrors darkf-engine's own DEFAULT_TIMEOUT_MS (run.ts), same reason
|
|
15
20
|
// claude-code.ts does: kill the subprocess in step with the engine's own
|
|
16
21
|
// timeout instead of leaving it running past the point the engine moved on.
|
|
17
22
|
const DEFAULT_TIMEOUT_MS = 60 * 60 * 1000;
|
|
18
23
|
|
|
19
|
-
function buildPrompt(
|
|
20
|
-
def: AgentStateDef,
|
|
21
|
-
handoff: NodeResult,
|
|
22
|
-
info: { validEvents: string[]; hasFallback: boolean },
|
|
23
|
-
path: string,
|
|
24
|
-
): string {
|
|
25
|
-
const parts = [def.prompt, `Input from the previous step:\n${JSON.stringify(handoff)}`];
|
|
26
|
-
|
|
27
|
-
if (info.validEvents.length > 0) {
|
|
28
|
-
const fallbackNote = info.hasFallback ? ` If none apply, you may omit "event" instead.` : "";
|
|
29
|
-
parts.push(
|
|
30
|
-
`Your "event" must be exactly one of: ${info.validEvents.join(", ")}.${fallbackNote}`,
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
parts.push(handoffContractText(path));
|
|
35
|
-
return parts.join("\n\n");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
24
|
export interface StepFinishScan {
|
|
39
25
|
reason?: string;
|
|
40
26
|
sessionId?: string;
|
|
@@ -54,7 +40,7 @@ export interface StepFinishScan {
|
|
|
54
40
|
// installed opencode binary — matching on "step_finish" (underscore) here
|
|
55
41
|
// silently never matched, so this capture never actually fired.
|
|
56
42
|
//
|
|
57
|
-
// Extended (docs/specs/session-nudge/spec.md) to also pull `part.sessionID`
|
|
43
|
+
// Extended (docs/specs/_built/session-nudge/spec.md) to also pull `part.sessionID`
|
|
58
44
|
// and a count of step-finish events seen, in the same single pass:
|
|
59
45
|
// `stepCount` is the positive-evidence gate for ever reporting a session id
|
|
60
46
|
// at all — this is the resumability fix for the session that hung 15
|
|
@@ -84,7 +70,7 @@ export function scanStepFinish(stdout: string): StepFinishScan {
|
|
|
84
70
|
return { reason, sessionId, stepCount };
|
|
85
71
|
}
|
|
86
72
|
|
|
87
|
-
// Agent-liveness (docs/specs/agent-liveness/spec.md): a stalled LLM backend
|
|
73
|
+
// Agent-liveness (docs/specs/_built/agent-liveness/spec.md): a stalled LLM backend
|
|
88
74
|
// still produces a healthy engine heartbeat, because the engine only knows
|
|
89
75
|
// the process is alive, not whether the agent is making progress. Reading
|
|
90
76
|
// stdout incrementally (rather than once, at exit, as `scanStepFinish`'s
|
|
@@ -132,7 +118,7 @@ export async function readIncrementally(
|
|
|
132
118
|
// dispatch's failure reason; if the same dispatch key runs again, the
|
|
133
119
|
// retry's prompt opens with the reason so it can correct course (e.g.
|
|
134
120
|
// "handoff not written", "handoff unparseable", exit stderr tail).
|
|
135
|
-
// Unaffected by same-session nudging (docs/specs/session-nudge/spec.md):
|
|
121
|
+
// Unaffected by same-session nudging (docs/specs/_built/session-nudge/spec.md):
|
|
136
122
|
// this cache covers the fresh-session case, nudging covers the
|
|
137
123
|
// same-session case, and the two never fire on the same attempt.
|
|
138
124
|
const lastFailures = new Map<string, string>();
|
|
@@ -152,6 +138,38 @@ function contextBlock(rootDir: string, runId: string): string {
|
|
|
152
138
|
}
|
|
153
139
|
}
|
|
154
140
|
|
|
141
|
+
// Usage-limit detection (docs/specs/_built/usage-limit-backoff/spec.md, Detection):
|
|
142
|
+
// a provider quota wall surfaces as an API-level error — opencode exits
|
|
143
|
+
// non-zero with the provider's message in its output. Scan stderr and
|
|
144
|
+
// non-JSON stdout lines ONLY: stdout's NDJSON lines are event objects, i.e.
|
|
145
|
+
// agent-authored content — a limit-shaped string inside one must never match
|
|
146
|
+
// (a false positive turns a real crash into a silent hours-long wait; the
|
|
147
|
+
// worse error). Markers, case-insensitive, from the 2026-11-01 live capture
|
|
148
|
+
// ("Usage limit reached for 5 hour. Your limit will reset at ..."): the
|
|
149
|
+
// quoted reset time is display text darkf never parses — see the spec's Wait
|
|
150
|
+
// section for why a fixed interval is the honest response. Returns the first
|
|
151
|
+
// matched line; callers consult this on the non-zero-exit branch only, so a
|
|
152
|
+
// limit-shaped string on the exit-0 + missing-handoff path stays a
|
|
153
|
+
// `handoff-missing` on its existing nudge/repair path.
|
|
154
|
+
const USAGE_LIMIT_MARKERS = ["usage limit", "rate limit", "limit exceeded", "429"];
|
|
155
|
+
|
|
156
|
+
export function matchUsageLimit(stderr: string, stdout: string): string | undefined {
|
|
157
|
+
for (const text of [stderr, stdout]) {
|
|
158
|
+
for (const line of text.split("\n")) {
|
|
159
|
+
if (!line.trim()) continue;
|
|
160
|
+
try {
|
|
161
|
+
JSON.parse(line);
|
|
162
|
+
continue; // event object — agent-authored, never matched
|
|
163
|
+
} catch {
|
|
164
|
+
// not JSON — runner/provider output
|
|
165
|
+
}
|
|
166
|
+
const lowered = line.toLowerCase();
|
|
167
|
+
if (USAGE_LIMIT_MARKERS.some((marker) => lowered.includes(marker))) return line;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
155
173
|
export const opencodeRunner: AgentRunner = {
|
|
156
174
|
kind: "opencode",
|
|
157
175
|
async run(id, def, handoff, info: DispatchInfo, onProgress?: (p: AgentProgress) => void) {
|
|
@@ -179,16 +197,33 @@ export const opencodeRunner: AgentRunner = {
|
|
|
179
197
|
|
|
180
198
|
const dispatchKey = `${info.runId}:${info.step}:${id}`;
|
|
181
199
|
|
|
182
|
-
// Same-session nudge (docs/specs/session-nudge/spec.md): when the
|
|
200
|
+
// Same-session nudge (docs/specs/_built/session-nudge/spec.md): when the
|
|
183
201
|
// previous attempt failed in a repairable way and we have its session
|
|
184
202
|
// id, send a short corrective message into that session instead of a
|
|
185
203
|
// fresh prompt. `-s` resume is scoped strictly to this case — see the
|
|
186
204
|
// "No -s outside a nudge" note below.
|
|
187
205
|
const nudge = nudgeMessage(info, path);
|
|
188
206
|
|
|
207
|
+
// Post-limit continuation (docs/specs/_built/usage-limit-backoff/spec.md, Wait
|
|
208
|
+
// and resume): when the engine re-dispatches this attempt after waiting
|
|
209
|
+
// out a usage limit, resume the interrupted session with a short
|
|
210
|
+
// continuation prompt instead of replaying the full fresh prompt — the
|
|
211
|
+
// dispatch itself doubles as the limit probe (a still-limited provider
|
|
212
|
+
// rejects it before processing; a lifted limit continues mid-flight with
|
|
213
|
+
// all pre-wall work intact). A present agentSessionId IS the evidence
|
|
214
|
+
// gate: the runner only ever attaches one when `scanStepFinish` counted
|
|
215
|
+
// step events (stepCount > 0), the same bar that makes `-s` safe for
|
|
216
|
+
// nudges. Without a session id the dispatch is fresh, exactly as before.
|
|
217
|
+
const continuation =
|
|
218
|
+
info.previousFailure?.kind === "usage-limit" && info.agentSessionId !== undefined
|
|
219
|
+
? `A provider usage limit interrupted your previous turn. Continue where you left off.\n\n${handoffContractText(path)}`
|
|
220
|
+
: undefined;
|
|
221
|
+
|
|
189
222
|
let prompt: string;
|
|
190
223
|
if (nudge) {
|
|
191
224
|
prompt = nudge;
|
|
225
|
+
} else if (continuation) {
|
|
226
|
+
prompt = continuation;
|
|
192
227
|
} else {
|
|
193
228
|
const promptParts: string[] = [];
|
|
194
229
|
|
|
@@ -225,16 +260,17 @@ export const opencodeRunner: AgentRunner = {
|
|
|
225
260
|
// terminal runner crash. `scanStepFinish`'s `stepCount` guard (above) is
|
|
226
261
|
// what makes `-s` safe again — the hang's root cause was resuming a
|
|
227
262
|
// session with no evidence it had done anything, not resuming as such —
|
|
228
|
-
// but it's deliberately only ever used for
|
|
229
|
-
//
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
//
|
|
263
|
+
// but it's deliberately only ever used for two explicitly-scoped cases:
|
|
264
|
+
// a nudge (immediately after a nudgeable failure in the same outer
|
|
265
|
+
// attempt) and the post-limit continuation (usage-limit-backoff spec —
|
|
266
|
+
// same evidence gate, same reasoning). A fresh or exhausted-nudge
|
|
267
|
+
// dispatch always starts a brand-new session, exactly as today, even
|
|
268
|
+
// when `info.agentSessionId` happens to be set.
|
|
233
269
|
const bin = Bun.which("opencode") ?? "opencode";
|
|
234
270
|
const args = [
|
|
235
271
|
bin,
|
|
236
272
|
"run",
|
|
237
|
-
...(nudge ? ["-s", info.agentSessionId!] : []),
|
|
273
|
+
...(nudge || continuation ? ["-s", info.agentSessionId!] : []),
|
|
238
274
|
...(auto ? ["--auto"] : []),
|
|
239
275
|
"-m",
|
|
240
276
|
model,
|
|
@@ -285,6 +321,19 @@ export const opencodeRunner: AgentRunner = {
|
|
|
285
321
|
const reason = `opencode exited ${exitCode}: ${stderr.trim().slice(-400)}`;
|
|
286
322
|
lastFailures.set(dispatchKey, reason);
|
|
287
323
|
const scan = scanStepFinish(stdout);
|
|
324
|
+
// Usage-limit classification (docs/specs/_built/usage-limit-backoff/spec.md):
|
|
325
|
+
// consulted on this non-zero-exit branch ONLY, before the generic
|
|
326
|
+
// throw — a quota wall is a known temporary condition, and the engine
|
|
327
|
+
// waits it out instead of burning retries against it. The session id
|
|
328
|
+
// stays evidence-gated (stepCount > 0) exactly as below. No match
|
|
329
|
+
// keeps the existing runner-error throw unchanged.
|
|
330
|
+
const limitLine = matchUsageLimit(stderr, stdout);
|
|
331
|
+
if (limitLine !== undefined) {
|
|
332
|
+
throw new AgentFailure(reason, {
|
|
333
|
+
agentSessionId: scan.stepCount > 0 ? scan.sessionId : undefined,
|
|
334
|
+
crashReason: { kind: "usage-limit", detail: limitLine },
|
|
335
|
+
});
|
|
336
|
+
}
|
|
288
337
|
throw new AgentFailure(reason, {
|
|
289
338
|
agentSessionId: scan.stepCount > 0 ? scan.sessionId : undefined,
|
|
290
339
|
crashReason: { kind: "runner-error", error: reason },
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
type ProjectConfig,
|
|
4
|
+
parseBacklog,
|
|
5
|
+
parseBacklogJson,
|
|
6
|
+
parseProjectConfig,
|
|
7
|
+
parseProjectJson,
|
|
8
|
+
parseSpecDocument,
|
|
9
|
+
parseSpecFrontmatter,
|
|
10
|
+
SPEC_FORMAT_VERSION,
|
|
11
|
+
SpecFormatError,
|
|
12
|
+
validateSpecGraph,
|
|
13
|
+
} from "./specs.ts";
|
|
14
|
+
|
|
15
|
+
const ID = "a8169a9c-1a53-4e0b-8a55-1318fef44bce";
|
|
16
|
+
const DEP = "0b9f8c2e-51a7-4c3d-9a11-7f6e5d4c3b2a";
|
|
17
|
+
|
|
18
|
+
function issuesOf(run: () => unknown): string[] {
|
|
19
|
+
try {
|
|
20
|
+
run();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
expect(error).toBeInstanceOf(SpecFormatError);
|
|
23
|
+
return (error as SpecFormatError).issues;
|
|
24
|
+
}
|
|
25
|
+
throw new Error("expected a SpecFormatError");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe("parseSpecFrontmatter", () => {
|
|
29
|
+
test("accepts the minimal shape", () => {
|
|
30
|
+
expect(parseSpecFrontmatter({ id: ID, slug: "billing-v2", owner: "alice" })).toEqual({
|
|
31
|
+
id: ID,
|
|
32
|
+
slug: "billing-v2",
|
|
33
|
+
owner: "alice",
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("accepts dependencies", () => {
|
|
38
|
+
const spec = parseSpecFrontmatter({
|
|
39
|
+
id: ID,
|
|
40
|
+
slug: "cutover",
|
|
41
|
+
owner: "alice",
|
|
42
|
+
depends_on: [DEP],
|
|
43
|
+
});
|
|
44
|
+
expect(spec.depends_on).toEqual([DEP]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("rejects unknown fields", () => {
|
|
48
|
+
expect(
|
|
49
|
+
issuesOf(() => parseSpecFrontmatter({ id: ID, slug: "x", owner: "a", priority: 1 })),
|
|
50
|
+
).toEqual(['frontmatter: unknown field "priority"']);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("rejects a non-object", () => {
|
|
54
|
+
expect(issuesOf(() => parseSpecFrontmatter("nope"))).toEqual([
|
|
55
|
+
"frontmatter must be a YAML object",
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("rejects a missing or non-v4 id", () => {
|
|
60
|
+
expect(issuesOf(() => parseSpecFrontmatter({ slug: "x", owner: "a" }))).toContain(
|
|
61
|
+
'frontmatter: "id" must be a UUIDv4 string',
|
|
62
|
+
);
|
|
63
|
+
expect(
|
|
64
|
+
issuesOf(() => parseSpecFrontmatter({ id: "not-a-uuid", slug: "x", owner: "a" })),
|
|
65
|
+
).toContain('frontmatter: "id" must be a UUIDv4 string');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("rejects a bad slug and an empty owner", () => {
|
|
69
|
+
const issues = issuesOf(() =>
|
|
70
|
+
parseSpecFrontmatter({ id: ID, slug: "Not_A_Slug", owner: " " }),
|
|
71
|
+
);
|
|
72
|
+
expect(issues).toContain('frontmatter: "slug" must be lowercase kebab-case');
|
|
73
|
+
expect(issues).toContain('frontmatter: "owner" must be a non-empty string');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("rejects duplicate and self dependencies", () => {
|
|
77
|
+
expect(
|
|
78
|
+
issuesOf(() =>
|
|
79
|
+
parseSpecFrontmatter({ id: ID, slug: "x", owner: "a", depends_on: [DEP, DEP] }),
|
|
80
|
+
),
|
|
81
|
+
).toContain(`frontmatter: depends_on: duplicate "${DEP}"`);
|
|
82
|
+
expect(
|
|
83
|
+
issuesOf(() => parseSpecFrontmatter({ id: ID, slug: "x", owner: "a", depends_on: [ID] })),
|
|
84
|
+
).toContain("frontmatter: a spec cannot depend on itself");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("rejects non-uuid dependency entries", () => {
|
|
88
|
+
expect(
|
|
89
|
+
issuesOf(() => parseSpecFrontmatter({ id: ID, slug: "x", owner: "a", depends_on: ["nope"] })),
|
|
90
|
+
).toContain('frontmatter: depends_on entry "nope" is not a UUIDv4');
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("parseSpecDocument", () => {
|
|
95
|
+
test("splits frontmatter and body", () => {
|
|
96
|
+
const text = `---\nid: ${ID}\nslug: billing-v2\nowner: alice\n---\n\n# Billing\n\nBody.\n`;
|
|
97
|
+
const doc = parseSpecDocument(text);
|
|
98
|
+
expect(doc.frontmatter).toEqual({ id: ID, slug: "billing-v2", owner: "alice" });
|
|
99
|
+
expect(doc.body.trim()).toBe("# Billing\n\nBody.");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("rejects a missing frontmatter block", () => {
|
|
103
|
+
expect(issuesOf(() => parseSpecDocument("# No frontmatter\n"))).toEqual([
|
|
104
|
+
"spec.md must start with a --- frontmatter block",
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("wraps YAML errors", () => {
|
|
109
|
+
const issues = issuesOf(() => parseSpecDocument("---\nkey: [unclosed\n---\n"));
|
|
110
|
+
expect(issues[0]).toStartWith("frontmatter is not valid YAML:");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("parseBacklog", () => {
|
|
115
|
+
test("accepts an ordered list", () => {
|
|
116
|
+
expect(parseBacklog({ version: 1, order: [ID, DEP] })).toEqual({
|
|
117
|
+
version: 1,
|
|
118
|
+
order: [ID, DEP],
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("accepts an empty order", () => {
|
|
123
|
+
expect(parseBacklog({ version: 1, order: [] })).toEqual({ version: 1, order: [] });
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("rejects a version mismatch and unknown fields", () => {
|
|
127
|
+
const issues = issuesOf(() => parseBacklog({ version: 2, order: [], extra: true }));
|
|
128
|
+
expect(issues).toContain(`backlog: "version" must be ${SPEC_FORMAT_VERSION}`);
|
|
129
|
+
expect(issues).toContain('backlog: unknown field "extra"');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("rejects duplicates and non-uuid entries", () => {
|
|
133
|
+
const issues = issuesOf(() => parseBacklog({ version: 1, order: [ID, ID, "nope"] }));
|
|
134
|
+
expect(issues).toContain(`backlog: order: duplicate "${ID}"`);
|
|
135
|
+
expect(issues).toContain('backlog: order entry "nope" is not a UUIDv4');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("parseBacklogJson wraps JSON errors", () => {
|
|
139
|
+
expect(issuesOf(() => parseBacklogJson("{"))[0]).toStartWith("backlog.json is not valid JSON:");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("parseProjectConfig", () => {
|
|
144
|
+
const full: ProjectConfig = {
|
|
145
|
+
version: 1,
|
|
146
|
+
title: "darkf backplane",
|
|
147
|
+
harness: { runner: "opencode", model: "openai/gpt-5" },
|
|
148
|
+
sandbox: {
|
|
149
|
+
image: "ghcr.io/psimona/backplane-ci:latest",
|
|
150
|
+
runtimeClass: "gvisor",
|
|
151
|
+
mounts: [{ name: "bun-cache", mountPath: "/root/.bun", size: "10Gi" }],
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
test("accepts the full shape", () => {
|
|
156
|
+
expect(parseProjectConfig(full)).toEqual(full);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("accepts the minimal shape", () => {
|
|
160
|
+
expect(parseProjectConfig({ version: 1 })).toEqual({ version: 1 });
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("rejects unknown fields at every level", () => {
|
|
164
|
+
const issues = issuesOf(() =>
|
|
165
|
+
parseProjectConfig({
|
|
166
|
+
version: 1,
|
|
167
|
+
extra: true,
|
|
168
|
+
harness: { runner: "opencode", apiKey: "x" },
|
|
169
|
+
sandbox: {
|
|
170
|
+
image: "i",
|
|
171
|
+
privileged: true,
|
|
172
|
+
mounts: [{ name: "a", mountPath: "/a", mode: "rw" }],
|
|
173
|
+
},
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
176
|
+
expect(issues).toContain('project: unknown field "extra"');
|
|
177
|
+
expect(issues).toContain('project.harness: unknown field "apiKey"');
|
|
178
|
+
expect(issues).toContain('project.sandbox: unknown field "privileged"');
|
|
179
|
+
expect(issues).toContain('project.sandbox.mounts[0]: unknown field "mode"');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("requires a runner when a harness is present", () => {
|
|
183
|
+
expect(issuesOf(() => parseProjectConfig({ version: 1, harness: {} }))).toContain(
|
|
184
|
+
'project.harness: "runner" must be a non-empty string',
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("requires absolute mount paths", () => {
|
|
189
|
+
const issues = issuesOf(() =>
|
|
190
|
+
parseProjectConfig({
|
|
191
|
+
version: 1,
|
|
192
|
+
sandbox: { mounts: [{ name: "a", mountPath: "relative" }] },
|
|
193
|
+
}),
|
|
194
|
+
);
|
|
195
|
+
expect(issues).toContain('project.sandbox.mounts[0]: "mountPath" must be an absolute path');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("parseProjectJson wraps JSON errors", () => {
|
|
199
|
+
expect(issuesOf(() => parseProjectJson("nope"))[0]).toStartWith(
|
|
200
|
+
"project.json is not valid JSON:",
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe("validateSpecGraph", () => {
|
|
206
|
+
const base = { owner: "alice" };
|
|
207
|
+
|
|
208
|
+
test("accepts a valid graph", () => {
|
|
209
|
+
expect(() =>
|
|
210
|
+
validateSpecGraph([
|
|
211
|
+
{ ...base, id: ID, slug: "parent" },
|
|
212
|
+
{ ...base, id: DEP, slug: "child", depends_on: [ID] },
|
|
213
|
+
]),
|
|
214
|
+
).not.toThrow();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("rejects duplicate ids and slugs", () => {
|
|
218
|
+
const issues = issuesOf(() =>
|
|
219
|
+
validateSpecGraph([
|
|
220
|
+
{ ...base, id: ID, slug: "same" },
|
|
221
|
+
{ ...base, id: ID, slug: "same" },
|
|
222
|
+
]),
|
|
223
|
+
);
|
|
224
|
+
expect(issues).toContain(`spec graph: id: duplicate "${ID}"`);
|
|
225
|
+
expect(issues).toContain('spec graph: slug: duplicate "same"');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("rejects missing dependency targets", () => {
|
|
229
|
+
expect(
|
|
230
|
+
issuesOf(() => validateSpecGraph([{ ...base, id: ID, slug: "child", depends_on: [DEP] }])),
|
|
231
|
+
).toContain(
|
|
232
|
+
'spec child: depends_on target "0b9f8c2e-51a7-4c3d-9a11-7f6e5d4c3b2a" does not exist',
|
|
233
|
+
);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("rejects cycles", () => {
|
|
237
|
+
const third = "11111111-1111-4111-8111-111111111111";
|
|
238
|
+
const issues = issuesOf(() =>
|
|
239
|
+
validateSpecGraph([
|
|
240
|
+
{ ...base, id: ID, slug: "a", depends_on: [DEP] },
|
|
241
|
+
{ ...base, id: DEP, slug: "b", depends_on: [third] },
|
|
242
|
+
{ ...base, id: third, slug: "c", depends_on: [ID] },
|
|
243
|
+
]),
|
|
244
|
+
);
|
|
245
|
+
expect(issues).toContain("spec graph: dependency cycle a -> b -> c -> a");
|
|
246
|
+
});
|
|
247
|
+
});
|