@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 114 lines 3.83 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 logging from "@distilled.cloud/gcp/logging_v2";
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 // Folder-scoped: set GOOGLE_FOLDER_ID when the credentials administer a
12 // folder (the testing project sits directly under the organization).
13 const folderId = process.env.GOOGLE_FOLDER_ID?.trim().replace(/^folders\//, "");
14
15 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
16
17 const waitUntilGone = (name: string) =>
18 logging.getFoldersExclusions({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("1 second"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider.skipIf(!folderId)(
29 "getFoldersExclusions on a missing exclusion fails with NotFound",
30 (stack) =>
31 Effect.gen(function* () {
32 yield* stack.destroy();
33
34 const error = yield* Effect.flip(
35 logging.getFoldersExclusions({
36 name: `folders/${folderId}/exclusions/alchemy-missing`,
37 }),
38 );
39 expect(error._tag).toEqual("NotFound");
40
41 yield* stack.destroy();
42 }).pipe(logLevel),
43 { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 90_000 },
44 );
45
46 test.provider.skipIf(!folderId)(
47 "create, update, replace, and delete a folder exclusion",
48 (stack) =>
49 Effect.gen(function* () {
50 yield* stack.destroy();
51
52 const created = yield* stack.deploy(
53 Effect.gen(function* () {
54 return yield* GCP.Logging.FolderExclusion("DropDebug", {
55 folderId,
56 filter: "severity=DEBUG",
57 description: "drop debug entries",
58 });
59 }),
60 );
61
62 expect(created.exclusionId).toEqual(expect.any(String));
63 expect(created.folderId).toEqual(folderId);
64 expect(created.name).toEqual(`folders/${folderId}/exclusions/${created.exclusionId}`);
65 expect(created.filter).toEqual("severity=DEBUG");
66 expect(created.description).toEqual("drop debug entries");
67
68 const fetched = yield* logging.getFoldersExclusions({
69 name: created.name,
70 });
71 expect(fetched.filter).toEqual("severity=DEBUG");
72 expect(fetched.description).toContain("alchemy-id=");
73
74 const updated = yield* stack.deploy(
75 Effect.gen(function* () {
76 return yield* GCP.Logging.FolderExclusion("DropDebug", {
77 folderId,
78 exclusionId: created.exclusionId,
79 filter: "severity<ERROR",
80 description: "drop non-errors",
81 disabled: true,
82 });
83 }),
84 );
85
86 expect(updated.filter).toEqual("severity<ERROR");
87 expect(updated.disabled).toEqual(true);
88
89 const last = created.exclusionId.at(-1) ?? "a";
90 const nextExclusionId = `${created.exclusionId.slice(0, -1)}${last === "z" ? "0" : "z"}`;
91
92 const replaced = yield* stack.deploy(
93 Effect.gen(function* () {
94 return yield* GCP.Logging.FolderExclusion("DropDebug", {
95 folderId,
96 exclusionId: nextExclusionId,
97 filter: "severity=DEBUG",
98 description: "replaced exclusion",
99 });
100 }),
101 );
102
103 expect(replaced.exclusionId).not.toEqual(created.exclusionId);
104
105 const previousGone = yield* waitUntilGone(created.name);
106 expect(previousGone).toEqual("gone");
107
108 yield* stack.destroy();
109
110 const gone = yield* waitUntilGone(replaced.name);
111 expect(gone).toEqual("gone");
112 }).pipe(logLevel),
113 { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 90_000 },
114 );