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

main
ts 90 lines 2.72 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 pubsub from "@distilled.cloud/gcp/pubsub_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const AVRO_V1 = JSON.stringify({
14 type: "record",
15 name: "Event",
16 fields: [{ name: "id", type: "string" }],
17 });
18
19 const AVRO_V2 = JSON.stringify({
20 type: "record",
21 name: "Event",
22 fields: [
23 { name: "id", type: "string" },
24 { name: "count", type: "int", default: 0 },
25 ],
26 });
27
28 const waitUntilGone = (name: string) =>
29 pubsub.getProjectsSchemas({ name, view: "BASIC" }).pipe(
30 Effect.as("found" as const),
31 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
32 Effect.repeat({
33 schedule: Schedule.spaced("1 second"),
34 until: (status) => status === "gone",
35 times: 10,
36 }),
37 );
38
39 test.provider(
40 "create, update, and delete a schema",
41 (stack) =>
42 Effect.gen(function* () {
43 yield* stack.destroy();
44
45 const created = yield* stack.deploy(
46 Effect.gen(function* () {
47 return yield* GCP.PubSub.Schema("Events", {
48 type: "AVRO",
49 definition: AVRO_V1,
50 });
51 }),
52 );
53
54 expect(created.name).toContain("/schemas/");
55 expect(created.schemaId).toEqual(expect.any(String));
56 expect(created.type).toEqual("AVRO");
57 expect(created.definition).toContain("string");
58 expect(created.revisionId).toEqual(expect.any(String));
59
60 const fetched = yield* pubsub.getProjectsSchemas({
61 name: created.name,
62 view: "FULL",
63 });
64 expect(fetched.name).toEqual(created.name);
65 expect(fetched.type).toEqual("AVRO");
66 expect(fetched.definition).toBeDefined();
67
68 const updated = yield* stack.deploy(
69 Effect.gen(function* () {
70 return yield* GCP.PubSub.Schema("Events", {
71 schemaId: created.schemaId,
72 type: "AVRO",
73 definition: AVRO_V2,
74 });
75 }),
76 );
77
78 expect(updated.name).toEqual(created.name);
79 expect(updated.type).toEqual("AVRO");
80 expect(updated.revisionId).toEqual(expect.any(String));
81 expect(updated.revisionId).not.toEqual(created.revisionId);
82 expect(updated.definition).toContain("count");
83
84 yield* stack.destroy();
85
86 const gone = yield* waitUntilGone(created.name);
87 expect(gone).toEqual("gone");
88 }).pipe(logLevel),
89 { tags: ["provider:gcp", "provider:gcp:pubsub", "live"], timeout: 90_000 },
90 );