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
| 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 bigquery from "@distilled.cloud/gcp/bigquery_v2"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 12 | |
| 13 | const waitUntilGone = (projectId: string, datasetId: string, tableId: string, policyId: string) => |
| 14 | bigquery |
| 15 | .getRowAccessPolicies({ |
| 16 | projectId, |
| 17 | datasetId, |
| 18 | tableId, |
| 19 | policyId, |
| 20 | }) |
| 21 | .pipe( |
| 22 | Effect.as("found" as const), |
| 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 | "create, update, and delete a row access policy", |
| 33 | (stack) => |
| 34 | Effect.gen(function* () { |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const created = yield* stack.deploy( |
| 38 | Effect.gen(function* () { |
| 39 | const dataset = yield* GCP.BigQuery.Dataset("Analytics", { |
| 40 | location: "US-CENTRAL1", |
| 41 | forceDestroy: true, |
| 42 | }); |
| 43 | const table = yield* GCP.BigQuery.Table("Events", { |
| 44 | datasetId: dataset.datasetId, |
| 45 | schema: [{ name: "nullable_field", type: "STRING" }], |
| 46 | }); |
| 47 | return yield* GCP.BigQuery.RowAccessPolicy("Visible", { |
| 48 | datasetId: dataset.datasetId, |
| 49 | tableId: table.tableId, |
| 50 | filterPredicate: "nullable_field IS NOT NULL", |
| 51 | }); |
| 52 | }), |
| 53 | ); |
| 54 | |
| 55 | expect(created.policyId).toEqual(expect.any(String)); |
| 56 | expect(created.policyId).toMatch(/^[a-zA-Z0-9_]+$/); |
| 57 | expect(created.datasetId).toEqual(expect.any(String)); |
| 58 | expect(created.tableId).toEqual(expect.any(String)); |
| 59 | expect(created.project).toEqual(expect.any(String)); |
| 60 | expect(created.filterPredicate).toEqual("nullable_field IS NOT NULL"); |
| 61 | |
| 62 | const fetched = yield* bigquery.getRowAccessPolicies({ |
| 63 | projectId: created.project, |
| 64 | datasetId: created.datasetId, |
| 65 | tableId: created.tableId, |
| 66 | policyId: created.policyId, |
| 67 | }); |
| 68 | expect(fetched.rowAccessPolicyReference?.policyId).toEqual(created.policyId); |
| 69 | // The predicate is sent verbatim — no ownership tautology. |
| 70 | expect(fetched.filterPredicate).toEqual("nullable_field IS NOT NULL"); |
| 71 | |
| 72 | const updated = yield* stack.deploy( |
| 73 | Effect.gen(function* () { |
| 74 | const dataset = yield* GCP.BigQuery.Dataset("Analytics", { |
| 75 | datasetId: created.datasetId, |
| 76 | location: "US-CENTRAL1", |
| 77 | forceDestroy: true, |
| 78 | }); |
| 79 | const table = yield* GCP.BigQuery.Table("Events", { |
| 80 | datasetId: dataset.datasetId, |
| 81 | tableId: created.tableId, |
| 82 | schema: [{ name: "nullable_field", type: "STRING" }], |
| 83 | }); |
| 84 | return yield* GCP.BigQuery.RowAccessPolicy("Visible", { |
| 85 | datasetId: dataset.datasetId, |
| 86 | tableId: table.tableId, |
| 87 | policyId: created.policyId, |
| 88 | filterPredicate: "TRUE", |
| 89 | }); |
| 90 | }), |
| 91 | ); |
| 92 | |
| 93 | expect(updated.name).toEqual(created.name); |
| 94 | expect(updated.policyId).toEqual(created.policyId); |
| 95 | expect(updated.filterPredicate).toEqual("TRUE"); |
| 96 | |
| 97 | const fetchedUpdate = yield* bigquery.getRowAccessPolicies({ |
| 98 | projectId: created.project, |
| 99 | datasetId: created.datasetId, |
| 100 | tableId: created.tableId, |
| 101 | policyId: created.policyId, |
| 102 | }); |
| 103 | expect(fetchedUpdate.filterPredicate).toEqual("TRUE"); |
| 104 | |
| 105 | yield* stack.destroy(); |
| 106 | |
| 107 | const gone = yield* waitUntilGone( |
| 108 | created.project, |
| 109 | created.datasetId, |
| 110 | created.tableId, |
| 111 | created.policyId, |
| 112 | ); |
| 113 | expect(gone).toEqual("gone"); |
| 114 | }).pipe(logLevel), |
| 115 | { tags: ["provider:gcp", "provider:gcp:bigquery", "live"], timeout: 90_000 }, |
| 116 | ); |