@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 139 lines 4.82 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 cw from "@distilled.cloud/gcp/contentwarehouse_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 // Document AI Warehouse is disabled on the testing project: calls fail with
15 // ServiceDisabled "Document AI Warehouse API has not been used in project ...
16 // before or it is disabled" (the service also needs per-project
17 // provisioning). Set GCP_TEST_CONTENTWAREHOUSE=1 on a provisioned project.
18 const runLifecycle = !process.env.FAST && !!process.env.GCP_TEST_CONTENTWAREHOUSE;
19
20 const location = "us";
21
22 const waitUntilGone = (name: string) =>
23 cw.getProjectsLocationsDocumentSchemas({ name }).pipe(
24 Effect.as("found" as const),
25 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
26 Effect.repeat({
27 schedule: Schedule.spaced("1 second"),
28 until: (status) => status === "gone",
29 times: 10,
30 }),
31 );
32
33 // Skipped: the Content Warehouse endpoint answers every request with an HTML
34 // 502 after ~20s (Document AI Warehouse is being retired), so the
35 // ServiceDisabled probe can't complete.
36 test.provider.skip(
37 "getProjectsLocationsDocumentSchemas without Document AI Warehouse enabled fails with ServiceDisabled",
38 (stack) =>
39 Effect.gen(function* () {
40 const { project } = yield* GcpEnvironment.current;
41 const parent = `projects/${project}/locations/${location}`;
42 yield* stack.destroy();
43
44 const error = yield* Effect.flip(
45 cw.getProjectsLocationsDocumentSchemas({
46 name: `${parent}/documentSchemas/alchemy-missing-schema`,
47 }),
48 );
49 expect(error._tag).toEqual("ServiceDisabled");
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 {
54 tags: ["provider:gcp", "provider:gcp:contentwarehouse", "live"],
55 timeout: 90_000,
56 },
57 );
58
59 test.provider.skipIf(!runLifecycle)(
60 "create, update, and delete a document schema",
61 (stack) =>
62 Effect.gen(function* () {
63 const { project } = yield* GcpEnvironment.current;
64 const parent = `projects/${project}/locations/${location}`;
65 yield* stack.destroy();
66
67 const created = yield* stack.deploy(
68 Effect.gen(function* () {
69 return yield* GCP.ContentWarehouse.DocumentSchema("Invoice", {
70 location,
71 displayName: "invoice",
72 description: "invoice fields",
73 propertyDefinitions: [
74 {
75 name: "title",
76 displayName: "Title",
77 isSearchable: true,
78 textTypeOptions: {},
79 },
80 ],
81 });
82 }),
83 );
84
85 expect(created.documentSchemaId).toEqual(expect.any(String));
86 expect(created.name).toContain("/documentSchemas/");
87 expect(created.location).toEqual(location);
88 expect(created.displayName).toEqual("invoice");
89 expect(created.description).toEqual("invoice fields");
90 expect((created.propertyDefinitions ?? []).length).toBeGreaterThan(0);
91
92 const fetched = yield* cw.getProjectsLocationsDocumentSchemas({
93 name: created.name,
94 });
95 expect(fetched.name).toEqual(created.name);
96 expect(fetched.description).toContain("alchemy-id=");
97 expect(fetched.description).toContain("invoice fields");
98
99 const updated = yield* stack.deploy(
100 Effect.gen(function* () {
101 return yield* GCP.ContentWarehouse.DocumentSchema("Invoice", {
102 documentSchemaId: created.documentSchemaId,
103 location,
104 displayName: "invoice-v2",
105 description: "invoice v2",
106 propertyDefinitions: [
107 {
108 name: "title",
109 displayName: "Title",
110 isSearchable: true,
111 textTypeOptions: {},
112 },
113 {
114 name: "amount",
115 displayName: "Amount",
116 isFilterable: true,
117 floatTypeOptions: {},
118 },
119 ],
120 });
121 }),
122 );
123
124 expect(updated.name).toEqual(created.name);
125 expect(updated.displayName).toEqual("invoice-v2");
126 expect(updated.description).toEqual("invoice v2");
127 expect(
128 (updated.propertyDefinitions ?? []).some((property) => property.name === "amount"),
129 ).toEqual(true);
130
131 yield* stack.destroy();
132 const gone = yield* waitUntilGone(created.name);
133 expect(gone).toEqual("gone");
134 }).pipe(logLevel),
135 {
136 tags: ["provider:gcp", "provider:gcp:contentwarehouse", "live"],
137 timeout: 90_000,
138 },
139 );