The best way to control Claude Code, Codex and more from any computer or phone

main
ts 83 lines 3.25 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Session } from "@alchemy.run/aws/Macie2/Session";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as macie2 from "@distilled.cloud/aws/macie2";
6 import * as Provider from "alchemy/Provider";
7 import * as Effect from "effect/Effect";
8 import { makeMacie2TestLease } from "./TestLease.ts";
9
10 const { test, beforeAll, afterAll } = Test.make({ providers: AWS.providers() });
11 const testLease = makeMacie2TestLease();
12
13 // Lease acquisition may queue behind the complete lifecycle of every other
14 // Macie file. This does not widen any cloud-operation polling budget.
15 beforeAll(testLease.acquire, { timeout: 3_600_000 });
16 afterAll(testLease.release);
17
18 // `getMacieSession` throws `AccessDeniedException` ("Macie is not enabled")
19 // when the account has no session.
20 const getSession = macie2.getMacieSession({}).pipe(
21 Effect.map((s) => s as macie2.GetMacieSessionResponse | undefined),
22 Effect.catchTag("AccessDeniedException", () => Effect.succeed(undefined)),
23 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
24 );
25
26 // The Macie session is an account/region singleton. This test only runs when
27 // Macie is not already enabled — it must never disable a session the user
28 // already operates (capture-and-restore safety).
29 test.provider(
30 "lifecycle: enable Macie, update frequency, disable",
31 (stack) =>
32 Effect.gen(function* () {
33 const preexisting = yield* getSession;
34 if (preexisting) {
35 yield* Effect.logInfo("Macie already enabled — skipping destructive lifecycle test");
36 return;
37 }
38
39 yield* stack.destroy();
40
41 // Create — enable Macie with six-hour publishing.
42 const created = yield* stack.deploy(
43 Effect.gen(function* () {
44 return yield* Session("Macie", {
45 status: "ENABLED",
46 findingPublishingFrequency: "SIX_HOURS",
47 });
48 }),
49 );
50 expect(created.status).toBe("ENABLED");
51 expect(created.findingPublishingFrequency).toBe("SIX_HOURS");
52
53 // Out-of-band verification.
54 const live = yield* macie2.getMacieSession({});
55 expect(live.status).toBe("ENABLED");
56 expect(live.findingPublishingFrequency).toBe("SIX_HOURS");
57
58 // Canonical list() coverage.
59 const provider = yield* Provider.findProvider(Session);
60 const all = yield* provider.list();
61 expect(all.some((s) => s.status === "ENABLED")).toBe(true);
62
63 // Update — change frequency + pause in place (no replacement).
64 const updated = yield* stack.deploy(
65 Effect.gen(function* () {
66 return yield* Session("Macie", {
67 status: "PAUSED",
68 findingPublishingFrequency: "FIFTEEN_MINUTES",
69 });
70 }),
71 );
72 expect(updated.accountId).toBe(created.accountId);
73 const afterUpdate = yield* macie2.getMacieSession({});
74 expect(afterUpdate.status).toBe("PAUSED");
75 expect(afterUpdate.findingPublishingFrequency).toBe("FIFTEEN_MINUTES");
76
77 // Destroy — Macie is disabled and the account is unenrolled.
78 yield* stack.destroy();
79 const after = yield* getSession;
80 expect(after).toBeUndefined();
81 }),
82 { tags: ["provider:aws", "provider:aws:macie2", "live"], timeout: 180_000 },
83 );