Skip to content

Commit 8c2bd65

Browse files
committed
test: a post-result cut after a Cursor-side AwaitShell sleep or timed-out wait refuses as opaque-activity
1 parent 2ea6994 commit 8c2bd65

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

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

Lines changed: 44 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+
"await-sleep", "await-timed-out", "await-named-poll", "await-finished", "web-fetch",
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-"))
@@ -490,6 +491,46 @@ describe("checkpoint eligibility across host results", () => {
490491
if (scenario === "missing-read" || scenario === "refused-read") {
491492
send({ exec_server_message: { id: 60, read_args: { path: path.join(root, "absent.txt"), tool_call_id: "absent" } } })
492493
}
494+
// AwaitShell runs in Cursor; only its lifecycle reaches the provider. The schema lacks AwaitToolCall.result #2:
495+
// AwaitResult success #4 { complete #1 / still_running #2 { task_id #1, runtime_ms #2, output_file_path #3,
496+
// output_length #4, exit_code #7 } }. A sleep's args hold only block_until_ms #2.
497+
if (scenario === "await-sleep" || scenario === "await-timed-out" || scenario === "await-named-poll"
498+
|| scenario === "await-finished") {
499+
const varint = (value: number) => {
500+
const out: number[] = []
501+
for (; value > 0x7f; value >>>= 7) out.push((value & 0x7f) | 0x80)
502+
return [...out, value]
503+
}
504+
const bytes = (fn: number, value: number[]) => [...varint((fn << 3) | 2), ...varint(value.length), ...value]
505+
const text = (fn: number, value: string) => bytes(fn, [...Buffer.from(value)])
506+
const number = (fn: number, value: number) => [...varint(fn << 3), ...varint(value)]
507+
const sleep = scenario === "await-sleep"
508+
const argFields = sleep ? number(2, 20_000) : [...text(1, "7"), ...number(2, 30_000)]
509+
send({ interaction_update: { tool_call_started: { call_id: "wait", tool_call: { await_tool_call: {
510+
args: sleep ? { block_until_ms: 20_000 } : { task_id: "7", block_until_ms: 30_000 },
511+
} } } } })
512+
if (!sleep) {
513+
const env = sessionManager.findOpenByOpenCodeSessionId(`ses_result_history_${scenario}`)!.requestContext.env as { project_folder: string }
514+
const record = path.join(env.project_folder, "terminals", "7.txt")
515+
fs.mkdirSync(path.dirname(record), { recursive: true })
516+
fs.writeFileSync(record, "running\n")
517+
for (const poll of [50, 51]) {
518+
send({ exec_server_message: { id: poll, read_args: { path: record,
519+
...scenario === "await-named-poll" ? { tool_call_id: "wait" } : {} } } })
520+
}
521+
}
522+
const task = [...text(1, "7"), ...number(2, 30_000), ...text(3, "terminals/7.txt"), ...number(4, 812)]
523+
const result = bytes(2, bytes(4, sleep ? bytes(1, number(2, 20_000))
524+
: scenario === "await-finished" ? bytes(1, [...task, ...number(7, 0)]) : bytes(2, task)))
525+
const completion = bytes(3, [...text(1, "wait"), ...bytes(2, bytes(42, [...bytes(1, argFields), ...result]))])
526+
stream.write(frame(Uint8Array.from(bytes(1, completion))))
527+
}
528+
// A call Cursor ran itself whose result history cannot hold.
529+
if (scenario === "web-fetch") {
530+
const fetch = { web_fetch_tool_call: { args: { url: "https://example.com/status" } } }
531+
send({ interaction_update: { tool_call_started: { call_id: "fetch", tool_call: fetch } } })
532+
send({ interaction_update: { tool_call_completed: { call_id: "fetch", tool_call: fetch } } })
533+
}
493534
// A new file's edit: the provider answers its read with an empty file, then the write goes to the host.
494535
if (newFileEdit) {
495536
const target = path.join(root, "created.txt")
@@ -564,7 +605,9 @@ describe("checkpoint eligibility across host results", () => {
564605
if (scenario === "missing-history") prompt.splice(1, 2)
565606
if (scenario === "complete" || scenario === "announced" || scenario === "announced-shell" || scenario === "inline-catalog"
566607
|| scenario === "unacknowledged-checkpoint" || scenario === "terminal-poll"
567-
|| scenario === "missing-read" || scenario === "new-file-edit") {
608+
|| scenario === "missing-read" || scenario === "new-file-edit"
609+
// A wait that timed out, or a plain sleep, changed nothing and told the model nothing history lacks.
610+
|| scenario === "await-sleep" || scenario === "await-timed-out" || scenario === "await-named-poll") {
568611
const parts = await read()
569612
expect(parts.some(part => part.type === "finish" && part.finishReason.unified === "stop")).toBe(true)
570613
expect(parts.some(part => part.type === "tool-call")).toBe(false)

0 commit comments

Comments
 (0)