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 { describe, 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 Data from "effect/Data"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as HttpClient from "effect/http/HttpClient"; |
| 8 | import * as HttpClientRequest from "effect/http/HttpClientRequest"; |
| 9 | import * as Schedule from "effect/Schedule"; |
| 10 | import AossBindingsFunctionLive, { AossBindingsFunction } from "./bindings-handler"; |
| 11 | |
| 12 | const testOptions = { providers: AWS.providers() }; |
| 13 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 14 | const sharedStack = Core.scratchStack(testOptions, "AossBindings"); |
| 15 | |
| 16 | // Lambda function URL cold-start (DNS, IAM propagation, init) can take well |
| 17 | // over 60s on a fresh deploy under parallel-suite load. |
| 18 | const readinessPolicy = Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(75)]); |
| 19 | |
| 20 | let baseUrl: string; |
| 21 | |
| 22 | class TransientUpstream extends Data.TaggedError("TransientUpstream")<{ |
| 23 | readonly status: number; |
| 24 | readonly body: string; |
| 25 | }> {} |
| 26 | |
| 27 | // The shared Lambda fixture occasionally answers a transient 5xx under load |
| 28 | // (cold re-init, IAM propagation on the freshly attached policy that the |
| 29 | // handler's `Effect.orDie` surfaces as a 500). Retry only 5xx; a genuine |
| 30 | // 4xx/assertion failure surfaces immediately. |
| 31 | const send = (request: HttpClientRequest.HttpClientRequest) => |
| 32 | HttpClient.execute(request).pipe( |
| 33 | Effect.flatMap((response) => |
| 34 | response.status >= 500 |
| 35 | ? response.text.pipe( |
| 36 | Effect.flatMap((body) => |
| 37 | Effect.fail(new TransientUpstream({ status: response.status, body })), |
| 38 | ), |
| 39 | ) |
| 40 | : Effect.succeed(response), |
| 41 | ), |
| 42 | Effect.retry({ |
| 43 | while: (e) => e._tag === "TransientUpstream", |
| 44 | schedule: Schedule.max([Schedule.exponential("500 millis"), Schedule.recurs(6)]), |
| 45 | }), |
| 46 | ); |
| 47 | |
| 48 | describe.sequential( |
| 49 | "OpenSearchServerless Bindings", |
| 50 | { |
| 51 | tags: [ |
| 52 | "provider:aws", |
| 53 | "provider:aws:batch", |
| 54 | "provider:aws:lambda", |
| 55 | "provider:aws:opensearchserverless", |
| 56 | "live", |
| 57 | ], |
| 58 | }, |
| 59 | () => { |
| 60 | beforeAll( |
| 61 | Effect.gen(function* () { |
| 62 | yield* Effect.logInfo("AOSS test setup: destroying previous resources"); |
| 63 | yield* sharedStack.destroy(); |
| 64 | |
| 65 | yield* Effect.logInfo("AOSS test setup: deploying fixture"); |
| 66 | const { functionUrl } = yield* sharedStack.deploy( |
| 67 | Effect.gen(function* () { |
| 68 | return yield* AossBindingsFunction; |
| 69 | }).pipe(Effect.provide(AossBindingsFunctionLive)), |
| 70 | ); |
| 71 | |
| 72 | expect(functionUrl).toBeTruthy(); |
| 73 | baseUrl = functionUrl!.replace(/\/+$/, ""); |
| 74 | |
| 75 | const readinessUrl = `${baseUrl}/bindings`; |
| 76 | yield* Effect.logInfo(`AOSS test setup: probing readiness at ${readinessUrl}`); |
| 77 | yield* HttpClient.get(readinessUrl).pipe( |
| 78 | Effect.flatMap((response) => |
| 79 | response.status === 200 |
| 80 | ? Effect.succeed(response) |
| 81 | : Effect.fail(new Error(`Function not ready: ${response.status}`)), |
| 82 | ), |
| 83 | Effect.tapError((error) => |
| 84 | Effect.logWarning(`AOSS test setup: fixture not ready yet (${String(error)})`), |
| 85 | ), |
| 86 | Effect.retry({ schedule: readinessPolicy }), |
| 87 | ); |
| 88 | }), |
| 89 | { timeout: 240_000 }, |
| 90 | ); |
| 91 | |
| 92 | afterAll(sharedStack.destroy(), { timeout: 240_000 }); |
| 93 | |
| 94 | describe("binding registration", () => { |
| 95 | test.provider("all 4 capabilities initialize in the runtime", (_stack) => |
| 96 | Effect.gen(function* () { |
| 97 | const response = yield* send(HttpClientRequest.get(`${baseUrl}/bindings`)).pipe( |
| 98 | Effect.flatMap((r) => r.json), |
| 99 | ); |
| 100 | expect((response as any).bound).toHaveLength(4); |
| 101 | }), |
| 102 | ); |
| 103 | }); |
| 104 | |
| 105 | describe("GetAccountSettings", () => { |
| 106 | test.provider("reads the account's capacity limits", (_stack) => |
| 107 | Effect.gen(function* () { |
| 108 | const response = (yield* send(HttpClientRequest.get(`${baseUrl}/account-settings`)).pipe( |
| 109 | Effect.flatMap((r) => r.json), |
| 110 | )) as any; |
| 111 | // Limits may be unset on a fresh account — the call round-tripping |
| 112 | // proves the grant. |
| 113 | expect(response).toHaveProperty("capacityLimits"); |
| 114 | }), |
| 115 | ); |
| 116 | }); |
| 117 | |
| 118 | describe("UpdateAccountSettings", () => { |
| 119 | test.provider("writes back the observed capacity limits", (_stack) => |
| 120 | Effect.gen(function* () { |
| 121 | const response = (yield* send( |
| 122 | HttpClientRequest.post(`${baseUrl}/account-settings/noop`), |
| 123 | ).pipe(Effect.flatMap((r) => r.json))) as any; |
| 124 | expect(response.capacityLimits?.maxIndexingCapacityInOCU).toBeGreaterThan(0); |
| 125 | }), |
| 126 | ); |
| 127 | }); |
| 128 | |
| 129 | describe("GetPoliciesStats", () => { |
| 130 | test.provider("counts the account's aoss policies", (_stack) => |
| 131 | Effect.gen(function* () { |
| 132 | const response = (yield* send(HttpClientRequest.get(`${baseUrl}/policies-stats`)).pipe( |
| 133 | Effect.flatMap((r) => r.json), |
| 134 | )) as any; |
| 135 | expect(typeof response.total).toBe("number"); |
| 136 | }), |
| 137 | ); |
| 138 | }); |
| 139 | |
| 140 | describe("BatchGetEffectiveLifecyclePolicy", () => { |
| 141 | test.provider("resolves a nonexistent index through the error-detail channel", (_stack) => |
| 142 | Effect.gen(function* () { |
| 143 | const response = (yield* send( |
| 144 | HttpClientRequest.post(`${baseUrl}/effective-lifecycle`), |
| 145 | ).pipe(Effect.flatMap((r) => r.json))) as any; |
| 146 | expect(response.details + response.errors).toBeGreaterThan(0); |
| 147 | }), |
| 148 | ); |
| 149 | }); |
| 150 | }, |
| 151 | ); |