@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.3 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Detector } from "@alchemy.run/aws/GuardDuty/Detector";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as guardduty from "@distilled.cloud/aws/guardduty";
6 import * as Provider from "alchemy/Provider";
7 import * as Effect from "effect/Effect";
8 import { makeGuardDutyTestLease } from "./TestLease.ts";
9
10 const { test, beforeAll, afterAll } = Test.make({
11 providers: AWS.providers(),
12 });
13 const testLease = makeGuardDutyTestLease();
14
15 beforeAll(testLease.acquire, { timeout: 240_000 });
16 afterAll(testLease.release);
17
18 const firstDetectorId = guardduty.listDetectors({}).pipe(Effect.map((r) => r.DetectorIds?.[0]));
19
20 // The GuardDuty detector is an account/region singleton. This test only runs
21 // when the account has no detector — it must never disable a detector the user
22 // already operates (capture-and-restore safety).
23 test.provider(
24 "lifecycle: enable detector, update frequency, disable",
25 (stack) =>
26 Effect.gen(function* () {
27 const preexisting = yield* firstDetectorId;
28 if (preexisting) {
29 // Refuse to mutate a foreign detector; document and pass.
30 yield* Effect.logInfo(
31 `GuardDuty detector ${preexisting} already exists — skipping destructive lifecycle test`,
32 );
33 return;
34 }
35
36 yield* stack.destroy();
37
38 // Create — enable with six-hour publishing.
39 const created = yield* stack.deploy(
40 Effect.gen(function* () {
41 return yield* Detector("Detector", {
42 enable: true,
43 findingPublishingFrequency: "SIX_HOURS",
44 tags: { env: "test" },
45 });
46 }),
47 );
48 expect(created.detectorId).toBeTruthy();
49 expect(created.status).toBe("ENABLED");
50 expect(created.findingPublishingFrequency).toBe("SIX_HOURS");
51
52 // Out-of-band verification.
53 const live = yield* guardduty.getDetector({
54 DetectorId: created.detectorId,
55 });
56 expect(live.Status).toBe("ENABLED");
57 expect(live.FindingPublishingFrequency).toBe("SIX_HOURS");
58 expect(live.Tags?.["env"]).toBe("test");
59 expect(live.Tags?.["alchemy::id"]).toBe("Detector");
60
61 // Canonical list() coverage.
62 const provider = yield* Provider.findProvider(Detector);
63 const all = yield* provider.list();
64 expect(all.some((d) => d.detectorId === created.detectorId)).toBe(true);
65
66 // Update — change frequency + retag in place (no replacement).
67 const updated = yield* stack.deploy(
68 Effect.gen(function* () {
69 return yield* Detector("Detector", {
70 enable: true,
71 findingPublishingFrequency: "FIFTEEN_MINUTES",
72 tags: { env: "prod" },
73 });
74 }),
75 );
76 expect(updated.detectorId).toBe(created.detectorId);
77 const afterUpdate = yield* guardduty.getDetector({
78 DetectorId: created.detectorId,
79 });
80 expect(afterUpdate.FindingPublishingFrequency).toBe("FIFTEEN_MINUTES");
81 expect(afterUpdate.Tags?.["env"]).toBe("prod");
82
83 // Destroy — the detector is deleted and the region is clean again.
84 yield* stack.destroy();
85 const after = yield* firstDetectorId;
86 expect(after).toBeUndefined();
87 }),
88 {
89 tags: ["provider:aws", "provider:aws:guardduty", "live"],
90 timeout: 180_000,
91 },
92 );