@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 95 lines 3.36 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as compute from "@distilled.cloud/gcp/compute_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const runLifecycle = !!process.env.GCP_TEST_BYOIP && !process.env.FAST;
15
16 const parentPrefix = process.env.GCP_TEST_PAP_PARENT ?? "";
17 const ipCidrRange = process.env.GCP_TEST_PDP_RANGE ?? "203.0.113.0/24";
18
19 const waitUntilGone = (project: string, publicDelegatedPrefix: string) =>
20 compute.getGlobalPublicDelegatedPrefixes({ project, publicDelegatedPrefix }).pipe(
21 Effect.as("found" as const),
22 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
23 Effect.repeat({
24 schedule: Schedule.spaced("2 seconds"),
25 until: (status) => status === "gone",
26 times: 10,
27 }),
28 );
29
30 test.provider(
31 "insertGlobalPublicDelegatedPrefixes with a malformed parentPrefix fails with BadRequest",
32 () =>
33 Effect.gen(function* () {
34 const { project } = yield* GcpEnvironment.current;
35 const error = yield* Effect.flip(
36 compute.insertGlobalPublicDelegatedPrefixes({
37 project,
38 body: {
39 name: "alchemy-pdp-probe",
40 description: "alchemy entitlement probe",
41 parentPrefix: parentPrefix || "does-not-exist",
42 ipCidrRange,
43 },
44 }),
45 );
46 expect(error._tag).toEqual("BadRequest");
47 }).pipe(logLevel),
48 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 60_000 },
49 );
50
51 test.provider.skipIf(!runLifecycle || !parentPrefix)(
52 "create, update, and delete a global public delegated prefix",
53 (stack) =>
54 Effect.gen(function* () {
55 yield* stack.destroy();
56
57 const created = yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* GCP.Compute.GlobalPublicDelegatedPrefix("Byoip", {
60 parentPrefix,
61 ipCidrRange,
62 description: "delegated range",
63 });
64 }),
65 );
66
67 expect(created.prefixName).toEqual(expect.any(String));
68 expect(created.ipCidrRange).toEqual(ipCidrRange);
69 expect(created.description).toEqual("delegated range");
70
71 const fetched = yield* compute.getGlobalPublicDelegatedPrefixes({
72 project: created.project,
73 publicDelegatedPrefix: created.prefixName,
74 });
75 expect(fetched.name).toEqual(created.prefixName);
76 expect(fetched.description).toContain("[alchemy ");
77
78 const updated = yield* stack.deploy(
79 Effect.gen(function* () {
80 return yield* GCP.Compute.GlobalPublicDelegatedPrefix("Byoip", {
81 prefixName: created.prefixName,
82 parentPrefix,
83 ipCidrRange,
84 description: "updated range",
85 });
86 }),
87 );
88 expect(updated.description).toEqual("updated range");
89
90 yield* stack.destroy();
91 const gone = yield* waitUntilGone(created.project, created.prefixName);
92 expect(gone).toEqual("gone");
93 }).pipe(logLevel),
94 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
95 );