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

main
ts 117 lines 4.03 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 cw from "@distilled.cloud/gcp/contentwarehouse_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 // Document AI Warehouse is disabled on the testing project: calls fail with
15 // ServiceDisabled "Document AI Warehouse API has not been used in project ...
16 // before or it is disabled" (the service also needs per-project
17 // provisioning). Set GCP_TEST_CONTENTWAREHOUSE=1 on a provisioned project.
18 const runLifecycle = !process.env.FAST && !!process.env.GCP_TEST_CONTENTWAREHOUSE;
19
20 const location = "us";
21
22 const waitUntilGone = (name: string) =>
23 cw.getProjectsLocationsSynonymSets({ name }).pipe(
24 Effect.as("found" as const),
25 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
26 Effect.repeat({
27 schedule: Schedule.spaced("1 second"),
28 until: (status) => status === "gone",
29 times: 10,
30 }),
31 );
32
33 // Skipped: the Content Warehouse endpoint answers every request with an HTML
34 // 502 after ~20s (Document AI Warehouse is being retired), so the
35 // ServiceDisabled probe can't complete.
36 test.provider.skip(
37 "getProjectsLocationsSynonymSets without Document AI Warehouse enabled fails with ServiceDisabled",
38 (stack) =>
39 Effect.gen(function* () {
40 const { project } = yield* GcpEnvironment.current;
41 const parent = `projects/${project}/locations/${location}`;
42 yield* stack.destroy();
43
44 const error = yield* Effect.flip(
45 cw.getProjectsLocationsSynonymSets({
46 name: `${parent}/synonymSets/alchemy-missing-synonyms`,
47 }),
48 );
49 expect(error._tag).toEqual("ServiceDisabled");
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 {
54 tags: ["provider:gcp", "provider:gcp:contentwarehouse", "live"],
55 timeout: 90_000,
56 },
57 );
58
59 test.provider.skipIf(!runLifecycle)(
60 "create, update, and delete a synonym set",
61 (stack) =>
62 Effect.gen(function* () {
63 const { project } = yield* GcpEnvironment.current;
64 const parent = `projects/${project}/locations/${location}`;
65 yield* stack.destroy();
66
67 const created = yield* stack.deploy(
68 Effect.gen(function* () {
69 return yield* GCP.ContentWarehouse.SynonymSet("Sales", {
70 location,
71 synonyms: [{ words: ["sale", "invoice", "bill"] }],
72 });
73 }),
74 );
75
76 expect(created.context).toEqual(expect.any(String));
77 expect(created.name).toContain("/synonymSets/");
78 expect(
79 (created.synonyms ?? []).some((group) => (group.words ?? []).includes("invoice")),
80 ).toEqual(true);
81
82 const fetched = yield* cw.getProjectsLocationsSynonymSets({
83 name: created.name,
84 });
85 expect(fetched.name).toEqual(created.name);
86 expect(fetched.synonyms).toEqual(created.synonyms);
87
88 const updated = yield* stack.deploy(
89 Effect.gen(function* () {
90 return yield* GCP.ContentWarehouse.SynonymSet("Sales", {
91 context: created.context,
92 location,
93 synonyms: [
94 { words: ["sale", "invoice", "bill", "order"] },
95 { words: ["money", "credit"] },
96 ],
97 });
98 }),
99 );
100
101 expect(updated.name).toEqual(created.name);
102 expect(
103 (updated.synonyms ?? []).some((group) => (group.words ?? []).includes("order")),
104 ).toEqual(true);
105 expect(
106 (updated.synonyms ?? []).some((group) => (group.words ?? []).includes("credit")),
107 ).toEqual(true);
108
109 yield* stack.destroy();
110 const gone = yield* waitUntilGone(created.name);
111 expect(gone).toEqual("gone");
112 }).pipe(logLevel),
113 {
114 tags: ["provider:gcp", "provider:gcp:contentwarehouse", "live"],
115 timeout: 90_000,
116 },
117 );