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

main
ts 85 lines 3.35 KB
Raw
1 /**
2 * True `alchemy dev` end-to-end for the Job app — the regression test for
3 * the dev-mode apply failure where the SNS→Lambda glue resources
4 * (AWS.SNS.Subscription and the AWS.Lambda.Permission behind
5 * `consumeTopicNotifications`) were created against REAL AWS with floci
6 * ARNs and died with `InvalidParameterException: Invalid parameter:
7 * TopicArn` / `ResourceNotFoundException: Function not found`.
8 *
9 * This stack is also the mixed-mode case: the DynamoDB table, SQS queue,
10 * SNS topic, Lambda function, event source mapping, subscription, and
11 * permission are all local (floci), while the mode-agnostic CloudWatch
12 * Dashboard + Alarm deploy live — so the run needs AWS credentials, and a
13 * green apply proves local glue and live mode-agnostic resources coexist.
14 *
15 * Mirrored from examples/aws-dev/test/dev.test.ts (which owns the broader
16 * per-binding + hot-reload coverage); this suite drives the real app:
17 * POST a job over the emulator-served Function URL, read it back, and let
18 * the notification publish ride the local Subscription.
19 */
20 import { afterAll, expect, test } from "bun:test";
21 import * as path from "node:path";
22 import { DevCli, fetchOk } from "@alchemy.run/test/DevCli";
23
24 const root = path.resolve(import.meta.dirname, "..");
25 const STAGE = "dev-cli-test";
26 const cli = new DevCli({ root, stage: STAGE });
27
28 afterAll(async () => {
29 await cli.stop();
30 if (!process.env.NO_DESTROY) {
31 cli.destroy();
32 }
33 }, 180_000);
34
35 test(
36 "alchemy dev applies the mixed local/live Job stack and serves jobs",
37 async () => {
38 cli.start();
39
40 // The first dev deploy may pull the floci image and provision the
41 // local data plane before printing stack outputs.
42 const url = await cli.pollUntil("url in stack outputs", () => cli.outputUrl("url"), {
43 tries: 300,
44 delayMs: 1000,
45 });
46
47 // Dev identity: the function URL is served locally, not by AWS
48 // (e.g. http://<id>.lambda-url.us-east-1.localhost:<port>/). The port
49 // is whatever the emulator bound — never hard-code it, only the URL
50 // captured from the CLI's stdout is authoritative.
51 expect(new URL(url).hostname).toEndWith("localhost");
52 expect(url).not.toContain("amazonaws.com");
53
54 // The bug failed the APPLY itself: Subscription/Permission creation
55 // against real AWS with floci ARNs. Outputs printing means apply
56 // succeeded, but pin the failure banner too so a partial apply that
57 // still prints outputs can never sneak past.
58 expect(cli.output).not.toContain("apply failed");
59
60 const api = new URL(url);
61 api.search = "";
62
63 // POST a job: stores it in the local table AND publishes the
64 // job.created notification over the local topic — which only works
65 // when the Subscription + invoke Permission were created on floci.
66 const content = `hello from alchemy dev ${crypto.randomUUID()}`;
67 const created = (await (
68 await fetchOk(api, {
69 method: "POST",
70 headers: { "content-type": "text/plain" },
71 body: content,
72 })
73 ).json()) as { jobId: string };
74 expect(created.jobId).toBeString();
75
76 // Read it back through the local DynamoDB storage.
77 const job = (await (await fetchOk(new URL(`/?jobId=${created.jobId}`, api))).json()) as {
78 id: string;
79 content: string;
80 };
81 expect(job.id).toBe(created.jobId);
82 expect(job.content).toBe(content);
83 },
84 { timeout: 600_000 },
85 );