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

main
ts 106 lines 3.73 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.getProjectsLocationsPhraseSets({ 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 "getProjectsLocationsPhraseSets on a missing phrase set 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.getProjectsLocationsPhraseSets({
31 name: `${parent}/phraseSets/alchemy-missing-phrases`,
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 phrase set",
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.PhraseSet("Hints", {
51 location,
52 phrases: [{ value: "weather", boost: 10 }],
53 boost: 5,
54 });
55 }),
56 );
57
58 expect(created.name).toMatch(new RegExp(`^projects/[^/]+/locations/${location}/phraseSets/`));
59 expect(created.phraseSetId.length).toBeGreaterThanOrEqual(4);
60 expect(created.project).toEqual(project);
61 expect(created.location).toEqual(location);
62 expect(created.boost).toEqual(5);
63 expect(
64 created.phrases.some((phrase) => phrase.value === "weather" && phrase.boost === 10),
65 ).toEqual(true);
66
67 const fetched = yield* speech.getProjectsLocationsPhraseSets({
68 name: created.name,
69 });
70 expect(fetched.name).toEqual(created.name);
71 expect(fetched.boost).toEqual(5);
72 const fetchedValues = (fetched.phrases ?? []).map((phrase) => phrase.value ?? "");
73 expect(fetchedValues).toContain("weather");
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.PhraseSet("Hints", {
80 location,
81 phraseSetId: created.phraseSetId,
82 phrases: [{ value: "weather", boost: 15 }, { value: "forecast" }],
83 boost: 8,
84 });
85 }),
86 );
87
88 expect(updated.name).toEqual(created.name);
89 expect(updated.boost).toEqual(8);
90 expect(updated.phrases.map((phrase) => phrase.value).sort()).toEqual(["forecast", "weather"]);
91
92 const fetchedUpdate = yield* speech.getProjectsLocationsPhraseSets({
93 name: created.name,
94 });
95 expect(fetchedUpdate.boost).toEqual(8);
96 const updatedValues = (fetchedUpdate.phrases ?? []).map((phrase) => phrase.value ?? "");
97 expect(updatedValues).toContain("weather");
98 expect(updatedValues).toContain("forecast");
99
100 yield* stack.destroy();
101
102 const gone = yield* waitUntilGone(created.name);
103 expect(gone).toEqual("gone");
104 }).pipe(logLevel),
105 { tags: ["provider:gcp", "provider:gcp:speech", "live"], timeout: 90_000 },
106 );