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