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

main
ts 105 lines 3.91 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 logging from "@distilled.cloud/gcp/logging_v2";
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
14 const waitUntilGone = (name: string) =>
15 logging.getFoldersLocationsSavedQueries({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "create, update, replace, and delete a folder logging saved query",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30
31 yield* stack.destroy();
32
33 const created = yield* stack.deploy(
34 Effect.gen(function* () {
35 return yield* GCP.Logging.FolderSavedQuery("Errors", {
36 displayName: "application errors",
37 loggingQuery: { filter: "severity>=ERROR" },
38 description: "error query",
39 });
40 }),
41 );
42
43 expect(created.savedQueryId).toEqual(expect.any(String));
44 expect(created.location).toEqual("global");
45 expect(created.parent).toEqual(`projects/${project}`);
46 expect(created.name).toEqual(
47 `projects/${project}/locations/global/savedQueries/${created.savedQueryId}`,
48 );
49 expect(created.displayName).toEqual("application errors");
50 expect(created.visibility).toEqual("PRIVATE");
51 expect(created.loggingQuery?.filter).toEqual("severity>=ERROR");
52 expect(created.description).toEqual("error query");
53
54 const fetched = yield* logging.getFoldersLocationsSavedQueries({
55 name: created.name,
56 });
57 expect(fetched.name).toEqual(created.name);
58 expect(fetched.displayName).toEqual("application errors");
59 expect(fetched.loggingQuery?.filter).toEqual("severity>=ERROR");
60 expect(fetched.description).toContain("alchemy-id=");
61 expect(fetched.description).toContain("error query");
62
63 const updated = yield* stack.deploy(
64 Effect.gen(function* () {
65 return yield* GCP.Logging.FolderSavedQuery("Errors", {
66 savedQueryId: created.savedQueryId,
67 displayName: "warnings and errors",
68 loggingQuery: { filter: "severity>=WARNING" },
69 description: "warning query",
70 });
71 }),
72 );
73
74 expect(updated.name).toEqual(created.name);
75 expect(updated.displayName).toEqual("warnings and errors");
76 expect(updated.loggingQuery?.filter).toEqual("severity>=WARNING");
77 expect(updated.description).toEqual("warning query");
78
79 const last = created.savedQueryId.at(-1) ?? "a";
80 const nextId = `${created.savedQueryId.slice(0, -1)}${last === "z" ? "0" : "z"}`;
81
82 const replaced = yield* stack.deploy(
83 Effect.gen(function* () {
84 return yield* GCP.Logging.FolderSavedQuery("Errors", {
85 savedQueryId: nextId,
86 displayName: "replaced query",
87 loggingQuery: { filter: "severity>=WARNING" },
88 description: "replaced query",
89 });
90 }),
91 );
92
93 expect(replaced.savedQueryId).not.toEqual(created.savedQueryId);
94 expect(replaced.displayName).toEqual("replaced query");
95
96 const previousGone = yield* waitUntilGone(created.name);
97 expect(previousGone).toEqual("gone");
98
99 yield* stack.destroy();
100
101 const gone = yield* waitUntilGone(replaced.name);
102 expect(gone).toEqual("gone");
103 }).pipe(logLevel),
104 { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 90_000 },
105 );