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 { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as logging from "@distilled.cloud/gcp/logging_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 | // Organization-scoped: set GOOGLE_ORGANIZATION_ID when the credentials |
| 12 | // administer the organization (the testing service account does not). |
| 13 | const organizationId = process.env.GOOGLE_ORGANIZATION_ID?.trim().replace(/^organizations\//, ""); |
| 14 | const organization = `organizations/${organizationId}`; |
| 15 | |
| 16 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 17 | |
| 18 | const waitUntilGone = (name: string) => |
| 19 | logging.getOrganizationsLocationsBuckets({ name }).pipe( |
| 20 | Effect.map((bucket) => |
| 21 | bucket.lifecycleState === "DELETE_REQUESTED" ? ("gone" as const) : ("found" as const), |
| 22 | ), |
| 23 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 24 | Effect.repeat({ |
| 25 | schedule: Schedule.spaced("1 second"), |
| 26 | until: (status) => status === "gone", |
| 27 | times: 10, |
| 28 | }), |
| 29 | ); |
| 30 | |
| 31 | test.provider.skipIf(!organizationId)( |
| 32 | "getOrganizationsLocationsBuckets on a missing bucket fails with NotFound", |
| 33 | (stack) => |
| 34 | Effect.gen(function* () { |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const error = yield* Effect.flip( |
| 38 | logging.getOrganizationsLocationsBuckets({ |
| 39 | name: `${organization}/locations/global/buckets/alchemy-missing`, |
| 40 | }), |
| 41 | ); |
| 42 | expect(error._tag).toEqual("NotFound"); |
| 43 | |
| 44 | yield* stack.destroy(); |
| 45 | }).pipe(logLevel), |
| 46 | { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 90_000 }, |
| 47 | ); |
| 48 | |
| 49 | test.provider.skipIf(!organizationId)( |
| 50 | "create, update, replace, and delete an organization logging bucket", |
| 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.Logging.OrganizationLogBucket("AppLogs", { |
| 58 | organization, |
| 59 | description: "application logs", |
| 60 | retentionDays: 31, |
| 61 | }); |
| 62 | }), |
| 63 | ); |
| 64 | |
| 65 | expect(created.bucketId).toEqual(expect.any(String)); |
| 66 | expect(created.location).toEqual("global"); |
| 67 | expect(created.organization).toEqual(organization); |
| 68 | expect(created.name).toEqual(`${organization}/locations/global/buckets/${created.bucketId}`); |
| 69 | expect(created.description).toEqual("application logs"); |
| 70 | expect(created.retentionDays).toEqual(31); |
| 71 | |
| 72 | const fetched = yield* logging.getOrganizationsLocationsBuckets({ |
| 73 | name: created.name, |
| 74 | }); |
| 75 | expect(fetched.retentionDays).toEqual(31); |
| 76 | expect(fetched.description).toContain("alchemy-id="); |
| 77 | |
| 78 | const updated = yield* stack.deploy( |
| 79 | Effect.gen(function* () { |
| 80 | return yield* GCP.Logging.OrganizationLogBucket("AppLogs", { |
| 81 | organization, |
| 82 | bucketId: created.bucketId, |
| 83 | location: created.location, |
| 84 | description: "retained application logs", |
| 85 | retentionDays: 60, |
| 86 | }); |
| 87 | }), |
| 88 | ); |
| 89 | |
| 90 | expect(updated.name).toEqual(created.name); |
| 91 | expect(updated.retentionDays).toEqual(60); |
| 92 | |
| 93 | const last = created.bucketId.at(-1) ?? "a"; |
| 94 | const nextBucketId = `${created.bucketId.slice(0, -1)}${last === "z" ? "0" : "z"}`; |
| 95 | |
| 96 | const replaced = yield* stack.deploy( |
| 97 | Effect.gen(function* () { |
| 98 | return yield* GCP.Logging.OrganizationLogBucket("AppLogs", { |
| 99 | organization, |
| 100 | bucketId: nextBucketId, |
| 101 | location: "global", |
| 102 | description: "replaced bucket", |
| 103 | retentionDays: 31, |
| 104 | }); |
| 105 | }), |
| 106 | ); |
| 107 | |
| 108 | expect(replaced.bucketId).not.toEqual(created.bucketId); |
| 109 | |
| 110 | const previousGone = yield* waitUntilGone(created.name); |
| 111 | expect(previousGone).toEqual("gone"); |
| 112 | |
| 113 | yield* stack.destroy(); |
| 114 | |
| 115 | const gone = yield* waitUntilGone(replaced.name); |
| 116 | expect(gone).toEqual("gone"); |
| 117 | }).pipe(logLevel), |
| 118 | { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 90_000 }, |
| 119 | ); |