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

main
ts 117 lines 3.79 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 import { UsersSource } from "./fixtures/features.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 const waitUntilGone = (name: string) =>
16 aiplatform.getProjectsLocationsFeatureGroups({ name }).pipe(
17 Effect.as("found" as const),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.repeat({
20 schedule: Schedule.spaced("2 seconds"),
21 until: (status) => status === "gone",
22 times: 10,
23 }),
24 );
25
26 test.provider(
27 "getProjectsLocationsFeatureGroups on a missing group fails with a typed tag",
28 (stack) =>
29 Effect.gen(function* () {
30 const { project } = yield* GcpEnvironment.current;
31 const parent = `projects/${project}/locations/us-central1`;
32 yield* stack.destroy();
33
34 const error = yield* Effect.flip(
35 aiplatform.getProjectsLocationsFeatureGroups({
36 name: `${parent}/featureGroups/alchemy_missing`,
37 }),
38 );
39 expect(error._tag).toEqual("NotFound");
40 const page = yield* aiplatform.listProjectsLocationsFeatureGroups({
41 parent,
42 pageSize: 10,
43 });
44 expect((page.featureGroups ?? []).map((item) => item.name)).not.toContain(
45 `${parent}/featureGroups/alchemy_missing`,
46 );
47
48 yield* stack.destroy();
49 }).pipe(logLevel),
50 {
51 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
52 timeout: 90_000,
53 },
54 );
55
56 test.provider(
57 "create, update, and delete a feature group",
58 (stack) =>
59 Effect.gen(function* () {
60 yield* stack.destroy();
61
62 const created = yield* stack.deploy(
63 Effect.gen(function* () {
64 const inputUri = yield* UsersSource;
65 return yield* GCP.AIPlatform.FeatureGroup("Users", {
66 location: "us-central1",
67 description: "user features",
68 labels: { env: "test" },
69 bigQuery: {
70 inputUri,
71 entityIdColumns: ["entity_id"],
72 },
73 });
74 }),
75 );
76
77 expect(created.name).toContain("/featureGroups/");
78 expect(created.location).toEqual("us-central1");
79 expect(created.labels).toMatchObject({ env: "test" });
80 expect(created.description).toEqual("user features");
81
82 const fetched = yield* aiplatform.getProjectsLocationsFeatureGroups({
83 name: created.name,
84 });
85 expect(fetched.name).toEqual(created.name);
86 expect(fetched.labels?.env).toEqual("test");
87
88 const updated = yield* stack.deploy(
89 Effect.gen(function* () {
90 const inputUri = yield* UsersSource;
91 return yield* GCP.AIPlatform.FeatureGroup("Users", {
92 featureGroupId: created.featureGroupId,
93 location: "us-central1",
94 description: "user features v2",
95 labels: { env: "prod", role: "features" },
96 bigQuery: {
97 inputUri,
98 entityIdColumns: ["entity_id"],
99 },
100 });
101 }),
102 );
103
104 expect(updated.name).toEqual(created.name);
105 expect(updated.description).toEqual("user features v2");
106 expect(updated.labels).toMatchObject({ env: "prod", role: "features" });
107
108 yield* stack.destroy();
109
110 const gone = yield* waitUntilGone(created.name);
111 expect(gone).toEqual("gone");
112 }).pipe(logLevel),
113 {
114 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
115 timeout: 600_000,
116 },
117 );