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

main
ts 133 lines 4.4 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as recommendationengine from "@distilled.cloud/gcp/recommendationengine_v1beta1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { currentProject, entitled, logLevel, missingNameOf } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 recommendationengine.getProjectsLocationsCatalogsCatalogItems({ name }).pipe(
13 Effect.as("found" as const),
14 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
15 Effect.repeat({
16 schedule: Schedule.spaced("1 second"),
17 until: (status) => status === "gone",
18 times: 10,
19 }),
20 );
21
22 test.provider.skipIf(!entitled)(
23 "getProjectsLocationsCatalogsCatalogItems on a missing item fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 const project = yield* currentProject;
27 yield* stack.destroy();
28
29 const error = yield* Effect.flip(
30 recommendationengine.getProjectsLocationsCatalogsCatalogItems({
31 name: missingNameOf(project),
32 }),
33 );
34 expect(error._tag).toEqual("NotFound");
35
36 yield* stack.destroy();
37 }).pipe(logLevel),
38 {
39 tags: ["provider:gcp", "provider:gcp:recommendationengine", "live"],
40 timeout: 90_000,
41 },
42 );
43
44 test.provider.skipIf(entitled)(
45 "getProjectsLocationsCatalogsCatalogItems fails with ServiceDisabled while the API is disabled",
46 (stack) =>
47 Effect.gen(function* () {
48 const project = yield* currentProject;
49 yield* stack.destroy();
50
51 const error = yield* Effect.flip(
52 recommendationengine.getProjectsLocationsCatalogsCatalogItems({
53 name: missingNameOf(project),
54 }),
55 );
56 expect(["ServiceDisabled", "NotFound"]).toContain(error._tag);
57
58 yield* stack.destroy();
59 }).pipe(logLevel),
60 {
61 tags: ["provider:gcp", "provider:gcp:recommendationengine", "live"],
62 timeout: 90_000,
63 },
64 );
65
66 test.provider.skipIf(!entitled || !!process.env.FAST)(
67 "create, update, and delete a catalog item",
68 (stack) =>
69 Effect.gen(function* () {
70 yield* stack.destroy();
71
72 const created = yield* stack.deploy(
73 Effect.gen(function* () {
74 return yield* GCP.RecommendationEngine.CatalogsCatalogItem("Shirt", {
75 title: "Cotton tee",
76 description: "test tee",
77 categoryHierarchies: [{ categories: ["Apparel", "T-Shirts"] }],
78 productMetadata: {
79 currencyCode: "USD",
80 exactPrice: { displayPrice: 20 },
81 stockState: "IN_STOCK",
82 },
83 });
84 }),
85 );
86
87 expect(created.name).toContain("/catalogItems/");
88 expect(created.title).toEqual("Cotton tee");
89 expect(created.description).toEqual("test tee");
90 expect(created.categoryHierarchies[0]?.categories).toEqual(
91 expect.arrayContaining(["Apparel", "T-Shirts"]),
92 );
93
94 const fetched = yield* recommendationengine.getProjectsLocationsCatalogsCatalogItems({
95 name: created.name,
96 });
97 expect(fetched.id).toEqual(created.catalogItemId);
98 // Description and tags feed recommendations: no ownership marker.
99 expect(fetched.description).toEqual("test tee");
100 expect(fetched.title).toEqual("Cotton tee");
101
102 const updated = yield* stack.deploy(
103 Effect.gen(function* () {
104 return yield* GCP.RecommendationEngine.CatalogsCatalogItem("Shirt", {
105 catalogItemId: created.catalogItemId,
106 catalog: created.catalog,
107 location: created.location,
108 title: "Linen tee",
109 description: "updated tee",
110 categoryHierarchies: [{ categories: ["Apparel", "T-Shirts"] }],
111 productMetadata: {
112 currencyCode: "USD",
113 exactPrice: { displayPrice: 24 },
114 stockState: "IN_STOCK",
115 },
116 });
117 }),
118 );
119
120 expect(updated.name).toEqual(created.name);
121 expect(updated.title).toEqual("Linen tee");
122 expect(updated.productMetadata?.exactPrice?.displayPrice).toEqual(24);
123
124 yield* stack.destroy();
125
126 const gone = yield* waitUntilGone(created.name);
127 expect(gone).toEqual("gone");
128 }).pipe(logLevel),
129 {
130 tags: ["provider:gcp", "provider:gcp:recommendationengine", "live"],
131 timeout: 90_000,
132 },
133 );