@psimona/darkf 0.6.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 +18 -5
- package/docs/concepts/node-types.md +4 -2
- package/docs/guides/plan-with-a-task-queue.md +6 -5
- package/docs/guides/write-your-first-workflow.md +8 -2
- package/docs/index.mdx +4 -0
- package/docs/reference/core-types.md +5 -0
- package/docs/reference/package-map.md +12 -8
- package/docs/start-here/quickstart.md +12 -5
- package/package.json +9 -2
- package/skills/darkf-writing-workflows/SKILL.md +131 -6
- package/src/cli/doctor.test.ts +1 -1
- package/src/cli/index.ts +25 -15
- package/src/cli/setup.ts +4 -9
- package/src/cli/state-file.ts +14 -0
- package/src/cli/tarball.test.ts +3 -1
- package/src/cli/update.ts +4 -9
- package/src/core/tasks.ts +1 -1
- package/src/core/types.test.ts +52 -0
- package/src/core/types.ts +27 -18
- package/src/engine/run.test.ts +286 -4
- package/src/engine/run.ts +51 -9
- 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 +1 -1
- package/src/kit/agents/opencode.ts +14 -28
- package/src/kit/specs.test.ts +247 -0
- package/src/kit/specs.ts +344 -0
- package/src/kit/status.ts +6 -6
- 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 +23 -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 +164 -68
- /package/workflows/dev-loop/scripts/{check.ts → test.ts} +0 -0
|
@@ -1,44 +1,14 @@
|
|
|
1
1
|
import { mkdir } from "node:fs/promises";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
type AgentRunner,
|
|
6
|
-
type AgentStateDef,
|
|
7
|
-
type NodeResult,
|
|
8
|
-
} from "../../core/index.ts";
|
|
9
|
-
import {
|
|
10
|
-
handoffContractText,
|
|
11
|
-
handoffPath,
|
|
12
|
-
nudgeMessage,
|
|
13
|
-
readHandoff,
|
|
14
|
-
usagePath,
|
|
15
|
-
} from "./handoff.ts";
|
|
3
|
+
import { AgentFailure, type AgentRunner, type NodeResult } from "../../core/index.ts";
|
|
4
|
+
import { buildPrompt, handoffPath, nudgeMessage, readHandoff, usagePath } from "./handoff.ts";
|
|
16
5
|
|
|
17
6
|
// Mirrors darkf-engine's own DEFAULT_TIMEOUT_MS (run.ts) so this runner can
|
|
18
7
|
// kill its own subprocess in step with the engine's timeout instead of
|
|
19
8
|
// leaving it running past the point where the engine has moved on — see
|
|
20
|
-
// docs/specs/agent-handoff/spec.md's retry-overwrite race note.
|
|
9
|
+
// docs/specs/_built/agent-handoff/spec.md's retry-overwrite race note.
|
|
21
10
|
const DEFAULT_TIMEOUT_MS = 60 * 60 * 1000;
|
|
22
11
|
|
|
23
|
-
function buildPrompt(
|
|
24
|
-
def: AgentStateDef,
|
|
25
|
-
handoff: NodeResult,
|
|
26
|
-
info: { validEvents: string[]; hasFallback: boolean },
|
|
27
|
-
path: string,
|
|
28
|
-
): string {
|
|
29
|
-
const parts = [def.prompt, `Input from the previous step:\n${JSON.stringify(handoff)}`];
|
|
30
|
-
|
|
31
|
-
if (info.validEvents.length > 0) {
|
|
32
|
-
const fallbackNote = info.hasFallback ? ` If none apply, you may omit "event" instead.` : "";
|
|
33
|
-
parts.push(
|
|
34
|
-
`Your "event" must be exactly one of: ${info.validEvents.join(", ")}.${fallbackNote}`,
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
parts.push(handoffContractText(path));
|
|
39
|
-
return parts.join("\n\n");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
12
|
interface ClaudeCodeStdout {
|
|
43
13
|
session_id?: string;
|
|
44
14
|
total_cost_usd?: number;
|
|
@@ -102,7 +72,7 @@ export const claudeCodeRunner: AgentRunner = {
|
|
|
102
72
|
const permissionMode =
|
|
103
73
|
(agentConfig.permissionMode as string | undefined) ?? "bypassPermissions";
|
|
104
74
|
const model = agentConfig.model as string | undefined;
|
|
105
|
-
// Same-session nudge (docs/specs/session-nudge/spec.md): when the
|
|
75
|
+
// Same-session nudge (docs/specs/_built/session-nudge/spec.md): when the
|
|
106
76
|
// previous attempt failed in a repairable way and we have its session
|
|
107
77
|
// id, send a short corrective message into that session instead of
|
|
108
78
|
// replaying the full prompt. `--resume` itself is unconditional on
|
|
@@ -126,3 +126,15 @@ test("nudgeMessage builds the no-transition repair text, naming the bad event an
|
|
|
126
126
|
expect(msg).toContain("ok, changes_requested");
|
|
127
127
|
expect(msg).toContain("routable event");
|
|
128
128
|
});
|
|
129
|
+
|
|
130
|
+
test("nudgeMessage builds the validation-failed repair text, quoting the message", () => {
|
|
131
|
+
const info = baseInfo({
|
|
132
|
+
agentSessionId: "sess-1",
|
|
133
|
+
previousFailure: { kind: "validation-failed", message: "tasks[2].title: required" },
|
|
134
|
+
});
|
|
135
|
+
const msg = nudgeMessage(info, "/root/.darkf/run/run-1/handoff/0001-Plan.json")!;
|
|
136
|
+
expect(msg).toContain("failed validation");
|
|
137
|
+
expect(msg).toContain("tasks[2].title: required");
|
|
138
|
+
expect(msg).toContain('Rewrite the handoff\'s "output" field');
|
|
139
|
+
expect(msg).toContain("/root/.darkf/run/run-1/handoff/0001-Plan.json");
|
|
140
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import type { DispatchInfo } from "../../core/index.ts";
|
|
3
|
+
import type { AgentStateDef, DispatchInfo, NodeResult } from "../../core/index.ts";
|
|
4
4
|
|
|
5
5
|
// Shared, harness-agnostic half of the agent-handoff contract. See
|
|
6
|
-
// docs/specs/agent-handoff/spec.md. Per-harness runners own everything else
|
|
6
|
+
// docs/specs/_built/agent-handoff/spec.md. Per-harness runners own everything else
|
|
7
7
|
// (invocation, native structured-output vs. prompt fallback, agentSessionId,
|
|
8
8
|
// subprocess lifecycle).
|
|
9
9
|
|
|
@@ -35,13 +35,35 @@ export async function readHandoff(path: string): Promise<unknown> {
|
|
|
35
35
|
return JSON.parse(text);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** Builds one agent's prompt from its state def, the previous step's
|
|
39
|
+
* handoff, and the valid outgoing events — identical for every harness,
|
|
40
|
+
* so each runner calls this instead of building its own. */
|
|
41
|
+
export function buildPrompt(
|
|
42
|
+
def: AgentStateDef,
|
|
43
|
+
handoff: NodeResult,
|
|
44
|
+
info: { validEvents: string[]; hasFallback: boolean },
|
|
45
|
+
path: string,
|
|
46
|
+
): string {
|
|
47
|
+
const parts = [def.prompt, `Input from the previous step:\n${JSON.stringify(handoff)}`];
|
|
48
|
+
|
|
49
|
+
if (info.validEvents.length > 0) {
|
|
50
|
+
const fallbackNote = info.hasFallback ? ` If none apply, you may omit "event" instead.` : "";
|
|
51
|
+
parts.push(
|
|
52
|
+
`Your "event" must be exactly one of: ${info.validEvents.join(", ")}.${fallbackNote}`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
parts.push(handoffContractText(path));
|
|
57
|
+
return parts.join("\n\n");
|
|
58
|
+
}
|
|
59
|
+
|
|
38
60
|
/**
|
|
39
|
-
* Shared same-session repair text for the
|
|
40
|
-
*
|
|
41
|
-
* nudge" — either there's no `previousFailure`, no
|
|
42
|
-
* resume, or the failure isn't one of the
|
|
43
|
-
* runners call this identically; only the CLI invocation that
|
|
44
|
-
* message differs per harness.
|
|
61
|
+
* Shared same-session repair text for the nudgeable `CrashReason` kinds
|
|
62
|
+
* (docs/specs/_built/session-nudge/spec.md, docs/specs/output-validation/spec.md).
|
|
63
|
+
* `undefined` means "don't nudge" — either there's no `previousFailure`, no
|
|
64
|
+
* `agentSessionId` to resume, or the failure isn't one of the repairable
|
|
65
|
+
* kinds. Both runners call this identically; only the CLI invocation that
|
|
66
|
+
* sends the message differs per harness.
|
|
45
67
|
*/
|
|
46
68
|
export function nudgeMessage(info: DispatchInfo, path: string): string | undefined {
|
|
47
69
|
const failure = info.previousFailure;
|
|
@@ -54,6 +76,8 @@ export function nudgeMessage(info: DispatchInfo, path: string): string | undefin
|
|
|
54
76
|
return `The JSON at ${path} failed to parse (${failure.parseError}). Rewrite it as a single valid JSON object with the contract fields.`;
|
|
55
77
|
case "no-transition":
|
|
56
78
|
return `You reported event ${failure.event}; this state only routes ${validEvents}. Re-issue the handoff with a routable event.`;
|
|
79
|
+
case "validation-failed":
|
|
80
|
+
return `Your output failed validation: ${failure.message}\n\nRewrite the handoff's "output" field to fix this and write it again to ${path}.`;
|
|
57
81
|
default:
|
|
58
82
|
return undefined;
|
|
59
83
|
}
|
|
@@ -140,7 +140,7 @@ describe("readIncrementally", () => {
|
|
|
140
140
|
});
|
|
141
141
|
});
|
|
142
142
|
|
|
143
|
-
// --- usage-limit-backoff (docs/specs/usage-limit-backoff/spec.md) ---
|
|
143
|
+
// --- usage-limit-backoff (docs/specs/_built/usage-limit-backoff/spec.md) ---
|
|
144
144
|
|
|
145
145
|
describe("matchUsageLimit", () => {
|
|
146
146
|
test("matches the captured usage-limit line, case-insensitively, returning the line itself", () => {
|
|
@@ -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,7 +138,7 @@ function contextBlock(rootDir: string, runId: string): string {
|
|
|
152
138
|
}
|
|
153
139
|
}
|
|
154
140
|
|
|
155
|
-
// Usage-limit detection (docs/specs/usage-limit-backoff/spec.md, Detection):
|
|
141
|
+
// Usage-limit detection (docs/specs/_built/usage-limit-backoff/spec.md, Detection):
|
|
156
142
|
// a provider quota wall surfaces as an API-level error — opencode exits
|
|
157
143
|
// non-zero with the provider's message in its output. Scan stderr and
|
|
158
144
|
// non-JSON stdout lines ONLY: stdout's NDJSON lines are event objects, i.e.
|
|
@@ -211,14 +197,14 @@ export const opencodeRunner: AgentRunner = {
|
|
|
211
197
|
|
|
212
198
|
const dispatchKey = `${info.runId}:${info.step}:${id}`;
|
|
213
199
|
|
|
214
|
-
// Same-session nudge (docs/specs/session-nudge/spec.md): when the
|
|
200
|
+
// Same-session nudge (docs/specs/_built/session-nudge/spec.md): when the
|
|
215
201
|
// previous attempt failed in a repairable way and we have its session
|
|
216
202
|
// id, send a short corrective message into that session instead of a
|
|
217
203
|
// fresh prompt. `-s` resume is scoped strictly to this case — see the
|
|
218
204
|
// "No -s outside a nudge" note below.
|
|
219
205
|
const nudge = nudgeMessage(info, path);
|
|
220
206
|
|
|
221
|
-
// Post-limit continuation (docs/specs/usage-limit-backoff/spec.md, Wait
|
|
207
|
+
// Post-limit continuation (docs/specs/_built/usage-limit-backoff/spec.md, Wait
|
|
222
208
|
// and resume): when the engine re-dispatches this attempt after waiting
|
|
223
209
|
// out a usage limit, resume the interrupted session with a short
|
|
224
210
|
// continuation prompt instead of replaying the full fresh prompt — the
|
|
@@ -335,7 +321,7 @@ export const opencodeRunner: AgentRunner = {
|
|
|
335
321
|
const reason = `opencode exited ${exitCode}: ${stderr.trim().slice(-400)}`;
|
|
336
322
|
lastFailures.set(dispatchKey, reason);
|
|
337
323
|
const scan = scanStepFinish(stdout);
|
|
338
|
-
// Usage-limit classification (docs/specs/usage-limit-backoff/spec.md):
|
|
324
|
+
// Usage-limit classification (docs/specs/_built/usage-limit-backoff/spec.md):
|
|
339
325
|
// consulted on this non-zero-exit branch ONLY, before the generic
|
|
340
326
|
// throw — a quota wall is a known temporary condition, and the engine
|
|
341
327
|
// waits it out instead of burning retries against it. The session id
|
|
@@ -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
|
+
});
|