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

main
ts 55 lines 2.56 KB
Raw
1 import type { TestOptions } from "@alchemy.run/test";
2 import * as Test from "@alchemy.run/test/Alchemy";
3 import { makeApiGatewayTestLease } from "./TestLease.ts";
4
5 const apiGatewayOptions = (options: TestOptions | undefined): TestOptions => {
6 const normalized = typeof options === "number" ? { timeout: options } : options;
7 return {
8 ...normalized,
9 // Once a file owns the service lease an individual lifecycle is fast —
10 // observed passes at suite concurrency 32 run 3–30s. The failures that
11 // motivated this budget were throttle storms at concurrency 64: the
12 // account-wide REST control-plane quota is shared with ApiGatewayV2 and
13 // the rest of the run, so distilled's TooManyRequests backoff can stack
14 // a 3s operation past 120s. 300s absorbs the storm while still failing
15 // a genuine provider hang fast relative to the full-run timeout.
16 timeout: normalized?.timeout ?? 300_000,
17 // API Gateway REST mutations share an account-wide throttle. A timed-out
18 // retry starts with a fresh scratch state and therefore cannot reclaim the
19 // physical API from the interrupted attempt, so these live tests run once.
20 // TestLease serializes only this service's files; do not use the runner's
21 // global `exclusive` lock here because that would also block unrelated AWS
22 // services while API Gateway waits on its slow control plane.
23 retry: 0,
24 };
25 };
26
27 /**
28 * API Gateway REST test adapter.
29 *
30 * The old Vitest project ran this directory in a single fork with file
31 * concurrency disabled. A shared root-hook lease restores that scheduling
32 * contract without teaching the generic runner about service paths.
33 */
34 export const make = <ROut = any>(options: Test.MakeOptions<ROut>) => {
35 const api = Test.make(options);
36 const testLease = makeApiGatewayTestLease();
37
38 // The first 12 files can enter the runner together. Waiting here is
39 // intentional service scheduling rather than a cloud operation, so allow
40 // the queue to span the full hard-walled AWS run.
41 api.beforeAll(testLease.acquire, { timeout: 3_600_000 });
42 api.afterAll(testLease.release);
43
44 const provider = api.test.provider;
45
46 const providerWithOptions = ((name, fn, testOptions) =>
47 provider(name, fn, apiGatewayOptions(testOptions))) as typeof provider;
48 providerWithOptions.skip = (name, fn, testOptions) =>
49 provider.skip(name, fn, apiGatewayOptions(testOptions));
50 providerWithOptions.skipIf = (condition) => (name, fn, testOptions) =>
51 provider.skipIf(condition)(name, fn, apiGatewayOptions(testOptions));
52
53 api.test.provider = providerWithOptions;
54 return api;
55 };