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 apigee from "@distilled.cloud/gcp/apigee_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 siteId = process.env.GCP_TEST_APIGEE_SITE ?? ""; |
| 15 | const apiProductName = process.env.GCP_TEST_APIGEE_PRODUCT ?? ""; |
| 16 | |
| 17 | // Needs a provisioned Apigee organization on the testing project (paid, or |
| 18 | // ~1h eval provisioning); without one calls fail with ApigeeResourceNotFound (403 "Permission |
| 19 | // denied on resource \"organizations/{project}\" (or it may not exist)"). |
| 20 | // Set GCP_TEST_APIGEE_ORG=1 when the org exists. |
| 21 | const runLifecycle = !!process.env.GCP_TEST_APIGEE_ORG && !!siteId && !!apiProductName; |
| 22 | |
| 23 | const waitUntilGone = (name: string) => |
| 24 | apigee.getOrganizationsSitesApidocs({ name }).pipe( |
| 25 | Effect.as("found" as const), |
| 26 | Effect.catchTag(["NotFound", "ApigeeResourceNotFound"], () => Effect.succeed("gone" as const)), |
| 27 | Effect.repeat({ |
| 28 | schedule: Schedule.spaced("1 second"), |
| 29 | until: (status) => status === "gone", |
| 30 | times: 10, |
| 31 | }), |
| 32 | ); |
| 33 | |
| 34 | test.provider( |
| 35 | "getOrganizationsSitesApidocs on a missing catalog item fails with ApigeeResourceNotFound", |
| 36 | (stack) => |
| 37 | Effect.gen(function* () { |
| 38 | const { project } = yield* GcpEnvironment.current; |
| 39 | |
| 40 | yield* stack.destroy(); |
| 41 | |
| 42 | const error = yield* Effect.flip( |
| 43 | apigee.getOrganizationsSitesApidocs({ |
| 44 | name: `organizations/${project}/sites/alchemy-missing-site/apidocs/alchemy-missing-doc`, |
| 45 | }), |
| 46 | ); |
| 47 | expect(error._tag).toEqual("ApigeeResourceNotFound"); |
| 48 | |
| 49 | yield* stack.destroy(); |
| 50 | }).pipe(logLevel), |
| 51 | { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 }, |
| 52 | ); |
| 53 | |
| 54 | test.provider.skipIf(!runLifecycle)( |
| 55 | "create, update, and delete an Apigee catalog item", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | const { project } = yield* GcpEnvironment.current; |
| 59 | |
| 60 | yield* stack.destroy(); |
| 61 | |
| 62 | const created = yield* stack.deploy( |
| 63 | Effect.gen(function* () { |
| 64 | return yield* GCP.Apigee.SitesApidoc("Checkout", { |
| 65 | siteId, |
| 66 | apiProductName, |
| 67 | title: "Checkout API", |
| 68 | description: "place orders", |
| 69 | }); |
| 70 | }), |
| 71 | ); |
| 72 | |
| 73 | expect(created.apiDocId).toEqual(expect.any(String)); |
| 74 | expect(created.organization).toEqual(project); |
| 75 | expect(created.siteId).toEqual(siteId); |
| 76 | expect(created.apiProductName).toEqual(apiProductName); |
| 77 | expect(created.title).toEqual("Checkout API"); |
| 78 | expect(created.description).toEqual("place orders"); |
| 79 | expect(created.published).toEqual(false); |
| 80 | expect(created.name).toEqual( |
| 81 | `organizations/${project}/sites/${siteId}/apidocs/${created.apiDocId}`, |
| 82 | ); |
| 83 | |
| 84 | const fetched = yield* apigee.getOrganizationsSitesApidocs({ |
| 85 | name: created.name, |
| 86 | }); |
| 87 | expect(fetched.data?.id).toEqual(created.apiDocId); |
| 88 | expect(fetched.data?.description).toEqual("place orders"); |
| 89 | |
| 90 | const updated = yield* stack.deploy( |
| 91 | Effect.gen(function* () { |
| 92 | return yield* GCP.Apigee.SitesApidoc("Checkout", { |
| 93 | siteId, |
| 94 | apiProductName, |
| 95 | title: "Checkout API v2", |
| 96 | description: "place and refund orders", |
| 97 | published: true, |
| 98 | }); |
| 99 | }), |
| 100 | ); |
| 101 | |
| 102 | expect(updated.apiDocId).toEqual(created.apiDocId); |
| 103 | expect(updated.title).toEqual("Checkout API v2"); |
| 104 | expect(updated.description).toEqual("place and refund orders"); |
| 105 | expect(updated.published).toEqual(true); |
| 106 | |
| 107 | const fetchedUpdate = yield* apigee.getOrganizationsSitesApidocs({ |
| 108 | name: updated.name, |
| 109 | }); |
| 110 | expect(fetchedUpdate.data?.title).toEqual("Checkout API v2"); |
| 111 | expect(fetchedUpdate.data?.description).toContain("place and refund orders"); |
| 112 | expect(fetchedUpdate.data?.published).toEqual(true); |
| 113 | |
| 114 | yield* stack.destroy(); |
| 115 | |
| 116 | const gone = yield* waitUntilGone(created.name); |
| 117 | expect(gone).toEqual("gone"); |
| 118 | }).pipe(logLevel), |
| 119 | { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 }, |
| 120 | ); |