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 { 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 discoveryengine from "@distilled.cloud/gcp/discoveryengine_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { ensureDataStore, quotaTolerant } from "./parent.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | const runLifecycle = !process.env.FAST; |
| 16 | const parentId = "alchds3schx"; |
| 17 | |
| 18 | const waitUntilGone = (name: string) => |
| 19 | discoveryengine.getProjectsLocationsDataStoresSchemas({ name }).pipe( |
| 20 | Effect.as("found" as const), |
| 21 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 22 | Effect.repeat({ |
| 23 | schedule: Schedule.spaced("2 seconds"), |
| 24 | until: (status) => status === "gone", |
| 25 | times: 10, |
| 26 | }), |
| 27 | ); |
| 28 | |
| 29 | test.provider( |
| 30 | "getProjectsLocationsDataStoresSchemas on a missing schema fails with a typed tag", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | const { project } = yield* GcpEnvironment.current; |
| 34 | |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const error = yield* Effect.flip( |
| 38 | discoveryengine.getProjectsLocationsDataStoresSchemas({ |
| 39 | name: `projects/${project}/locations/global/dataStores/alchemy-missing/schemas/alchemy-missing`, |
| 40 | }), |
| 41 | ); |
| 42 | expect(error._tag).toEqual("NotFound"); |
| 43 | |
| 44 | yield* stack.destroy(); |
| 45 | }).pipe(logLevel, quotaTolerant), |
| 46 | { |
| 47 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 48 | timeout: 90_000, |
| 49 | }, |
| 50 | ); |
| 51 | |
| 52 | test.provider.skipIf(!runLifecycle)( |
| 53 | "create, update, and delete a data store schema", |
| 54 | (stack) => |
| 55 | Effect.gen(function* () { |
| 56 | const { project } = yield* GcpEnvironment.current; |
| 57 | |
| 58 | yield* stack.destroy(); |
| 59 | |
| 60 | const parent = yield* ensureDataStore(project, parentId, { |
| 61 | contentConfig: "NO_CONTENT", |
| 62 | skipDefaultSchemaCreation: true, |
| 63 | }); |
| 64 | |
| 65 | const created = yield* stack.deploy( |
| 66 | Effect.gen(function* () { |
| 67 | return yield* GCP.DiscoveryEngine.DataStoresSchema("Catalog", { |
| 68 | dataStore: parent.name ?? "", |
| 69 | schemaId: "alchschema", |
| 70 | jsonSchema: JSON.stringify({ |
| 71 | $schema: "https://json-schema.org/draft/2020-12/schema", |
| 72 | type: "object", |
| 73 | properties: { |
| 74 | title: { type: "string" }, |
| 75 | sku: { type: "string" }, |
| 76 | }, |
| 77 | }), |
| 78 | }); |
| 79 | }), |
| 80 | ); |
| 81 | |
| 82 | expect(created.name).toContain("/schemas/"); |
| 83 | expect(created.jsonSchema).toContain("sku"); |
| 84 | |
| 85 | const fetched = yield* discoveryengine.getProjectsLocationsDataStoresSchemas({ |
| 86 | name: created.name, |
| 87 | }); |
| 88 | expect(fetched.name).toEqual(created.name); |
| 89 | |
| 90 | const updated = yield* stack.deploy( |
| 91 | Effect.gen(function* () { |
| 92 | return yield* GCP.DiscoveryEngine.DataStoresSchema("Catalog", { |
| 93 | dataStore: parent.name ?? "", |
| 94 | schemaId: "alchschema", |
| 95 | jsonSchema: JSON.stringify({ |
| 96 | $schema: "https://json-schema.org/draft/2020-12/schema", |
| 97 | type: "object", |
| 98 | properties: { |
| 99 | title: { type: "string" }, |
| 100 | sku: { type: "string" }, |
| 101 | }, |
| 102 | }), |
| 103 | }); |
| 104 | }), |
| 105 | ); |
| 106 | |
| 107 | expect(updated.name).toEqual(created.name); |
| 108 | expect(updated.jsonSchema).toContain("sku"); |
| 109 | |
| 110 | yield* stack.destroy(); |
| 111 | |
| 112 | const gone = yield* waitUntilGone(created.name); |
| 113 | expect(gone).toEqual("gone"); |
| 114 | }).pipe(logLevel, quotaTolerant), |
| 115 | { |
| 116 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 117 | timeout: 120_000, |
| 118 | }, |
| 119 | ); |