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

main
ts 123 lines 4.05 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
19 .getProjectsLocationsCollectionsDataStoresSiteSearchEngineTargetSites({
20 name,
21 })
22 .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 "getProjectsLocationsCollectionsDataStoresSiteSearchEngineTargetSites on a missing target site 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.getProjectsLocationsCollectionsDataStoresSiteSearchEngineTargetSites({
42 name: `projects/${project}/locations/global/collections/default_collection/dataStores/alchemy-missing/siteSearchEngine/targetSites/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)(
56 "create, update, and delete a collection data store target site",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Web", {
64 location: "global",
65 displayName: "docs",
66 contentConfig: "PUBLIC_WEBSITE",
67 disableCmek: true,
68 });
69 const site = yield* GCP.DiscoveryEngine.CollectionsDataStoresSiteSearchEngineTargetSite(
70 "Docs",
71 {
72 dataStore: store.name,
73 providedUriPattern: "www.example.com/docs/",
74 type: "INCLUDE",
75 },
76 );
77 return { store, site };
78 }),
79 );
80
81 expect(created.site.name).toContain("/targetSites/");
82 expect(created.site.type).toEqual("INCLUDE");
83
84 const fetched =
85 yield* discoveryengine.getProjectsLocationsCollectionsDataStoresSiteSearchEngineTargetSites(
86 { name: created.site.name },
87 );
88 expect(fetched.name).toEqual(created.site.name);
89
90 const updated = yield* stack.deploy(
91 Effect.gen(function* () {
92 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Web", {
93 dataStoreId: created.store.dataStoreId,
94 location: "global",
95 collection: created.store.collection,
96 displayName: "docs",
97 contentConfig: "PUBLIC_WEBSITE",
98 disableCmek: true,
99 });
100 const site = yield* GCP.DiscoveryEngine.CollectionsDataStoresSiteSearchEngineTargetSite(
101 "Docs",
102 {
103 dataStore: store.name,
104 providedUriPattern: "www.example.com/docs/",
105 type: "EXCLUDE",
106 },
107 );
108 return { store, site };
109 }),
110 );
111
112 expect(updated.site.name).toEqual(created.site.name);
113
114 yield* stack.destroy();
115
116 const gone = yield* waitUntilGone(created.site.name);
117 expect(gone).toEqual("gone");
118 }).pipe(logLevel, quotaTolerant),
119 {
120 tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"],
121 timeout: 120_000,
122 },
123 );