The best way to control Claude Code, Codex and more from any computer or phone

main
ts 146 lines 5.22 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 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
17 const waitUntilGone = (name: string) =>
18 discoveryengine.getProjectsLocationsCollectionsDataStoresServingConfigs({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("2 seconds"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider(
29 "getProjectsLocationsCollectionsDataStoresServingConfigs on a missing serving config fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 discoveryengine.getProjectsLocationsCollectionsDataStoresServingConfigs({
38 name: `projects/${project}/locations/global/collections/default_collection/dataStores/alchemy-missing/servingConfigs/alchemy-missing`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 yield* stack.destroy();
44 }).pipe(logLevel, quotaTolerant),
45 {
46 tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"],
47 timeout: 90_000,
48 },
49 );
50
51 test.provider.skipIf(!runLifecycle)(
52 "create, update, and delete a collection data store serving config",
53 (stack) =>
54 Effect.gen(function* () {
55 yield* stack.destroy();
56
57 const parent = yield* stack.deploy(
58 Effect.gen(function* () {
59 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
60 location: "global",
61 displayName: "docs",
62 disableCmek: true,
63 });
64 const engine = yield* GCP.DiscoveryEngine.CollectionsEngine("Search", {
65 location: "global",
66 dataStoreIds: [store.dataStoreId],
67 displayName: "eng",
68 solutionType: "SOLUTION_TYPE_SEARCH",
69 industryVertical: "GENERIC",
70 });
71 return { store, engine };
72 }),
73 );
74
75 const created = yield* stack.deploy(
76 Effect.gen(function* () {
77 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
78 dataStoreId: parent.store.dataStoreId,
79 location: "global",
80 collection: parent.store.collection,
81 displayName: "docs",
82 disableCmek: true,
83 });
84 const engine = yield* GCP.DiscoveryEngine.CollectionsEngine("Search", {
85 engineId: parent.engine.engineId,
86 location: "global",
87 dataStoreIds: [store.dataStoreId],
88 displayName: "eng",
89 solutionType: "SOLUTION_TYPE_SEARCH",
90 industryVertical: "GENERIC",
91 });
92 const serving = yield* GCP.DiscoveryEngine.CollectionsDataStoresServingConfig("Preview", {
93 dataStore: store.name,
94 displayName: parent.engine.engineId.slice(0, 2),
95 });
96 return { store, engine, serving };
97 }),
98 );
99
100 expect(created.serving.name).toContain("/servingConfigs/");
101
102 const fetched =
103 yield* discoveryengine.getProjectsLocationsCollectionsDataStoresServingConfigs({
104 name: created.serving.name,
105 });
106 expect(fetched.name).toEqual(created.serving.name);
107 expect(fetched.displayName).toEqual(created.serving.displayName);
108
109 const updated = yield* stack.deploy(
110 Effect.gen(function* () {
111 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
112 dataStoreId: created.store.dataStoreId,
113 location: "global",
114 collection: created.store.collection,
115 displayName: "docs",
116 disableCmek: true,
117 });
118 const engine = yield* GCP.DiscoveryEngine.CollectionsEngine("Search", {
119 engineId: created.engine.engineId,
120 location: "global",
121 dataStoreIds: [store.dataStoreId],
122 displayName: "eng",
123 solutionType: "SOLUTION_TYPE_SEARCH",
124 industryVertical: "GENERIC",
125 });
126 const serving = yield* GCP.DiscoveryEngine.CollectionsDataStoresServingConfig("Preview", {
127 dataStore: store.name,
128 servingConfigId: created.serving.servingConfigId,
129 displayName: created.engine.engineId.slice(0, 4),
130 });
131 return { store, engine, serving };
132 }),
133 );
134
135 expect(updated.serving.name).toEqual(created.serving.name);
136
137 yield* stack.destroy();
138
139 const gone = yield* waitUntilGone(created.serving.name);
140 expect(gone).toEqual("gone");
141 }).pipe(logLevel, quotaTolerant),
142 {
143 tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"],
144 timeout: 120_000,
145 },
146 );