@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 115 lines 4.12 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 networkservices from "@distilled.cloud/gcp/networkservices_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 waitUntilGone = (name: string) =>
15 networkservices.getProjectsLocationsAgentGateways({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsAgentGateways on a missing gateway fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 const { project } = yield* GcpEnvironment.current;
32 const error = yield* Effect.flip(
33 networkservices.getProjectsLocationsAgentGateways({
34 name: `projects/${project}/locations/us-central1/agentGateways/alchemy-missing`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 // Agent gateway create + update + delete takes ~7 minutes.
48 test.provider.skipIf(!process.env.GCP_TEST_SLOW || !!process.env.FAST)(
49 "create, update, and delete an agent gateway",
50 (stack) =>
51 Effect.gen(function* () {
52 yield* stack.destroy();
53
54 const created = yield* stack.deploy(
55 Effect.gen(function* () {
56 return yield* GCP.NetworkServices.AgentGateway("Agents", {
57 location: "us-central1",
58 description: "agent gateway a",
59 labels: { env: "test" },
60 googleManaged: { governedAccessPath: "AGENT_TO_ANYWHERE" },
61 });
62 }),
63 );
64
65 expect(created.name).toContain("/agentGateways/");
66 expect(created.agentGatewayId).toEqual(expect.any(String));
67 expect(created.location).toEqual("us-central1");
68 expect(created.description).toEqual("agent gateway a");
69 expect(created.labels).toMatchObject({ env: "test" });
70 expect(created.googleManaged?.governedAccessPath).toEqual("AGENT_TO_ANYWHERE");
71 expect(created.createTime).toEqual(expect.any(String));
72
73 const fetched = yield* networkservices.getProjectsLocationsAgentGateways({
74 name: created.name,
75 });
76 expect(fetched.name).toEqual(created.name);
77 expect(fetched.description).toEqual("agent gateway a");
78 expect(fetched.labels?.env).toEqual("test");
79 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
80 true,
81 );
82
83 const updated = yield* stack.deploy(
84 Effect.gen(function* () {
85 return yield* GCP.NetworkServices.AgentGateway("Agents", {
86 agentGatewayId: created.agentGatewayId,
87 location: "us-central1",
88 description: "agent gateway b",
89 labels: { env: "prod", role: "agents" },
90 googleManaged: { governedAccessPath: "AGENT_TO_ANYWHERE" },
91 });
92 }),
93 );
94
95 expect(updated.name).toEqual(created.name);
96 expect(updated.description).toEqual("agent gateway b");
97 expect(updated.labels).toMatchObject({ env: "prod", role: "agents" });
98
99 const refetched = yield* networkservices.getProjectsLocationsAgentGateways({
100 name: created.name,
101 });
102 expect(refetched.description).toEqual("agent gateway b");
103 expect(refetched.labels?.env).toEqual("prod");
104 expect(refetched.labels?.role).toEqual("agents");
105
106 yield* stack.destroy();
107
108 const gone = yield* waitUntilGone(created.name);
109 expect(gone).toEqual("gone");
110 }).pipe(logLevel),
111 {
112 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
113 timeout: 900_000,
114 },
115 );