@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 98 lines 3.42 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.getProjectsLocationsCatalogsModels({ 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 "getProjectsLocationsCatalogsModels on a missing model 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.getProjectsLocationsCatalogsModels({
40 name: `projects/${project}/locations/global/catalogs/default_catalog/models/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 model",
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.CatalogsModel("Homepage", {
59 displayName: "homepage recs",
60 type: "recommended-for-you",
61 trainingState: "PAUSED",
62 filteringOption: "RECOMMENDATIONS_FILTERING_DISABLED",
63 });
64 }),
65 );
66
67 expect(created.name).toContain("/models/");
68 expect(created.type).toEqual("recommended-for-you");
69
70 const fetched = yield* retail.getProjectsLocationsCatalogsModels({
71 name: created.name,
72 });
73 expect(fetched.name).toEqual(created.name);
74 expect(fetched.displayName).toEqual(created.displayName);
75
76 const updated = yield* stack.deploy(
77 Effect.gen(function* () {
78 return yield* GCP.Retail.CatalogsModel("Homepage", {
79 modelId: created.modelId,
80 catalog: created.catalog,
81 displayName: "homepage recs",
82 type: "recommended-for-you",
83 trainingState: "PAUSED",
84 filteringOption: "RECOMMENDATIONS_FILTERING_ENABLED",
85 });
86 }),
87 );
88
89 expect(updated.name).toEqual(created.name);
90 expect(updated.filteringOption).toEqual("RECOMMENDATIONS_FILTERING_ENABLED");
91
92 yield* stack.destroy();
93
94 const gone = yield* waitUntilGone(created.name);
95 expect(gone).toEqual("gone");
96 }).pipe(logLevel),
97 { tags: ["provider:gcp", "provider:gcp:retail", "live"], timeout: 120_000 },
98 );