Skip to content

Commit bc843bb

Browse files
Claude Agentclaude
andcommitted
test(opencode): add headless E2E + background-abort-mix coverage for nested subagents
Issue 8 (nested-headless.test.ts): a full headless end-to-end against the REAL server prompt loop (the entrypoint `opencode run`/`opencode serve` reach over the instance HTTP API, not the in-process `SessionPrompt.loop` seam the T7 suite drives). Drives `sdk.session.prompt` over the wire against a deterministic TestLLMServer and reads back the persisted session tree plus the per-level request bodies. Covers a depth-3 spawn chain (tree nests, results bubble up, level-at-maxDepth loses task+workflow at the wire), the typed SubagentResumeError surfacing for an ancestor resume instead of hanging, and the SubagentTreeLimitError once the lifetime cap is exhausted. Issue 9 (nested-background-abort.test.ts): the abort cascade is covered for pure-foreground chains and a pure-background release race, but not the MIX. Drives a parent with background AND foreground children live at once across levels through the real prompt loop with experimental background subagents on, aborts the parent, and verifies every child of both modes terminates with no orphaned background job, the release-race fix (5582da5) stays closed, and cancel never blocks on the foreground hang (no permit/budget wait). task.ts: the three no-unsafe-type-assertion oxlint warnings are false positives — the casts narrow the intentionally loose `ctx.extra: { [key: string]: unknown }` tool bag and are load-bearing (removing any one breaks the typecheck). Suppressed with targeted oxlint-disable-next-line directives plus a rationale; no logic change. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 11c850a commit bc843bb

3 files changed

Lines changed: 867 additions & 2 deletions

File tree

‎packages/opencode/src/tool/task.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ export const TaskTool = Tool.define(
196196
}
197197
// Budget spawn gate (design-final §4.6, soft cap): an exhausted
198198
// shared turn pool refuses NEW subagents while running ones finish.
199-
// No pool (the interactive default) means no gate.
199+
// No pool (the interactive default) means no gate. The cast narrows
200+
// the loosely-typed ctx.extra bag (false positive, see ops above).
201+
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion
200202
const pool = ctx.extra?.turnBudget as TurnBudget.Pool | undefined
201203
if (pool !== undefined) {
202204
const headroom = TurnBudget.remaining(pool)
@@ -272,6 +274,10 @@ export const TaskTool = Tool.define(
272274
metadata,
273275
})
274276

277+
// ctx.extra is the loosely-typed `{ [key: string]: unknown }` tool bag, so
278+
// narrowing the promptOps it carries is required (removing the assertion
279+
// breaks the typecheck) — a false positive for no-unsafe-type-assertion.
280+
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion
275281
const ops = ctx.extra?.promptOps as TaskPromptOps
276282
if (!ops) return yield* Effect.fail(new Error("TaskTool requires promptOps in ctx.extra"))
277283

@@ -286,7 +292,9 @@ export const TaskTool = Tool.define(
286292
// the previous behavior (rootID === ctx.sessionID).
287293
permissionSessionID: rootID,
288294
// The shared turn pool travels BY REFERENCE into the child loop so
289-
// all nesting levels charge the root turn's budget (§4.6).
295+
// all nesting levels charge the root turn's budget (§4.6). The cast
296+
// narrows the loosely-typed ctx.extra bag (false positive, see above).
297+
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion
290298
turnBudgetPool: ctx.extra?.turnBudget as TurnBudget.Pool | undefined,
291299
model: {
292300
modelID: model.modelID,

0 commit comments

Comments
 (0)