@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, 06:00 UTC

main
ts 69 lines 2.44 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as ConfigProvider from "effect/ConfigProvider";
5 import * as Effect from "effect/Effect";
6 import * as HttpClient from "effect/http/HttpClient";
7 import * as pathe from "pathe";
8 import { expectUrlContains } from "../Utils/Http.ts";
9 import RestArgsCaller from "./fixtures/rpc-rest-args/caller.ts";
10
11 const { test } = Test.make({ providers: Cloudflare.providers() });
12
13 const hostMain = pathe.resolve(import.meta.dirname, "fixtures/rpc-rest-args/host.ts");
14
15 const restArgsHost = () =>
16 Cloudflare.Worker("RestArgsHost", {
17 main: hostMain,
18 env: { REST_ARGS: Cloudflare.DurableObject("RestArgs") },
19 });
20
21 describe(
22 "Durable Object RPC arguments",
23 { tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"] },
24 () => {
25 test.provider(
26 "a plain-JS Durable Object method receives exactly the caller's arguments",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 // The caller binds the host's class by script name, so the host
32 // deploys first.
33 const host = yield* stack.deploy(restArgsHost());
34 const currentConfig = yield* ConfigProvider.ConfigProvider;
35 const caller = yield* stack
36 .deploy(
37 Effect.gen(function* () {
38 yield* restArgsHost();
39 return yield* RestArgsCaller;
40 }),
41 )
42 .pipe(
43 Effect.provideService(
44 ConfigProvider.ConfigProvider,
45 ConfigProvider.orElse(
46 ConfigProvider.fromUnknown({ REST_ARGS_HOST: host.workerName }),
47 currentConfig,
48 ),
49 ),
50 );
51
52 // The caller calls inside a span; a trace context appended to the
53 // call would show up as a third argument.
54 const url = caller.url as string;
55 yield* expectUrlContains(url, '"args":', {
56 timeout: "180 seconds",
57 label: "caller reaches the plain-JS Durable Object",
58 });
59 const client = yield* HttpClient.HttpClient;
60 const response = yield* client.get(url);
61 expect(response.status).toBe(200);
62 expect(yield* response.json).toEqual({ args: ["a", "b"] });
63
64 yield* stack.destroy();
65 }),
66 { timeout: 300_000 },
67 );
68 },
69 );