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
| 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 osconfig from "@distilled.cloud/gcp/osconfig_v2"; |
| 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 | osconfig.getProjectsLocationsGlobalPolicyOrchestrators({ name }).pipe( |
| 16 | Effect.as("found" as const), |
| 17 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 18 | Effect.repeat({ |
| 19 | schedule: Schedule.spaced("1 second"), |
| 20 | until: (status) => status === "gone", |
| 21 | times: 10, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | // The OS Config API is disabled on the testing project (every call fails |
| 26 | // with ServiceDisabled). Set GCP_TEST_OSCONFIG=1 on a project with OS Config |
| 27 | // enabled. |
| 28 | const runLifecycle = !!process.env.GCP_TEST_OSCONFIG; |
| 29 | |
| 30 | test.provider( |
| 31 | "getProjectsLocationsGlobalPolicyOrchestrators on a missing orchestrator fails with a typed tag", |
| 32 | (stack) => |
| 33 | Effect.gen(function* () { |
| 34 | const { project } = yield* GcpEnvironment.current; |
| 35 | const parent = `projects/${project}/locations/global`; |
| 36 | yield* stack.destroy(); |
| 37 | |
| 38 | const error = yield* Effect.flip( |
| 39 | osconfig.getProjectsLocationsGlobalPolicyOrchestrators({ |
| 40 | name: `${parent}/policyOrchestrators/alchemy-missing-orch`, |
| 41 | }), |
| 42 | ); |
| 43 | expect(["ServiceDisabled", "NotFound"]).toContain(error._tag); |
| 44 | |
| 45 | yield* stack.destroy(); |
| 46 | }).pipe(logLevel), |
| 47 | { tags: ["provider:gcp", "provider:gcp:osconfig", "live"], timeout: 90_000 }, |
| 48 | ); |
| 49 | |
| 50 | test.provider.skipIf(!runLifecycle)( |
| 51 | "create, update, and delete a project policy orchestrator", |
| 52 | (stack) => |
| 53 | Effect.gen(function* () { |
| 54 | const { project } = yield* GcpEnvironment.current; |
| 55 | const parent = `projects/${project}/locations/global`; |
| 56 | yield* stack.destroy(); |
| 57 | |
| 58 | const created = yield* stack.deploy( |
| 59 | Effect.gen(function* () { |
| 60 | return yield* GCP.OSConfig.ProjectsLocationsGlobalPolicyOrchestrator("Debian", { |
| 61 | description: "validation only", |
| 62 | labels: { env: "test" }, |
| 63 | state: "STOPPED", |
| 64 | }); |
| 65 | }), |
| 66 | ); |
| 67 | |
| 68 | expect(created.policyOrchestratorId).toEqual(expect.any(String)); |
| 69 | expect(created.parent).toEqual(parent); |
| 70 | expect(created.name).toEqual(`${parent}/policyOrchestrators/${created.policyOrchestratorId}`); |
| 71 | expect(created.action).toEqual("UPSERT"); |
| 72 | expect(created.state).toEqual("STOPPED"); |
| 73 | expect(created.description).toEqual("validation only"); |
| 74 | expect(created.labels).toMatchObject({ env: "test" }); |
| 75 | |
| 76 | const fetched = yield* osconfig.getProjectsLocationsGlobalPolicyOrchestrators({ |
| 77 | name: created.name, |
| 78 | }); |
| 79 | expect(fetched.name).toEqual(created.name); |
| 80 | expect(fetched.labels?.env).toEqual("test"); |
| 81 | expect(fetched.state).toEqual("STOPPED"); |
| 82 | |
| 83 | const updated = yield* stack.deploy( |
| 84 | Effect.gen(function* () { |
| 85 | return yield* GCP.OSConfig.ProjectsLocationsGlobalPolicyOrchestrator("Debian", { |
| 86 | policyOrchestratorId: created.policyOrchestratorId, |
| 87 | description: "updated", |
| 88 | labels: { env: "prod", role: "os" }, |
| 89 | state: "STOPPED", |
| 90 | }); |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | expect(updated.name).toEqual(created.name); |
| 95 | expect(updated.description).toEqual("updated"); |
| 96 | expect(updated.labels).toMatchObject({ env: "prod", role: "os" }); |
| 97 | |
| 98 | const refetched = yield* osconfig.getProjectsLocationsGlobalPolicyOrchestrators({ |
| 99 | name: created.name, |
| 100 | }); |
| 101 | expect(refetched.description).toEqual("updated"); |
| 102 | expect(refetched.labels?.env).toEqual("prod"); |
| 103 | |
| 104 | yield* stack.destroy(); |
| 105 | const gone = yield* waitUntilGone(created.name); |
| 106 | expect(gone).toEqual("gone"); |
| 107 | }).pipe(logLevel), |
| 108 | { tags: ["provider:gcp", "provider:gcp:osconfig", "live"], timeout: 90_000 }, |
| 109 | ); |