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
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Graph } from "@alchemy.run/aws/Detective/Graph"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as detective from "@distilled.cloud/aws/detective"; |
| 6 | import * as Provider from "alchemy/Provider"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { makeDetectiveTestLease } from "./TestLease.ts"; |
| 9 | |
| 10 | const { test, beforeAll, afterAll } = Test.make({ |
| 11 | providers: AWS.providers(), |
| 12 | }); |
| 13 | const testLease = makeDetectiveTestLease(); |
| 14 | |
| 15 | beforeAll(testLease.acquire, { timeout: 240_000 }); |
| 16 | afterAll(testLease.release); |
| 17 | |
| 18 | const firstGraphArn = detective.listGraphs({}).pipe(Effect.map((r) => r.GraphList?.[0]?.Arn)); |
| 19 | |
| 20 | // The Detective behavior graph is an account/region singleton. This test only |
| 21 | // runs when the account has no graph — it must never delete a graph the user |
| 22 | // already operates (capture-and-restore safety). |
| 23 | test.provider( |
| 24 | "lifecycle: enable behavior graph, retag, disable", |
| 25 | (stack) => |
| 26 | Effect.gen(function* () { |
| 27 | const preexisting = yield* firstGraphArn; |
| 28 | if (preexisting) { |
| 29 | yield* Effect.logInfo( |
| 30 | `Detective graph ${preexisting} already exists — skipping destructive lifecycle test`, |
| 31 | ); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | // Create — enable the behavior graph with tags. |
| 38 | const created = yield* stack.deploy( |
| 39 | Effect.gen(function* () { |
| 40 | return yield* Graph("Graph", { tags: { env: "test" } }); |
| 41 | }), |
| 42 | ); |
| 43 | expect(created.graphArn).toContain(":graph:"); |
| 44 | |
| 45 | // Out-of-band verification. |
| 46 | const live = yield* firstGraphArn; |
| 47 | expect(live).toBe(created.graphArn); |
| 48 | const tags = yield* detective.listTagsForResource({ |
| 49 | ResourceArn: created.graphArn, |
| 50 | }); |
| 51 | expect(tags.Tags?.["env"]).toBe("test"); |
| 52 | expect(tags.Tags?.["alchemy::id"]).toBe("Graph"); |
| 53 | |
| 54 | // Canonical list() coverage. |
| 55 | const provider = yield* Provider.findProvider(Graph); |
| 56 | const all = yield* provider.list(); |
| 57 | expect(all.some((g) => g.graphArn === created.graphArn)).toBe(true); |
| 58 | |
| 59 | // Update — retag in place (no replacement; ARN is stable). |
| 60 | const updated = yield* stack.deploy( |
| 61 | Effect.gen(function* () { |
| 62 | return yield* Graph("Graph", { tags: { env: "prod" } }); |
| 63 | }), |
| 64 | ); |
| 65 | expect(updated.graphArn).toBe(created.graphArn); |
| 66 | const updatedTags = yield* detective.listTagsForResource({ |
| 67 | ResourceArn: created.graphArn, |
| 68 | }); |
| 69 | expect(updatedTags.Tags?.["env"]).toBe("prod"); |
| 70 | |
| 71 | // Destroy — the graph is deleted and the region is clean again. |
| 72 | yield* stack.destroy(); |
| 73 | const after = yield* firstGraphArn; |
| 74 | expect(after).toBeUndefined(); |
| 75 | }), |
| 76 | { |
| 77 | tags: ["provider:aws", "provider:aws:detective", "live"], |
| 78 | timeout: 180_000, |
| 79 | }, |
| 80 | ); |