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 backupdr from "@distilled.cloud/gcp/backupdr_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 dailyRule = { |
| 15 | ruleId: "daily", |
| 16 | backupRetentionDays: 1, |
| 17 | standardSchedule: { |
| 18 | recurrenceType: "DAILY" as const, |
| 19 | timeZone: "UTC", |
| 20 | backupWindow: { startHourOfDay: 1, endHourOfDay: 5 }, |
| 21 | }, |
| 22 | }; |
| 23 | |
| 24 | const waitUntilGone = (name: string) => |
| 25 | backupdr.getProjectsLocationsBackupPlans({ name }).pipe( |
| 26 | Effect.as("found" as const), |
| 27 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 28 | Effect.repeat({ |
| 29 | schedule: Schedule.spaced("2 seconds"), |
| 30 | until: (status) => status === "gone", |
| 31 | times: 10, |
| 32 | }), |
| 33 | ); |
| 34 | |
| 35 | test.provider( |
| 36 | "getProjectsLocationsBackupPlans on a missing plan fails with a typed tag", |
| 37 | (stack) => |
| 38 | Effect.gen(function* () { |
| 39 | const { project } = yield* GcpEnvironment.current; |
| 40 | |
| 41 | yield* stack.destroy(); |
| 42 | |
| 43 | const error = yield* Effect.flip( |
| 44 | backupdr.getProjectsLocationsBackupPlans({ |
| 45 | name: `projects/${project}/locations/us-central1/backupPlans/alchemy-backupdr-missing`, |
| 46 | }), |
| 47 | ); |
| 48 | expect(error._tag).toEqual("NotFound"); |
| 49 | |
| 50 | const page = yield* backupdr.listProjectsLocationsBackupPlans({ |
| 51 | parent: `projects/${project}/locations/-`, |
| 52 | pageSize: 10, |
| 53 | }); |
| 54 | expect((page.backupPlans ?? []).map((item) => item.name)).not.toContain( |
| 55 | `projects/${project}/locations/us-central1/backupPlans/alchemy-backupdr-missing`, |
| 56 | ); |
| 57 | |
| 58 | yield* stack.destroy(); |
| 59 | }).pipe(logLevel), |
| 60 | { tags: ["provider:gcp", "provider:gcp:backupdr", "live"], timeout: 90_000 }, |
| 61 | ); |
| 62 | |
| 63 | test.provider( |
| 64 | "create against a missing vault is rejected with a typed tag", |
| 65 | (stack) => |
| 66 | Effect.gen(function* () { |
| 67 | const { project } = yield* GcpEnvironment.current; |
| 68 | |
| 69 | yield* stack.destroy(); |
| 70 | |
| 71 | const error = yield* Effect.flip( |
| 72 | stack.deploy( |
| 73 | Effect.gen(function* () { |
| 74 | return yield* GCP.BackupDR.BackupPlan("Nightly", { |
| 75 | backupVault: `projects/${project}/locations/us-central1/backupVaults/alchemy-backupdr-missing`, |
| 76 | resourceType: "compute.googleapis.com/Instance", |
| 77 | backupRules: [dailyRule], |
| 78 | description: "alchemy-test-plan", |
| 79 | labels: { env: "test" }, |
| 80 | }); |
| 81 | }), |
| 82 | ), |
| 83 | ); |
| 84 | expect(error._tag).toEqual("BackupVaultReferenceNotFound"); |
| 85 | |
| 86 | yield* stack.destroy(); |
| 87 | }).pipe(logLevel), |
| 88 | { tags: ["provider:gcp", "provider:gcp:backupdr", "live"], timeout: 90_000 }, |
| 89 | ); |
| 90 | |
| 91 | test.provider( |
| 92 | "create, update, and delete a backup plan", |
| 93 | (stack) => |
| 94 | Effect.gen(function* () { |
| 95 | yield* stack.destroy(); |
| 96 | |
| 97 | const created = yield* stack.deploy( |
| 98 | Effect.gen(function* () { |
| 99 | const vault = yield* GCP.BackupDR.BackupVault("Vault", { |
| 100 | backupMinimumEnforcedRetentionDuration: "86400s", |
| 101 | description: "alchemy-test-plan-vault", |
| 102 | labels: { env: "test" }, |
| 103 | }); |
| 104 | return yield* GCP.BackupDR.BackupPlan("Nightly", { |
| 105 | backupVault: vault.name, |
| 106 | resourceType: "compute.googleapis.com/Instance", |
| 107 | backupRules: [dailyRule], |
| 108 | description: "alchemy-test-plan", |
| 109 | labels: { env: "test" }, |
| 110 | }); |
| 111 | }), |
| 112 | ); |
| 113 | |
| 114 | expect(created.name).toContain("/backupPlans/"); |
| 115 | expect(created.backupPlanId).toEqual(expect.any(String)); |
| 116 | expect(created.location).toEqual("us-central1"); |
| 117 | expect(created.resourceType).toEqual("compute.googleapis.com/Instance"); |
| 118 | expect(created.description).toEqual("alchemy-test-plan"); |
| 119 | expect(created.labels).toMatchObject({ env: "test" }); |
| 120 | |
| 121 | const fetched = yield* backupdr.getProjectsLocationsBackupPlans({ |
| 122 | name: created.name, |
| 123 | }); |
| 124 | expect(fetched.name).toEqual(created.name); |
| 125 | expect(fetched.description).toEqual("alchemy-test-plan"); |
| 126 | expect(fetched.labels?.env).toEqual("test"); |
| 127 | |
| 128 | const updated = yield* stack.deploy( |
| 129 | Effect.gen(function* () { |
| 130 | const vault = yield* GCP.BackupDR.BackupVault("Vault", { |
| 131 | backupVaultId: created.backupVault ? created.backupVault.split("/").pop() : undefined, |
| 132 | backupMinimumEnforcedRetentionDuration: "86400s", |
| 133 | description: "alchemy-test-plan-vault", |
| 134 | labels: { env: "test" }, |
| 135 | }); |
| 136 | return yield* GCP.BackupDR.BackupPlan("Nightly", { |
| 137 | backupPlanId: created.backupPlanId, |
| 138 | backupVault: vault.name, |
| 139 | resourceType: "compute.googleapis.com/Instance", |
| 140 | backupRules: [dailyRule], |
| 141 | description: "alchemy-prod-plan", |
| 142 | labels: { env: "test" }, |
| 143 | }); |
| 144 | }), |
| 145 | ); |
| 146 | |
| 147 | expect(updated.name).toEqual(created.name); |
| 148 | expect(updated.description).toEqual("alchemy-prod-plan"); |
| 149 | |
| 150 | const refetched = yield* backupdr.getProjectsLocationsBackupPlans({ |
| 151 | name: created.name, |
| 152 | }); |
| 153 | expect(refetched.description).toEqual("alchemy-prod-plan"); |
| 154 | |
| 155 | yield* stack.destroy(); |
| 156 | |
| 157 | const gone = yield* waitUntilGone(created.name); |
| 158 | expect(gone).toEqual("gone"); |
| 159 | }).pipe(logLevel), |
| 160 | { tags: ["provider:gcp", "provider:gcp:backupdr", "live"], timeout: 300_000 }, |
| 161 | ); |