The best way to control Claude Code, Codex and more from any computer or phone

main
ts 130 lines 4.72 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.getProjectsLocationsIntegrationsVersionsTestCases({ 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_testcase",
37 properties: { "Trigger name": "alchemy_testcase" },
38 },
39 ];
40
41 test.provider(
42 "getProjectsLocationsIntegrationsVersionsTestCases on a missing case 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.getProjectsLocationsIntegrationsVersionsTestCases({
50 name: `projects/${project}/locations/us-central1/integrations/alchemy-missing/versions/00000000-0000-0000-0000-000000000000/testCases/missing`,
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 test case",
65 (stack) =>
66 Effect.gen(function* () {
67 yield* stack.destroy();
68
69 const created = yield* stack.deploy(
70 Effect.gen(function* () {
71 const version = yield* GCP.Integrations.IntegrationsVersion("Orders", {
72 location: "us-central1",
73 description: "testcase parent",
74 triggerConfigs: apiTrigger,
75 });
76 const testCase = yield* GCP.Integrations.IntegrationsVersionsTestCases("HappyPath", {
77 version: version.name,
78 location: "us-central1",
79 displayName: "happy-path",
80 description: "fires the API trigger",
81 triggerId: "api_trigger/alchemy_testcase",
82 });
83 return { version, testCase };
84 }),
85 );
86
87 expect(created.testCase.name).toContain("/testCases/");
88 expect(created.testCase.displayName).toEqual("happy-path");
89 expect(created.testCase.description).toEqual("fires the API trigger");
90 expect(created.testCase.triggerId).toEqual("api_trigger/alchemy_testcase");
91
92 const fetched = yield* integrations.getProjectsLocationsIntegrationsVersionsTestCases({
93 name: created.testCase.name,
94 });
95 expect(fetched.name).toEqual(created.testCase.name);
96 expect(fetched.description).toContain("alchemy-id=");
97
98 const updated = yield* stack.deploy(
99 Effect.gen(function* () {
100 const version = yield* GCP.Integrations.IntegrationsVersion("Orders", {
101 integrationId: created.version.integrationId,
102 versionId: created.version.versionId,
103 location: "us-central1",
104 description: "testcase parent",
105 triggerConfigs: apiTrigger,
106 });
107 const testCase = yield* GCP.Integrations.IntegrationsVersionsTestCases("HappyPath", {
108 version: version.name,
109 testCaseId: created.testCase.testCaseId,
110 location: "us-central1",
111 displayName: "happy-path",
112 description: "updated case",
113 triggerId: "api_trigger/alchemy_testcase",
114 });
115 return { version, testCase };
116 }),
117 );
118
119 expect(updated.testCase.name).toEqual(created.testCase.name);
120 expect(updated.testCase.description).toEqual("updated case");
121
122 yield* stack.destroy();
123 const gone = yield* waitUntilGone(created.testCase.name);
124 expect(gone).toEqual("gone");
125 }).pipe(logLevel),
126 {
127 tags: ["provider:gcp", "provider:gcp:integrations", "live"],
128 timeout: 90_000,
129 },
130 );