Skip to content

Commit 5b6845f

Browse files
committed
test: a soft-denied force_background_shell earlier in a Run refuses a post-result rebuild
1 parent 15c90db commit 5b6845f

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎test/run-error-host.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ describe("checkpoint eligibility across host results", () => {
414414
"inline-catalog", "spilled-catalog", "unfinished-catalog", "unacknowledged-checkpoint",
415415
"terminal-poll", "terminal-poll-after-result",
416416
"missing-read", "missing-read-after-result", "refused-read", "new-file-edit",
417+
"soft-denied-background", "soft-denied-background-after-result",
417418
] as const) {
418419
it(`recovers a post-result drop only from represented completed work (${scenario})`, async () => {
419420
const root = fs.mkdtempSync(path.join(os.tmpdir(), "cursor-result-history-"))
@@ -427,6 +428,7 @@ describe("checkpoint eligibility across host results", () => {
427428
const shellVariant = scenario === "announced-shell" ? "shell_args" : "shell_stream_args"
428429
const newFileEdit = scenario === "new-file-edit"
429430
const fileReads = newFileEdit || scenario === "missing-read" || scenario === "missing-read-after-result"
431+
const softDenied: number[] = []
430432
scripted = (stream, message) => {
431433
const send = (value: Record<string, unknown>) => stream.write(frame(encodeMessage("AgentServerMessage", value)))
432434
const shell = (callId: string, command: string) => ({ shell_tool_call: { args: { command, tool_call_id: callId } } })
@@ -436,6 +438,13 @@ describe("checkpoint eligibility across host results", () => {
436438
const completed = (callId: string, command: string) => {
437439
if (lifecycle) send({ interaction_update: { tool_call_completed: { call_id: callId, tool_call: shell(callId, command) } } })
438440
}
441+
// ExecServerMessage #30 force_background_shell_args, which the provider soft-denies as unsupported.
442+
// Raw bytes as in test/parallel-pump.test.ts: the schema has no type for the request.
443+
const forceBackground = (id: number, callId: string) => {
444+
const args = [0x0a, callId.length, ...Buffer.from(callId)]
445+
const exec = [0x08, id, 0xf2, 0x01, args.length, ...args]
446+
stream.write(frame(Uint8Array.from([0x12, exec.length, ...exec])))
447+
}
439448
if (message.run_request) {
440449
requests.push(message.run_request as RunRequest)
441450
if (requests.length > (scenario === "followup-before-result" ? 2 : 1)) {
@@ -469,6 +478,7 @@ describe("checkpoint eligibility across host results", () => {
469478
send({ exec_server_message: { id: 1, [shellVariant]: { command: "echo first", tool_call_id: "first" } } })
470479
} else if (message.exec_client_message) {
471480
const id = (message.exec_client_message as { id: number }).id
481+
if ((message.exec_client_message as { force_background_shell_result?: unknown }).force_background_shell_result) softDenied.push(id)
472482
// A result is complete with its exit; a large stdout arrives first.
473483
const hostReply = message.exec_client_message as { shell_stream?: { exit?: unknown }; shell_result?: unknown; write_result?: unknown }
474484
if ((!hostReply.shell_stream?.exit && !hostReply.shell_result && !hostReply.write_result) || delivered.includes(id)) return
@@ -490,6 +500,9 @@ describe("checkpoint eligibility across host results", () => {
490500
if (scenario === "missing-read" || scenario === "refused-read") {
491501
send({ exec_server_message: { id: 60, read_args: { path: path.join(root, "absent.txt"), tool_call_id: "absent" } } })
492502
}
503+
// Cursor asks to move a shell to the background (it does so to deliver a queued host note);
504+
// the provider refuses the unsupported request itself and nothing reaches the host.
505+
if (scenario === "soft-denied-background") forceBackground(70, "first")
493506
// A new file's edit: the provider answers its read with an empty file, then the write goes to the host.
494507
if (newFileEdit) {
495508
const target = path.join(root, "created.txt")
@@ -511,6 +524,7 @@ describe("checkpoint eligibility across host results", () => {
511524
if (scenario === "missing-read-after-result") {
512525
send({ exec_server_message: { id: 60, read_args: { path: path.join(root, "absent.txt"), tool_call_id: "absent" } } })
513526
}
527+
if (scenario === "soft-denied-background-after-result") forceBackground(71, "second")
514528
if (scenario === "malformed-completion" || scenario === "repeated-completion-id") {
515529
// Independent lifecycle wire: completion #3, call_id #1.
516530
// The decoder discards the unknown field or duplicate call id.
@@ -564,7 +578,7 @@ describe("checkpoint eligibility across host results", () => {
564578
if (scenario === "missing-history") prompt.splice(1, 2)
565579
if (scenario === "complete" || scenario === "announced" || scenario === "announced-shell" || scenario === "inline-catalog"
566580
|| scenario === "unacknowledged-checkpoint" || scenario === "terminal-poll"
567-
|| scenario === "missing-read" || scenario === "new-file-edit") {
581+
|| scenario === "missing-read" || scenario === "new-file-edit" || scenario === "soft-denied-background") {
568582
const parts = await read()
569583
expect(parts.some(part => part.type === "finish" && part.finishReason.unified === "stop")).toBe(true)
570584
expect(parts.some(part => part.type === "tool-call")).toBe(false)
@@ -588,6 +602,8 @@ describe("checkpoint eligibility across host results", () => {
588602
expect(requests).toHaveLength(scenario === "followup-before-result" ? 2 : 1)
589603
}
590604
expect(delivered).toEqual([1, 2])
605+
// The provider answered the request itself; nothing reached the host.
606+
if (scenario === "soft-denied-background") expect(softDenied).toEqual([70])
591607
} finally {
592608
sessionManager.dispose()
593609
await settleRunSavesForTests()

0 commit comments

Comments
 (0)