The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { User } from "@alchemy.run/aws/MemoryDB"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as memorydb from "@distilled.cloud/aws/memorydb"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as Redacted from "effect/Redacted"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | // A fixed test password (16-128 printable chars). Not a real secret. |
| 13 | const TEST_PASSWORD = Redacted.make("AlchemyMemoryDbTestPass01"); |
| 14 | |
| 15 | // MemoryDB user deletion takes ~2 minutes server-side. Deletion is verified |
| 16 | // as INITIATED (status `deleting`, irreversible) or fully gone — waiting for |
| 17 | // full disappearance would burn most of the test's timeout budget. |
| 18 | const assertDeletingOrGone = (name: string) => |
| 19 | Effect.gen(function* () { |
| 20 | const status = yield* memorydb.describeUsers({ UserName: name }).pipe( |
| 21 | Effect.map((r) => r.Users?.[0]?.Status ?? "gone"), |
| 22 | Effect.catchTag("UserNotFoundFault", () => Effect.succeed("gone" as const)), |
| 23 | ); |
| 24 | if (status !== "gone" && status !== "deleting") { |
| 25 | return yield* Effect.fail(new Error(`user '${name}' still exists (status: ${status})`)); |
| 26 | } |
| 27 | }).pipe( |
| 28 | Effect.retry({ |
| 29 | schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(15)]), |
| 30 | }), |
| 31 | ); |
| 32 | |
| 33 | test.provider( |
| 34 | "create, update access string, delete a MemoryDB user", |
| 35 | (stack) => |
| 36 | Effect.gen(function* () { |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const { user } = yield* stack.deploy( |
| 40 | Effect.gen(function* () { |
| 41 | const user = yield* User("AppUser", { |
| 42 | authenticationMode: { |
| 43 | type: "password", |
| 44 | passwords: [TEST_PASSWORD], |
| 45 | }, |
| 46 | accessString: "on ~* +@all", |
| 47 | tags: { fixture: "memorydb-user" }, |
| 48 | }); |
| 49 | return { user }; |
| 50 | }), |
| 51 | ); |
| 52 | |
| 53 | expect(user.userName).toBeDefined(); |
| 54 | expect(user.userArn).toContain(":user/"); |
| 55 | expect(user.accessString).toContain("~*"); |
| 56 | expect(user.authenticationType).toBe("password"); |
| 57 | |
| 58 | // Out-of-band verification. |
| 59 | const described = yield* memorydb.describeUsers({ |
| 60 | UserName: user.userName, |
| 61 | }); |
| 62 | const observed = described.Users?.[0]; |
| 63 | expect(observed?.Status).toBe("active"); |
| 64 | expect(observed?.Authentication?.Type).toBe("password"); |
| 65 | |
| 66 | // Update the access string in place (name unchanged). |
| 67 | const { user: updated } = yield* stack.deploy( |
| 68 | Effect.gen(function* () { |
| 69 | const user = yield* User("AppUser", { |
| 70 | authenticationMode: { |
| 71 | type: "password", |
| 72 | passwords: [TEST_PASSWORD], |
| 73 | }, |
| 74 | accessString: "on ~app:* +@read", |
| 75 | tags: { fixture: "memorydb-user", env: "test" }, |
| 76 | }); |
| 77 | return { user }; |
| 78 | }), |
| 79 | ); |
| 80 | expect(updated.userName).toBe(user.userName); |
| 81 | expect(updated.accessString).toContain("~app:*"); |
| 82 | |
| 83 | const redescribed = yield* memorydb.describeUsers({ |
| 84 | UserName: user.userName, |
| 85 | }); |
| 86 | expect(redescribed.Users?.[0]?.AccessString).toContain("~app:*"); |
| 87 | |
| 88 | yield* stack.destroy(); |
| 89 | yield* assertDeletingOrGone(user.userName); |
| 90 | }), |
| 91 | { tags: ["provider:aws", "provider:aws:memorydb", "live"], timeout: 240_000 }, |
| 92 | ); |