@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 104 lines 3.64 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as speech from "@distilled.cloud/gcp/speech_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { location, logLevel, currentParent, currentProject } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 speech.getProjectsLocationsCustomClasses({ name }).pipe(
13 Effect.as("found" as const),
14 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
15 Effect.repeat({
16 schedule: Schedule.spaced("1 second"),
17 until: (status) => status === "gone",
18 times: 10,
19 }),
20 );
21
22 test.provider(
23 "getProjectsLocationsCustomClasses on a missing class fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 const parent = yield* currentParent;
27 yield* stack.destroy();
28
29 const error = yield* Effect.flip(
30 speech.getProjectsLocationsCustomClasses({
31 name: `${parent}/customClasses/alchemy-missing-class`,
32 }),
33 );
34 expect(error._tag).toEqual("NotFound");
35
36 yield* stack.destroy();
37 }).pipe(logLevel),
38 { tags: ["provider:gcp", "provider:gcp:speech", "live"], timeout: 90_000 },
39 );
40
41 test.provider(
42 "create, update, and delete a custom class",
43 (stack) =>
44 Effect.gen(function* () {
45 const project = yield* currentProject;
46 yield* stack.destroy();
47
48 const created = yield* stack.deploy(
49 Effect.gen(function* () {
50 return yield* GCP.Speech.CustomClass("Ships", {
51 location,
52 items: [{ value: "sloop" }, { value: "ketch" }],
53 });
54 }),
55 );
56
57 expect(created.name).toMatch(
58 new RegExp(`^projects/[^/]+/locations/${location}/customClasses/`),
59 );
60 expect(created.customClassId.length).toBeGreaterThanOrEqual(4);
61 expect(created.project).toEqual(project);
62 expect(created.location).toEqual(location);
63 expect(created.items.map((item) => item.value).sort()).toEqual(["ketch", "sloop"]);
64
65 const fetched = yield* speech.getProjectsLocationsCustomClasses({
66 name: created.name,
67 });
68 expect(fetched.name).toEqual(created.name);
69 const fetchedValues = (fetched.items ?? [])
70 .map((item) => item.value ?? "")
71 .filter((value) => value.length > 0);
72 expect(fetchedValues).toContain("sloop");
73 expect(fetchedValues).toContain("ketch");
74 // Items steer recognition: Alchemy adds no ownership item.
75 expect(fetchedValues.some((value) => value.startsWith("alc "))).toEqual(false);
76
77 const updated = yield* stack.deploy(
78 Effect.gen(function* () {
79 return yield* GCP.Speech.CustomClass("Ships", {
80 location,
81 customClassId: created.customClassId,
82 items: [{ value: "brig" }, { value: "barque" }],
83 });
84 }),
85 );
86
87 expect(updated.name).toEqual(created.name);
88 expect(updated.items.map((item) => item.value).sort()).toEqual(["barque", "brig"]);
89
90 const fetchedUpdate = yield* speech.getProjectsLocationsCustomClasses({
91 name: created.name,
92 });
93 const updatedValues = (fetchedUpdate.items ?? []).map((item) => item.value ?? "");
94 expect(updatedValues).toContain("brig");
95 expect(updatedValues).toContain("barque");
96 expect(updatedValues).not.toContain("sloop");
97
98 yield* stack.destroy();
99
100 const gone = yield* waitUntilGone(created.name);
101 expect(gone).toEqual("gone");
102 }).pipe(logLevel),
103 { tags: ["provider:gcp", "provider:gcp:speech", "live"], timeout: 90_000 },
104 );