@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 5.13 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 { hubLocation, logLevel, currentProject, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (parent: string, name: string) =>
12 analyticshub.listProjectsLocationsDataExchangesListings({ parent, pageSize: 100 }).pipe(
13 Effect.map((page) =>
14 (page.listings ?? []).some((item) => item.name === name)
15 ? ("found" as const)
16 : ("gone" as const),
17 ),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.catchTag("InternalServerError", () => Effect.succeed("found" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("2 seconds"),
22 until: (status) => status === "gone",
23 times: 20,
24 }),
25 );
26
27 test.provider(
28 "getProjectsLocationsDataExchangesListings on a missing listing fails with a typed tag",
29 (stack) =>
30 Effect.gen(function* () {
31 const project = yield* currentProject;
32
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 analyticshub.getProjectsLocationsDataExchangesListings({
37 name: `projects/${project}/locations/${hubLocation}/dataExchanges/missing/listings/alchemy_missing_listing`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41
42 yield* stack.destroy();
43 }).pipe(logLevel),
44 {
45 tags: ["provider:gcp", "provider:gcp:analyticshub", "live"],
46 timeout: 90_000,
47 },
48 );
49
50 test.provider.skipIf(!runLifecycle)(
51 "listing lifecycle",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 const dataset = yield* GCP.BigQuery.Dataset("Source", {
59 location: hubLocation,
60 forceDestroy: true,
61 });
62 const exchange = yield* GCP.AnalyticsHub.DataExchange("Hub", {
63 location: hubLocation,
64 displayName: "Hub",
65 });
66 const listing = yield* GCP.AnalyticsHub.DataExchangesListing("Orders", {
67 dataExchange: exchange.name,
68 location: hubLocation,
69 displayName: "Orders",
70 description: "order events",
71 bigqueryDataset: { dataset: dataset.name },
72 });
73 return { dataset, exchange, listing };
74 }),
75 );
76
77 expect(created.listing.name).toContain("/listings/");
78 expect(created.listing.dataExchange).toEqual(created.exchange.name);
79 expect(created.listing.displayName).toEqual("Orders");
80 expect(created.listing.description).toEqual("order events");
81 expect(created.listing.bigqueryDataset?.dataset).toContain(created.dataset.datasetId);
82
83 const fetched = yield* analyticshub.getProjectsLocationsDataExchangesListings({
84 name: created.listing.name,
85 });
86 expect(fetched.name).toEqual(created.listing.name);
87 expect(fetched.displayName).toEqual("Orders");
88 expect(fetched.description).toContain("alchemy-id=");
89 expect(fetched.description).toContain("order events");
90 expect(fetched.bigqueryDataset?.dataset).toContain(created.dataset.datasetId);
91
92 const updated = yield* stack.deploy(
93 Effect.gen(function* () {
94 const dataset = yield* GCP.BigQuery.Dataset("Source", {
95 datasetId: created.dataset.datasetId,
96 location: hubLocation,
97 forceDestroy: true,
98 });
99 const exchange = yield* GCP.AnalyticsHub.DataExchange("Hub", {
100 dataExchangeId: created.exchange.dataExchangeId,
101 location: hubLocation,
102 displayName: "Hub",
103 });
104 const listing = yield* GCP.AnalyticsHub.DataExchangesListing("Orders", {
105 dataExchange: exchange.name,
106 listingId: created.listing.listingId,
107 location: hubLocation,
108 displayName: "Orders v2",
109 description: "order facts",
110 primaryContact: "orders@example.com",
111 bigqueryDataset: { dataset: dataset.name },
112 });
113 return { dataset, exchange, listing };
114 }),
115 );
116
117 expect(updated.listing.name).toEqual(created.listing.name);
118 expect(updated.listing.displayName).toEqual("Orders v2");
119 expect(updated.listing.description).toEqual("order facts");
120 expect(updated.listing.primaryContact).toEqual("orders@example.com");
121
122 const fetchedUpdate = yield* analyticshub.getProjectsLocationsDataExchangesListings({
123 name: created.listing.name,
124 });
125 expect(fetchedUpdate.displayName).toEqual("Orders v2");
126 expect(fetchedUpdate.description).toContain("order facts");
127 expect(fetchedUpdate.primaryContact).toEqual("orders@example.com");
128
129 yield* stack.destroy();
130 const gone = yield* waitUntilGone(created.exchange.name, created.listing.name);
131 expect(gone).toEqual("gone");
132 }).pipe(logLevel),
133 {
134 tags: ["provider:gcp", "provider:gcp:analyticshub", "live"],
135 timeout: 120_000,
136 },
137 );