test: harden HTTP scenario execution evidence

This commit is contained in:
DongHyeonka
2026-08-02 11:36:27 +09:00
parent e08d8c2dd8
commit d2eb320936
6 changed files with 143 additions and 28 deletions
+18 -4
View File
@@ -3,7 +3,7 @@ import type { SpawnSyncOptionsWithStringEncoding } from "node:child_process";
export const PNPM_SCRIPT_TIMEOUT_MS = 60_000;
export const PNPM_SCRIPT_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
type BoundedPnpmScriptInvocation = Readonly<{
type BoundedChildInvocation = Readonly<{
command: string;
arguments: readonly string[];
options: SpawnSyncOptionsWithStringEncoding;
@@ -20,11 +20,25 @@ export function createBoundedPnpmScriptInvocation(input: Readonly<{
pnpmCli: string;
script: string;
environment: NodeJS.ProcessEnv;
}>): BoundedPnpmScriptInvocation {
return Object.freeze({
}>): BoundedChildInvocation {
return createBoundedChildInvocation({
command: input.nodePath,
arguments: Object.freeze([input.pnpmCli, "run", input.script]),
arguments: [input.pnpmCli, "run", input.script],
environment: input.environment,
});
}
export function createBoundedChildInvocation(input: Readonly<{
command: string;
arguments: readonly string[];
environment: NodeJS.ProcessEnv;
cwd?: string;
}>): BoundedChildInvocation {
return Object.freeze({
command: input.command,
arguments: Object.freeze([...input.arguments]),
options: Object.freeze({
...(input.cwd === undefined ? {} : { cwd: input.cwd }),
encoding: "utf8",
env: input.environment,
killSignal: "SIGTERM",
+20
View File
@@ -80,6 +80,26 @@ export const httpScenarioAssertionGroupsSchema = z
if (groups.retry.count !== groups.retry.reasons.length) {
fail(["retry", "count"], "must equal retry reasons length");
}
if (groups.retry.count !== groups.fetch.count - 1) {
fail(["retry", "count"], "must equal the non-final fetch attempt count");
}
for (const [index, reason] of groups.retry.reasons.entries()) {
const status = groups.status.attempts[index];
const expectedReason =
status === "NETWORK_REJECTION"
? "NETWORK_FAILURE"
: status === 429
? "HTTP_429"
: status === 503
? "HTTP_503"
: null;
if (reason !== expectedReason) {
fail(
["retry", "reasons", index],
"must match the corresponding non-final attempt status",
);
}
}
if (groups.fetch.count !== groups.status.attempts.length) {
fail(["fetch", "count"], "must equal status attempts length");
}