@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 113 lines 4.16 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as osconfig from "@distilled.cloud/gcp/osconfig_v2";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (name: string) =>
14 osconfig.getOrganizationsLocationsGlobalPolicyOrchestrators({ name }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 // The OS Config API is disabled on the testing project (every call fails
25 // with ServiceDisabled). Set GCP_TEST_OSCONFIG=1 and GOOGLE_ORGANIZATION_ID
26 // on a project with OS Config enabled and org-level OS Config roles.
27 const organizationId = process.env.GOOGLE_ORGANIZATION_ID;
28 const runLifecycle = !!process.env.GCP_TEST_OSCONFIG && !!organizationId;
29
30 const organizationOf = () =>
31 Effect.succeed(
32 organizationId === undefined
33 ? ""
34 : organizationId.startsWith("organizations/")
35 ? organizationId
36 : `organizations/${organizationId}`,
37 );
38
39 test.provider(
40 "getOrganizationsLocationsGlobalPolicyOrchestrators on a missing orchestrator fails with a typed tag",
41 (stack) =>
42 Effect.gen(function* () {
43 yield* stack.destroy();
44
45 const organization = (yield* organizationOf()) || "organizations/0";
46 const error = yield* Effect.flip(
47 osconfig.getOrganizationsLocationsGlobalPolicyOrchestrators({
48 name: `${organization}/locations/global/policyOrchestrators/alchemy-missing-orch`,
49 }),
50 );
51 expect(["ServiceDisabled", "Forbidden"]).toContain(error._tag);
52
53 yield* stack.destroy();
54 }).pipe(logLevel),
55 { tags: ["provider:gcp", "provider:gcp:osconfig", "live"], timeout: 90_000 },
56 );
57
58 test.provider.skipIf(!runLifecycle)(
59 "create, update, and delete an organization policy orchestrator",
60 (stack) =>
61 Effect.gen(function* () {
62 yield* stack.destroy();
63
64 const organization = yield* organizationOf();
65
66 const created = yield* stack.deploy(
67 Effect.gen(function* () {
68 return yield* GCP.OSConfig.OrganizationsLocationsGlobalPolicyOrchestrator("Debian", {
69 organizationId: organization,
70 description: "org validation",
71 labels: { env: "test" },
72 state: "STOPPED",
73 });
74 }),
75 );
76
77 expect(created.policyOrchestratorId).toEqual(expect.any(String));
78 expect(created.organizationId).toEqual(organization.replace("organizations/", ""));
79 expect(created.parent).toEqual(`${organization}/locations/global`);
80 expect(created.name).toEqual(
81 `${organization}/locations/global/policyOrchestrators/${created.policyOrchestratorId}`,
82 );
83 expect(created.state).toEqual("STOPPED");
84 expect(created.labels).toMatchObject({ env: "test" });
85
86 const fetched = yield* osconfig.getOrganizationsLocationsGlobalPolicyOrchestrators({
87 name: created.name,
88 });
89 expect(fetched.name).toEqual(created.name);
90 expect(fetched.labels?.env).toEqual("test");
91
92 const updated = yield* stack.deploy(
93 Effect.gen(function* () {
94 return yield* GCP.OSConfig.OrganizationsLocationsGlobalPolicyOrchestrator("Debian", {
95 organizationId: organization,
96 policyOrchestratorId: created.policyOrchestratorId,
97 description: "updated org",
98 labels: { env: "prod" },
99 state: "STOPPED",
100 });
101 }),
102 );
103
104 expect(updated.name).toEqual(created.name);
105 expect(updated.description).toEqual("updated org");
106 expect(updated.labels).toMatchObject({ env: "prod" });
107
108 yield* stack.destroy();
109 const gone = yield* waitUntilGone(created.name);
110 expect(gone).toEqual("gone");
111 }).pipe(logLevel),
112 { tags: ["provider:gcp", "provider:gcp:osconfig", "live"], timeout: 90_000 },
113 );