@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 124 lines 4.17 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.getProjectsLocationsCollectionsDataStoresBranchesDocuments({ 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 "getProjectsLocationsCollectionsDataStoresBranchesDocuments on a missing document 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.getProjectsLocationsCollectionsDataStoresBranchesDocuments({
38 name: `projects/${project}/locations/global/collections/default_collection/dataStores/alchemy-missing/branches/default_branch/documents/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 document",
53 (stack) =>
54 Effect.gen(function* () {
55 yield* stack.destroy();
56
57 const created = yield* stack.deploy(
58 Effect.gen(function* () {
59 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
60 location: "global",
61 displayName: "docs",
62 contentConfig: "NO_CONTENT",
63 disableCmek: true,
64 });
65 const document = yield* GCP.DiscoveryEngine.CollectionsDataStoresBranchesDocument(
66 "About",
67 {
68 dataStore: store.name,
69 jsonData: JSON.stringify({
70 title: "About us",
71 uri: "https://example.com/about",
72 }),
73 },
74 );
75 return { store, document };
76 }),
77 );
78
79 expect(created.document.name).toContain("/documents/");
80 expect(created.document.dataStore).toEqual(created.store.name);
81
82 const fetched =
83 yield* discoveryengine.getProjectsLocationsCollectionsDataStoresBranchesDocuments({
84 name: created.document.name,
85 });
86 expect(fetched.name).toEqual(created.document.name);
87
88 const updated = yield* stack.deploy(
89 Effect.gen(function* () {
90 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
91 dataStoreId: created.store.dataStoreId,
92 location: "global",
93 collection: created.store.collection,
94 displayName: "docs",
95 contentConfig: "NO_CONTENT",
96 disableCmek: true,
97 });
98 const document = yield* GCP.DiscoveryEngine.CollectionsDataStoresBranchesDocument(
99 "About",
100 {
101 dataStore: store.name,
102 documentId: created.document.documentId,
103 jsonData: JSON.stringify({
104 title: "About the team",
105 uri: "https://example.com/about",
106 }),
107 },
108 );
109 return { store, document };
110 }),
111 );
112
113 expect(updated.document.name).toEqual(created.document.name);
114
115 yield* stack.destroy();
116
117 const gone = yield* waitUntilGone(created.document.name);
118 expect(gone).toEqual("gone");
119 }).pipe(logLevel, quotaTolerant),
120 {
121 tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"],
122 timeout: 120_000,
123 },
124 );