@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 126 lines 4.01 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 parametermanager from "@distilled.cloud/gcp/parametermanager_v1";
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 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (name: string) =>
14 parametermanager.getProjectsLocationsParameters({ name }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 test.provider(
25 "create, update, and delete a parameter",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const created = yield* stack.deploy(
31 Effect.gen(function* () {
32 return yield* GCP.ParameterManager.Parameter("AppConfig", {
33 labels: { env: "test" },
34 });
35 }),
36 );
37
38 expect(created.name).toContain("/parameters/");
39 expect(created.parameterId).toEqual(expect.any(String));
40 expect(created.location).toEqual("global");
41 expect(created.format).toEqual("UNFORMATTED");
42 expect(created.labels).toMatchObject({ env: "test" });
43
44 const fetched = yield* parametermanager.getProjectsLocationsParameters({
45 name: created.name,
46 });
47 expect(fetched.name).toEqual(created.name);
48 expect(fetched.labels?.env).toEqual("test");
49 expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String));
50 expect(fetched.format === undefined || fetched.format === "UNFORMATTED").toBe(true);
51
52 const updated = yield* stack.deploy(
53 Effect.gen(function* () {
54 return yield* GCP.ParameterManager.Parameter("AppConfig", {
55 parameterId: created.parameterId,
56 location: created.location,
57 labels: { env: "prod", role: "config" },
58 });
59 }),
60 );
61
62 expect(updated.name).toEqual(created.name);
63 expect(updated.labels).toMatchObject({ env: "prod", role: "config" });
64
65 const fetchedUpdate = yield* parametermanager.getProjectsLocationsParameters({
66 name: created.name,
67 });
68 expect(fetchedUpdate.labels?.env).toEqual("prod");
69 expect(fetchedUpdate.labels?.role).toEqual("config");
70
71 yield* stack.destroy();
72
73 const gone = yield* waitUntilGone(created.name);
74 expect(gone).toEqual("gone");
75 }).pipe(logLevel),
76 {
77 tags: ["provider:gcp", "provider:gcp:parametermanager", "live"],
78 timeout: 90_000,
79 },
80 );
81
82 test.provider(
83 "replace a parameter when format changes",
84 (stack) =>
85 Effect.gen(function* () {
86 yield* stack.destroy();
87
88 const created = yield* stack.deploy(
89 Effect.gen(function* () {
90 return yield* GCP.ParameterManager.Parameter("TypedConfig", {
91 format: "UNFORMATTED",
92 });
93 }),
94 );
95
96 expect(created.format).toEqual("UNFORMATTED");
97
98 const replaced = yield* stack.deploy(
99 Effect.gen(function* () {
100 return yield* GCP.ParameterManager.Parameter("TypedConfig", {
101 parameterId: created.parameterId,
102 location: created.location,
103 format: "JSON",
104 });
105 }),
106 );
107
108 expect(replaced.name).toEqual(created.name);
109 expect(replaced.parameterId).toEqual(created.parameterId);
110 expect(replaced.format).toEqual("JSON");
111
112 const fetched = yield* parametermanager.getProjectsLocationsParameters({
113 name: replaced.name,
114 });
115 expect(fetched.format).toEqual("JSON");
116
117 yield* stack.destroy();
118
119 const gone = yield* waitUntilGone(replaced.name);
120 expect(gone).toEqual("gone");
121 }).pipe(logLevel),
122 {
123 tags: ["provider:gcp", "provider:gcp:parametermanager", "live"],
124 timeout: 90_000,
125 },
126 );