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 { |
| 2 | fromDurableObjectState, |
| 3 | type DurableObjectAbortOptions, |
| 4 | } from "@alchemy.run/cloudflare/Workers/DurableObjectState"; |
| 5 | import { describe, expect, it } from "@alchemy.run/test"; |
| 6 | import { RuntimeContext } from "alchemy/RuntimeContext"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | |
| 9 | describe( |
| 10 | "fromDurableObjectState.abort", |
| 11 | { |
| 12 | tags: ["unit", "provider:cloudflare", "provider:cloudflare:worker", "local"], |
| 13 | }, |
| 14 | () => { |
| 15 | const mockState = (abort: (...args: unknown[]) => void) => |
| 16 | fromDurableObjectState({ |
| 17 | id: { toString: () => "id" }, |
| 18 | storage: { sql: {} }, |
| 19 | abort, |
| 20 | } as never); |
| 21 | |
| 22 | it.effect("forwards reason to the raw DurableObjectState", () => |
| 23 | Effect.gen(function* () { |
| 24 | const calls: unknown[][] = []; |
| 25 | const state = mockState((...args) => { |
| 26 | calls.push(args); |
| 27 | }); |
| 28 | yield* state.abort("Hello, World!"); |
| 29 | expect(calls).toEqual([["Hello, World!", undefined]]); |
| 30 | }).pipe(Effect.provide(RuntimeContext.phantom)), |
| 31 | ); |
| 32 | |
| 33 | it.effect("forwards retryAlarm options to the raw DurableObjectState", () => |
| 34 | Effect.gen(function* () { |
| 35 | const calls: unknown[][] = []; |
| 36 | const state = mockState((...args) => { |
| 37 | calls.push(args); |
| 38 | }); |
| 39 | const options: DurableObjectAbortOptions = { retryAlarm: false }; |
| 40 | yield* state.abort("Cleanup complete", options); |
| 41 | expect(calls).toEqual([["Cleanup complete", options]]); |
| 42 | }).pipe(Effect.provide(RuntimeContext.phantom)), |
| 43 | ); |
| 44 | }, |
| 45 | ); |