The best way to control Claude Code, Codex and more from any computer or phone

main
ts 68 lines 2.35 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { EventBus } from "@alchemy.run/aws/EventBridge/EventBus";
3 import { Permission } from "@alchemy.run/aws/EventBridge/Permission";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as eventbridge from "@distilled.cloud/aws/eventbridge";
7 import * as Provider from "alchemy/Provider";
8 import * as Effect from "effect/Effect";
9 import * as Schedule from "effect/Schedule";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 /** Typed wait-until-gone: poll describeEventBus until ResourceNotFoundException. */
14 const assertBusGone = Effect.fn(function* (name: string) {
15 const gone = yield* eventbridge.describeEventBus({ Name: name }).pipe(
16 Effect.map(() => false),
17 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (isGone): boolean => isGone,
21 times: 10,
22 }),
23 );
24 expect(gone).toBe(true);
25 });
26
27 // Canonical `list()` test. An EventBridge Permission is a statement in an event
28 // bus resource policy (there is no list-permissions API). `list()` enumerates
29 // every bus, parses each bus's Policy JSON, and emits one Attributes per Sid.
30 // Deploy a bus + a permission, resolve the provider via the typed
31 // `findProvider`, call `list()`, and assert the deployed statement appears.
32 test.provider(
33 "list enumerates the deployed permission",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const permission = yield* stack.deploy(
39 Effect.gen(function* () {
40 const bus = yield* EventBus("ListPermissionBus", {
41 name: "alchemy-test-permission-list",
42 });
43 return yield* Permission("ListPermission", {
44 eventBusName: bus.eventBusName,
45 principal: "123456789012",
46 });
47 }),
48 );
49
50 const provider = yield* Provider.findProvider(Permission);
51 const all = yield* provider.list();
52
53 expect(
54 all.some(
55 (p) =>
56 p.statementId === permission.statementId && p.eventBusName === permission.eventBusName,
57 ),
58 ).toBe(true);
59
60 yield* stack.destroy();
61
62 yield* assertBusGone("alchemy-test-permission-list");
63 }),
64 {
65 tags: ["provider:aws", "provider:aws:eventbridge", "live"],
66 timeout: 120_000,
67 },
68 );