test: harden HTTP scenario execution evidence
This commit is contained in:
@@ -3,9 +3,9 @@ import path from "node:path";
|
||||
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
|
||||
import { readBoundedBytes } from "../../src/adapters/http/bounded-body-reader.ts";
|
||||
import { createContractHttpExecutor } from "../../src/adapters/http/http-execution-v3.ts";
|
||||
import {
|
||||
HTTP_EXECUTION_CEILINGS,
|
||||
type InstalledHttpContract,
|
||||
} from "../../src/contracts/external-contract-runtime.ts";
|
||||
import type { CacheScopeSnapshot } from "../../src/contracts/server-state-scope.ts";
|
||||
@@ -42,6 +42,7 @@ type AttemptTrace = {
|
||||
status: AttemptStatus;
|
||||
media: string | null;
|
||||
pulledBytes: number;
|
||||
appliedCeiling: number | null;
|
||||
completed: boolean;
|
||||
cancelled: boolean;
|
||||
};
|
||||
@@ -73,6 +74,7 @@ function tracingFetcher(attempts: AttemptTrace[]): typeof fetch {
|
||||
status: "PENDING_ABORT",
|
||||
media: null,
|
||||
pulledBytes: 0,
|
||||
appliedCeiling: null,
|
||||
completed: false,
|
||||
cancelled: false,
|
||||
};
|
||||
@@ -109,6 +111,9 @@ function tracingFetcher(attempts: AttemptTrace[]): typeof fetch {
|
||||
},
|
||||
cancel(reason) {
|
||||
trace.cancelled = true;
|
||||
// MSW-transferred oversized bodies leave the original cancel promise
|
||||
// permanently pending. Record and request cancellation without making
|
||||
// the proxy response less responsive than the real executor contract.
|
||||
void reader.cancel(reason).catch(() => {});
|
||||
},
|
||||
},
|
||||
@@ -161,19 +166,6 @@ function bodyDisposition(
|
||||
throw new Error(`Response body was neither consumed nor cancelled: ${trace.status}`);
|
||||
}
|
||||
|
||||
function appliedBodyCeiling(
|
||||
trace: AttemptTrace,
|
||||
operation: InstalledHttpContract<unknown, unknown, unknown>,
|
||||
): number {
|
||||
if (typeof trace.status !== "number") return 0;
|
||||
if (operation.contract.acceptedStatuses.includes(trace.status)) {
|
||||
return operation.frontend.responseByteLimit;
|
||||
}
|
||||
return [404, 409, 422, 503].includes(trace.status)
|
||||
? HTTP_EXECUTION_CEILINGS.problemResponseBytes
|
||||
: 0;
|
||||
}
|
||||
|
||||
async function waitForHandler(
|
||||
ready: Promise<void>,
|
||||
executionId: string,
|
||||
@@ -240,6 +232,15 @@ async function executeScenario(
|
||||
}),
|
||||
fetcher,
|
||||
random: () => 0,
|
||||
readBoundedResponseBytes: async (response, maximumBytes) => {
|
||||
const trace = physicalAttempts.at(-1);
|
||||
if (!trace) throw new Error("Body reader ran before a physical attempt");
|
||||
if (trace.appliedCeiling !== null) {
|
||||
throw new Error("Body reader ran more than once for one attempt");
|
||||
}
|
||||
trace.appliedCeiling = maximumBytes;
|
||||
return readBoundedBytes(response, maximumBytes);
|
||||
},
|
||||
sleep: async () => {
|
||||
const prior = physicalAttempts.at(-1);
|
||||
if (!prior) throw new Error("Retry sleep occurred before an attempt");
|
||||
@@ -331,7 +332,7 @@ async function executeScenario(
|
||||
Object.freeze({
|
||||
disposition: bodyDisposition(attempt, outcome),
|
||||
pulledBytes: attempt.pulledBytes,
|
||||
ceiling: appliedBodyCeiling(attempt, operation),
|
||||
ceiling: attempt.appliedCeiling ?? 0,
|
||||
}),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user