The best way to control Claude Code, Codex and more from any computer or phone
| 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 integrations from "@distilled.cloud/gcp/integrations_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 location = "us-central1"; |
| 15 | |
| 16 | const waitUntilGone = (name: string) => |
| 17 | integrations.getProjectsLocationsTemplates({ name }).pipe( |
| 18 | Effect.as("found" as const), |
| 19 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 20 | Effect.repeat({ |
| 21 | schedule: Schedule.spaced("1 second"), |
| 22 | until: (status) => status === "gone", |
| 23 | times: 10, |
| 24 | }), |
| 25 | ); |
| 26 | |
| 27 | test.provider( |
| 28 | "getProjectsLocationsTemplates on a missing template fails with a typed tag", |
| 29 | (stack) => |
| 30 | Effect.gen(function* () { |
| 31 | const { project } = yield* GcpEnvironment.current; |
| 32 | yield* stack.destroy(); |
| 33 | |
| 34 | const error = yield* Effect.flip( |
| 35 | integrations.getProjectsLocationsTemplates({ |
| 36 | name: `projects/${project}/locations/${location}/templates/alchemy-missing-template`, |
| 37 | }), |
| 38 | ); |
| 39 | expect(error._tag).toEqual("NotFound"); |
| 40 | |
| 41 | yield* stack.destroy(); |
| 42 | }).pipe(logLevel), |
| 43 | { |
| 44 | tags: ["provider:gcp", "provider:gcp:integrations", "live"], |
| 45 | timeout: 90_000, |
| 46 | }, |
| 47 | ); |
| 48 | |
| 49 | test.provider( |
| 50 | "create, update, and delete an integration template", |
| 51 | (stack) => |
| 52 | Effect.gen(function* () { |
| 53 | const { project } = yield* GcpEnvironment.current; |
| 54 | yield* stack.destroy(); |
| 55 | |
| 56 | const created = yield* stack.deploy( |
| 57 | Effect.gen(function* () { |
| 58 | return yield* GCP.Integrations.Template("Orders", { |
| 59 | location, |
| 60 | displayName: "order-sync", |
| 61 | description: "sync orders", |
| 62 | tags: ["orders"], |
| 63 | categories: ["SALES_AND_MARKETING"], |
| 64 | visibility: "PRIVATE", |
| 65 | }); |
| 66 | }), |
| 67 | ); |
| 68 | |
| 69 | expect(created.templateId).toEqual(expect.any(String)); |
| 70 | expect(created.location).toEqual(location); |
| 71 | expect(created.project).toEqual(project); |
| 72 | expect(created.name).toEqual( |
| 73 | `projects/${project}/locations/${location}/templates/${created.templateId}`, |
| 74 | ); |
| 75 | expect(created.displayName).toEqual("order-sync"); |
| 76 | expect(created.description).toEqual("sync orders"); |
| 77 | expect(created.tags).toContain("orders"); |
| 78 | expect(created.categories).toContain("SALES_AND_MARKETING"); |
| 79 | expect(created.visibility).toEqual("PRIVATE"); |
| 80 | |
| 81 | const fetched = yield* integrations.getProjectsLocationsTemplates({ |
| 82 | name: created.name, |
| 83 | }); |
| 84 | expect(fetched.name).toEqual(created.name); |
| 85 | expect(fetched.description).toContain("alchemy-id="); |
| 86 | expect(fetched.displayName).toEqual("order-sync"); |
| 87 | |
| 88 | const updated = yield* stack.deploy( |
| 89 | Effect.gen(function* () { |
| 90 | return yield* GCP.Integrations.Template("Orders", { |
| 91 | templateId: created.templateId, |
| 92 | location, |
| 93 | displayName: "order-sync-v2", |
| 94 | description: "sync orders v2", |
| 95 | tags: ["orders", "v2"], |
| 96 | categories: ["SALES_AND_MARKETING", "UTILITY"], |
| 97 | visibility: "PRIVATE", |
| 98 | }); |
| 99 | }), |
| 100 | ); |
| 101 | |
| 102 | expect(updated.name).toEqual(created.name); |
| 103 | expect(updated.displayName).toEqual("order-sync-v2"); |
| 104 | expect(updated.description).toEqual("sync orders v2"); |
| 105 | expect(updated.tags).toEqual(expect.arrayContaining(["orders", "v2"])); |
| 106 | expect(updated.categories).toContain("UTILITY"); |
| 107 | |
| 108 | yield* stack.destroy(); |
| 109 | |
| 110 | const gone = yield* waitUntilGone(created.name); |
| 111 | expect(gone).toEqual("gone"); |
| 112 | }).pipe(logLevel), |
| 113 | { |
| 114 | tags: ["provider:gcp", "provider:gcp:integrations", "live"], |
| 115 | timeout: 90_000, |
| 116 | }, |
| 117 | ); |