@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 88 lines 3.2 KB
Raw
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 // Needs a provisioned Apigee organization on the testing project (paid, or
15 // ~1h eval provisioning); without one calls fail with ApigeeResourceNotFound (403 "Permission
16 // denied on resource \"organizations/{project}\" (or it may not exist)").
17 // Set GCP_TEST_APIGEE_ORG=1 when the org exists.
18 const runLifecycle = !!process.env.GCP_TEST_APIGEE_ORG && !!process.env.GCP_TEST_APIGEE_ENDPOINT;
19
20 const waitUntilGone = (name: string) =>
21 apigee.getOrganizationsEndpointAttachments({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.catchTag("ApigeeResourceNotFound", () => Effect.succeed("gone" as const)),
25 Effect.repeat({
26 schedule: Schedule.spaced("2 seconds"),
27 until: (status) => status === "gone",
28 times: 10,
29 }),
30 );
31
32 test.provider(
33 "getOrganizationsEndpointAttachments on a missing attachment fails with ApigeeResourceNotFound",
34 (stack) =>
35 Effect.gen(function* () {
36 const { project } = yield* GcpEnvironment.current;
37 const org = `organizations/${project}`;
38
39 yield* stack.destroy();
40
41 const error = yield* Effect.flip(
42 apigee.getOrganizationsEndpointAttachments({
43 name: `${org}/endpointAttachments/alchemy-missing`,
44 }),
45 );
46 expect(error._tag).toEqual("ApigeeResourceNotFound");
47
48 yield* stack.destroy();
49 }).pipe(logLevel),
50 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
51 );
52
53 test.provider.skipIf(!runLifecycle)(
54 "create and delete an endpoint attachment",
55 (stack) =>
56 Effect.gen(function* () {
57 const { project } = yield* GcpEnvironment.current;
58 const serviceAttachment =
59 process.env.GCP_TEST_APIGEE_SERVICE_ATTACHMENT ??
60 `projects/${project}/regions/us-central1/serviceAttachments/alchemy-backend`;
61
62 yield* stack.destroy();
63
64 const created = yield* stack.deploy(
65 Effect.gen(function* () {
66 return yield* GCP.Apigee.EndpointAttachment("Backend", {
67 location: "us-central1",
68 serviceAttachment,
69 });
70 }),
71 );
72
73 expect(created.endpointAttachmentId.startsWith("alc")).toEqual(true);
74 expect(created.location).toEqual("us-central1");
75 expect(created.serviceAttachment).toEqual(serviceAttachment);
76
77 const fetched = yield* apigee.getOrganizationsEndpointAttachments({
78 name: created.name,
79 });
80 expect(fetched.name).toEqual(created.name);
81
82 yield* stack.destroy();
83
84 const gone = yield* waitUntilGone(created.name);
85 expect(gone).toEqual("gone");
86 }).pipe(logLevel),
87 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
88 );