@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 110 lines 3.64 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.getProjectsLocationsCollectionsDataStores({ 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 "getProjectsLocationsCollectionsDataStores on a missing store fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33 const collectionParent = `projects/${project}/locations/global/collections/default_collection`;
34
35 yield* stack.destroy();
36
37 const error = yield* Effect.flip(
38 discoveryengine.getProjectsLocationsCollectionsDataStores({
39 name: `${collectionParent}/dataStores/alchemy-cds-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 collection data store",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const created = yield* stack.deploy(
59 Effect.gen(function* () {
60 return yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
61 location: "global",
62 displayName: "docs",
63 industryVertical: "GENERIC",
64 contentConfig: "NO_CONTENT",
65 solutionTypes: ["SOLUTION_TYPE_SEARCH"],
66 disableCmek: true,
67 });
68 }),
69 );
70
71 expect(created.name).toContain("/collections/");
72 expect(created.name).toContain("/dataStores/");
73 expect(created.location).toEqual("global");
74 expect(created.displayName).toEqual("docs");
75 expect(created.industryVertical).toEqual("GENERIC");
76
77 const fetched = yield* discoveryengine.getProjectsLocationsCollectionsDataStores({
78 name: created.name,
79 });
80 expect(fetched.name).toEqual(created.name);
81 expect(fetched.displayName).toEqual("docs");
82
83 const updated = yield* stack.deploy(
84 Effect.gen(function* () {
85 return yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
86 dataStoreId: created.dataStoreId,
87 location: "global",
88 collection: created.collection,
89 displayName: "prod",
90 industryVertical: "GENERIC",
91 contentConfig: "NO_CONTENT",
92 solutionTypes: ["SOLUTION_TYPE_SEARCH"],
93 disableCmek: true,
94 });
95 }),
96 );
97
98 expect(updated.name).toEqual(created.name);
99 expect(updated.displayName).toEqual("prod");
100
101 yield* stack.destroy();
102
103 const gone = yield* waitUntilGone(created.name);
104 expect(gone).toEqual("gone");
105 }).pipe(logLevel, quotaTolerant),
106 {
107 tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"],
108 timeout: 120_000,
109 },
110 );