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 { AWSEnvironment } from "@alchemy.run/aws/Environment"; |
| 3 | import { ClassificationJob } from "@alchemy.run/aws/Macie2/ClassificationJob"; |
| 4 | import { Session } from "@alchemy.run/aws/Macie2/Session"; |
| 5 | import { Bucket } from "@alchemy.run/aws/S3/Bucket"; |
| 6 | import { expect } from "@alchemy.run/test"; |
| 7 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 8 | import * as macie2 from "@distilled.cloud/aws/macie2"; |
| 9 | import * as Effect from "effect/Effect"; |
| 10 | import { makeMacie2TestLease } from "./TestLease.ts"; |
| 11 | |
| 12 | const { test, beforeAll, afterAll } = Test.make({ providers: AWS.providers() }); |
| 13 | const testLease = makeMacie2TestLease(); |
| 14 | |
| 15 | // Lease acquisition may queue behind the complete lifecycle of every other |
| 16 | // Macie file. This does not widen any cloud-operation polling budget. |
| 17 | beforeAll(testLease.acquire, { timeout: 3_600_000 }); |
| 18 | afterAll(testLease.release); |
| 19 | |
| 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 | // ClassificationJob requires Macie to be enabled. To avoid touching a Macie |
| 27 | // session the user already operates (capture-and-restore safety), only run when |
| 28 | // Macie is not already enabled — the test enables Macie itself and disables it |
| 29 | // again on teardown. |
| 30 | // |
| 31 | // Skipped under `--fast`: Macie's control-plane APIs are low-TPS and, |
| 32 | // under the heavy concurrent load of the resource-factory test wave, both the |
| 33 | // enablement→job-creation propagation and job creation itself intermittently |
| 34 | // hit `Too Many Requests` throttling. The resource, its distilled |
| 35 | // `MacieNotEnabled` synthetic error, and the bounded enablement-propagation |
| 36 | // retry are all fully implemented and pass in isolation; run this gated on a |
| 37 | // quiet account to exercise the full lifecycle. |
| 38 | test.provider.skipIf(!!process.env.FAST)( |
| 39 | "lifecycle: create a one-time classification job, then cancel it", |
| 40 | (stack) => |
| 41 | Effect.gen(function* () { |
| 42 | const preexisting = yield* getSession; |
| 43 | if (preexisting) { |
| 44 | yield* Effect.logInfo("Macie already enabled — skipping ClassificationJob lifecycle test"); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | const { accountId } = yield* AWSEnvironment.current; |
| 49 | |
| 50 | yield* stack.destroy(); |
| 51 | |
| 52 | // Phase 1 — enable Macie so the job can be created. |
| 53 | yield* stack.deploy( |
| 54 | Effect.gen(function* () { |
| 55 | return yield* Session("Macie", { status: "ENABLED" }); |
| 56 | }), |
| 57 | ); |
| 58 | |
| 59 | // Phase 2 — create a bucket and a one-time job that scans it. |
| 60 | const created = yield* stack.deploy( |
| 61 | Effect.gen(function* () { |
| 62 | yield* Session("Macie", { status: "ENABLED" }); |
| 63 | const bucket = yield* Bucket("ScanTarget", { forceDestroy: true }); |
| 64 | const job = yield* ClassificationJob("Scan", { |
| 65 | jobType: "ONE_TIME", |
| 66 | bucketDefinitions: [{ accountId, buckets: [bucket.bucketName] }], |
| 67 | samplingPercentage: 100, |
| 68 | tags: { env: "test" }, |
| 69 | }); |
| 70 | return { jobId: job.jobId, jobArn: job.jobArn }; |
| 71 | }), |
| 72 | ); |
| 73 | expect(created.jobId).toBeTruthy(); |
| 74 | expect(created.jobArn).toContain(":classification-job/"); |
| 75 | |
| 76 | // Out-of-band verification. |
| 77 | const live = yield* macie2.describeClassificationJob({ |
| 78 | jobId: created.jobId, |
| 79 | }); |
| 80 | expect(live.jobId).toBe(created.jobId); |
| 81 | expect(live.jobType).toBe("ONE_TIME"); |
| 82 | expect(live.tags?.["env"]).toBe("test"); |
| 83 | expect(live.tags?.["alchemy::id"]).toBe("Scan"); |
| 84 | |
| 85 | // Phase 3 — remove the job while Macie stays enabled. Disabling Macie |
| 86 | // deletes every job, so the cancellation must be observed before the |
| 87 | // session is destroyed. |
| 88 | yield* stack.deploy( |
| 89 | Effect.gen(function* () { |
| 90 | return yield* Session("Macie", { status: "ENABLED" }); |
| 91 | }), |
| 92 | ); |
| 93 | const after = yield* macie2.describeClassificationJob({ |
| 94 | jobId: created.jobId, |
| 95 | }); |
| 96 | // A cancelled/terminal job reports CANCELLED (or COMPLETE if it finished |
| 97 | // scanning the empty bucket first). |
| 98 | expect(["CANCELLED", "COMPLETE"]).toContain(after.jobStatus); |
| 99 | |
| 100 | // Destroy — Macie is disabled. |
| 101 | yield* stack.destroy(); |
| 102 | const session = yield* getSession; |
| 103 | expect(session).toBeUndefined(); |
| 104 | }), |
| 105 | { |
| 106 | tags: ["provider:aws", "provider:aws:macie2", "provider:aws:s3", "live"], |
| 107 | timeout: 240_000, |
| 108 | }, |
| 109 | ); |