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 { ACL, 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 | const TEST_PASSWORD = Redacted.make("AlchemyMemoryDbTestPass01"); |
| 13 | |
| 14 | // Ungated typed-error probe: proves the not-found tag the read/delete paths |
| 15 | // depend on is in the distilled error union. |
| 16 | test.provider( |
| 17 | "describeACLs on a nonexistent ACL fails with ACLNotFoundFault", |
| 18 | () => |
| 19 | Effect.gen(function* () { |
| 20 | const error = yield* Effect.flip( |
| 21 | memorydb.describeACLs({ ACLName: "alchemy-nonexistent-acl-probe" }), |
| 22 | ); |
| 23 | expect(error._tag).toBe("ACLNotFoundFault"); |
| 24 | }), |
| 25 | { tags: ["provider:aws", "provider:aws:memorydb", "live"] }, |
| 26 | ); |
| 27 | |
| 28 | const assertGone = (name: string) => |
| 29 | memorydb.describeACLs({ ACLName: name }).pipe( |
| 30 | Effect.flatMap(() => Effect.fail(new Error(`acl '${name}' still exists`))), |
| 31 | Effect.catchTag("ACLNotFoundFault", () => Effect.void), |
| 32 | Effect.retry({ schedule: Schedule.max([Schedule.fixed("5 seconds"), Schedule.recurs(18)]) }), |
| 33 | ); |
| 34 | |
| 35 | // Single-deploy lifecycle: create an ACL with a custom user, verify, destroy. |
| 36 | // The reserved built-in `default` user cannot be added to a custom ACL, so |
| 37 | // RBAC ACLs reference custom users. |
| 38 | // |
| 39 | // MemoryDB ACL create/delete cascades through "modifying"/"deleting" state |
| 40 | // transitions that are latency-heavy (~2 minutes end to end observed; ACLs |
| 41 | // and users are free), so the live lifecycle is skipped under --fast. |
| 42 | test.provider.skipIf(!!process.env.FAST)( |
| 43 | "create ACL with a user, verify membership, delete", |
| 44 | (stack) => |
| 45 | Effect.gen(function* () { |
| 46 | yield* stack.destroy(); |
| 47 | |
| 48 | const { acl, user } = yield* stack.deploy( |
| 49 | Effect.gen(function* () { |
| 50 | const user = yield* User("AclUser", { |
| 51 | authenticationMode: { type: "password", passwords: [TEST_PASSWORD] }, |
| 52 | accessString: "on ~* +@all", |
| 53 | }); |
| 54 | const acl = yield* ACL("AppAcl", { |
| 55 | userNames: [user.userName], |
| 56 | tags: { fixture: "memorydb-acl" }, |
| 57 | }); |
| 58 | return { acl, user }; |
| 59 | }), |
| 60 | ); |
| 61 | |
| 62 | expect(acl.aclName).toBeDefined(); |
| 63 | expect(acl.aclArn).toContain(":acl/"); |
| 64 | expect(acl.userNames).toEqual([user.userName]); |
| 65 | |
| 66 | // Out-of-band verification. |
| 67 | const described = yield* memorydb.describeACLs({ ACLName: acl.aclName }); |
| 68 | expect(described.ACLs?.[0]?.UserNames).toEqual([user.userName]); |
| 69 | expect(described.ACLs?.[0]?.Status).toBe("active"); |
| 70 | |
| 71 | yield* stack.destroy(); |
| 72 | yield* assertGone(acl.aclName); |
| 73 | }), |
| 74 | { tags: ["provider:aws", "provider:aws:memorydb", "live"], timeout: 300_000 }, |
| 75 | ); |