Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/runtime-playground/src/wordpress-command-runners.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createHash, randomBytes } from "node:crypto"
import { mkdir, writeFile } from "node:fs/promises"
import { dirname, join } from "node:path"
import { dirname, join, posix } from "node:path"
import type { BrowserArtifact } from "./browser-artifacts.js"
import { promoteBrowserMetricsToBenchResults } from "./browser-metrics.js"
import { writePluginCheckArtifacts, writeThemeCheckArtifacts, type PluginCheckArtifact, type ThemeCheckArtifact } from "./check-artifacts.js"
Expand Down Expand Up @@ -976,7 +976,7 @@ export async function runPhpunitCommand({
projectAutoloadFile: argValue(args, "project-autoload-file")?.trim() || "",
testsDir: argValue(args, "tests-dir")?.trim() || "/wp-codebox-vendor/wp-phpunit/wp-phpunit",
testRoot: argValue(args, "test-root")?.trim() || `/wordpress/wp-content/plugins/${pluginSlug}/tests`,
phpunitXml: phpunitXmlArg?.trim() || `/wordpress/wp-content/plugins/${pluginSlug}/phpunit.xml.dist`,
phpunitXml: posix.resolve(`/wordpress/wp-content/plugins/${pluginSlug}`, phpunitXmlArg?.trim() || "phpunit.xml.dist"),
phpunitXmlIsDefault: phpunitXmlArg === undefined || booleanArg(args, "phpunit-xml-default"),
selectedTestFile,
changedTestFiles,
Expand Down
60 changes: 59 additions & 1 deletion tests/phpunit-discovery-only.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from "node:assert/strict"
import test from "node:test"
import { execFileSync } from "node:child_process"
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { buildWordPressPhpunitRecipe } from "../packages/runtime-core/src/recipe-builders.js"
Expand Down Expand Up @@ -113,6 +113,64 @@ test("discovery-only returns its schema-bound result directly", async () => {
assert.deepEqual(JSON.parse(output), payload)
})

test("relative managed config discovery matches absolute sandbox paths (issue #2601)", async () => {
const pluginRoot = "/wordpress/wp-content/plugins/fixture"
const configPath = `${pluginRoot}/phpunit-managed.xml.dist`
const tempDir = mkdtempSync(join(tmpdir(), "wp-codebox-phpunit-2601-"))
try {
mkdirSync(join(tempDir, "tests", "Unit"), { recursive: true })
writeFileSync(join(tempDir, "tests", "Unit", "FixtureTest.php"), "<?php\n")
writeFileSync(join(tempDir, "phpunit-managed.xml.dist"),
'<phpunit><testsuites><testsuite name="managed"><directory>./tests/Unit</directory></testsuite></testsuites></phpunit>')

const generated: string[] = []
const results: unknown[] = []
for (const config of ["phpunit-managed.xml.dist", configPath]) {
let runtimeOutput = ""
const result = await runPhpunitCommand({
artifactRoot: "/tmp/artifacts",
mounts: [],
runPlaygroundCommand: async (_command, _server, input) => {
const code = input.code ?? ""
generated.push(code)
assert.ok(code.includes(JSON.stringify(configPath)), "runner must canonicalize the config before generating PHP")
const start = code.indexOf("if ($discovery_only) {")
const end = code.indexOf("if (!is_array($wp_config_defines))", start)
assert.ok(start >= 0 && end > start)
// Execute the real discovery block on the host, mapping only the VFS root.
const scriptPath = join(tempDir, "discover.php")
writeFileSync(scriptPath, `<?php
function pg_log($message) { echo $message, "\\n"; }
function pg_stage_begin($stage) {}
function pg_stage_ok($stage) {}
function pg_stage_fail($stage, Throwable $e) { echo 'STAGE_FAIL:', $e->getMessage(), "\\n"; }
${extractPhpFunction(code, "wp_codebox_phpunit_parse_config")}
${extractPhpFunction(code, "wp_codebox_phpunit_discover")}
$discovery_only = true;
$plugin_slug = 'fixture';
$test_root = ${phpString(join(tempDir, "tests"))};
$selected_testsuites = array();
${code.slice(start, end).replaceAll(pluginRoot, tempDir)}
`)
runtimeOutput = execFileSync("php", [scriptPath], { encoding: "utf8" }).replaceAll(tempDir, pluginRoot)
return { exitCode: 0, errors: "", text: "" }
},
runtimeSpec: wordpressRuntimeSpec({ commands: ["wordpress.phpunit"] }),
server: { playground: { readFileAsText: async () => runtimeOutput } } as never,
spec: { command: "wordpress.phpunit", args: ["plugin-slug=fixture", "discovery-only=true", `phpunit-xml=${config}`] },
})
const payload = JSON.parse(result as string)
assert.equal(payload.phpunit_xml, configPath)
assert.deepEqual(payload.files, [`${pluginRoot}/./tests/Unit/FixtureTest.php`])
results.push(payload)
}
assert.equal(generated[0], generated[1], "discovery and execution must receive identical canonical options")
assert.deepEqual(results[0], results[1])
} finally {
rmSync(tempDir, { recursive: true, force: true })
}
})

test("recipe setup uses canonical boolean parsing and rejects mixed workflows", () => {
const recipe = buildWordPressPhpunitRecipe({ pluginSlug: "fixture", discoveryOnly: true })
const args = recipe.workflow.steps[0].args
Expand Down
Loading