@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 92 lines 3.2 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 networkconnectivity from "@distilled.cloud/gcp/networkconnectivity_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { defaultNetworkSelfLink } from "../networkQuota.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 const runLifecycle = !process.env.FAST;
16
17 const waitUntilGone = (name: string) =>
18 networkconnectivity.getProjectsLocationsServiceConnectionTokens({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("2 seconds"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider(
29 "getProjectsLocationsServiceConnectionTokens on a missing token fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 networkconnectivity.getProjectsLocationsServiceConnectionTokens({
37 name: `projects/${project}/locations/us-central1/serviceConnectionTokens/alchemy-missing`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41
42 yield* stack.destroy();
43 }).pipe(logLevel),
44 {
45 tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"],
46 timeout: 90_000,
47 },
48 );
49
50 test.provider.skipIf(!runLifecycle)(
51 "create and delete a service connection token",
52 (stack) =>
53 Effect.gen(function* () {
54 const { project } = yield* GcpEnvironment.current;
55 yield* stack.destroy();
56
57 const created = yield* stack.deploy(
58 Effect.gen(function* () {
59 const token = yield* GCP.NetworkConnectivity.ServiceConnectionToken("Consumer", {
60 network: defaultNetworkSelfLink(project),
61 description: "token a",
62 labels: { env: "test" },
63 });
64 return { token };
65 }),
66 );
67
68 expect(created.token.name).toContain("/serviceConnectionTokens/");
69 expect(created.token.location).toEqual("us-central1");
70 expect(created.token.description).toEqual("token a");
71 expect(created.token.labels).toMatchObject({ env: "test" });
72 expect(created.token.serviceConnectionTokenId).toEqual(expect.any(String));
73
74 const fetched = yield* networkconnectivity.getProjectsLocationsServiceConnectionTokens({
75 name: created.token.name,
76 });
77 expect(fetched.name).toEqual(created.token.name);
78 expect(fetched.labels?.env).toEqual("test");
79 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
80 true,
81 );
82
83 yield* stack.destroy();
84
85 const gone = yield* waitUntilGone(created.token.name);
86 expect(gone).toEqual("gone");
87 }).pipe(logLevel),
88 {
89 tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"],
90 timeout: 600_000,
91 },
92 );