@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 54 lines 2.15 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import { CloudflareEnvironment } from "@alchemy.run/cloudflare/CloudflareEnvironment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as Provider from "alchemy/Provider";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import { testName } from "../../names.ts";
9
10 const { test } = Test.make({ providers: Cloudflare.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 // Account collection (pattern b): Gateway rules live under
15 // `/accounts/{id}/gateway/rules`. Deploy one rule, then resolve the provider
16 // with the typed `Provider.findProvider` helper and assert `list()` returns
17 // the exhaustively-paginated set hydrated into the exact `read` Attributes
18 // shape (so the deployed rule's id is present).
19 test.provider(
20 "list enumerates the deployed Gateway rule",
21 (stack) =>
22 Effect.gen(function* () {
23 const { accountId } = yield* yield* CloudflareEnvironment;
24
25 yield* stack.destroy();
26
27 const rule = yield* stack.deploy(
28 Cloudflare.Gateway.Rule("ListRule", {
29 name: testName("alchemy-zt-rule-list"),
30 action: "block",
31 filters: ["dns"],
32 traffic: 'any(dns.domains[*] == "list-test.alchemy-test.example")',
33 enabled: true,
34 }),
35 );
36
37 expect(rule.ruleId).toBeTruthy();
38 expect(rule.accountId).toEqual(accountId);
39
40 const provider = yield* Provider.findProvider(Cloudflare.Gateway.Rule);
41 const all = yield* provider.list();
42
43 // The deployed rule appears in the exhaustively-paginated result, and the
44 // hydrated element matches the `read` Attributes shape exactly.
45 const found = all.find((r) => r.ruleId === rule.ruleId);
46 expect(found).toBeDefined();
47 expect(found?.accountId).toEqual(accountId);
48 expect(found?.action).toEqual("block");
49 expect(found?.name).toEqual(testName("alchemy-zt-rule-list"));
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 { tags: ["provider:cloudflare", "provider:cloudflare:gateway", "live"] },
54 );