Skip to content

Commit 9025ac7

Browse files
committed
Reject incomplete PHPUnit bootstrap runs
1 parent 72e2acd commit 9025ac7

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

packages/runtime-playground/src/playground-runtime.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,9 +1898,11 @@ echo json_encode(array('command' => 'inspect-mounted-inputs', 'mounts' => $inspe
18981898

18991899
function executionSpecWithEnvironment(spec: ExecutionSpec): ExecutionSpec {
19001900
if (!spec.environment || Object.keys(spec.environment).length === 0) return spec
1901+
const args = spec.args ?? []
1902+
const runtimeEnvironment = JSON.parse(argValue(args, "runtime-env-json") ?? "{}") as Record<string, string>
19011903
return {
19021904
...spec,
1903-
args: [...(spec.args ?? []).filter((argument) => !argument.startsWith("runtime-env-json=")), `runtime-env-json=${JSON.stringify(spec.environment)}`],
1905+
args: [...args.filter((argument) => !argument.startsWith("runtime-env-json=")), `runtime-env-json=${JSON.stringify({ ...runtimeEnvironment, ...spec.environment })}`],
19041906
}
19051907
}
19061908

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,9 @@ export async function runPhpunitCommand({
966966
}
967967
throw error
968968
}
969+
if (structured) {
970+
throw attachPlaygroundDiagnostics(new Error("wordpress.phpunit terminated before completing bootstrap"), "wordpress.phpunit structured diagnostics", structured)
971+
}
969972

970973
return response.text
971974
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ await assert.rejects(
1515
mounts: [],
1616
runPlaygroundCommand: async (_command, _server, input) => {
1717
submittedCode = input.code
18-
return { exitCode: 1, errors: "", text: "" }
18+
return { exitCode: 0, errors: "", text: "" }
1919
},
2020
runtimeSpec: { environment: { kind: "wordpress", name: "test", version: "latest" }, policy: { commands: ["wordpress.phpunit"] } } as never,
2121
server: {
@@ -29,7 +29,7 @@ await assert.rejects(
2929
spec: { command: "wordpress.phpunit", args: ["plugin-slug=demo-plugin"] },
3030
}),
3131
(error: Error) => {
32-
assert.match(error.message, /wordpress\.phpunit failed with exit code 1/)
32+
assert.match(error.message, /wordpress\.phpunit terminated before completing bootstrap/)
3333
assert.match(error.message, /wordpress\.phpunit structured diagnostics/)
3434
assert.match(error.message, /Bootstrap failed with token: \[redacted\]/)
3535
assert.match(error.message, /\[diagnostic truncated\]/)

tests/playground-phpunit-bootstrap-failure.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ try {
5252
assert.match(commandLog, /PHPUnit bootstrap fixture token: \[redacted\]/)
5353
assert.doesNotMatch(commandLog, new RegExp(secret))
5454

55-
await writeFile(fatalMuPlugin, `<?php\necho 'PHPUnit bootstrap exit fixture token: ${secret}';\nexit(1);\n`)
55+
await writeFile(fatalMuPlugin, `<?php\necho 'PHPUnit bootstrap exit fixture token: ${secret}';\nexit;\n`)
5656
const exitOutput = await runFailedRecipe(exitArtifactsPath)
5757
assert.equal(exitOutput.success, false, JSON.stringify(exitOutput))
5858
const exitMessage = exitOutput.error?.message ?? ""

0 commit comments

Comments
 (0)