@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 113 lines 4.08 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 const projectNameOf = (project: string) => `projects/${project}`;
14
15 const waitUntilGone = (name: string) =>
16 logging.getProjectsLocationsLogScopes({ name }).pipe(
17 Effect.as("found" as const),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.repeat({
20 schedule: Schedule.spaced("1 second"),
21 until: (status) => status === "gone",
22 times: 10,
23 }),
24 );
25
26 test.provider(
27 "create, update, replace, and delete a logging log scope",
28 (stack) =>
29 Effect.gen(function* () {
30 const { project } = yield* GcpEnvironment.current;
31
32 yield* stack.destroy();
33
34 const created = yield* stack.deploy(
35 Effect.gen(function* () {
36 return yield* GCP.Logging.LogScope("App", {
37 resourceNames: [projectNameOf(project)],
38 description: "application logs",
39 });
40 }),
41 );
42
43 expect(created.logScopeId).toEqual(expect.any(String));
44 expect(created.location).toEqual("global");
45 expect(created.project).toEqual(project);
46 expect(created.name).toEqual(
47 `projects/${project}/locations/global/logScopes/${created.logScopeId}`,
48 );
49 expect(created.resourceNames).toEqual([projectNameOf(project)]);
50 expect(created.description).toEqual("application logs");
51
52 const fetched = yield* logging.getProjectsLocationsLogScopes({
53 name: created.name,
54 });
55 expect(fetched.name).toEqual(created.name);
56 expect(fetched.resourceNames).toEqual([projectNameOf(project)]);
57 expect(fetched.description).toContain("alchemy-id=");
58 expect(fetched.description).toContain("application logs");
59
60 const updated = yield* stack.deploy(
61 Effect.gen(function* () {
62 return yield* GCP.Logging.LogScope("App", {
63 logScopeId: created.logScopeId,
64 resourceNames: [projectNameOf(project)],
65 description: "all application logs",
66 });
67 }),
68 );
69
70 expect(updated.name).toEqual(created.name);
71 expect(updated.logScopeId).toEqual(created.logScopeId);
72 expect(updated.description).toEqual("all application logs");
73 expect(updated.createTime).toEqual(created.createTime);
74
75 const fetchedUpdate = yield* logging.getProjectsLocationsLogScopes({
76 name: created.name,
77 });
78 expect(fetchedUpdate.description).toContain("all application logs");
79
80 const last = created.logScopeId.at(-1) ?? "a";
81 const nextLogScopeId = `${created.logScopeId.slice(0, -1)}${last === "z" ? "0" : "z"}`;
82
83 const replaced = yield* stack.deploy(
84 Effect.gen(function* () {
85 return yield* GCP.Logging.LogScope("App", {
86 logScopeId: nextLogScopeId,
87 resourceNames: [projectNameOf(project)],
88 description: "replaced scope",
89 });
90 }),
91 );
92
93 expect(replaced.logScopeId).not.toEqual(created.logScopeId);
94 expect(replaced.name).toEqual(
95 `projects/${project}/locations/global/logScopes/${replaced.logScopeId}`,
96 );
97 expect(replaced.description).toEqual("replaced scope");
98
99 const fetchedReplacement = yield* logging.getProjectsLocationsLogScopes({
100 name: replaced.name,
101 });
102 expect(fetchedReplacement.name).toEqual(replaced.name);
103
104 const previousGone = yield* waitUntilGone(created.name);
105 expect(previousGone).toEqual("gone");
106
107 yield* stack.destroy();
108
109 const gone = yield* waitUntilGone(replaced.name);
110 expect(gone).toEqual("gone");
111 }).pipe(logLevel),
112 { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 90_000 },
113 );