@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 107 lines 3.47 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 waitUntilGone = (name: string) =>
16 documentai.getProjectsLocationsSchemas({ name }).pipe(
17 Effect.as("found" as const),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.repeat({
20 schedule: Schedule.spaced("2 seconds"),
21 until: (status) => status === "gone",
22 times: 10,
23 }),
24 );
25
26 test.provider(
27 "getProjectsLocationsSchemas on a missing schema fails with a typed tag",
28 (stack) =>
29 Effect.gen(function* () {
30 const { project } = yield* GcpEnvironment.current;
31 const parent = `projects/${project}/locations/${location}`;
32 yield* stack.destroy();
33
34 const error = yield* Effect.flip(
35 documentai.getProjectsLocationsSchemas({
36 name: `${parent}/schemas/alchemy-missing-schema`,
37 }),
38 );
39 expect(error._tag).toEqual("NotFound");
40
41 yield* stack.destroy();
42 }).pipe(logLevel),
43 {
44 tags: ["provider:gcp", "provider:gcp:documentai", "live"],
45 timeout: 90_000,
46 },
47 );
48
49 test.provider.skipIf(!!process.env.FAST)(
50 "create, update, and delete a schema",
51 (stack) =>
52 Effect.gen(function* () {
53 const { project } = yield* GcpEnvironment.current;
54 const parent = `projects/${project}/locations/${location}`;
55 yield* stack.destroy();
56
57 const created = yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* GCP.DocumentAI.Schema("Invoice", {
60 location,
61 displayName: "invoice-schema",
62 labels: { env: "test" },
63 });
64 }),
65 );
66
67 expect(created.schemaId).toEqual(expect.any(String));
68 expect(created.name).toContain("/schemas/");
69 expect(created.location).toEqual(location);
70 expect(created.displayName).toEqual("invoice-schema");
71 expect(created.labels).toMatchObject({ env: "test" });
72
73 const fetched = yield* documentai.getProjectsLocationsSchemas({
74 name: created.name,
75 });
76 expect(fetched.name).toEqual(created.name);
77 expect(fetched.displayName).toEqual("invoice-schema");
78 expect(fetched.labels?.env).toEqual("test");
79 expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String));
80
81 const updated = yield* stack.deploy(
82 Effect.gen(function* () {
83 return yield* GCP.DocumentAI.Schema("Invoice", {
84 schemaId: created.schemaId,
85 location,
86 displayName: "invoice-schema-v2",
87 labels: { env: "prod", role: "schema" },
88 });
89 }),
90 );
91
92 expect(updated.name).toEqual(created.name);
93 expect(updated.displayName).toEqual("invoice-schema-v2");
94 expect(updated.labels).toMatchObject({
95 env: "prod",
96 role: "schema",
97 });
98
99 yield* stack.destroy();
100 const gone = yield* waitUntilGone(created.name);
101 expect(gone).toEqual("gone");
102 }).pipe(logLevel),
103 {
104 tags: ["provider:gcp", "provider:gcp:documentai", "live"],
105 timeout: 120_000,
106 },
107 );