@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 90 lines 2.95 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 networksecurity from "@distilled.cloud/gcp/networksecurity_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.FAST;
15
16 const waitUntilGone = (name: string) =>
17 networksecurity.getProjectsLocationsSacRealms({ name }).pipe(
18 Effect.as("found" as const),
19 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("2 seconds"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 );
26
27 test.provider(
28 "getProjectsLocationsSacRealms on a missing realm fails with a typed tag",
29 (stack) =>
30 Effect.gen(function* () {
31 yield* stack.destroy();
32
33 const { project } = yield* GcpEnvironment.current;
34 const error = yield* Effect.flip(
35 networksecurity.getProjectsLocationsSacRealms({
36 name: `projects/${project}/locations/global/sacRealms/alchemy-missing`,
37 }),
38 );
39 expect(error._tag).toEqual("NotFound");
40
41 yield* stack.destroy();
42 }).pipe(logLevel),
43 {
44 tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
45 timeout: 90_000,
46 },
47 );
48
49 test.provider.skipIf(!runLifecycle)(
50 "create and delete a sac realm",
51 (stack) =>
52 Effect.gen(function* () {
53 yield* stack.destroy();
54
55 const created = yield* stack.deploy(
56 Effect.gen(function* () {
57 return yield* GCP.NetworkSecurity.SacRealm("Prisma", {
58 securityService: "PALO_ALTO_PRISMA_ACCESS",
59 labels: { env: "test" },
60 });
61 }),
62 );
63
64 expect(created.name).toContain("/sacRealms/");
65 expect(created.name).toContain("/locations/global/");
66 expect(created.sacRealmId).toEqual(expect.any(String));
67 expect(created.location).toEqual("global");
68 expect(created.securityService).toEqual("PALO_ALTO_PRISMA_ACCESS");
69 expect(created.labels).toMatchObject({ env: "test" });
70
71 const fetched = yield* networksecurity.getProjectsLocationsSacRealms({
72 name: created.name,
73 });
74 expect(fetched.name).toEqual(created.name);
75 expect(fetched.securityService).toEqual("PALO_ALTO_PRISMA_ACCESS");
76 expect(fetched.labels?.env).toEqual("test");
77 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
78 true,
79 );
80
81 yield* stack.destroy();
82
83 const gone = yield* waitUntilGone(created.name);
84 expect(gone).toEqual("gone");
85 }).pipe(logLevel),
86 {
87 tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
88 timeout: 90_000,
89 },
90 );