Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

test(agent-runtime): retain plain Bash job lifecycle coverage

jeffry887b706ce26580
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index d89def734..7601314f0 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -20497,9 +20497,11 @@ Scenario: E2E-REVIEW-ROUNDS (local desktop, implemented)
loop, deterministic localhost HTTP provider. No external model account.
- Sequence: start a background test, list it, wait for failure and Unicode
output tails; start a service, time out waiting, call default stop, then
- explicitly stop and wait for the same job. The first waits include empty
- `delegationIds`, `mode: all/any`, and `minCompleted: 1`; explicit stop includes
- empty `delegationIds`, matching model-generated redundant defaults.
+ explicitly stop and wait for the same job using plain `{job}` selectors.
+ Then re-read the failed job with empty `delegationIds`, `mode: all`, and
+ `minCompleted: 1`; start a second service, time out with `mode: any` and the
+ same defaults, stop with empty `delegationIds`, and confirm it is stopped.
+ Both plain and model-generated redundant forms retain independent coverage.
- Expected: correct exit code and both final tails, per-stream UTF-8 limits,
cross-session list/read/stop isolation, timeout and default stop preserve Bash,
explicit stop reaches terminal state, repeated reads and desktop output agree.
@@ -20507,8 +20509,9 @@ Scenario: E2E-REVIEW-ROUNDS (local desktop, implemented)
- Runtime tests cover new input/parent abort during a pending Host wait, late
Host rejection, old Host/remote capability behavior, conflicting/malformed
delegation selectors, harmless Bash defaults and conflicting/malformed Bash
- selector rejection, existing delegation
- controls and registration without a subagent catalog.
+ selector rejection, existing delegation controls and registration without a
+ subagent catalog. Plain-job timeout/abort cases remain intact; additional
+ cases exercise both `all` and `any` defaults through those same lifecycles.
- Host tests cover pre-settled observation, repeatable output, Unicode clipping,
ownership lookup, idempotent stop and stop acknowledgement before termination.
Existing Windows child/grandchild cleanup tests remain required; record native
diff --git a/packages/agent-runtime/src/background-job-tools.test.ts b/packages/agent-runtime/src/background-job-tools.test.ts
index 6dd1c3181..522dc6d2b 100644
--- a/packages/agent-runtime/src/background-job-tools.test.ts
+++ b/packages/agent-runtime/src/background-job-tools.test.ts
@@ -125,7 +125,7 @@ describe("session job controls", () => {
await new Promise(resolve => setTimeout(resolve, 1000));
return { ...snapshot, state: "running", exitCode: null };
});
- const result = wait.execute("wait", { job: snapshot.job, delegationIds: [], mode: "all", minCompleted: 1, timeoutSeconds: 2 });
+ const result = wait.execute("wait", { job: snapshot.job, timeoutSeconds: 2 });
await vi.advanceTimersByTimeAsync(2000);
expect((await result).details).toMatchObject({ status: "timeout", job: { state: "running", exitCode: null } });
expect(dispatch.mock.calls.map(call => call[0])).not.toContain("backgroundJobs.stop");
@@ -138,7 +138,38 @@ describe("session job controls", () => {
? { version: 1, supported: true }
: new Promise((_, reject) => { fail = reject; }));
const controller = new AbortController();
- const result = wait.execute("wait", { job: snapshot.job, delegationIds: [], mode: "any", minCompleted: 1 }, controller.signal);
+ const result = wait.execute("wait", { job: snapshot.job }, controller.signal);
+ const assertion = expect(result).rejects.toMatchObject({ errorCode: "TOOL_ABORTED" });
+ await vi.waitFor(() => expect(dispatch).toHaveBeenCalledWith("backgroundJobs.wait", expect.anything()));
+ controller.abort();
+ await assertion;
+ fail(new Error("late transport failure"));
+ await Promise.resolve();
+ expect(dispatch.mock.calls.map(call => call[0])).not.toContain("backgroundJobs.stop");
+ });
+
+ it.each(["all", "any"])("redundant %s defaults preserve the wait deadline without stopping", async mode => {
+ vi.useFakeTimers();
+ const { wait, dispatch, snapshot } = fixture();
+ dispatch.mockImplementation(async method => {
+ if (method.endsWith("capabilities")) return { version: 1, supported: true };
+ await new Promise(resolve => setTimeout(resolve, 1000));
+ return { ...snapshot, state: "running", exitCode: null };
+ });
+ const result = wait.execute("wait", { job: snapshot.job, delegationIds: [], mode, minCompleted: 1, timeoutSeconds: 2 });
+ await vi.advanceTimersByTimeAsync(2000);
+ expect((await result).details).toMatchObject({ status: "timeout", job: { state: "running", exitCode: null } });
+ expect(dispatch.mock.calls.map(call => call[0])).not.toContain("backgroundJobs.stop");
+ });
+
+ it.each(["all", "any"])("redundant %s defaults preserve cancellation and late-failure handling", async mode => {
+ const { wait, dispatch, snapshot } = fixture();
+ let fail: (error: Error) => void = () => {};
+ dispatch.mockImplementation(async method => method.endsWith("capabilities")
+ ? { version: 1, supported: true }
+ : new Promise((_, reject) => { fail = reject; }));
+ const controller = new AbortController();
+ const result = wait.execute("wait", { job: snapshot.job, delegationIds: [], mode, minCompleted: 1 }, controller.signal);
const assertion = expect(result).rejects.toMatchObject({ errorCode: "TOOL_ABORTED" });
await vi.waitFor(() => expect(dispatch).toHaveBeenCalledWith("backgroundJobs.wait", expect.anything()));
controller.abort();
diff --git a/scripts/e2e-session-background-jobs.mjs b/scripts/e2e-session-background-jobs.mjs
index f0221aff6..c64b3583a 100644
--- a/scripts/e2e-session-background-jobs.mjs
+++ b/scripts/e2e-session-background-jobs.mjs
@@ -28,7 +28,7 @@ const host = new Host(resolveHostBinary(), join(scratch, "data"), {
env: { PATH: [dirname(process.execPath), process.env.PATH].filter(Boolean).join(delimiter) },
});
let round = 0;
-let failedJob, serviceJob, foreign;
+let failedJob, serviceJob, foreign, failedSnapshot;
let fixtureFailure;
const calls = [];
const toolResult = (body, id) => {
@@ -54,10 +54,11 @@ const server = createServer(async (req, res) => {
break;
case 2:
assert(toolResult(body, "call-2").includes(failedJob.id));
- name = "TaskWait"; args = { job: failedJob, delegationIds: [], mode: "all", minCompleted: 1, timeoutSeconds: 20 };
+ name = "TaskWait"; args = { job: failedJob, timeoutSeconds: 20 };
break;
case 3: {
const result = parseResult(body, "call-3");
+ failedSnapshot = result;
assert.equal(result.state, "failed");
assert.equal(result.exitCode, 1);
assert.equal(result.truncated, true);
@@ -84,7 +85,7 @@ const server = createServer(async (req, res) => {
await host.call("backgroundJobs.capabilities", { sessionId: owner.id });
assert.equal(observed, false, "waiting must release the global Host lock");
assert.equal((await pending).state, "running");
- name = "TaskWait"; args = { job: serviceJob, delegationIds: [], mode: "any", minCompleted: 1, timeoutSeconds: 1 };
+ name = "TaskWait"; args = { job: serviceJob, timeoutSeconds: 1 };
break;
case 5:
assert.equal(parseResult(body, "call-5").status, "timeout");
@@ -93,7 +94,7 @@ const server = createServer(async (req, res) => {
break;
case 6:
assert.equal((await host.call("backgroundJobs.wait", { sessionId: owner.id, id: serviceJob.id })).state, "running");
- name = "TaskStop"; args = { job: serviceJob, delegationIds: [] };
+ name = "TaskStop"; args = { job: serviceJob };
break;
case 7:
assert.equal(parseResult(body, "call-7").stopRequested, true);
@@ -101,6 +102,32 @@ const server = createServer(async (req, res) => {
break;
case 8:
assert.equal(parseResult(body, "call-8").state, "stopped");
+ name = "TaskWait"; args = { job: failedJob, delegationIds: [], mode: "all", minCompleted: 1, timeoutSeconds: 20 };
+ break;
+ case 9: {
+ const result = parseResult(body, "call-9");
+ for (const key of ["state", "exitCode", "stdout", "stderr", "truncated"]) {
+ assert.deepEqual(result[key], failedSnapshot[key], "redundant wait must preserve " + key);
+ }
+ name = "Bash"; args = { command: "node service.cjs", runInBackground: true };
+ break;
+ }
+ case 10:
+ serviceJob = parseResult(body, "call-10").job;
+ assert.equal(serviceJob.kind, "bash");
+ name = "TaskWait"; args = { job: serviceJob, delegationIds: [], mode: "any", minCompleted: 1, timeoutSeconds: 1 };
+ break;
+ case 11:
+ assert.equal(parseResult(body, "call-11").status, "timeout");
+ assert.equal(parseResult(body, "call-11").state, "running");
+ name = "TaskStop"; args = { job: serviceJob, delegationIds: [] };
+ break;
+ case 12:
+ assert.equal(parseResult(body, "call-12").stopRequested, true);
+ name = "TaskWait"; args = { job: serviceJob, timeoutSeconds: 20 };
+ break;
+ case 13:
+ assert.equal(parseResult(body, "call-13").state, "stopped");
break;
default: throw new Error("Unexpected provider round");
}
@@ -147,7 +174,7 @@ try {
});
await runtime.prompt("Run the background fixtures and inspect their outcomes.", "fixture-user", turnId);
if (fixtureFailure) throw fixtureFailure;
- assert.equal(round, 9);
+ assert.equal(round, 14);
assert.equal(events.some(event => event.type === "error"), false);
const repeated = await host.call("backgroundJobs.wait", { sessionId: owner.id, id: failedJob.id });
assert.equal(repeated.exitCode, 1);
@@ -159,7 +186,7 @@ try {
turnId = undefined;
await configureSession(host, owner, "plan", "auto");
await assert.rejects(host.call("backgroundJobs.wait", { sessionId: owner.id, id: failedJob.id }), error => error.errorCode === "PERMISSION_DENIED");
- console.log(JSON.stringify({ ok: true, calls, rounds: round, shell: shell.id, checks: ["real model tool loop", "no subagents configured", "failure and bounded Unicode output", "cross-session read/stop denied", "wait releases Host lock", "timeout preserves process", "default stop preserves Bash", "explicit stop settles", "repeated reads", "desktop parity", "plan mode denied"] }, null, 2));
+ console.log(JSON.stringify({ ok: true, calls, rounds: round, shell: shell.id, checks: ["real model tool loop", "no subagents configured", "failure and bounded Unicode output", "cross-session read/stop denied", "wait releases Host lock", "timeout preserves process", "default stop preserves Bash", "plain job wait/timeout/stop", "redundant defaults wait/timeout/stop", "explicit stop settles", "repeated reads", "desktop parity", "plan mode denied"] }, null, 2));
} finally {
await runtime?.dispose();
if (turnId) await endTurn(host, turnId, "aborted").catch(() => {});