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 { 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 | // Conversations need the Large Language Model add-on (BadRequest "This |
| 17 | // feature is only available when Large Language Model add-on is enabled."). |
| 18 | // Set GCP_TEST_DISCOVERYENGINE_LLM=1 on a project with the add-on. |
| 19 | const runLlmLifecycle = runLifecycle && !!process.env.GCP_TEST_DISCOVERYENGINE_LLM; |
| 20 | |
| 21 | const waitUntilGone = (name: string) => |
| 22 | discoveryengine.getProjectsLocationsCollectionsDataStoresConversations({ name }).pipe( |
| 23 | Effect.as("found" as const), |
| 24 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 25 | Effect.repeat({ |
| 26 | schedule: Schedule.spaced("2 seconds"), |
| 27 | until: (status) => status === "gone", |
| 28 | times: 10, |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | test.provider( |
| 33 | "getProjectsLocationsCollectionsDataStoresConversations on a missing conversation fails with a typed tag", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | const { project } = yield* GcpEnvironment.current; |
| 37 | |
| 38 | yield* stack.destroy(); |
| 39 | |
| 40 | const error = yield* Effect.flip( |
| 41 | discoveryengine.getProjectsLocationsCollectionsDataStoresConversations({ |
| 42 | name: `projects/${project}/locations/global/collections/default_collection/dataStores/alchemy-missing/conversations/alchemy-missing`, |
| 43 | }), |
| 44 | ); |
| 45 | expect(error._tag).toEqual("NotFound"); |
| 46 | |
| 47 | yield* stack.destroy(); |
| 48 | }).pipe(logLevel, quotaTolerant), |
| 49 | { |
| 50 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 51 | timeout: 90_000, |
| 52 | }, |
| 53 | ); |
| 54 | |
| 55 | test.provider.skipIf(!runLifecycle || runLlmLifecycle)( |
| 56 | "create conversation without LLM add-on fails with LlmAddOnRequired", |
| 57 | (stack) => |
| 58 | Effect.gen(function* () { |
| 59 | yield* stack.destroy(); |
| 60 | |
| 61 | const store = yield* stack.deploy( |
| 62 | Effect.gen(function* () { |
| 63 | return yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", { |
| 64 | location: "global", |
| 65 | displayName: "docs", |
| 66 | disableCmek: true, |
| 67 | }); |
| 68 | }), |
| 69 | ); |
| 70 | |
| 71 | const error = yield* Effect.flip( |
| 72 | discoveryengine.createProjectsLocationsCollectionsDataStoresConversations({ |
| 73 | parent: store.name, |
| 74 | body: { userPseudoId: "probe", state: "IN_PROGRESS" }, |
| 75 | }), |
| 76 | ); |
| 77 | expect(error._tag).toEqual("LlmAddOnRequired"); |
| 78 | |
| 79 | yield* stack.destroy(); |
| 80 | }).pipe(logLevel, quotaTolerant), |
| 81 | { |
| 82 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 83 | timeout: 120_000, |
| 84 | }, |
| 85 | ); |
| 86 | |
| 87 | test.provider.skipIf(!runLlmLifecycle)( |
| 88 | "create, update, and delete a collection data store conversation", |
| 89 | (stack) => |
| 90 | Effect.gen(function* () { |
| 91 | yield* stack.destroy(); |
| 92 | |
| 93 | const created = yield* stack.deploy( |
| 94 | Effect.gen(function* () { |
| 95 | const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", { |
| 96 | location: "global", |
| 97 | displayName: "docs", |
| 98 | disableCmek: true, |
| 99 | }); |
| 100 | const conversation = yield* GCP.DiscoveryEngine.CollectionsDataStoresConversation( |
| 101 | "Visitor", |
| 102 | { |
| 103 | dataStore: store.name, |
| 104 | userPseudoId: "user-1", |
| 105 | state: "IN_PROGRESS", |
| 106 | }, |
| 107 | ); |
| 108 | return { store, conversation }; |
| 109 | }), |
| 110 | ); |
| 111 | |
| 112 | expect(created.conversation.name).toContain("/conversations/"); |
| 113 | expect(created.conversation.userPseudoId).toEqual("user-1"); |
| 114 | |
| 115 | const fetched = yield* discoveryengine.getProjectsLocationsCollectionsDataStoresConversations( |
| 116 | { name: created.conversation.name }, |
| 117 | ); |
| 118 | expect(fetched.name).toEqual(created.conversation.name); |
| 119 | expect(fetched.userPseudoId).toContain("alc-"); |
| 120 | |
| 121 | const updated = yield* stack.deploy( |
| 122 | Effect.gen(function* () { |
| 123 | const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", { |
| 124 | dataStoreId: created.store.dataStoreId, |
| 125 | location: "global", |
| 126 | collection: created.store.collection, |
| 127 | displayName: "docs", |
| 128 | disableCmek: true, |
| 129 | }); |
| 130 | const conversation = yield* GCP.DiscoveryEngine.CollectionsDataStoresConversation( |
| 131 | "Visitor", |
| 132 | { |
| 133 | dataStore: store.name, |
| 134 | userPseudoId: "user-2", |
| 135 | state: "COMPLETED", |
| 136 | }, |
| 137 | ); |
| 138 | return { store, conversation }; |
| 139 | }), |
| 140 | ); |
| 141 | |
| 142 | expect(updated.conversation.name).toEqual(created.conversation.name); |
| 143 | expect(updated.conversation.userPseudoId).toEqual("user-2"); |
| 144 | expect(updated.conversation.state).toEqual("COMPLETED"); |
| 145 | |
| 146 | yield* stack.destroy(); |
| 147 | |
| 148 | const gone = yield* waitUntilGone(created.conversation.name); |
| 149 | expect(gone).toEqual("gone"); |
| 150 | }).pipe(logLevel, quotaTolerant), |
| 151 | { |
| 152 | tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"], |
| 153 | timeout: 120_000, |
| 154 | }, |
| 155 | ); |