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

main
ts 94 lines 3.27 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 retail from "@distilled.cloud/gcp/retail_v2";
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 // Retail only serves projects that accepted the Retail data use terms (a
15 // one-time console step); until then every call fails with
16 // RetailDataUseTermsNotAccepted. Set GCP_TEST_RETAIL_TERMS=1 once accepted.
17 const runLifecycle = !!process.env.GCP_TEST_RETAIL_TERMS;
18
19 const waitUntilGone = (name: string) =>
20 retail.getProjectsLocationsCatalogsControls({ name }).pipe(
21 Effect.as("found" as const),
22 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
23 Effect.repeat({
24 schedule: Schedule.spaced("2 seconds"),
25 until: (status) => status === "gone",
26 times: 10,
27 }),
28 );
29
30 test.provider(
31 "getProjectsLocationsCatalogsControls on a missing control fails with a typed tag",
32 (stack) =>
33 Effect.gen(function* () {
34 const { project } = yield* GcpEnvironment.current;
35
36 yield* stack.destroy();
37
38 const error = yield* Effect.flip(
39 retail.getProjectsLocationsCatalogsControls({
40 name: `projects/${project}/locations/global/catalogs/default_catalog/controls/alchemy-missing`,
41 }),
42 );
43 expect(error._tag).toEqual(runLifecycle ? "NotFound" : "RetailDataUseTermsNotAccepted");
44
45 yield* stack.destroy();
46 }).pipe(logLevel),
47 { tags: ["provider:gcp", "provider:gcp:retail", "live"], timeout: 90_000 },
48 );
49
50 test.provider.skipIf(!runLifecycle)(
51 "create, update, and delete a catalog control",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 return yield* GCP.Retail.CatalogsControl("Greetings", {
59 displayName: "greetings",
60 synonyms: ["hello", "hi"],
61 });
62 }),
63 );
64
65 expect(created.name).toContain("/controls/");
66 expect(created.synonyms).toEqual(expect.arrayContaining(["hello", "hi"]));
67
68 const fetched = yield* retail.getProjectsLocationsCatalogsControls({
69 name: created.name,
70 });
71 expect(fetched.name).toEqual(created.name);
72 expect(fetched.displayName).toEqual(created.displayName);
73
74 const updated = yield* stack.deploy(
75 Effect.gen(function* () {
76 return yield* GCP.Retail.CatalogsControl("Greetings", {
77 controlId: created.controlId,
78 catalog: created.catalog,
79 displayName: "greetings-updated",
80 synonyms: ["hello", "hi", "hey"],
81 });
82 }),
83 );
84
85 expect(updated.name).toEqual(created.name);
86 expect(updated.synonyms).toEqual(expect.arrayContaining(["hello", "hi", "hey"]));
87
88 yield* stack.destroy();
89
90 const gone = yield* waitUntilGone(created.name);
91 expect(gone).toEqual("gone");
92 }).pipe(logLevel),
93 { tags: ["provider:gcp", "provider:gcp:retail", "live"], timeout: 90_000 },
94 );