Skip to content

Commit e7b4170

Browse files
committed
Preserve PHPUnit zero-summary diagnostics
1 parent 3fad338 commit e7b4170

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,11 @@ 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-
throw new Error("wordpress.phpunit exited successfully without a non-zero PHPUnit test summary")
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")
978+
throw attachPlaygroundDiagnostics(new Error("wordpress.phpunit exited successfully without a non-zero PHPUnit test summary"), "wordpress.phpunit successful response diagnostics", diagnostics)
975979
}
976980

977981
return response.text

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,32 @@ const wordpressBootstrap = decodedBootstrap.indexOf("require_once '/wordpress/wp
5050
assert.ok(preBootstrapRecorder >= 0 && preBootstrapRecorder < wordpressBootstrap, "fatal diagnostics must be recorded before the WordPress bootstrap boundary")
5151

5252
const emptySuccessArtifactRoot = await mkdtemp(join(tmpdir(), "wp-codebox-phpunit-empty-success-"))
53+
const successfulResponseSecret = "ghp_abcdefghijklmnopqrstuvwxyz1234567890"
5354
await assert.rejects(
5455
() => runPhpunitCommand({
5556
artifactRoot: emptySuccessArtifactRoot,
5657
mounts: [],
57-
runPlaygroundCommand: async () => ({ exitCode: 0, errors: "", text: "WPCOM Codebox PHPUnit shutdown: mysql_port=unset" }),
58+
runPlaygroundCommand: async () => ({
59+
exitCode: 0,
60+
errors: `PHPUnit stderr token=${successfulResponseSecret}`,
61+
text: `WPCOM Codebox PHPUnit shutdown: mysql_port=unset\n${"x".repeat(25_000)}`,
62+
}),
5863
runtimeSpec: { environment: { kind: "wordpress", name: "test", version: "latest" }, policy: { commands: ["wordpress.phpunit"] } } as never,
5964
server: { playground: { readFileAsText: async () => { throw new Error("missing") } } } as never,
6065
spec: { command: "wordpress.phpunit", args: ["plugin-slug=demo-plugin"] },
6166
}),
62-
/exited successfully without a non-zero PHPUnit test summary/,
67+
(error: Error) => {
68+
assert.match(error.message, /exited successfully without a non-zero PHPUnit test summary/)
69+
assert.match(error.message, /wordpress\.phpunit successful response diagnostics/)
70+
assert.match(error.message, /--- stderr ---/)
71+
assert.match(error.message, /--- stdout ---/)
72+
assert.match(error.message, /WPCOM Codebox \[redacted\] shutdown: mysql_port=unset/)
73+
assert.match(error.message, /PHPUnit stderr token=\[redacted\]/)
74+
assert.match(error.message, /\[diagnostic truncated\]/)
75+
assert.doesNotMatch(error.message, new RegExp(successfulResponseSecret))
76+
assert.ok(error.message.length < 21_000, "successful response diagnostics must remain bounded")
77+
return true
78+
},
6379
)
6480

6581
console.log("phpunit runtime failure diagnostics ok")

0 commit comments

Comments
 (0)