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 logging from "@distilled.cloud/gcp/logging_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 | logging.getProjectsExclusions({ 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 | test.provider( |
| 26 | "create, update, replace, and delete a logging exclusion", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | const { project } = yield* GcpEnvironment.current; |
| 30 | |
| 31 | yield* stack.destroy(); |
| 32 | |
| 33 | const created = yield* stack.deploy( |
| 34 | Effect.gen(function* () { |
| 35 | return yield* GCP.Logging.Exclusion("DropDebug", { |
| 36 | filter: "severity=DEBUG", |
| 37 | description: "drop debug entries", |
| 38 | }); |
| 39 | }), |
| 40 | ); |
| 41 | |
| 42 | expect(created.exclusionId).toEqual(expect.any(String)); |
| 43 | expect(created.name).toEqual(`projects/${project}/exclusions/${created.exclusionId}`); |
| 44 | expect(created.project).toEqual(project); |
| 45 | expect(created.filter).toEqual("severity=DEBUG"); |
| 46 | expect(created.description).toEqual("drop debug entries"); |
| 47 | expect(created.disabled).toEqual(false); |
| 48 | |
| 49 | const fetched = yield* logging.getProjectsExclusions({ |
| 50 | name: created.name, |
| 51 | }); |
| 52 | expect(fetched.name).toEqual(created.exclusionId); |
| 53 | expect(fetched.filter).toEqual("severity=DEBUG"); |
| 54 | expect(fetched.description).toContain("alchemy-id="); |
| 55 | expect(fetched.description).toContain("drop debug entries"); |
| 56 | |
| 57 | const updated = yield* stack.deploy( |
| 58 | Effect.gen(function* () { |
| 59 | return yield* GCP.Logging.Exclusion("DropDebug", { |
| 60 | exclusionId: created.exclusionId, |
| 61 | filter: "severity<ERROR", |
| 62 | description: "drop non-errors", |
| 63 | disabled: true, |
| 64 | }); |
| 65 | }), |
| 66 | ); |
| 67 | |
| 68 | expect(updated.name).toEqual(created.name); |
| 69 | expect(updated.exclusionId).toEqual(created.exclusionId); |
| 70 | expect(updated.filter).toEqual("severity<ERROR"); |
| 71 | expect(updated.description).toEqual("drop non-errors"); |
| 72 | expect(updated.disabled).toEqual(true); |
| 73 | expect(updated.createTime).toEqual(created.createTime); |
| 74 | |
| 75 | const fetchedUpdate = yield* logging.getProjectsExclusions({ |
| 76 | name: created.name, |
| 77 | }); |
| 78 | expect(fetchedUpdate.filter).toEqual("severity<ERROR"); |
| 79 | expect(fetchedUpdate.disabled).toEqual(true); |
| 80 | expect(fetchedUpdate.description).toContain("drop non-errors"); |
| 81 | |
| 82 | const last = created.exclusionId.at(-1) ?? "a"; |
| 83 | const nextExclusionId = `${created.exclusionId.slice(0, -1)}${last === "z" ? "0" : "z"}`; |
| 84 | |
| 85 | const replaced = yield* stack.deploy( |
| 86 | Effect.gen(function* () { |
| 87 | return yield* GCP.Logging.Exclusion("DropDebug", { |
| 88 | exclusionId: nextExclusionId, |
| 89 | filter: "severity=DEBUG", |
| 90 | description: "replaced exclusion", |
| 91 | }); |
| 92 | }), |
| 93 | ); |
| 94 | |
| 95 | expect(replaced.exclusionId).not.toEqual(created.exclusionId); |
| 96 | expect(replaced.name).toEqual(`projects/${project}/exclusions/${replaced.exclusionId}`); |
| 97 | expect(replaced.description).toEqual("replaced exclusion"); |
| 98 | |
| 99 | const fetchedReplacement = yield* logging.getProjectsExclusions({ |
| 100 | name: replaced.name, |
| 101 | }); |
| 102 | expect(fetchedReplacement.name).toEqual(replaced.exclusionId); |
| 103 | |
| 104 | const previousGone = yield* waitUntilGone(created.name); |
| 105 | expect(previousGone).toEqual("gone"); |
| 106 | |
| 107 | yield* stack.destroy(); |
| 108 | |
| 109 | const gone = yield* waitUntilGone(replaced.name); |
| 110 | expect(gone).toEqual("gone"); |
| 111 | }).pipe(logLevel), |
| 112 | { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 90_000 }, |
| 113 | ); |