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 { App } from "@alchemy.run/aws/Amplify"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as amplify from "@distilled.cloud/aws/amplify"; |
| 6 | import * as Data from "effect/Data"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { makeAmplifyTestLease } from "./TestLease.ts"; |
| 10 | |
| 11 | const { test, beforeAll, afterAll } = Test.make({ providers: AWS.providers() }); |
| 12 | const testLease = makeAmplifyTestLease(); |
| 13 | |
| 14 | beforeAll(testLease.acquire, { timeout: 240_000 }); |
| 15 | afterAll(testLease.release); |
| 16 | |
| 17 | const findApp = (appId: string) => |
| 18 | amplify.getApp({ appId }).pipe( |
| 19 | Effect.map((r) => r.app), |
| 20 | Effect.catchTag("NotFoundException", () => Effect.succeed(undefined)), |
| 21 | ); |
| 22 | |
| 23 | class AppStillExists extends Data.TaggedError("AppStillExists")<{ |
| 24 | readonly appId: string; |
| 25 | }> {} |
| 26 | |
| 27 | const assertAppDeleted = (appId: string) => |
| 28 | findApp(appId).pipe( |
| 29 | Effect.flatMap((app) => |
| 30 | app === undefined ? Effect.void : Effect.fail(new AppStillExists({ appId })), |
| 31 | ), |
| 32 | Effect.retry({ |
| 33 | while: (e) => e._tag === "AppStillExists", |
| 34 | schedule: Schedule.max([Schedule.spaced("2 seconds"), Schedule.recurs(15)]), |
| 35 | }), |
| 36 | ); |
| 37 | |
| 38 | // Amplify apps normally connect a Git repository, but that requires an OAuth |
| 39 | // handshake (CodeConnections / personal token) that is human-in-the-loop and |
| 40 | // cannot be automated from infrastructure code. This test therefore exercises |
| 41 | // the repo-less path: create the app container, assert it exists, update it, |
| 42 | // and delete it. Connecting a repo + branches is a console/CLI follow-up. |
| 43 | test.provider( |
| 44 | "create an Amplify app without a connected repo, update, and delete", |
| 45 | (stack) => |
| 46 | Effect.gen(function* () { |
| 47 | yield* stack.destroy(); |
| 48 | |
| 49 | const app = yield* stack.deploy( |
| 50 | Effect.gen(function* () { |
| 51 | return yield* App("TestAmplifyApp", { |
| 52 | description: "initial description", |
| 53 | platform: "WEB", |
| 54 | environmentVariables: { STAGE: "test" }, |
| 55 | tags: { Environment: "test" }, |
| 56 | }); |
| 57 | }), |
| 58 | ); |
| 59 | |
| 60 | expect(app.appId).toBeDefined(); |
| 61 | expect(app.appArn).toContain(":apps/"); |
| 62 | expect(app.defaultDomain).toContain("amplifyapp.com"); |
| 63 | |
| 64 | const live = yield* findApp(app.appId); |
| 65 | expect(live?.description).toBe("initial description"); |
| 66 | expect(live?.repository ?? "").toBe(""); |
| 67 | expect(live?.tags?.["alchemy::id"]).toBe("TestAmplifyApp"); |
| 68 | |
| 69 | // Update description + env vars. |
| 70 | const updated = yield* stack.deploy( |
| 71 | Effect.gen(function* () { |
| 72 | return yield* App("TestAmplifyApp", { |
| 73 | description: "updated description", |
| 74 | platform: "WEB", |
| 75 | environmentVariables: { STAGE: "test", REGION: "us-west-2" }, |
| 76 | tags: { Environment: "test", Extra: "yes" }, |
| 77 | }); |
| 78 | }), |
| 79 | ); |
| 80 | expect(updated.appId).toBe(app.appId); |
| 81 | |
| 82 | const live2 = yield* findApp(app.appId); |
| 83 | expect(live2?.description).toBe("updated description"); |
| 84 | expect(live2?.environmentVariables?.REGION).toBe("us-west-2"); |
| 85 | expect(live2?.tags?.Extra).toBe("yes"); |
| 86 | |
| 87 | yield* stack.destroy(); |
| 88 | yield* assertAppDeleted(app.appId); |
| 89 | }), |
| 90 | { tags: ["provider:aws", "provider:aws:amplify", "live"], timeout: 180_000 }, |
| 91 | ); |