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 { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Core from "@alchemy.run/test/Core"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | import { AuthHttpError, getJson, postJson, toCookieHeader } from "../http.ts"; |
| 8 | import AuroraAuthFunctionLive, { AuroraAuthFunction } from "./fixtures/aurora-handler.ts"; |
| 9 | |
| 10 | /** |
| 11 | * Aurora Serverless v2 provisioning takes ~10 minutes, so this suite is |
| 12 | * skipped under `--fast` (the established FAST=1 convention for |
| 13 | * long-provisioning resources). The Data API dialect itself is pinned |
| 14 | * ungated by AuroraDataApi.test.ts. |
| 15 | */ |
| 16 | const enabled = !process.env.FAST; |
| 17 | |
| 18 | const testOptions = { providers: AWS.providers() }; |
| 19 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 20 | const sharedStack = Core.scratchStack(testOptions, "BetterAuthAurora", "test/AWS/Aurora.test.ts"); |
| 21 | |
| 22 | let baseUrl: string; |
| 23 | |
| 24 | const readinessRetry = Effect.retry({ |
| 25 | schedule: Schedule.exponential("3 seconds", 1.5), |
| 26 | times: 10, |
| 27 | }); |
| 28 | |
| 29 | beforeAll( |
| 30 | Effect.gen(function* () { |
| 31 | if (!enabled) { |
| 32 | return; |
| 33 | } |
| 34 | if (!process.env.NO_DESTROY) { |
| 35 | yield* sharedStack.destroy(); |
| 36 | } |
| 37 | const { functionUrl } = yield* sharedStack.deploy( |
| 38 | Effect.gen(function* () { |
| 39 | return yield* AuroraAuthFunction; |
| 40 | }).pipe(Effect.provide(AuroraAuthFunctionLive)), |
| 41 | ); |
| 42 | expect(functionUrl).toBeTruthy(); |
| 43 | baseUrl = functionUrl!.replace(/\/+$/, ""); |
| 44 | yield* getJson<{ email: string | null }>(`${baseUrl}/me`).pipe( |
| 45 | Effect.tapError((error) => |
| 46 | Effect.logWarning(`Aurora Lambda not ready yet: ${error.message}`), |
| 47 | ), |
| 48 | readinessRetry, |
| 49 | ); |
| 50 | }), |
| 51 | { timeout: 1_500_000 }, |
| 52 | ); |
| 53 | |
| 54 | afterAll.skipIf(!!process.env.NO_DESTROY)(sharedStack.destroy(), { |
| 55 | timeout: 1_500_000, |
| 56 | }); |
| 57 | |
| 58 | test.skipIf(!enabled)( |
| 59 | "Lambda -> Aurora over the Data API: sign-up, sign-in, session", |
| 60 | Effect.gen(function* () { |
| 61 | const email = "aurora-user@example.com"; |
| 62 | const password = "password1234"; |
| 63 | |
| 64 | yield* postJson(`${baseUrl}/auth/sign-up/email`, { |
| 65 | email, |
| 66 | password, |
| 67 | name: "Aurora User", |
| 68 | }).pipe( |
| 69 | Effect.filterOrFail( |
| 70 | (response) => response.status === 200 || response.body.includes("USER_ALREADY_EXISTS"), |
| 71 | (response) => new AuthHttpError({ url: baseUrl, ...response }), |
| 72 | ), |
| 73 | ); |
| 74 | |
| 75 | const signIn = yield* postJson(`${baseUrl}/auth/sign-in/email`, { |
| 76 | email, |
| 77 | password, |
| 78 | }).pipe( |
| 79 | Effect.filterOrFail( |
| 80 | (response) => response.status === 200, |
| 81 | (response) => new AuthHttpError({ url: baseUrl, ...response }), |
| 82 | ), |
| 83 | ); |
| 84 | expect(signIn.setCookies.length).toBeGreaterThan(0); |
| 85 | |
| 86 | const me = yield* getJson<{ email: string | null }>(`${baseUrl}/me`, { |
| 87 | cookie: toCookieHeader(signIn.setCookies), |
| 88 | }); |
| 89 | expect(me.email).toBe(email); |
| 90 | }), |
| 91 | { |
| 92 | tags: ["provider:aws", "provider:aws:ec2", "provider:aws:lambda", "provider:aws:rds", "live"], |
| 93 | timeout: 120_000, |
| 94 | }, |
| 95 | ); |