@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 92 lines 3.26 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.getProjectsLocationsCatalogsServingConfigs({ 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 "getProjectsLocationsCatalogsServingConfigs on a missing serving config 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.getProjectsLocationsCatalogsServingConfigs({
40 name: `projects/${project}/locations/global/catalogs/default_catalog/servingConfigs/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 serving config",
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.CatalogsServingConfig("Preview", {
59 displayName: "preview search",
60 });
61 }),
62 );
63
64 expect(created.name).toContain("/servingConfigs/");
65 expect(created.solutionTypes).toEqual(expect.arrayContaining(["SOLUTION_TYPE_SEARCH"]));
66
67 const fetched = yield* retail.getProjectsLocationsCatalogsServingConfigs({
68 name: created.name,
69 });
70 expect(fetched.name).toEqual(created.name);
71 expect(fetched.displayName).toEqual(created.displayName);
72
73 const updated = yield* stack.deploy(
74 Effect.gen(function* () {
75 return yield* GCP.Retail.CatalogsServingConfig("Preview", {
76 servingConfigId: created.servingConfigId,
77 catalog: created.catalog,
78 displayName: "preview search updated",
79 });
80 }),
81 );
82
83 expect(updated.name).toEqual(created.name);
84 expect(updated.displayName).toEqual("preview search updated");
85
86 yield* stack.destroy();
87
88 const gone = yield* waitUntilGone(created.name);
89 expect(gone).toEqual("gone");
90 }).pipe(logLevel),
91 { tags: ["provider:gcp", "provider:gcp:retail", "live"], timeout: 90_000 },
92 );