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

main
ts 100 lines 3.31 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 datacatalog from "@distilled.cloud/gcp/datacatalog_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { location, logLevel, currentProject } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 datacatalog.getProjectsLocationsTaxonomies({ 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 "getProjectsLocationsTaxonomies on a missing taxonomy 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 datacatalog.getProjectsLocationsTaxonomies({
31 name: `projects/${project}/locations/${location}/taxonomies/alchemy-missing-taxonomy`,
32 }),
33 );
34 expect(error._tag).toEqual("NotFound");
35
36 yield* stack.destroy();
37 }).pipe(logLevel),
38 {
39 tags: ["provider:gcp", "provider:gcp:datacatalog", "live"],
40 timeout: 90_000,
41 },
42 );
43
44 test.provider(
45 "create, update, and delete a taxonomy",
46 (stack) =>
47 Effect.gen(function* () {
48 const project = yield* currentProject;
49 yield* stack.destroy();
50
51 const created = yield* stack.deploy(
52 Effect.gen(function* () {
53 return yield* GCP.DataCatalog.Taxonomy("Pii", {
54 location,
55 description: "taxonomy a",
56 activatedPolicyTypes: ["FINE_GRAINED_ACCESS_CONTROL"],
57 });
58 }),
59 );
60
61 expect(created.name).toContain("/taxonomies/");
62 expect(created.taxonomyId).toEqual(expect.any(String));
63 expect(created.project).toEqual(project);
64 expect(created.location).toEqual(location);
65 expect(created.displayName).toEqual(expect.any(String));
66 expect(created.description).toEqual("taxonomy a");
67 expect(created.activatedPolicyTypes).toContain("FINE_GRAINED_ACCESS_CONTROL");
68
69 const fetched = yield* datacatalog.getProjectsLocationsTaxonomies({
70 name: created.name,
71 });
72 expect(fetched.name).toEqual(created.name);
73 expect(fetched.description).toContain("alchemy-id=");
74 expect(fetched.description).toContain("taxonomy a");
75 expect(fetched.displayName).toEqual(created.displayName);
76
77 const updated = yield* stack.deploy(
78 Effect.gen(function* () {
79 return yield* GCP.DataCatalog.Taxonomy("Pii", {
80 location,
81 displayName: created.displayName,
82 description: "taxonomy b",
83 activatedPolicyTypes: ["FINE_GRAINED_ACCESS_CONTROL"],
84 });
85 }),
86 );
87
88 expect(updated.name).toEqual(created.name);
89 expect(updated.displayName).toEqual(created.displayName);
90 expect(updated.description).toEqual("taxonomy b");
91
92 yield* stack.destroy();
93 const gone = yield* waitUntilGone(created.name);
94 expect(gone).toEqual("gone");
95 }).pipe(logLevel),
96 {
97 tags: ["provider:gcp", "provider:gcp:datacatalog", "live"],
98 timeout: 90_000,
99 },
100 );