@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 114 lines 3.81 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 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 // Project setup (one-time): Application Integration must be provisioned in
13 // us-central1, else calls fail with `Found zero or more than one active
14 // project` / `Failed to client for project`:
15 // POST https://integrations.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/clients:provision
16 // {"createSampleWorkflows": false}
17
18 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
19
20 const waitUntilGone = (name: string) =>
21 integrations.getProjectsLocationsIntegrationsVersions({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("1 second"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 const apiTrigger = [
32 {
33 label: "API Trigger",
34 triggerType: "API" as const,
35 triggerNumber: "1",
36 triggerId: "api_trigger/alchemy_orders",
37 properties: { "Trigger name": "alchemy_orders" },
38 },
39 ];
40
41 test.provider(
42 "getProjectsLocationsIntegrationsVersions on a missing version fails with a typed tag",
43 (stack) =>
44 Effect.gen(function* () {
45 const { project } = yield* GcpEnvironment.current;
46 yield* stack.destroy();
47
48 const error = yield* Effect.flip(
49 integrations.getProjectsLocationsIntegrationsVersions({
50 name: `projects/${project}/locations/us-central1/integrations/alchemy-missing/versions/00000000-0000-0000-0000-000000000000`,
51 }),
52 );
53 expect(error._tag).toEqual("NotFound");
54
55 yield* stack.destroy();
56 }).pipe(logLevel),
57 {
58 tags: ["provider:gcp", "provider:gcp:integrations", "live"],
59 timeout: 90_000,
60 },
61 );
62
63 test.provider(
64 "create, update, and delete an integration version",
65 (stack) =>
66 Effect.gen(function* () {
67 yield* stack.destroy();
68
69 const created = yield* stack.deploy(
70 Effect.gen(function* () {
71 return yield* GCP.Integrations.IntegrationsVersion("Orders", {
72 location: "us-central1",
73 description: "order workflow",
74 triggerConfigs: apiTrigger,
75 });
76 }),
77 );
78
79 expect(created.name).toContain("/integrations/");
80 expect(created.name).toContain("/versions/");
81 expect(created.location).toEqual("us-central1");
82 expect(created.description).toEqual("order workflow");
83
84 const fetched = yield* integrations.getProjectsLocationsIntegrationsVersions({
85 name: created.name,
86 });
87 expect(fetched.name).toEqual(created.name);
88 expect(fetched.description).toContain("alchemy-id=");
89 expect(fetched.description).toContain("order workflow");
90
91 const updated = yield* stack.deploy(
92 Effect.gen(function* () {
93 return yield* GCP.Integrations.IntegrationsVersion("Orders", {
94 integrationId: created.integrationId,
95 versionId: created.versionId,
96 location: "us-central1",
97 description: "updated workflow",
98 triggerConfigs: apiTrigger,
99 });
100 }),
101 );
102
103 expect(updated.name).toEqual(created.name);
104 expect(updated.description).toEqual("updated workflow");
105
106 yield* stack.destroy();
107 const gone = yield* waitUntilGone(created.name);
108 expect(gone).toEqual("gone");
109 }).pipe(logLevel),
110 {
111 tags: ["provider:gcp", "provider:gcp:integrations", "live"],
112 timeout: 90_000,
113 },
114 );