Skip to content

Commit 13dfa1d

Browse files
committed
test(harness): accept async prompt cleanup finalizer
1 parent e7151f2 commit 13dfa1d

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎packages/opencode/test/upstream/bridge-merge-e2e.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,11 @@ describe("E2E: SessionStatus.set async drift fixed (cycle 4)", () => {
687687
expect(content).toMatch(/export\s+async\s+function\s+cancel\s*\(/)
688688
})
689689

690-
test("SessionPrompt.prompt uses `await using` for cancel disposer", async () => {
690+
test("SessionPrompt.prompt awaits cancel before restoring idle in its async disposer", async () => {
691691
const content = readFileSync(path.join(srcDir, "session", "prompt.ts"), "utf-8")
692-
expect(content).toMatch(/await\s+using\s+_\s*=\s*defer\(\s*\(\s*\)\s*=>\s*cancel\s*\(/)
692+
expect(content).toMatch(
693+
/await\s+using\s+_\s*=\s*defer\(\s*async\s*\(\s*\)\s*=>\s*\{[\s\S]*?await\s+cancel\s*\(\s*sessionID\s*\)[\s\S]*?await\s+SessionStatus\.set\s*\(\s*sessionID\s*,\s*\{\s*type:\s*"idle"/,
694+
)
693695
})
694696
})
695697

‎packages/opencode/test/upstream/bridge-merge-v3.test.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,11 +723,13 @@ describe("bridge merge cycle 4: SessionStatus.set async drift", () => {
723723
expect(content).toMatch(/export\s+async\s+function\s+cancel\s*\(/)
724724
})
725725

726-
test("SessionPrompt.prompt uses `await using` for cancel disposer (not plain `using`)", async () => {
726+
test("SessionPrompt.prompt awaits cancel before restoring idle in its async disposer", async () => {
727727
const content = await readText(path.join(srcDir, "session", "prompt.ts"))
728-
// cancel() became async, so the defer disposer must be awaited or the cleanup
729-
// race-condition returns at function scope before idle state flushes.
730-
expect(content).toMatch(/await\s+using\s+_\s*=\s*defer\(\s*\(\s*\)\s*=>\s*cancel\s*\(/)
728+
// The disposer is async because both operations must settle before prompt()
729+
// leaves scope. Keep the order: cancel first, then the fail-safe idle write.
730+
expect(content).toMatch(
731+
/await\s+using\s+_\s*=\s*defer\(\s*async\s*\(\s*\)\s*=>\s*\{[\s\S]*?await\s+cancel\s*\(\s*sessionID\s*\)[\s\S]*?await\s+SessionStatus\.set\s*\(\s*sessionID\s*,\s*\{\s*type:\s*"idle"/,
732+
)
731733
})
732734
})
733735

0 commit comments

Comments
 (0)