@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 113 lines 3.94 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 apihub from "@distilled.cloud/gcp/apihub_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 API Hub instance in us-central1 (one per project,
15 // behind a host project registration); without one writes fail with
16 // BadRequest ("Invalid resource state … API Hub instance …"). Set
17 // GCP_TEST_APIHUB_INSTANCE=1 when the hub exists.
18 const runLifecycle = !!process.env.GCP_TEST_APIHUB_INSTANCE;
19 const location = "us-central1";
20
21 const endpointOf = (project: string) => ({
22 applicationIntegrationEndpointDetails: {
23 uri: `https://integrations.googleapis.com/v1/projects/${project}/locations/${location}/integrations/alchemy-curate:execute`,
24 triggerId: "api_trigger/alchemy-curate",
25 },
26 });
27
28 const waitUntilGone = (name: string) =>
29 apihub.getProjectsLocationsCurations({ name }).pipe(
30 Effect.as("found" as const),
31 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
32 Effect.repeat({
33 schedule: Schedule.spaced("1 second"),
34 until: (status) => status === "gone",
35 times: 10,
36 }),
37 );
38
39 test.provider(
40 "getProjectsLocationsCurations on a missing curation fails with a typed tag",
41 (stack) =>
42 Effect.gen(function* () {
43 const { project } = yield* GcpEnvironment.current;
44 yield* stack.destroy();
45
46 const error = yield* Effect.flip(
47 apihub.getProjectsLocationsCurations({
48 name: `projects/${project}/locations/${location}/curations/alchemy-missing-curation`,
49 }),
50 );
51 expect(error._tag).toEqual("NotFound");
52
53 yield* stack.destroy();
54 }).pipe(logLevel),
55 { tags: ["provider:gcp", "provider:gcp:apihub", "live"], timeout: 90_000 },
56 );
57
58 test.provider.skipIf(!runLifecycle)(
59 "create, update, and delete an API Hub curation",
60 (stack) =>
61 Effect.gen(function* () {
62 const { project } = yield* GcpEnvironment.current;
63 const endpoint = endpointOf(project);
64 yield* stack.destroy();
65
66 const created = yield* stack.deploy(
67 Effect.gen(function* () {
68 return yield* GCP.ApiHub.Curation("Curate", {
69 location,
70 displayName: "curate-apis",
71 description: "curate metadata",
72 endpoint,
73 });
74 }),
75 );
76
77 expect(created.name).toContain("/curations/");
78 expect(created.curationId).toEqual(expect.any(String));
79 expect(created.displayName).toEqual("curate-apis");
80 expect(created.description).toEqual("curate metadata");
81 expect(created.endpoint?.applicationIntegrationEndpointDetails.triggerId).toEqual(
82 "api_trigger/alchemy-curate",
83 );
84
85 const fetched = yield* apihub.getProjectsLocationsCurations({
86 name: created.name,
87 });
88 expect(fetched.name).toEqual(created.name);
89 expect(fetched.description).toContain("alchemy-id=");
90
91 const updated = yield* stack.deploy(
92 Effect.gen(function* () {
93 return yield* GCP.ApiHub.Curation("Curate", {
94 curationId: created.curationId,
95 location,
96 displayName: "curate-apis-v2",
97 description: "curate metadata v2",
98 endpoint,
99 });
100 }),
101 );
102
103 expect(updated.name).toEqual(created.name);
104 expect(updated.displayName).toEqual("curate-apis-v2");
105 expect(updated.description).toEqual("curate metadata v2");
106
107 yield* stack.destroy();
108
109 const gone = yield* waitUntilGone(created.name);
110 expect(gone).toEqual("gone");
111 }).pipe(logLevel),
112 { tags: ["provider:gcp", "provider:gcp:apihub", "live"], timeout: 90_000 },
113 );