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

main
ts 113 lines 4.05 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 analyticshub from "@distilled.cloud/gcp/analyticshub_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { location, logLevel, currentProject, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 analyticshub.getProjectsLocationsDataExchanges({ name }).pipe(
13 Effect.as("found" as const),
14 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
15 Effect.catchTag("InternalServerError", () => Effect.succeed("found" as const)),
16 Effect.repeat({
17 schedule: Schedule.spaced("2 seconds"),
18 until: (status) => status === "gone",
19 times: 20,
20 }),
21 );
22
23 test.provider(
24 "getProjectsLocationsDataExchanges on a missing exchange fails with a typed tag",
25 (stack) =>
26 Effect.gen(function* () {
27 const project = yield* currentProject;
28
29 yield* stack.destroy();
30
31 const error = yield* Effect.flip(
32 analyticshub.getProjectsLocationsDataExchanges({
33 name: `projects/${project}/locations/${location}/dataExchanges/alchemy_missing_exchange`,
34 }),
35 );
36 expect(error._tag).toEqual("NotFound");
37
38 yield* stack.destroy();
39 }).pipe(logLevel),
40 {
41 tags: ["provider:gcp", "provider:gcp:analyticshub", "live"],
42 timeout: 90_000,
43 },
44 );
45
46 test.provider.skipIf(!runLifecycle)(
47 "create, update, and delete a data exchange",
48 (stack) =>
49 Effect.gen(function* () {
50 yield* stack.destroy();
51
52 const created = yield* stack.deploy(
53 Effect.gen(function* () {
54 return yield* GCP.AnalyticsHub.DataExchange("Marketplace", {
55 location,
56 displayName: "Marketplace",
57 description: "shared datasets",
58 primaryContact: "data@example.com",
59 });
60 }),
61 );
62
63 expect(created.name).toContain("/dataExchanges/");
64 expect(created.location.toLowerCase()).toEqual(location);
65 expect(created.displayName).toEqual("Marketplace");
66 expect(created.description).toEqual("shared datasets");
67 expect(created.primaryContact).toEqual("data@example.com");
68 expect(created.dataExchangeId).toMatch(/^[a-zA-Z][a-zA-Z0-9_]*$/);
69
70 const fetched = yield* analyticshub.getProjectsLocationsDataExchanges({
71 name: created.name,
72 });
73 expect(fetched.name).toEqual(created.name);
74 expect(fetched.displayName).toEqual("Marketplace");
75 expect(fetched.description).toContain("alchemy-id=");
76 expect(fetched.description).toContain("shared datasets");
77 expect(fetched.primaryContact).toEqual("data@example.com");
78
79 const updated = yield* stack.deploy(
80 Effect.gen(function* () {
81 return yield* GCP.AnalyticsHub.DataExchange("Marketplace", {
82 dataExchangeId: created.dataExchangeId,
83 location,
84 displayName: "Marketplace v2",
85 description: "updated catalogs",
86 primaryContact: "catalog@example.com",
87 documentation: "https://example.com/docs",
88 });
89 }),
90 );
91
92 expect(updated.name).toEqual(created.name);
93 expect(updated.displayName).toEqual("Marketplace v2");
94 expect(updated.description).toEqual("updated catalogs");
95 expect(updated.primaryContact).toEqual("catalog@example.com");
96 expect(updated.documentation).toEqual("https://example.com/docs");
97
98 const fetchedUpdate = yield* analyticshub.getProjectsLocationsDataExchanges({
99 name: created.name,
100 });
101 expect(fetchedUpdate.displayName).toEqual("Marketplace v2");
102 expect(fetchedUpdate.description).toContain("updated catalogs");
103 expect(fetchedUpdate.primaryContact).toEqual("catalog@example.com");
104
105 yield* stack.destroy();
106 const gone = yield* waitUntilGone(created.name);
107 expect(gone).toEqual("gone");
108 }).pipe(logLevel),
109 {
110 tags: ["provider:gcp", "provider:gcp:analyticshub", "live"],
111 timeout: 90_000,
112 },
113 );