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