@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 04:45 UTC

main
ts 66 lines 2.51 KB
Raw
1 import { assert, describe, it } from "@effect/vitest"
2 import { Effect } from "effect"
3 import * as esbuild from "esbuild"
4 import { Miniflare } from "miniflare"
5 import { fileURLToPath } from "node:url"
6
7 const workerPath = fileURLToPath(new URL("./fixtures/eventJournal.ts", import.meta.url))
8
9 describe("SqlEventJournal on Durable Object storage", () => {
10 it.live(
11 "keeps local writes working after an enclosing transaction rolls back an import at the maximum timestamp",
12 () =>
13 Effect.gen(function*() {
14 const bundle = yield* Effect.promise(() =>
15 esbuild.build({
16 entryPoints: [workerPath],
17 bundle: true,
18 format: "esm",
19 platform: "browser",
20 target: "es2022",
21 conditions: ["workerd", "worker", "browser"],
22 write: false
23 })
24 )
25 const miniflare = yield* Effect.acquireRelease(
26 Effect.sync(() =>
27 new Miniflare({
28 workers: [{
29 config: {
30 name: "test",
31 compatibilityDate: "2026-09-11",
32 compatibilityFlags: ["nodejs_compat"],
33 manifest: {
34 mainModule: "index.mjs",
35 modules: {
36 "index.mjs": { type: "esm", contents: bundle.outputFiles[0].text }
37 }
38 },
39 exports: {
40 JournalObject: { type: "durable-object", storage: "sqlite" }
41 },
42 env: {
43 JOURNAL: { type: "durable-object", worker: "test", exportName: "JournalObject" }
44 }
45 }
46 }]
47 })
48 ),
49 (miniflare) => Effect.promise(() => miniflare.dispose())
50 )
51 const response = yield* Effect.promise(() => miniflare.dispatchFetch("http://localhost/"))
52 assert.strictEqual(response.status, 200, yield* Effect.promise(() => response.clone().text()))
53 const { entries, rolledBack, written } = yield* Effect.promise(() =>
54 response.json() as Promise<{
55 readonly rolledBack: string
56 readonly written: ReadonlyArray<string> | string
57 readonly entries: ReadonlyArray<string>
58 }>
59 )
60 assert.strictEqual(rolledBack, "Failure")
61 if (typeof written === "string") return assert.fail("the local write failed after the import was rolled back")
62 assert.deepStrictEqual(entries, written)
63 }),
64 { timeout: 40_000 }
65 )
66 })