Skip to content

Commit ddae9e8

Browse files
committed
Bound PHPUnit response streams independently
1 parent e7b4170 commit ddae9e8

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

packages/runtime-playground/src/wordpress-command-runners.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,16 +971,21 @@ export async function runPhpunitCommand({
971971
throw attachPlaygroundDiagnostics(new Error("wordpress.phpunit terminated before completing bootstrap"), "wordpress.phpunit structured diagnostics", structured)
972972
}
973973
if (!phpunitArgs.includes("--list-tests") && !/\bOK(?:, but there were issues!)? \([1-9]\d* tests?,/m.test(response.text)) {
974-
const diagnostics = [
975-
response.errors?.trim() ? `--- stderr ---\n${response.errors.trim()}` : "",
976-
response.text.trim() ? `--- stdout ---\n${response.text.trim()}` : "",
977-
].filter(Boolean).join("\n")
974+
const diagnostics = successfulPhpunitResponseDiagnostics(response)
978975
throw attachPlaygroundDiagnostics(new Error("wordpress.phpunit exited successfully without a non-zero PHPUnit test summary"), "wordpress.phpunit successful response diagnostics", diagnostics)
979976
}
980977

981978
return response.text
982979
}
983980

981+
function successfulPhpunitResponseDiagnostics(response: PlaygroundRunResponse): string {
982+
const boundedStream = (value: string): string => value.length > 9_000 ? `${value.slice(0, 9_000)}\n[stream truncated]` : value
983+
return [
984+
response.errors?.trim() ? `--- stderr ---\n${boundedStream(response.errors.trim())}` : "",
985+
response.text.trim() ? `--- stdout ---\n${boundedStream(response.text.trim())}` : "",
986+
].filter(Boolean).join("\n")
987+
}
988+
984989
function boundedProcessIdentity(value: string | undefined): string {
985990
if (!value) return ""
986991
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(value)) throw new Error(`Invalid PHPUnit process identity: ${value}`)

tests/phpunit-runtime-failure-diagnostics.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ await assert.rejects(
5757
mounts: [],
5858
runPlaygroundCommand: async () => ({
5959
exitCode: 0,
60-
errors: `PHPUnit stderr token=${successfulResponseSecret}`,
60+
errors: `PHPUnit stderr token=${successfulResponseSecret}\n${"e".repeat(25_000)}`,
6161
text: `WPCOM Codebox PHPUnit shutdown: mysql_port=unset\n${"x".repeat(25_000)}`,
6262
}),
6363
runtimeSpec: { environment: { kind: "wordpress", name: "test", version: "latest" }, policy: { commands: ["wordpress.phpunit"] } } as never,
@@ -71,9 +71,9 @@ await assert.rejects(
7171
assert.match(error.message, /--- stdout ---/)
7272
assert.match(error.message, /WPCOM Codebox \[redacted\] shutdown: mysql_port=unset/)
7373
assert.match(error.message, /PHPUnit stderr token=\[redacted\]/)
74-
assert.match(error.message, /\[diagnostic truncated\]/)
74+
assert.match(error.message, /\[stream truncated\]/)
7575
assert.doesNotMatch(error.message, new RegExp(successfulResponseSecret))
76-
assert.ok(error.message.length < 21_000, "successful response diagnostics must remain bounded")
76+
assert.ok(error.message.length < 19_000, "successful response diagnostics must remain bounded")
7777
return true
7878
},
7979
)

0 commit comments

Comments
 (0)