@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 111 lines 4.29 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;
19
20 // Empty `proxies/` directory zip used as archive payload.
21 const ARCHIVE_ZIP =
22 "UEsDBAoAAAAAAIdO4kgAAAAAAAAAAAAAAAAJAAAAcHJveGllcy9QSwECFAAKAAAAAACHTuJIAAAAAAAAAAAAAAAACTAAAAAAAAAAABAAAAAAAAAAcHJveGllcy9QSwUGAAAAAAEAAQA3AAAAJwAAAAAA";
23
24 const waitUntilGone = (name: string) =>
25 apigee.getOrganizationsEnvironmentsArchiveDeployments({ name }).pipe(
26 Effect.as("found" as const),
27 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
28 Effect.catchTag("ApigeeResourceNotFound", () => Effect.succeed("gone" as const)),
29 Effect.repeat({
30 schedule: Schedule.spaced("2 seconds"),
31 until: (status) => status === "gone",
32 times: 10,
33 }),
34 );
35
36 test.provider(
37 "getOrganizationsEnvironmentsArchiveDeployments on a missing archive fails with ApigeeResourceNotFound",
38 (stack) =>
39 Effect.gen(function* () {
40 const { project } = yield* GcpEnvironment.current;
41 const org = `organizations/${project}`;
42
43 yield* stack.destroy();
44
45 const error = yield* Effect.flip(
46 apigee.getOrganizationsEnvironmentsArchiveDeployments({
47 name: `${org}/environments/alchemy-missing/archiveDeployments/alchemy-missing`,
48 }),
49 );
50 expect(error._tag).toEqual("ApigeeResourceNotFound");
51
52 yield* stack.destroy();
53 }).pipe(logLevel),
54 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
55 );
56
57 test.provider.skipIf(!runLifecycle)(
58 "create, update, and delete an archive deployment",
59 (stack) =>
60 Effect.gen(function* () {
61 yield* stack.destroy();
62
63 const created = yield* stack.deploy(
64 Effect.gen(function* () {
65 const environment = yield* GCP.Apigee.Environment("Runtime", {
66 displayName: "runtime",
67 });
68 const archive = yield* GCP.Apigee.EnvironmentsArchiveDeployment("Bundle", {
69 environment: environment.environmentId,
70 archiveZip: ARCHIVE_ZIP,
71 labels: { env: "test" },
72 });
73 return { environment, archive };
74 }),
75 );
76
77 expect(created.archive.archiveDeploymentId).toEqual(expect.any(String));
78 expect(created.archive.environmentId).toEqual(created.environment.environmentId);
79 expect(created.archive.labels).toMatchObject({ env: "test" });
80
81 const fetched = yield* apigee.getOrganizationsEnvironmentsArchiveDeployments({
82 name: created.archive.name,
83 });
84 expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String));
85
86 const updated = yield* stack.deploy(
87 Effect.gen(function* () {
88 const environment = yield* GCP.Apigee.Environment("Runtime", {
89 environmentId: created.environment.environmentId,
90 displayName: "runtime",
91 });
92 const archive = yield* GCP.Apigee.EnvironmentsArchiveDeployment("Bundle", {
93 environment: environment.environmentId,
94 archiveDeploymentId: created.archive.archiveDeploymentId,
95 archiveZip: ARCHIVE_ZIP,
96 labels: { env: "prod" },
97 });
98 return { environment, archive };
99 }),
100 );
101
102 expect(updated.archive.name).toEqual(created.archive.name);
103 expect(updated.archive.labels).toMatchObject({ env: "prod" });
104
105 yield* stack.destroy();
106
107 const gone = yield* waitUntilGone(created.archive.name);
108 expect(gone).toEqual("gone");
109 }).pipe(logLevel),
110 { tags: ["provider:gcp", "provider:gcp:apigee", "live"], timeout: 90_000 },
111 );