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

main
ts 124 lines 3.96 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 ml from "@distilled.cloud/gcp/ml_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { logLevel, currentProject, region, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 ml.getProjectsModels({ 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 "getProjectsModels on a missing model fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 const project = yield* currentProject;
27
28 yield* stack.destroy();
29
30 const error = yield* Effect.flip(
31 ml.getProjectsModels({
32 name: `projects/${project}/models/alchemy-missing-model`,
33 }),
34 );
35 expect(error._tag).toEqual("NotFound");
36
37 yield* stack.destroy();
38 }).pipe(logLevel),
39 { tags: ["provider:gcp", "provider:gcp:ml", "live"], timeout: 90_000 },
40 );
41
42 test.provider.skipIf(runLifecycle)(
43 "createProjectsModels is rejected with AiPlatformDeprecated",
44 (stack) =>
45 Effect.gen(function* () {
46 yield* stack.destroy();
47
48 const error = yield* Effect.flip(
49 stack.deploy(
50 Effect.gen(function* () {
51 return yield* GCP.ML.Model("Classifier", {
52 description: "probe",
53 labels: { env: "test" },
54 regions: [region],
55 });
56 }),
57 ),
58 );
59 expect(error._tag).toEqual("AiPlatformDeprecated");
60
61 yield* stack.destroy();
62 }).pipe(logLevel),
63 { tags: ["provider:gcp", "provider:gcp:ml", "live"], timeout: 90_000 },
64 );
65
66 test.provider.skipIf(!runLifecycle)(
67 "create, update, and delete a model",
68 (stack) =>
69 Effect.gen(function* () {
70 const project = yield* currentProject;
71
72 yield* stack.destroy();
73
74 const created = yield* stack.deploy(
75 Effect.gen(function* () {
76 return yield* GCP.ML.Model("Classifier", {
77 description: "image classifier",
78 labels: { env: "test" },
79 regions: [region],
80 });
81 }),
82 );
83
84 expect(created.name.startsWith(`projects/${project}/models/`)).toEqual(true);
85 expect(created.modelId.length).toBeGreaterThan(0);
86 expect(created.description).toEqual("image classifier");
87 expect(created.labels).toMatchObject({ env: "test" });
88 expect(created.regions).toEqual([region]);
89
90 const fetched = yield* ml.getProjectsModels({ name: created.name });
91 expect(fetched.name).toEqual(created.name);
92 expect(fetched.description).toContain("[alchemy ");
93 expect(fetched.description).toContain("image classifier");
94 expect(fetched.labels?.env).toEqual("test");
95 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
96 true,
97 );
98
99 const updated = yield* stack.deploy(
100 Effect.gen(function* () {
101 return yield* GCP.ML.Model("Classifier", {
102 modelId: created.modelId,
103 description: "image classifier v2",
104 labels: { env: "prod" },
105 regions: [region],
106 });
107 }),
108 );
109
110 expect(updated.name).toEqual(created.name);
111 expect(updated.description).toEqual("image classifier v2");
112
113 const fetchedUpdate = yield* ml.getProjectsModels({
114 name: created.name,
115 });
116 expect(fetchedUpdate.description).toContain("image classifier v2");
117 expect(fetchedUpdate.description).toContain("alchemy-id=");
118
119 yield* stack.destroy();
120 const gone = yield* waitUntilGone(created.name);
121 expect(gone).toEqual("gone");
122 }).pipe(logLevel),
123 { tags: ["provider:gcp", "provider:gcp:ml", "live"], timeout: 90_000 },
124 );