@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 137 lines 4.54 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, runVersionLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 ml.getProjectsModelsVersions({ name }).pipe(
13 Effect.as("found" as const),
14 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
15 Effect.repeat({
16 schedule: Schedule.spaced("2 seconds"),
17 until: (status) => status === "gone",
18 times: 10,
19 }),
20 );
21
22 test.provider(
23 "getProjectsModelsVersions on a missing version 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.getProjectsModelsVersions({
32 name: `projects/${project}/models/alchemy-missing-model/versions/v1`,
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 "createProjectsModelsVersions on a missing model fails with NotFound",
44 (stack) =>
45 Effect.gen(function* () {
46 const project = yield* currentProject;
47
48 yield* stack.destroy();
49
50 const error = yield* Effect.flip(
51 ml.createProjectsModelsVersions({
52 parent: `projects/${project}/models/alchemy-missing-model`,
53 body: {
54 name: "v1",
55 deploymentUri: `gs://${project}-ml-missing/model`,
56 description: "probe",
57 },
58 }),
59 );
60 expect(error._tag).toEqual("NotFound");
61
62 yield* stack.destroy();
63 }).pipe(logLevel),
64 { tags: ["provider:gcp", "provider:gcp:ml", "live"], timeout: 90_000 },
65 );
66
67 test.provider.skipIf(!runVersionLifecycle)(
68 "create, update, and delete a model version",
69 (stack) =>
70 Effect.gen(function* () {
71 yield* stack.destroy();
72
73 const deploymentUri = process.env.GCP_TEST_ML_DEPLOYMENT_URI ?? "";
74
75 const created = yield* stack.deploy(
76 Effect.gen(function* () {
77 const model = yield* GCP.ML.Model("Classifier", {
78 description: "image classifier",
79 regions: [region],
80 });
81 const version = yield* GCP.ML.ModelsVersion("V1", {
82 model: model.name,
83 deploymentUri,
84 runtimeVersion: "2.11",
85 pythonVersion: "3.7",
86 framework: "TENSORFLOW",
87 description: "first version",
88 labels: { env: "test" },
89 autoScaling: { minNodes: 0 },
90 });
91 return { model, version };
92 }),
93 );
94
95 expect(created.version.name).toContain("/versions/");
96 expect(created.version.model).toEqual(created.model.name);
97 expect(created.version.description).toEqual("first version");
98 expect(created.version.deploymentUri).toEqual(deploymentUri);
99 expect(created.version.labels).toMatchObject({ env: "test" });
100
101 const fetched = yield* ml.getProjectsModelsVersions({
102 name: created.version.name,
103 });
104 expect(fetched.name).toEqual(created.version.name);
105 expect(fetched.description).toContain("[alchemy ");
106 expect(fetched.description).toContain("first version");
107
108 const updated = yield* stack.deploy(
109 Effect.gen(function* () {
110 const model = yield* GCP.ML.Model("Classifier", {
111 modelId: created.model.modelId,
112 description: "image classifier",
113 regions: [region],
114 });
115 const version = yield* GCP.ML.ModelsVersion("V1", {
116 model: model.name,
117 versionId: created.version.versionId,
118 deploymentUri,
119 runtimeVersion: "2.11",
120 pythonVersion: "3.7",
121 framework: "TENSORFLOW",
122 description: "first version v2",
123 autoScaling: { minNodes: 0 },
124 });
125 return { model, version };
126 }),
127 );
128
129 expect(updated.version.name).toEqual(created.version.name);
130 expect(updated.version.description).toEqual("first version v2");
131
132 yield* stack.destroy();
133 const gone = yield* waitUntilGone(created.version.name);
134 expect(gone).toEqual("gone");
135 }).pipe(logLevel),
136 { tags: ["provider:gcp", "provider:gcp:ml", "live"], timeout: 120_000 },
137 );