@selesai/code 0.3.0 → 0.3.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/dist/core/diagnostics.d.ts +1 -0
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/diagnostics.js.map +1 -1
- package/dist/core/package-manager.d.ts +10 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +93 -8
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/package-manager.test.d.ts +2 -0
- package/dist/core/package-manager.test.d.ts.map +1 -0
- package/dist/core/package-manager.test.js +20 -0
- package/dist/core/package-manager.test.js.map +1 -0
- package/dist/core/resource-loader.d.ts +3 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +10 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/settings-manager.d.ts +1 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/extensions/caveman/caveman-instructions.cjs +39 -0
- package/dist/extensions/caveman/index.js +116 -0
- package/dist/extensions/caveman/package.json +8 -0
- package/dist/extensions/caveman/test/extension.test.js +185 -0
- package/dist/extensions/caveman/test/helpers.test.js +67 -0
- package/dist/extensions/pi-intercom/broker/broker.ts +2 -3
- package/dist/extensions/pi-intercom/broker/paths.ts +10 -5
- package/dist/extensions/pi-intercom/broker/spawn.ts +2 -3
- package/dist/extensions/pi-intercom/config.ts +2 -2
- package/dist/extensions/pi-intercom/index.ts +2 -2
- package/dist/extensions/pi-intercom/package.json +2 -2
- package/dist/extensions/pi-intercom/ui/compose.ts +3 -3
- package/dist/extensions/pi-intercom/ui/inline-message.ts +3 -3
- package/dist/extensions/pi-intercom/ui/session-list.ts +3 -3
- package/dist/extensions/pi-powerline-footer/bash-mode/history.ts +2 -1
- package/dist/extensions/pi-powerline-footer/index.ts +9 -16
- package/dist/extensions/pi-powerline-footer/welcome.ts +23 -16
- package/dist/extensions/pi-powerline-footer/working-vibes.ts +2 -9
- package/dist/extensions/pi-rewind-hook/index.ts +1 -1
- package/dist/extensions/pi-rewind-hook/package.json +1 -1
- package/dist/extensions/pi-subagents/README.md +224 -52
- package/dist/extensions/pi-subagents/install.mjs +93 -0
- package/dist/extensions/pi-subagents/package.json +4 -5
- package/dist/extensions/pi-subagents/prompts/parallel-context-build.md +1 -1
- package/dist/extensions/pi-subagents/prompts/parallel-handoff-plan.md +1 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +76 -13
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +179 -2
- package/dist/extensions/pi-subagents/src/agents/agent-memory.ts +254 -0
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +11 -0
- package/dist/extensions/pi-subagents/src/agents/agents.ts +193 -19
- package/dist/extensions/pi-subagents/src/agents/chain-serializer.ts +27 -2
- package/dist/extensions/pi-subagents/src/extension/config.ts +27 -4
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +1 -7
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +3 -2
- package/dist/extensions/pi-subagents/src/extension/index.ts +73 -71
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +369 -0
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +54 -10
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +200 -0
- package/dist/extensions/pi-subagents/src/intercom/intercom-bridge.ts +21 -253
- package/dist/extensions/pi-subagents/src/intercom/native-supervisor-channel.ts +519 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +195 -105
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +88 -2
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +67 -10
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +34 -4
- package/dist/extensions/pi-subagents/src/runs/background/completion-batcher.ts +166 -0
- package/dist/extensions/pi-subagents/src/runs/background/control-channel.ts +156 -1
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +515 -0
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +161 -44
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +1 -2
- package/dist/extensions/pi-subagents/src/runs/background/run-id-resolver.ts +3 -2
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +167 -6
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +514 -0
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +28 -1
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +873 -204
- package/dist/extensions/pi-subagents/src/runs/background/wait.ts +353 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-execution.ts +123 -27
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +174 -70
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +569 -81
- package/dist/extensions/pi-subagents/src/runs/shared/acceptance.ts +45 -22
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +3 -1
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +2 -2
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +172 -21
- package/dist/extensions/pi-subagents/src/runs/shared/model-scope.ts +128 -0
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +89 -0
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +50 -1
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +35 -4
- package/dist/extensions/pi-subagents/src/runs/shared/pi-spawn.ts +63 -45
- package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +2 -0
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +125 -5
- package/dist/extensions/pi-subagents/src/runs/shared/tool-budget.ts +74 -0
- package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +52 -0
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +28 -5
- package/dist/extensions/pi-subagents/src/shared/artifacts.ts +16 -1
- package/dist/extensions/pi-subagents/src/shared/atomic-json.ts +15 -2
- package/dist/extensions/pi-subagents/src/shared/child-transcript.ts +212 -0
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +133 -22
- package/dist/extensions/pi-subagents/src/shared/settings.ts +3 -1
- package/dist/extensions/pi-subagents/src/shared/types.ts +197 -4
- package/dist/extensions/pi-subagents/src/shared/utils.ts +100 -15
- package/dist/extensions/pi-subagents/src/slash/prompt-workflows.ts +330 -0
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +135 -4
- package/dist/extensions/pi-subagents/src/tui/render.ts +32 -12
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +94 -0
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +2772 -0
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +1107 -0
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +463 -0
- package/dist/extensions/pi-subagents/test/integration/chain-clarify.test.ts +274 -0
- package/dist/extensions/pi-subagents/test/integration/chain-execution.test.ts +1535 -0
- package/dist/extensions/pi-subagents/test/integration/detect-error.test.ts +242 -0
- package/dist/extensions/pi-subagents/test/integration/doctor-executor.test.ts +128 -0
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +252 -0
- package/dist/extensions/pi-subagents/test/integration/foreground-result-size.test.ts +188 -0
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +1306 -0
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +1033 -0
- package/dist/extensions/pi-subagents/test/integration/parallel-execution.test.ts +397 -0
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +583 -0
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +691 -0
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +892 -0
- package/dist/extensions/pi-subagents/test/integration/session-tokens.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1824 -0
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +1284 -0
- package/dist/extensions/pi-subagents/test/integration/slash-live-state.test.ts +127 -0
- package/dist/extensions/pi-subagents/test/integration/template-resolution.test.ts +299 -0
- package/dist/extensions/pi-subagents/test/integration/top-level-async.test.ts +37 -0
- package/dist/extensions/pi-subagents/test/support/helpers.ts +189 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi-script.mjs +335 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +129 -0
- package/dist/extensions/pi-subagents/test/support/real-session-child-cli.mjs +184 -0
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +285 -0
- package/dist/extensions/pi-subagents/test/support/register-loader.mjs +15 -0
- package/dist/extensions/pi-subagents/test/support/ts-loader.mjs +108 -0
- package/dist/extensions/pi-subagents/test/unit/acceptance.test.ts +421 -0
- package/dist/extensions/pi-subagents/test/unit/agent-disabled.test.ts +213 -0
- package/dist/extensions/pi-subagents/test/unit/agent-eject-disable.test.ts +343 -0
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +1199 -0
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +556 -0
- package/dist/extensions/pi-subagents/test/unit/agent-memory.test.ts +420 -0
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +579 -0
- package/dist/extensions/pi-subagents/test/unit/agent-scope.test.ts +20 -0
- package/dist/extensions/pi-subagents/test/unit/agent-selection.test.ts +88 -0
- package/dist/extensions/pi-subagents/test/unit/artifacts.test.ts +24 -0
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +86 -0
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +221 -0
- package/dist/extensions/pi-subagents/test/unit/async-permission-session.test.ts +98 -0
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +285 -0
- package/dist/extensions/pi-subagents/test/unit/atomic-json.test.ts +112 -0
- package/dist/extensions/pi-subagents/test/unit/chain-append.test.ts +206 -0
- package/dist/extensions/pi-subagents/test/unit/chain-root-attachment.test.ts +159 -0
- package/dist/extensions/pi-subagents/test/unit/chain-serializer.test.ts +229 -0
- package/dist/extensions/pi-subagents/test/unit/child-transcript.test.ts +225 -0
- package/dist/extensions/pi-subagents/test/unit/close-grace-timer.test.ts +101 -0
- package/dist/extensions/pi-subagents/test/unit/completion-batcher.test.ts +228 -0
- package/dist/extensions/pi-subagents/test/unit/completion-dedupe.test.ts +36 -0
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +152 -0
- package/dist/extensions/pi-subagents/test/unit/config-dir-runtime.test.ts +72 -0
- package/dist/extensions/pi-subagents/test/unit/control-channel.test.ts +327 -0
- package/dist/extensions/pi-subagents/test/unit/control-notices.test.ts +161 -0
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +159 -0
- package/dist/extensions/pi-subagents/test/unit/dynamic-fanout.test.ts +217 -0
- package/dist/extensions/pi-subagents/test/unit/extra-agent-dirs.test.ts +88 -0
- package/dist/extensions/pi-subagents/test/unit/file-coalescer.test.ts +68 -0
- package/dist/extensions/pi-subagents/test/unit/foreground-tool-call-compaction.test.ts +78 -0
- package/dist/extensions/pi-subagents/test/unit/fork-context.test.ts +415 -0
- package/dist/extensions/pi-subagents/test/unit/get-final-output.test.ts +126 -0
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +271 -0
- package/dist/extensions/pi-subagents/test/unit/intercom-bridge.test.ts +173 -0
- package/dist/extensions/pi-subagents/test/unit/jsonl-writer.test.ts +119 -0
- package/dist/extensions/pi-subagents/test/unit/live-async-resume.test.ts +170 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +346 -0
- package/dist/extensions/pi-subagents/test/unit/model-info.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/unit/model-scope-settings.test.ts +87 -0
- package/dist/extensions/pi-subagents/test/unit/model-scope.test.ts +145 -0
- package/dist/extensions/pi-subagents/test/unit/native-supervisor-channel.test.ts +162 -0
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +470 -0
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +329 -0
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +319 -0
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +70 -0
- package/dist/extensions/pi-subagents/test/unit/parallel-utils.test.ts +247 -0
- package/dist/extensions/pi-subagents/test/unit/path-handling.test.ts +113 -0
- package/dist/extensions/pi-subagents/test/unit/path-resolution.test.ts +94 -0
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +803 -0
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +209 -0
- package/dist/extensions/pi-subagents/test/unit/pi-spawn.test.ts +238 -0
- package/dist/extensions/pi-subagents/test/unit/proactive-skills.test.ts +118 -0
- package/dist/extensions/pi-subagents/test/unit/profiles.test.ts +299 -0
- package/dist/extensions/pi-subagents/test/unit/prompt-template-bridge.test.ts +408 -0
- package/dist/extensions/pi-subagents/test/unit/prompt-workflows.test.ts +134 -0
- package/dist/extensions/pi-subagents/test/unit/recursion-guard.test.ts +257 -0
- package/dist/extensions/pi-subagents/test/unit/render-helpers.test.ts +209 -0
- package/dist/extensions/pi-subagents/test/unit/result-intercom.test.ts +226 -0
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +294 -0
- package/dist/extensions/pi-subagents/test/unit/run-id-resolver.test.ts +147 -0
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +997 -0
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +478 -0
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +562 -0
- package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +213 -0
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +438 -0
- package/dist/extensions/pi-subagents/test/unit/slash-bridge.test.ts +54 -0
- package/dist/extensions/pi-subagents/test/unit/slash-chain-groups.test.ts +464 -0
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +255 -0
- package/dist/extensions/pi-subagents/test/unit/status-format.test.ts +19 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-control.test.ts +245 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +517 -0
- package/dist/extensions/pi-subagents/test/unit/temp-paths.test.ts +72 -0
- package/dist/extensions/pi-subagents/test/unit/tool-budget.test.ts +52 -0
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +237 -0
- package/dist/extensions/pi-subagents/test/unit/total-cost.test.ts +60 -0
- package/dist/extensions/pi-subagents/test/unit/ts-loader.test.ts +33 -0
- package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +202 -0
- package/dist/extensions/pi-subagents/test/unit/types-fork-preamble.test.ts +23 -0
- package/dist/extensions/pi-subagents/test/unit/wait.test.ts +398 -0
- package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +88 -0
- package/dist/extensions/pi-subagents/test/unit/windows-hide-spawn.test.ts +26 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-graph.test.ts +134 -0
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +479 -0
- package/dist/extensions/pi-web-agent/src/changelog-notice.ts +5 -2
- package/dist/extensions/pi-web-agent/src/presentation/config-store.ts +6 -4
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.js +19 -5
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/skills/caveman/SKILL.md +49 -0
- package/dist/skills/handoff-text/SKILL.md +13 -0
- package/docs/docs.json +4 -0
- package/docs/extensions.md +2 -0
- package/docs/settings.md +15 -0
- package/docs/shared-host-extensions.md +109 -0
- package/package.json +1 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { describe, it } from "node:test";
|
|
6
|
+
import { buildRevivedAsyncTask, resolveAsyncResumeTarget } from "../../src/runs/background/async-resume.ts";
|
|
7
|
+
|
|
8
|
+
function writeJson(filePath: string, value: object): void {
|
|
9
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
10
|
+
fs.writeFileSync(filePath, JSON.stringify(value, null, 2), "utf-8");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe("async resume lookup", () => {
|
|
14
|
+
it("resolves a completed single-child run from persisted status", () => {
|
|
15
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-async-resume-"));
|
|
16
|
+
try {
|
|
17
|
+
const asyncRoot = path.join(root, "runs");
|
|
18
|
+
const sessionFile = path.join(root, "session.jsonl");
|
|
19
|
+
fs.writeFileSync(sessionFile, "", "utf-8");
|
|
20
|
+
writeJson(path.join(asyncRoot, "run-abc", "status.json"), {
|
|
21
|
+
runId: "run-abc",
|
|
22
|
+
mode: "single",
|
|
23
|
+
state: "complete",
|
|
24
|
+
startedAt: 100,
|
|
25
|
+
endedAt: 200,
|
|
26
|
+
lastUpdate: 200,
|
|
27
|
+
cwd: root,
|
|
28
|
+
sessionFile,
|
|
29
|
+
steps: [{ agent: "worker", status: "complete" }],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const target = resolveAsyncResumeTarget({ id: "run-a" }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") });
|
|
33
|
+
|
|
34
|
+
assert.equal(target.kind, "revive");
|
|
35
|
+
assert.equal(target.runId, "run-abc");
|
|
36
|
+
assert.equal(target.agent, "worker");
|
|
37
|
+
assert.equal(target.sessionFile, sessionFile);
|
|
38
|
+
assert.equal(target.cwd, root);
|
|
39
|
+
assert.equal(target.intercomTarget, "subagent-worker-run-abc-1");
|
|
40
|
+
} finally {
|
|
41
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("rejects ambiguous run id prefixes", () => {
|
|
46
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-async-resume-ambiguous-"));
|
|
47
|
+
try {
|
|
48
|
+
const asyncRoot = path.join(root, "runs");
|
|
49
|
+
writeJson(path.join(asyncRoot, "run-aa", "status.json"), {
|
|
50
|
+
runId: "run-aa",
|
|
51
|
+
mode: "single",
|
|
52
|
+
state: "running",
|
|
53
|
+
startedAt: 100,
|
|
54
|
+
steps: [{ agent: "scout", status: "running" }],
|
|
55
|
+
});
|
|
56
|
+
writeJson(path.join(asyncRoot, "run-ab", "status.json"), {
|
|
57
|
+
runId: "run-ab",
|
|
58
|
+
mode: "single",
|
|
59
|
+
state: "running",
|
|
60
|
+
startedAt: 100,
|
|
61
|
+
steps: [{ agent: "worker", status: "running" }],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
assert.throws(
|
|
65
|
+
() => resolveAsyncResumeTarget({ id: "run-a" }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") }),
|
|
66
|
+
/Ambiguous async run id prefix 'run-a' matched: run-aa, run-ab/,
|
|
67
|
+
);
|
|
68
|
+
} finally {
|
|
69
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("rejects path-like ids and directories outside the async root", () => {
|
|
74
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-async-resume-paths-"));
|
|
75
|
+
try {
|
|
76
|
+
const asyncRoot = path.join(root, "runs");
|
|
77
|
+
assert.throws(
|
|
78
|
+
() => resolveAsyncResumeTarget({ id: "../run" }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") }),
|
|
79
|
+
/id must be an async run id or prefix, not a path/,
|
|
80
|
+
);
|
|
81
|
+
assert.throws(
|
|
82
|
+
() => resolveAsyncResumeTarget({ dir: path.join(root, "outside") }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") }),
|
|
83
|
+
/Async run directory must be inside/,
|
|
84
|
+
);
|
|
85
|
+
} finally {
|
|
86
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("rejects non-jsonl session files before reviving", () => {
|
|
91
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-async-resume-session-"));
|
|
92
|
+
try {
|
|
93
|
+
const asyncRoot = path.join(root, "runs");
|
|
94
|
+
const sessionFile = path.join(root, "session.txt");
|
|
95
|
+
fs.writeFileSync(sessionFile, "", "utf-8");
|
|
96
|
+
writeJson(path.join(asyncRoot, "run-session", "status.json"), {
|
|
97
|
+
runId: "run-session",
|
|
98
|
+
mode: "single",
|
|
99
|
+
state: "complete",
|
|
100
|
+
startedAt: 100,
|
|
101
|
+
lastUpdate: 200,
|
|
102
|
+
sessionFile,
|
|
103
|
+
steps: [{ agent: "worker", status: "complete" }],
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
assert.throws(
|
|
107
|
+
() => resolveAsyncResumeTarget({ id: "run-session" }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") }),
|
|
108
|
+
/session file must be a \.jsonl file/,
|
|
109
|
+
);
|
|
110
|
+
} finally {
|
|
111
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("rejects malformed result metadata before using session fields", () => {
|
|
116
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-async-resume-malformed-result-"));
|
|
117
|
+
try {
|
|
118
|
+
const resultsDir = path.join(root, "results");
|
|
119
|
+
writeJson(path.join(resultsDir, "run-result.json"), {
|
|
120
|
+
id: "run-result",
|
|
121
|
+
agent: "worker",
|
|
122
|
+
success: true,
|
|
123
|
+
state: "complete",
|
|
124
|
+
results: [{ agent: "worker", sessionFile: { path: "session.jsonl" } }],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
assert.throws(
|
|
128
|
+
() => resolveAsyncResumeTarget({ id: "run-result" }, { asyncDirRoot: path.join(root, "runs"), resultsDir }),
|
|
129
|
+
/results\[0\].sessionFile must be a string/,
|
|
130
|
+
);
|
|
131
|
+
} finally {
|
|
132
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("rejects malformed status session ids", () => {
|
|
137
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-async-resume-malformed-session-id-"));
|
|
138
|
+
try {
|
|
139
|
+
const asyncRoot = path.join(root, "runs");
|
|
140
|
+
writeJson(path.join(asyncRoot, "run-session-id", "status.json"), {
|
|
141
|
+
runId: "run-session-id",
|
|
142
|
+
sessionId: { value: "session" },
|
|
143
|
+
mode: "single",
|
|
144
|
+
state: "running",
|
|
145
|
+
startedAt: 100,
|
|
146
|
+
steps: [{ agent: "worker", status: "running" }],
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
assert.throws(
|
|
150
|
+
() => resolveAsyncResumeTarget({ id: "run-session-id" }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") }),
|
|
151
|
+
/sessionId must be a string/,
|
|
152
|
+
);
|
|
153
|
+
} finally {
|
|
154
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("returns a live intercom target for a running child", () => {
|
|
159
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-async-resume-live-"));
|
|
160
|
+
try {
|
|
161
|
+
const asyncRoot = path.join(root, "runs");
|
|
162
|
+
writeJson(path.join(asyncRoot, "run-live", "status.json"), {
|
|
163
|
+
runId: "run-live",
|
|
164
|
+
mode: "single",
|
|
165
|
+
state: "running",
|
|
166
|
+
startedAt: 100,
|
|
167
|
+
lastUpdate: 100,
|
|
168
|
+
steps: [{ agent: "scout", status: "running" }],
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const target = resolveAsyncResumeTarget({ id: "run-live" }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") });
|
|
172
|
+
|
|
173
|
+
assert.equal(target.kind, "live");
|
|
174
|
+
assert.equal(target.intercomTarget, "subagent-scout-run-live-1");
|
|
175
|
+
} finally {
|
|
176
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("revives a completed child by index while a sibling async child is still running", () => {
|
|
181
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-async-resume-partial-"));
|
|
182
|
+
try {
|
|
183
|
+
const asyncRoot = path.join(root, "runs");
|
|
184
|
+
const sessionFile = path.join(root, "done.jsonl");
|
|
185
|
+
fs.writeFileSync(sessionFile, "", "utf-8");
|
|
186
|
+
writeJson(path.join(asyncRoot, "run-partial", "status.json"), {
|
|
187
|
+
runId: "run-partial",
|
|
188
|
+
mode: "parallel",
|
|
189
|
+
state: "running",
|
|
190
|
+
startedAt: 100,
|
|
191
|
+
lastUpdate: 200,
|
|
192
|
+
steps: [
|
|
193
|
+
{ agent: "done", status: "complete", sessionFile },
|
|
194
|
+
{ agent: "active", status: "running" },
|
|
195
|
+
],
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const target = resolveAsyncResumeTarget({ id: "run-partial", index: 0 }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") });
|
|
199
|
+
assert.equal(target.kind, "revive");
|
|
200
|
+
assert.equal(target.agent, "done");
|
|
201
|
+
assert.equal(target.sessionFile, sessionFile);
|
|
202
|
+
} finally {
|
|
203
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("rejects pending indexed children in still-running async runs", () => {
|
|
208
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-async-resume-pending-"));
|
|
209
|
+
try {
|
|
210
|
+
const asyncRoot = path.join(root, "runs");
|
|
211
|
+
const sessionFile = path.join(root, "pending.jsonl");
|
|
212
|
+
fs.writeFileSync(sessionFile, "", "utf-8");
|
|
213
|
+
writeJson(path.join(asyncRoot, "run-pending", "status.json"), {
|
|
214
|
+
runId: "run-pending",
|
|
215
|
+
mode: "chain",
|
|
216
|
+
state: "running",
|
|
217
|
+
startedAt: 100,
|
|
218
|
+
lastUpdate: 200,
|
|
219
|
+
steps: [
|
|
220
|
+
{ agent: "active", status: "running" },
|
|
221
|
+
{ agent: "later", status: "pending", sessionFile },
|
|
222
|
+
],
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
assert.throws(
|
|
226
|
+
() => resolveAsyncResumeTarget({ id: "run-pending", index: 1 }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") }),
|
|
227
|
+
/pending and has not started yet/,
|
|
228
|
+
);
|
|
229
|
+
} finally {
|
|
230
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("resolves a completed multi-child run when an index and per-child session file are available", () => {
|
|
235
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-async-resume-multi-"));
|
|
236
|
+
try {
|
|
237
|
+
const asyncRoot = path.join(root, "runs");
|
|
238
|
+
const firstSession = path.join(root, "a.jsonl");
|
|
239
|
+
const secondSession = path.join(root, "b.jsonl");
|
|
240
|
+
fs.writeFileSync(firstSession, "", "utf-8");
|
|
241
|
+
fs.writeFileSync(secondSession, "", "utf-8");
|
|
242
|
+
writeJson(path.join(asyncRoot, "run-multi", "status.json"), {
|
|
243
|
+
runId: "run-multi",
|
|
244
|
+
mode: "chain",
|
|
245
|
+
state: "complete",
|
|
246
|
+
startedAt: 100,
|
|
247
|
+
lastUpdate: 200,
|
|
248
|
+
steps: [
|
|
249
|
+
{ agent: "a", status: "complete", sessionFile: firstSession },
|
|
250
|
+
{ agent: "b", status: "complete", sessionFile: secondSession },
|
|
251
|
+
],
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
assert.throws(
|
|
255
|
+
() => resolveAsyncResumeTarget({ id: "run-multi" }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") }),
|
|
256
|
+
/Provide index to choose one/,
|
|
257
|
+
);
|
|
258
|
+
const target = resolveAsyncResumeTarget({ id: "run-multi", index: 1 }, { asyncDirRoot: asyncRoot, resultsDir: path.join(root, "results") });
|
|
259
|
+
assert.equal(target.kind, "revive");
|
|
260
|
+
assert.equal(target.agent, "b");
|
|
261
|
+
assert.equal(target.index, 1);
|
|
262
|
+
assert.equal(target.sessionFile, secondSession);
|
|
263
|
+
} finally {
|
|
264
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("frames the revived follow-up with original run context", () => {
|
|
269
|
+
const task = buildRevivedAsyncTask({
|
|
270
|
+
kind: "revive",
|
|
271
|
+
runId: "run-old",
|
|
272
|
+
state: "complete",
|
|
273
|
+
agent: "worker",
|
|
274
|
+
index: 0,
|
|
275
|
+
intercomTarget: "subagent-worker-run-old-1",
|
|
276
|
+
sessionFile: "/tmp/session.jsonl",
|
|
277
|
+
}, "What changed?");
|
|
278
|
+
|
|
279
|
+
assert.match(task, /Original run: run-old/);
|
|
280
|
+
assert.doesNotMatch(task, /async subagent conversation/);
|
|
281
|
+
assert.match(task, /Original agent: worker/);
|
|
282
|
+
assert.match(task, /Original session file: \/tmp\/session\.jsonl/);
|
|
283
|
+
assert.match(task, /Follow-up:\nWhat changed\?/);
|
|
284
|
+
});
|
|
285
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import { createAtomicJsonWriter } from "../../src/shared/atomic-json.ts";
|
|
5
|
+
|
|
6
|
+
class FakeFs {
|
|
7
|
+
files = new Map<string, string>();
|
|
8
|
+
madeDirs: string[] = [];
|
|
9
|
+
renameCalls = 0;
|
|
10
|
+
failRenameCodes: string[] = [];
|
|
11
|
+
|
|
12
|
+
mkdirSync(dirPath: string): void {
|
|
13
|
+
this.madeDirs.push(dirPath);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
writeFileSync(filePath: string, contents: string): void {
|
|
17
|
+
this.files.set(filePath, contents);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
renameSync(sourcePath: string, targetPath: string): void {
|
|
21
|
+
this.renameCalls++;
|
|
22
|
+
const failureCode = this.failRenameCodes.shift();
|
|
23
|
+
if (failureCode) {
|
|
24
|
+
const error = new Error(`rename failed with ${failureCode}`) as NodeJS.ErrnoException;
|
|
25
|
+
error.code = failureCode;
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
const contents = this.files.get(sourcePath);
|
|
29
|
+
if (contents === undefined) throw new Error(`missing source file: ${sourcePath}`);
|
|
30
|
+
this.files.delete(sourcePath);
|
|
31
|
+
this.files.set(targetPath, contents);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
rmSync(filePath: string): void {
|
|
35
|
+
this.files.delete(filePath);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createWriter(fakeFs: FakeFs, waits: number[]) {
|
|
40
|
+
return createAtomicJsonWriter({
|
|
41
|
+
fs: fakeFs as any,
|
|
42
|
+
now: () => 12345,
|
|
43
|
+
pid: 678,
|
|
44
|
+
random: () => 0.5,
|
|
45
|
+
retryRenameErrors: true,
|
|
46
|
+
retryDelaysMs: [1, 2, 3],
|
|
47
|
+
wait: (delayMs) => waits.push(delayMs),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe("writeAtomicJson", () => {
|
|
52
|
+
it("retries transient rename failures before replacing the target", () => {
|
|
53
|
+
const fakeFs = new FakeFs();
|
|
54
|
+
fakeFs.failRenameCodes = ["EPERM", "EBUSY"];
|
|
55
|
+
const waits: number[] = [];
|
|
56
|
+
const writeAtomicJson = createWriter(fakeFs, waits);
|
|
57
|
+
const targetPath = path.join("/tmp", "status.json");
|
|
58
|
+
|
|
59
|
+
writeAtomicJson(targetPath, { state: "running" });
|
|
60
|
+
|
|
61
|
+
assert.equal(fakeFs.renameCalls, 3);
|
|
62
|
+
assert.deepEqual(waits, [1, 2]);
|
|
63
|
+
assert.deepEqual(fakeFs.madeDirs, [path.dirname(targetPath)]);
|
|
64
|
+
assert.equal(fakeFs.files.get(targetPath), JSON.stringify({ state: "running" }, null, 2));
|
|
65
|
+
assert.equal(fakeFs.files.size, 1);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("uses longer default retries for transient Windows rename locks", () => {
|
|
69
|
+
const fakeFs = new FakeFs();
|
|
70
|
+
fakeFs.failRenameCodes = ["EPERM", "EPERM", "EPERM", "EPERM", "EPERM", "EPERM"];
|
|
71
|
+
const waits: number[] = [];
|
|
72
|
+
const writeAtomicJson = createAtomicJsonWriter({
|
|
73
|
+
fs: fakeFs as any,
|
|
74
|
+
now: () => 12345,
|
|
75
|
+
pid: 678,
|
|
76
|
+
random: () => 0.5,
|
|
77
|
+
retryRenameErrors: true,
|
|
78
|
+
wait: (delayMs) => waits.push(delayMs),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
writeAtomicJson(path.join("/tmp", "status.json"), { state: "running" });
|
|
82
|
+
|
|
83
|
+
assert.equal(fakeFs.renameCalls, 7);
|
|
84
|
+
assert.deepEqual(waits, [10, 25, 50, 100, 200, 500]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("throws non-retryable rename failures without retrying", () => {
|
|
88
|
+
const fakeFs = new FakeFs();
|
|
89
|
+
fakeFs.failRenameCodes = ["ENOENT"];
|
|
90
|
+
const waits: number[] = [];
|
|
91
|
+
const writeAtomicJson = createWriter(fakeFs, waits);
|
|
92
|
+
|
|
93
|
+
assert.throws(() => writeAtomicJson(path.join("/tmp", "status.json"), { state: "running" }), /ENOENT/);
|
|
94
|
+
assert.equal(fakeFs.renameCalls, 1);
|
|
95
|
+
assert.deepEqual(waits, []);
|
|
96
|
+
assert.equal(fakeFs.files.size, 0);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("cleans up the temp file after retryable failures are exhausted", () => {
|
|
100
|
+
const fakeFs = new FakeFs();
|
|
101
|
+
fakeFs.failRenameCodes = ["EPERM", "EPERM", "EPERM", "EPERM"];
|
|
102
|
+
const waits: number[] = [];
|
|
103
|
+
const writeAtomicJson = createWriter(fakeFs, waits);
|
|
104
|
+
const targetPath = path.join("/tmp", "status.json");
|
|
105
|
+
|
|
106
|
+
assert.throws(() => writeAtomicJson(targetPath, { state: "running" }), /EPERM/);
|
|
107
|
+
assert.equal(fakeFs.renameCalls, 4);
|
|
108
|
+
assert.deepEqual(waits, [1, 2, 3]);
|
|
109
|
+
assert.equal(fakeFs.files.has(targetPath), false);
|
|
110
|
+
assert.equal(fakeFs.files.size, 0);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import {
|
|
6
|
+
appendRunnerStepsToStatus,
|
|
7
|
+
consumeChainAppendRequests,
|
|
8
|
+
countPendingChainAppendRequests,
|
|
9
|
+
enqueueChainAppendRequest,
|
|
10
|
+
readPendingChainAppendRequests,
|
|
11
|
+
runnerStepOutputNames,
|
|
12
|
+
} from "../../src/runs/background/chain-append.ts";
|
|
13
|
+
import type { AsyncStatus } from "../../src/shared/types.ts";
|
|
14
|
+
import type { RunnerStep } from "../../src/runs/shared/parallel-utils.ts";
|
|
15
|
+
import { createTempDir, removeTempDir } from "../support/helpers.ts";
|
|
16
|
+
|
|
17
|
+
function writeStatus(asyncDir: string, status: Partial<AsyncStatus> & Pick<AsyncStatus, "runId" | "mode" | "state" | "startedAt">): void {
|
|
18
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
19
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify(status), "utf-8");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function readStatus(asyncDir: string): AsyncStatus {
|
|
23
|
+
return JSON.parse(fs.readFileSync(path.join(asyncDir, "status.json"), "utf-8")) as AsyncStatus;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function runnerStep(agent: string, task = "Use {previous}"): RunnerStep {
|
|
27
|
+
return {
|
|
28
|
+
agent,
|
|
29
|
+
task,
|
|
30
|
+
inheritProjectContext: false,
|
|
31
|
+
inheritSkills: false,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe("chain append requests", () => {
|
|
36
|
+
it("persists append requests for running async chains and records pending status", () => {
|
|
37
|
+
const root = createTempDir("pi-chain-append-");
|
|
38
|
+
try {
|
|
39
|
+
const asyncDir = path.join(root, "run-a");
|
|
40
|
+
writeStatus(asyncDir, {
|
|
41
|
+
runId: "run-a",
|
|
42
|
+
mode: "chain",
|
|
43
|
+
state: "running",
|
|
44
|
+
startedAt: 100,
|
|
45
|
+
lastUpdate: 100,
|
|
46
|
+
chainStepCount: 1,
|
|
47
|
+
steps: [{ agent: "scout", status: "running" }],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const result = enqueueChainAppendRequest({
|
|
51
|
+
asyncDir,
|
|
52
|
+
runId: "run-a",
|
|
53
|
+
steps: [runnerStep("worker")],
|
|
54
|
+
now: 200,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
assert.equal(result.pendingCount, 1);
|
|
58
|
+
assert.equal(countPendingChainAppendRequests(asyncDir), 1);
|
|
59
|
+
const status = readStatus(asyncDir);
|
|
60
|
+
assert.equal(status.pendingAppends, 1);
|
|
61
|
+
assert.equal(status.lastUpdate, 200);
|
|
62
|
+
const eventLog = fs.readFileSync(path.join(asyncDir, "events.jsonl"), "utf-8");
|
|
63
|
+
assert.match(eventLog, /subagent\.chain\.append\.requested/);
|
|
64
|
+
|
|
65
|
+
const consumed = consumeChainAppendRequests(asyncDir);
|
|
66
|
+
assert.equal(consumed.length, 1);
|
|
67
|
+
assert.equal(consumed[0]!.id, result.request.id);
|
|
68
|
+
assert.equal(countPendingChainAppendRequests(asyncDir), 0);
|
|
69
|
+
} finally {
|
|
70
|
+
removeTempDir(root);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("reads pending append requests without consuming them and reports reserved output names", () => {
|
|
75
|
+
const root = createTempDir("pi-chain-append-pending-");
|
|
76
|
+
try {
|
|
77
|
+
const asyncDir = path.join(root, "run-pending");
|
|
78
|
+
writeStatus(asyncDir, {
|
|
79
|
+
runId: "run-pending",
|
|
80
|
+
mode: "chain",
|
|
81
|
+
state: "running",
|
|
82
|
+
startedAt: 100,
|
|
83
|
+
steps: [{ agent: "scout", status: "running" }],
|
|
84
|
+
});
|
|
85
|
+
enqueueChainAppendRequest({
|
|
86
|
+
asyncDir,
|
|
87
|
+
runId: "run-pending",
|
|
88
|
+
steps: [{
|
|
89
|
+
parallel: [
|
|
90
|
+
{ ...runnerStep("worker"), outputName: "draft" },
|
|
91
|
+
{ ...runnerStep("reviewer"), outputName: "review" },
|
|
92
|
+
],
|
|
93
|
+
}],
|
|
94
|
+
now: 200,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const pending = readPendingChainAppendRequests(asyncDir);
|
|
98
|
+
|
|
99
|
+
assert.equal(pending.length, 1);
|
|
100
|
+
assert.deepEqual(runnerStepOutputNames(pending[0]!.steps), ["draft", "review"]);
|
|
101
|
+
assert.equal(countPendingChainAppendRequests(asyncDir), 1);
|
|
102
|
+
} finally {
|
|
103
|
+
removeTempDir(root);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("rejects terminal and non-chain async runs", () => {
|
|
108
|
+
const root = createTempDir("pi-chain-append-reject-");
|
|
109
|
+
try {
|
|
110
|
+
const completeDir = path.join(root, "complete");
|
|
111
|
+
writeStatus(completeDir, {
|
|
112
|
+
runId: "complete",
|
|
113
|
+
mode: "chain",
|
|
114
|
+
state: "complete",
|
|
115
|
+
startedAt: 100,
|
|
116
|
+
steps: [{ agent: "scout", status: "complete" }],
|
|
117
|
+
});
|
|
118
|
+
assert.throws(
|
|
119
|
+
() => enqueueChainAppendRequest({ asyncDir: completeDir, runId: "complete", steps: [runnerStep("worker")] }),
|
|
120
|
+
/only running chain runs/,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const parallelDir = path.join(root, "parallel");
|
|
124
|
+
writeStatus(parallelDir, {
|
|
125
|
+
runId: "parallel",
|
|
126
|
+
mode: "parallel",
|
|
127
|
+
state: "running",
|
|
128
|
+
startedAt: 100,
|
|
129
|
+
steps: [{ agent: "scout", status: "running" }],
|
|
130
|
+
});
|
|
131
|
+
assert.throws(
|
|
132
|
+
() => enqueueChainAppendRequest({ asyncDir: parallelDir, runId: "parallel", steps: [runnerStep("worker")] }),
|
|
133
|
+
/only active chain runs/,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const drainedDir = path.join(root, "drained");
|
|
137
|
+
writeStatus(drainedDir, {
|
|
138
|
+
runId: "drained",
|
|
139
|
+
mode: "chain",
|
|
140
|
+
state: "running",
|
|
141
|
+
startedAt: 100,
|
|
142
|
+
steps: [{ agent: "scout", status: "complete" }],
|
|
143
|
+
});
|
|
144
|
+
assert.throws(
|
|
145
|
+
() => enqueueChainAppendRequest({ asyncDir: drainedDir, runId: "drained", steps: [runnerStep("worker")] }),
|
|
146
|
+
/no running or pending chain steps left/,
|
|
147
|
+
);
|
|
148
|
+
} finally {
|
|
149
|
+
removeTempDir(root);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("extends async chain status, parallel groups, and workflow graph", () => {
|
|
154
|
+
const status: AsyncStatus = {
|
|
155
|
+
runId: "run-graph",
|
|
156
|
+
mode: "chain",
|
|
157
|
+
state: "running",
|
|
158
|
+
startedAt: 100,
|
|
159
|
+
currentStep: 0,
|
|
160
|
+
chainStepCount: 1,
|
|
161
|
+
steps: [{ agent: "scout", status: "complete" }],
|
|
162
|
+
parallelGroups: [],
|
|
163
|
+
workflowGraph: {
|
|
164
|
+
runId: "run-graph",
|
|
165
|
+
mode: "chain",
|
|
166
|
+
phases: [],
|
|
167
|
+
nodes: [{
|
|
168
|
+
id: "step-0",
|
|
169
|
+
kind: "step",
|
|
170
|
+
agent: "scout",
|
|
171
|
+
label: "scout",
|
|
172
|
+
status: "completed",
|
|
173
|
+
flatIndex: 0,
|
|
174
|
+
stepIndex: 0,
|
|
175
|
+
}],
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
const appended: RunnerStep[] = [
|
|
179
|
+
runnerStep("worker"),
|
|
180
|
+
{
|
|
181
|
+
parallel: [
|
|
182
|
+
runnerStep("reviewer"),
|
|
183
|
+
runnerStep("auditor"),
|
|
184
|
+
],
|
|
185
|
+
concurrency: 2,
|
|
186
|
+
},
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
const result = appendRunnerStepsToStatus({ status, steps: appended, now: 300, pendingAppends: 0 });
|
|
190
|
+
|
|
191
|
+
assert.deepEqual(result, { addedChainSteps: 2, addedFlatSteps: 3 });
|
|
192
|
+
assert.equal(status.chainStepCount, 3);
|
|
193
|
+
assert.equal(status.pendingAppends, 0);
|
|
194
|
+
assert.equal(status.lastUpdate, 300);
|
|
195
|
+
assert.deepEqual(status.steps?.map((step) => `${step.agent}:${step.status}`), [
|
|
196
|
+
"scout:complete",
|
|
197
|
+
"worker:pending",
|
|
198
|
+
"reviewer:pending",
|
|
199
|
+
"auditor:pending",
|
|
200
|
+
]);
|
|
201
|
+
assert.deepEqual(status.parallelGroups, [{ start: 2, count: 2, stepIndex: 2 }]);
|
|
202
|
+
assert.equal(status.workflowGraph?.nodes[1]?.id, "step-1");
|
|
203
|
+
assert.equal(status.workflowGraph?.nodes[2]?.kind, "parallel-group");
|
|
204
|
+
assert.deepEqual(status.workflowGraph?.nodes[2]?.children?.map((child) => child.flatIndex), [2, 3]);
|
|
205
|
+
});
|
|
206
|
+
});
|