fix(agent): keep background sandbox tasks running
Auto-approve sandbox Shell only for host-bound task execution, stage native results within their owning session, and preserve active lease state on response stream loss. The repeated failures came from interactive approval in unattended runs and transport cleanup invalidating execution state; focused regressions cover both boundaries.
This commit is contained in:
@@ -714,3 +714,36 @@ describe("streamPromptResponse", () => {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe("background sandbox Shell approval", () => {
|
||||
it.each(["permission.asked", "permission.v2.asked"])("only auto-approves sandbox Shell for %s", async (type) => {
|
||||
const replies: Array<Record<string, unknown>> = [];
|
||||
const runtime = {
|
||||
subscribeEvents: async () => createEventStream([
|
||||
...["shell", "edit", "mcp_fixture_write"].map((action) => ({
|
||||
type,
|
||||
properties: {
|
||||
id: action, sessionID: "runtime-session-1",
|
||||
...(type === "permission.asked"
|
||||
? { permission: action, patterns: ["fixture"], always: [] }
|
||||
: { action, resources: ["fixture"], save: [] }),
|
||||
},
|
||||
})),
|
||||
{ type: "session.idle", properties: { sessionID: "runtime-session-1" } },
|
||||
]),
|
||||
prompt: async () => undefined,
|
||||
messages: async () => [],
|
||||
replyPermission: async (input: Record<string, unknown>) => { replies.push(input); },
|
||||
} as unknown as OpencodeRuntimeAdapter;
|
||||
const events: Array<{ event: string; data: Record<string, unknown> }> = [];
|
||||
await streamPromptResponse({
|
||||
runtime, sessionId: "runtime-session-1", clientSessionId: "client-session-1",
|
||||
message: "后台调查", approvalMode: "request", backgroundSandboxShell: true,
|
||||
write: (event, data) => events.push({ event, data }),
|
||||
});
|
||||
expect(replies).toEqual([{ requestId: "shell", sessionId: "runtime-session-1", reply: "once" }]);
|
||||
expect(events.filter(({ event }) => event === "permission_request")
|
||||
.map(({ data }) => data.permission)).toEqual(["edit", "mcp_fixture_write"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user