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

main
ts 138 lines 4.72 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 vision from "@distilled.cloud/gcp/vision_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { location, logLevel, currentProject, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 vision.getProjectsLocationsProducts({ 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(
23 "getProjectsLocationsProducts on a missing product 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 vision.getProjectsLocationsProducts({
31 name: `projects/${project}/locations/${location}/products/alchemy-missing-product`,
32 }),
33 );
34 expect(error._tag).toEqual("NotFound");
35
36 yield* stack.destroy();
37 }).pipe(logLevel),
38 { tags: ["provider:gcp", "provider:gcp:vision", "live"], timeout: 90_000 },
39 );
40
41 test.provider.skipIf(runLifecycle)(
42 "createProjectsLocationsProducts on a new project fails with ProductSearchNotOnboarded",
43 (stack) =>
44 Effect.gen(function* () {
45 const project = yield* currentProject;
46 yield* stack.destroy();
47
48 const error = yield* Effect.flip(
49 vision.createProjectsLocationsProducts({
50 parent: `projects/${project}/locations/${location}`,
51 productId: "alchemy-vision-probe",
52 body: {
53 displayName: "Alchemy probe",
54 productCategory: "homegoods-v2",
55 },
56 }),
57 );
58 expect(error._tag).toEqual("ProductSearchNotOnboarded");
59
60 yield* stack.destroy();
61 }).pipe(logLevel),
62 { tags: ["provider:gcp", "provider:gcp:vision", "live"], timeout: 90_000 },
63 );
64
65 test.provider.skipIf(!runLifecycle)(
66 "create, update, and delete a product",
67 (stack) =>
68 Effect.gen(function* () {
69 const project = yield* currentProject;
70 yield* stack.destroy();
71
72 const created = yield* stack.deploy(
73 Effect.gen(function* () {
74 return yield* GCP.Vision.Product("Shoe", {
75 location,
76 displayName: "Trail runner",
77 description: "mesh upper",
78 productCategory: "apparel-v2",
79 productLabels: [{ key: "color", value: "blue" }],
80 });
81 }),
82 );
83
84 expect(
85 created.name.startsWith(`projects/${project}/locations/${location}/products/`),
86 ).toEqual(true);
87 expect(created.productId.length).toBeGreaterThan(0);
88 expect(created.displayName).toEqual("Trail runner");
89 expect(created.description).toEqual("mesh upper");
90 expect(created.productCategory).toEqual("apparel-v2");
91 expect(created.productLabels).toEqual([{ key: "color", value: "blue" }]);
92
93 const fetched = yield* vision.getProjectsLocationsProducts({
94 name: created.name,
95 });
96 expect(fetched.name).toEqual(created.name);
97 expect(fetched.displayName).toEqual("Trail runner");
98 expect(fetched.description).toEqual("mesh upper");
99 expect(fetched.productCategory).toEqual("apparel-v2");
100 expect(fetched.productLabels).toEqual([{ key: "color", value: "blue" }]);
101
102 const updated = yield* stack.deploy(
103 Effect.gen(function* () {
104 return yield* GCP.Vision.Product("Shoe", {
105 location,
106 productId: created.productId,
107 displayName: "Trail runner v2",
108 description: "knit upper",
109 productCategory: "apparel-v2",
110 productLabels: [
111 { key: "color", value: "green" },
112 { key: "size", value: "10" },
113 ],
114 });
115 }),
116 );
117
118 expect(updated.name).toEqual(created.name);
119 expect(updated.displayName).toEqual("Trail runner v2");
120 expect(updated.description).toEqual("knit upper");
121 expect(updated.productLabels).toEqual([
122 { key: "color", value: "green" },
123 { key: "size", value: "10" },
124 ]);
125
126 const fetchedUpdate = yield* vision.getProjectsLocationsProducts({
127 name: created.name,
128 });
129 expect(fetchedUpdate.displayName).toEqual("Trail runner v2");
130 expect(fetchedUpdate.description).toEqual("knit upper");
131
132 yield* stack.destroy();
133
134 const gone = yield* waitUntilGone(created.name);
135 expect(gone).toEqual("gone");
136 }).pipe(logLevel),
137 { tags: ["provider:gcp", "provider:gcp:vision", "live"], timeout: 90_000 },
138 );