@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 114 lines 3.89 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 redis from "@distilled.cloud/gcp/redis_v1";
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
14 const waitUntilGone = (name: string) =>
15 redis.getProjectsLocationsAclPolicies({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsAclPolicies on a missing policy fails with NotFound",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30
31 yield* stack.destroy();
32
33 const error = yield* Effect.flip(
34 redis.getProjectsLocationsAclPolicies({
35 name: `projects/${project}/locations/us-central1/aclPolicies/alchemy-acl-missing`,
36 }),
37 );
38 expect(error._tag).toBe("NotFound");
39
40 const page = yield* redis.listProjectsLocationsAclPolicies({
41 parent: `projects/${project}/locations/-`,
42 pageSize: 10,
43 });
44 expect((page.aclPolicies ?? []).map((policy) => policy.name?.split("/").pop())).not.toContain(
45 "alchemy-acl-missing",
46 );
47
48 yield* stack.destroy();
49 }).pipe(logLevel),
50 { tags: ["provider:gcp", "provider:gcp:redis", "live"], timeout: 90_000 },
51 );
52
53 test.provider(
54 "create, update, and delete an ACL policy",
55 (stack) =>
56 Effect.gen(function* () {
57 yield* stack.destroy();
58
59 const created = yield* stack.deploy(
60 Effect.gen(function* () {
61 const policy = yield* GCP.Redis.AclPolicy("AppAcl", {
62 location: "us-central1",
63 rules: [{ username: "app", rule: "on ~keys:* +get" }],
64 });
65 return { policy };
66 }),
67 );
68
69 expect(created.policy.name).toContain("/aclPolicies/");
70 expect(created.policy.aclPolicyId).toEqual(expect.any(String));
71 expect(created.policy.location).toEqual("us-central1");
72 expect(created.policy.rules).toEqual([{ username: "app", rule: "on ~keys:* +get" }]);
73
74 const fetched = yield* redis.getProjectsLocationsAclPolicies({
75 name: created.policy.name,
76 });
77 expect(fetched.name).toEqual(created.policy.name);
78 expect(fetched.rules).toEqual([{ username: "app", rule: "on ~keys:* +get" }]);
79
80 const updated = yield* stack.deploy(
81 Effect.gen(function* () {
82 return yield* GCP.Redis.AclPolicy("AppAcl", {
83 location: "us-central1",
84 rules: [
85 { username: "app", rule: "on ~keys:* +get +set" },
86 { username: "readonly", rule: "off ~* -@all" },
87 ],
88 });
89 }),
90 );
91
92 expect(updated.name).toEqual(created.policy.name);
93 expect(updated.rules).toEqual([
94 { username: "app", rule: "on ~keys:* +get +set" },
95 { username: "readonly", rule: "off ~* -@all" },
96 ]);
97
98 const refetched = yield* redis.getProjectsLocationsAclPolicies({
99 name: created.policy.name,
100 });
101 expect(
102 (refetched.rules ?? []).some(
103 (rule) => rule.username === "app" && (rule.rule ?? "").includes("+set"),
104 ),
105 ).toEqual(true);
106 expect((refetched.rules ?? []).some((rule) => rule.username === "readonly")).toEqual(true);
107
108 yield* stack.destroy();
109
110 const gone = yield* waitUntilGone(created.policy.name);
111 expect(gone).toEqual("gone");
112 }).pipe(logLevel),
113 { tags: ["provider:gcp", "provider:gcp:redis", "live"], timeout: 120_000 },
114 );