@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 113 lines 3.97 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 aiplatform from "@distilled.cloud/gcp/aiplatform_v1";
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 const waitUntilGone = (name: string) =>
15 aiplatform.getProjectsLocationsMetadataStoresArtifacts({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsMetadataStoresArtifacts on a missing artifact fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 aiplatform.getProjectsLocationsMetadataStoresArtifacts({
34 name: `projects/${project}/locations/us-central1/metadataStores/alchemy-missing/artifacts/alchemy-missing`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 test.provider(
48 "create, update, and delete a metadata store artifact",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const created = yield* stack.deploy(
54 Effect.gen(function* () {
55 const store = yield* GCP.AIPlatform.MetadataStore("Mlmd", {
56 location: "us-central1",
57 description: "pipeline metadata",
58 });
59 const artifact = yield* GCP.AIPlatform.MetadataStoresArtifact("Model", {
60 metadataStore: store.name,
61 displayName: "trained-model",
62 description: "first",
63 uri: "gs://alchemy-aiplatform-test/model",
64 state: "LIVE",
65 labels: { env: "test" },
66 });
67 return { store, artifact };
68 }),
69 );
70
71 expect(created.artifact.name).toContain("/artifacts/");
72 expect(created.artifact.metadataStore).toEqual(created.store.name);
73 expect(created.artifact.displayName).toEqual("trained-model");
74 expect(created.artifact.labels).toMatchObject({ env: "test" });
75
76 const fetched = yield* aiplatform.getProjectsLocationsMetadataStoresArtifacts({
77 name: created.artifact.name,
78 });
79 expect(fetched.name).toEqual(created.artifact.name);
80
81 const updated = yield* stack.deploy(
82 Effect.gen(function* () {
83 const store = yield* GCP.AIPlatform.MetadataStore("Mlmd", {
84 metadataStoreId: created.store.metadataStoreId,
85 location: "us-central1",
86 description: "pipeline metadata",
87 });
88 const artifact = yield* GCP.AIPlatform.MetadataStoresArtifact("Model", {
89 metadataStore: store.name,
90 artifactId: created.artifact.artifactId,
91 displayName: "trained-model-v2",
92 description: "second",
93 uri: "gs://alchemy-aiplatform-test/model-v2",
94 state: "LIVE",
95 labels: { env: "prod" },
96 });
97 return { store, artifact };
98 }),
99 );
100
101 expect(updated.artifact.name).toEqual(created.artifact.name);
102 expect(updated.artifact.displayName).toEqual("trained-model-v2");
103 expect(updated.artifact.labels).toMatchObject({ env: "prod" });
104
105 yield* stack.destroy();
106 const gone = yield* waitUntilGone(created.artifact.name);
107 expect(gone).toEqual("gone");
108 }).pipe(logLevel),
109 {
110 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
111 timeout: 180_000,
112 },
113 );