@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 120 lines 4.17 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 bigqueryreservation from "@distilled.cloud/gcp/bigqueryreservation_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const parentOf = (name: string) => name.replace(/\/assignments\/[^/]+$/, "");
15
16 const waitUntilGone = (name: string) =>
17 bigqueryreservation
18 .listProjectsLocationsReservationsAssignments({
19 parent: parentOf(name),
20 pageSize: 100,
21 })
22 .pipe(
23 Effect.map((page) =>
24 (page.assignments ?? []).some((item) => item.name === name)
25 ? ("found" as const)
26 : ("gone" as const),
27 ),
28 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
29 Effect.repeat({
30 schedule: Schedule.spaced("1 second"),
31 until: (status) => status === "gone",
32 times: 10,
33 }),
34 );
35
36 test.provider(
37 "listProjectsLocationsReservationsAssignments on a missing reservation is empty",
38 (stack) =>
39 Effect.gen(function* () {
40 const { project } = yield* GcpEnvironment.current;
41 yield* stack.destroy();
42
43 // Listing under a missing reservation answers an empty page.
44 const page = yield* bigqueryreservation.listProjectsLocationsReservationsAssignments({
45 parent: `projects/${project}/locations/us-central1/reservations/alchemy-bq-assignment-missing`,
46 });
47 expect(page.assignments).toBeUndefined();
48
49 yield* stack.destroy();
50 }).pipe(logLevel),
51 {
52 tags: ["provider:gcp", "provider:gcp:bigqueryreservation", "live"],
53 timeout: 90_000,
54 },
55 );
56
57 test.provider.skipIf(!!process.env.FAST)(
58 "create, update, and delete a reservation assignment",
59 (stack) =>
60 Effect.gen(function* () {
61 const { project } = yield* GcpEnvironment.current;
62 yield* stack.destroy();
63
64 const created = yield* stack.deploy(
65 Effect.gen(function* () {
66 const reservation = yield* GCP.BigQueryReservation.Reservation("Slots", {
67 location: "us-central1",
68 edition: "ENTERPRISE",
69 slotCapacity: "0",
70 });
71 const assignment = yield* GCP.BigQueryReservation.Assignment("Query", {
72 reservation: reservation.name,
73 jobType: "QUERY",
74 });
75 return { reservation, assignment };
76 }),
77 );
78
79 expect(created.assignment.name).toContain("/assignments/");
80 expect(created.assignment.reservation).toEqual(created.reservation.name);
81 expect(created.assignment.jobType).toEqual("QUERY");
82 expect(created.assignment.assignee).toContain(`projects/${project}`);
83
84 const listed = yield* bigqueryreservation.listProjectsLocationsReservationsAssignments({
85 parent: created.reservation.name,
86 });
87 expect(
88 (listed.assignments ?? []).some((item) => item.name === created.assignment.name),
89 ).toEqual(true);
90
91 const updated = yield* stack.deploy(
92 Effect.gen(function* () {
93 const reservation = yield* GCP.BigQueryReservation.Reservation("Slots", {
94 reservationId: created.reservation.reservationId,
95 location: "us-central1",
96 edition: "ENTERPRISE",
97 slotCapacity: "0",
98 });
99 const assignment = yield* GCP.BigQueryReservation.Assignment("Query", {
100 assignmentId: created.assignment.assignmentId,
101 reservation: reservation.name,
102 jobType: "QUERY",
103 principal: created.assignment.principal,
104 });
105 return { reservation, assignment };
106 }),
107 );
108
109 expect(updated.assignment.name).toEqual(created.assignment.name);
110
111 yield* stack.destroy();
112
113 const gone = yield* waitUntilGone(created.assignment.name);
114 expect(gone).toEqual("gone");
115 }).pipe(logLevel),
116 {
117 tags: ["provider:gcp", "provider:gcp:bigqueryreservation", "live"],
118 timeout: 90_000,
119 },
120 );