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