@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 142 lines 4.66 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 documentai from "@distilled.cloud/gcp/documentai_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 const location = "us";
14
15 const invoiceSchema: GCP.DocumentAI.DocumentSchemaSpec = {
16 displayName: "invoice",
17 description: "invoice fields",
18 entityTypes: [
19 {
20 name: "invoice",
21 baseTypes: ["document"],
22 properties: [
23 {
24 name: "invoice_id",
25 valueType: "string",
26 occurrenceType: "OPTIONAL_ONCE",
27 },
28 ],
29 },
30 ],
31 };
32
33 const waitUntilGone = (name: string) =>
34 documentai.getProjectsLocationsSchemasSchemaVersions({ name }).pipe(
35 Effect.as("found" as const),
36 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
37 Effect.repeat({
38 schedule: Schedule.spaced("2 seconds"),
39 until: (status) => status === "gone",
40 times: 10,
41 }),
42 );
43
44 test.provider(
45 "getProjectsLocationsSchemasSchemaVersions on a missing version fails with a typed tag",
46 (stack) =>
47 Effect.gen(function* () {
48 const { project } = yield* GcpEnvironment.current;
49 const parent = `projects/${project}/locations/${location}`;
50 yield* stack.destroy();
51
52 const error = yield* Effect.flip(
53 documentai.getProjectsLocationsSchemasSchemaVersions({
54 name: `${parent}/schemas/missing/schemaVersions/alchemy-missing-version`,
55 }),
56 );
57 expect(error._tag).toEqual("NotFound");
58
59 yield* stack.destroy();
60 }).pipe(logLevel),
61 {
62 tags: ["provider:gcp", "provider:gcp:documentai", "live"],
63 timeout: 90_000,
64 },
65 );
66
67 test.provider.skipIf(!!process.env.FAST)(
68 "create, update, and delete a schema version",
69 (stack) =>
70 Effect.gen(function* () {
71 const { project } = yield* GcpEnvironment.current;
72 const parent = `projects/${project}/locations/${location}`;
73 yield* stack.destroy();
74
75 const created = yield* stack.deploy(
76 Effect.gen(function* () {
77 const schema = yield* GCP.DocumentAI.Schema("Invoice", {
78 location,
79 displayName: "invoice-parent",
80 labels: { env: "test" },
81 });
82 const version = yield* GCP.DocumentAI.SchemasSchemaVersion("V1", {
83 schema: schema.name,
84 location,
85 displayName: "v1",
86 documentSchema: invoiceSchema,
87 labels: { env: "test" },
88 });
89 return { schema, version };
90 }),
91 );
92
93 expect(created.version.schemaVersionId).toEqual(expect.any(String));
94 expect(created.version.name).toContain("/schemaVersions/");
95 expect(created.version.schema).toEqual(created.schema.name);
96 expect(created.version.displayName).toEqual("v1");
97 expect(created.version.labels).toMatchObject({ env: "test" });
98
99 const fetched = yield* documentai.getProjectsLocationsSchemasSchemaVersions({
100 name: created.version.name,
101 });
102 expect(fetched.name).toEqual(created.version.name);
103 expect(fetched.displayName).toEqual("v1");
104 expect(fetched.labels?.env).toEqual("test");
105 expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String));
106
107 const updated = yield* stack.deploy(
108 Effect.gen(function* () {
109 const schema = yield* GCP.DocumentAI.Schema("Invoice", {
110 schemaId: created.schema.schemaId,
111 location,
112 displayName: "invoice-parent",
113 labels: { env: "test" },
114 });
115 const version = yield* GCP.DocumentAI.SchemasSchemaVersion("V1", {
116 schema: schema.name,
117 schemaVersionId: created.version.schemaVersionId,
118 location,
119 displayName: "v1-prod",
120 documentSchema: invoiceSchema,
121 labels: { env: "prod", role: "version" },
122 });
123 return { schema, version };
124 }),
125 );
126
127 expect(updated.version.name).toEqual(created.version.name);
128 expect(updated.version.displayName).toEqual("v1-prod");
129 expect(updated.version.labels).toMatchObject({
130 env: "prod",
131 role: "version",
132 });
133
134 yield* stack.destroy();
135 const gone = yield* waitUntilGone(created.version.name);
136 expect(gone).toEqual("gone");
137 }).pipe(logLevel),
138 {
139 tags: ["provider:gcp", "provider:gcp:documentai", "live"],
140 timeout: 120_000,
141 },
142 );