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

main
ts 136 lines 4.6 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.getProjectsLocationsCollectionsDataStoresSchemas({ 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 "getProjectsLocationsCollectionsDataStoresSchemas on a missing schema 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.getProjectsLocationsCollectionsDataStoresSchemas({
38 name: `projects/${project}/locations/global/collections/default_collection/dataStores/alchemy-missing/schemas/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 schema",
53 (stack) =>
54 Effect.gen(function* () {
55 yield* stack.destroy();
56
57 const parent = yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
60 location: "global",
61 displayName: "docs",
62 skipDefaultSchemaCreation: true,
63 disableCmek: true,
64 });
65 }),
66 );
67
68 const created = yield* stack.deploy(
69 Effect.gen(function* () {
70 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
71 dataStoreId: parent.dataStoreId,
72 location: "global",
73 collection: parent.collection,
74 displayName: "docs",
75 skipDefaultSchemaCreation: true,
76 disableCmek: true,
77 });
78 const schema = yield* GCP.DiscoveryEngine.CollectionsDataStoresSchema("Fields", {
79 dataStore: store.name,
80 schemaId: "fields",
81 jsonSchema: JSON.stringify({
82 $schema: "https://json-schema.org/draft/2020-12/schema",
83 type: "object",
84 properties: { title: { type: "string" } },
85 }),
86 });
87 return { store, schema };
88 }),
89 );
90
91 expect(created.schema.name).toContain("/schemas/");
92 expect(created.schema.jsonSchema).toContain("title");
93
94 const fetched = yield* discoveryengine.getProjectsLocationsCollectionsDataStoresSchemas({
95 name: created.schema.name,
96 });
97 expect(fetched.name).toEqual(created.schema.name);
98
99 const updated = yield* stack.deploy(
100 Effect.gen(function* () {
101 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
102 dataStoreId: created.store.dataStoreId,
103 location: "global",
104 collection: created.store.collection,
105 displayName: "docs",
106 disableCmek: true,
107 });
108 const schema = yield* GCP.DiscoveryEngine.CollectionsDataStoresSchema("Fields", {
109 dataStore: store.name,
110 schemaId: "fields",
111 jsonSchema: JSON.stringify({
112 $schema: "https://json-schema.org/draft/2020-12/schema",
113 type: "object",
114 properties: {
115 title: { type: "string" },
116 uri: { type: "string" },
117 },
118 }),
119 });
120 return { store, schema };
121 }),
122 );
123
124 expect(updated.schema.name).toEqual(created.schema.name);
125 expect(updated.schema.jsonSchema).toContain("uri");
126
127 yield* stack.destroy();
128
129 const gone = yield* waitUntilGone(created.schema.name);
130 expect(gone).toEqual("gone");
131 }).pipe(logLevel, quotaTolerant),
132 {
133 tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"],
134 timeout: 120_000,
135 },
136 );