@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 92 lines 3.37 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { RegexPatternSet } from "@alchemy.run/aws/WAFv2";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as wafv2 from "@distilled.cloud/aws/wafv2";
6 import * as Data from "effect/Data";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 class RegexPatternSetStillExists extends Data.TaggedError("RegexPatternSetStillExists")<{
13 readonly name: string;
14 }> {}
15
16 const assertDeleted = (name: string, id: string) =>
17 wafv2.getRegexPatternSet({ Name: name, Scope: "REGIONAL", Id: id }).pipe(
18 Effect.flatMap(() => Effect.fail(new RegexPatternSetStillExists({ name }))),
19 Effect.catchTag("WAFNonexistentItemException", () => Effect.void),
20 Effect.retry({
21 while: (e) => e._tag === "RegexPatternSetStillExists",
22 schedule: Schedule.max([Schedule.exponential(500), Schedule.recurs(8)]),
23 }),
24 );
25
26 test.provider(
27 "create, update expressions and tags, delete",
28 (stack) =>
29 Effect.gen(function* () {
30 // reconcile away any prior partial/crashed deployment
31 yield* stack.destroy();
32
33 const set = yield* stack.deploy(
34 Effect.gen(function* () {
35 return yield* RegexPatternSet("LifecycleRegexSet", {
36 regularExpressions: ["^/wp-admin", "\\.php$"],
37 description: "bad paths",
38 tags: { Environment: "test" },
39 });
40 }),
41 );
42
43 expect(set.scope).toBe("REGIONAL");
44 expect([...set.regularExpressions].sort()).toEqual(["\\.php$", "^/wp-admin"]);
45
46 // out-of-band verification via distilled
47 const created = yield* wafv2.getRegexPatternSet({
48 Name: set.regexPatternSetName,
49 Scope: "REGIONAL",
50 Id: set.regexPatternSetId,
51 });
52 expect(
53 (created.RegexPatternSet?.RegularExpressionList ?? []).map((r) => r.RegexString).sort(),
54 ).toEqual(["\\.php$", "^/wp-admin"]);
55 expect(created.RegexPatternSet?.Description).toBe("bad paths");
56
57 const tags = yield* wafv2.listTagsForResource({
58 ResourceARN: set.regexPatternSetArn,
59 });
60 const tagRecord = Object.fromEntries(
61 (tags.TagInfoForResource?.TagList ?? []).map((t) => [t.Key, t.Value]),
62 );
63 expect(tagRecord.Environment).toBe("test");
64 expect(tagRecord["alchemy::id"]).toBe("LifecycleRegexSet");
65
66 // expressions are mutable — updated in place
67 const updated = yield* stack.deploy(
68 Effect.gen(function* () {
69 return yield* RegexPatternSet("LifecycleRegexSet", {
70 regularExpressions: ["^/admin"],
71 description: "bad paths",
72 tags: { Environment: "test", Extra: "1" },
73 });
74 }),
75 );
76 expect(updated.regexPatternSetId).toBe(set.regexPatternSetId);
77 expect(updated.regularExpressions).toEqual(["^/admin"]);
78
79 const afterUpdate = yield* wafv2.getRegexPatternSet({
80 Name: set.regexPatternSetName,
81 Scope: "REGIONAL",
82 Id: set.regexPatternSetId,
83 });
84 expect(
85 (afterUpdate.RegexPatternSet?.RegularExpressionList ?? []).map((r) => r.RegexString),
86 ).toEqual(["^/admin"]);
87
88 yield* stack.destroy();
89 yield* assertDeleted(set.regexPatternSetName, set.regexPatternSetId);
90 }),
91 { tags: ["provider:aws", "provider:aws:wafv2", "live"], timeout: 120_000 },
92 );