The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import { expect, test } from "bun:test"; |
| 2 | import { spawnSync } from "node:child_process"; |
| 3 | import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 4 | import { tmpdir } from "node:os"; |
| 5 | import { join, resolve } from "node:path"; |
| 6 | |
| 7 | const adapter = resolve(import.meta.dirname, "../src/Bun.ts"); |
| 8 | const effect = import.meta.resolve("effect/Effect"); |
| 9 | |
| 10 | // A `beforeAll` that outlives bun's hook timeout is interrupted before bun |
| 11 | // gives up on it, so its finalizers run before `afterAll`, the way a deploy |
| 12 | // must record what it created before the file's destroy runs. |
| 13 | test("a hook that outlives its timeout is interrupted before afterAll runs", () => { |
| 14 | const root = mkdtempSync(join(tmpdir(), "alchemy-test-bun-deadline-")); |
| 15 | try { |
| 16 | writeFileSync( |
| 17 | join(root, "deadline.test.ts"), |
| 18 | ` |
| 19 | import * as Test from ${JSON.stringify(adapter)}; |
| 20 | import * as Effect from ${JSON.stringify(effect)}; |
| 21 | const { beforeAll, afterAll } = Test.make({ providers: [] as any }); |
| 22 | let interrupted = false; |
| 23 | beforeAll( |
| 24 | Effect.never.pipe(Effect.onInterrupt(() => Effect.sync(() => { interrupted = true; }))), |
| 25 | { timeout: 12_000 }, |
| 26 | ); |
| 27 | afterAll(Effect.sync(() => console.log("INTERRUPTED_BEFORE_AFTERALL=" + interrupted))); |
| 28 | `, |
| 29 | ); |
| 30 | const result = spawnSync(process.execPath, ["test", "deadline.test.ts"], { |
| 31 | cwd: root, |
| 32 | encoding: "utf8", |
| 33 | timeout: 40_000, |
| 34 | }); |
| 35 | expect(result.stdout + result.stderr).toContain("INTERRUPTED_BEFORE_AFTERALL=true"); |
| 36 | } finally { |
| 37 | rmSync(root, { recursive: true, force: true }); |
| 38 | } |
| 39 | }, 45_000); |