From af5b6a9a6ab97fd4af171c64263d9fc24de30940 Mon Sep 17 00:00:00 2001 From: "homeboy-ci[bot]" <266378653+homeboy-ci[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 05:17:55 +0000 Subject: [PATCH] fix(phpunit): resolve relative config paths against plugin root --- .../src/wordpress-command-runners.ts | 4 +- tests/phpunit-discovery-only.test.ts | 60 ++++++++++++++++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/packages/runtime-playground/src/wordpress-command-runners.ts b/packages/runtime-playground/src/wordpress-command-runners.ts index a6a1c9af..fdd9d2a0 100644 --- a/packages/runtime-playground/src/wordpress-command-runners.ts +++ b/packages/runtime-playground/src/wordpress-command-runners.ts @@ -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" @@ -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, diff --git a/tests/phpunit-discovery-only.test.ts b/tests/phpunit-discovery-only.test.ts index 5ee17988..c6562b8c 100644 --- a/tests/phpunit-discovery-only.test.ts +++ b/tests/phpunit-discovery-only.test.ts @@ -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" @@ -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"), "./tests/Unit') + + 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, `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