@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 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.getOrganizationsLocationsBucketsViews({ 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 "getOrganizationsLocationsBucketsViews on a missing view fails with NotFound",
31 (stack) =>
32 Effect.gen(function* () {
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 logging.getOrganizationsLocationsBucketsViews({
37 name: `${organization}/locations/global/buckets/_Default/views/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 logging bucket view",
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.OrganizationBucketsView("Stdout", {
56 organization,
57 filter: 'LOG_ID("stdout")',
58 description: "stdout only",
59 });
60 }),
61 );
62
63 expect(created.viewId).toEqual(expect.any(String));
64 expect(created.organization).toEqual(organization);
65 expect(created.bucketId).toEqual("_Default");
66 expect(created.filter).toEqual('LOG_ID("stdout")');
67 expect(created.description).toEqual("stdout only");
68
69 const fetched = yield* logging.getOrganizationsLocationsBucketsViews({
70 name: created.name,
71 });
72 expect(fetched.filter).toEqual('LOG_ID("stdout")');
73 expect(fetched.description).toContain("alchemy-id=");
74
75 const updated = yield* stack.deploy(
76 Effect.gen(function* () {
77 return yield* GCP.Logging.OrganizationBucketsView("Stdout", {
78 organization,
79 viewId: created.viewId,
80 bucket: created.bucket,
81 filter: 'LOG_ID("stderr")',
82 description: "stderr only",
83 });
84 }),
85 );
86
87 expect(updated.name).toEqual(created.name);
88 expect(updated.filter).toEqual('LOG_ID("stderr")');
89
90 const last = created.viewId.at(-1) ?? "a";
91 const nextViewId = `${created.viewId.slice(0, -1)}${last === "z" ? "0" : "z"}`;
92
93 const replaced = yield* stack.deploy(
94 Effect.gen(function* () {
95 return yield* GCP.Logging.OrganizationBucketsView("Stdout", {
96 organization,
97 viewId: nextViewId,
98 bucket: created.bucket,
99 filter: 'LOG_ID("stdout")',
100 description: "replaced view",
101 });
102 }),
103 );
104
105 expect(replaced.viewId).not.toEqual(created.viewId);
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 );