@@ -201,10 +201,12 @@ assert.deepEqual(recipe.workflow.steps[0].args.filter((arg) => arg.includes("aut
201201 "autoload-file=/wp-codebox-vendor/autoload.php" ,
202202 `project-autoload-file=${ woocommerceAutoload } ` ,
203203] )
204+ assert . ok ( recipe . workflow . steps [ 0 ] . args . includes ( "autoload-file-role=harness" ) , "modern PHPUnit recipes explicitly preserve harness autoload intent" )
204205assert . deepEqual ( rewriteInputMountPathArgs ( recipe . workflow . steps [ 0 ] . args , recipeInputMountPathMap ( recipe ) ) . filter ( ( arg ) => arg . includes ( "autoload-file=" ) ) , [
205206 "autoload-file=/tmp/wp-codebox-inputs/0-wp-codebox-vendor-73845ca47d2f/autoload.php" ,
206207 `project-autoload-file=${ woocommerceAutoload } ` ,
207208] )
209+ assert . ok ( rewriteInputMountPathArgs ( recipe . workflow . steps [ 0 ] . args , recipeInputMountPathMap ( recipe ) ) . includes ( "autoload-file-role=harness" ) , "CLI path canonicalization preserves autoload intent" )
208210assert . ok ( recipe . workflow . steps [ 0 ] . args . includes ( "cwd=/home/example/public_html" ) )
209211assert . ok ( recipe . workflow . steps [ 0 ] . args . includes ( "test-root=/home/example/public_html/bin/tests/phpunit" ) )
210212assert . ok ( recipe . workflow . steps [ 0 ] . args . includes ( "phpunit-xml=/home/example/public_html/bin/tests/phpunit/phpunit.xml.dist" ) )
@@ -236,6 +238,8 @@ assert.ok(projectBootstrapIndex > bootIndex)
236238assert . ok ( projectAutoloadIndex > projectBootstrapIndex )
237239assert . ok ( projectModeCode . includes ( "'autoload_required' => $bootstrap_mode !== 'project' || $harness_autoload_file !== ''" ) )
238240assert . ok ( projectModeCode . includes ( "$legacy_project_autoload_file = $autoload_file" ) )
241+ assert . ok ( projectModeCode . includes ( '$autoload_file_role = "";' ) , "direct callers without an explicit role retain the legacy compatibility path" )
242+ assert . ok ( projectModeCode . includes ( "if ($autoload_file_role === '' && $bootstrap_mode === 'project'" ) )
239243assert . ok ( projectModeCode . includes ( "configured PHPUnit harness autoload file is not readable" ) )
240244assert . ok ( projectModeCode . includes ( "NOTICE:project bootstrap mode continuing without configured PHPUnit harness autoload" ) )
241245assert . ok ( projectModeCode . includes ( "$test_root = \"/home/example/public_html/bin/tests/phpunit\";" ) )
@@ -262,12 +266,47 @@ assert.ok(verifyHarnessIndex > 0, "verify_harness stage must be present")
262266assert . ok ( projectModeTestsuiteIndex > verifyHarnessIndex , "harness verification must precede TestSuite construction" )
263267assertProjectBootstrapHarnessGuard ( projectModeCode )
264268
265- let capturedDefaultProjectCode = ""
269+ const canonicalHarnessProjectModeCode = phpunitRunCode ( {
270+ pluginSlug : "woocommerce" ,
271+ cwd : "/wordpress/wp-content/plugins/woocommerce" ,
272+ autoloadFile : "/tmp/wp-codebox-inputs/0-wp-codebox-vendor-73845ca47d2f/autoload.php" ,
273+ autoloadFileRole : "harness" ,
274+ projectAutoloadFile : woocommerceAutoload ,
275+ testsDir : "/tmp/wp-codebox-inputs/0-wp-codebox-vendor-73845ca47d2f/wp-phpunit/wp-phpunit" ,
276+ testRoot : "/home/example/public_html/bin/tests/phpunit" ,
277+ phpunitXml : "/wordpress/wp-content/plugins/woocommerce/phpunit.xml.dist" ,
278+ selectedTestFile : "" ,
279+ changedTestFiles : [ ] ,
280+ phpunitArgs : [ ] ,
281+ env : { } ,
282+ wpConfigDefines : { } ,
283+ dependencyMounts : [ ] ,
284+ bootstrapFiles : [ ] ,
285+ bootstrapMode : "project" ,
286+ projectBootstrap : "tests/legacy/bootstrap.php" ,
287+ multisite : false ,
288+ } )
289+ assert . ok ( canonicalHarnessProjectModeCode . includes ( '$autoload_file_role = "harness";' ) )
290+ assert . ok ( canonicalHarnessProjectModeCode . includes ( '$harness_autoload_file = $legacy_project_autoload_file !== \'\' ? \'/wp-codebox-vendor/autoload.php\' : $autoload_file;' ) )
291+ const canonicalHarnessResolution = canonicalHarnessProjectModeCode . match ( / \$ l e g a c y _ p r o j e c t _ a u t o l o a d _ f i l e = ' ' ; [ \s \S ] * ?\$ h a r n e s s _ a u t o l o a d _ f i l e = [ ^ ; ] + ; / ) ?. [ 0 ]
292+ assert . ok ( canonicalHarnessResolution , "generated project-mode code must resolve harness autoload intent" )
293+ const canonicalHarnessProbe = join ( mkdtempSync ( join ( tmpdir ( ) , "wp-codebox-canonical-harness-" ) ) , "probe.php" )
294+ writeFileSync ( canonicalHarnessProbe , `<?php
295+ $bootstrap_mode = 'project';
296+ $autoload_file = '/tmp/wp-codebox-inputs/0-wp-codebox-vendor-73845ca47d2f/autoload.php';
297+ $autoload_file_role = 'harness';
298+ $project_autoload_file = ${ phpString ( woocommerceAutoload ) } ;
299+ ${ canonicalHarnessResolution }
300+ echo json_encode(array($legacy_project_autoload_file, $harness_autoload_file));
301+ ` )
302+ assert . deepEqual ( JSON . parse ( execFileSync ( "php" , [ canonicalHarnessProbe ] , { encoding : "utf8" } ) ) , [ "" , "/tmp/wp-codebox-inputs/0-wp-codebox-vendor-73845ca47d2f/autoload.php" ] , "a canonical staged harness path remains the harness in project mode" )
303+
304+ let capturedCanonicalHarnessCode = ""
266305await runPhpunitCommand ( {
267306 artifactRoot : mkdtempSync ( join ( tmpdir ( ) , "wp-codebox-phpunit-artifacts-" ) ) ,
268307 mounts : [ ] ,
269308 runPlaygroundCommand : async ( _command , _server , input ) => {
270- capturedDefaultProjectCode = input . code
309+ capturedCanonicalHarnessCode = input . code
271310 return { text : "ok" , exitCode : 0 }
272311 } ,
273312 server : { playground : { } } as never ,
@@ -276,13 +315,15 @@ await runPhpunitCommand({
276315 args : [
277316 "plugin-slug=ai-provider-for-openai" ,
278317 "bootstrap-mode=project" ,
318+ "autoload-file=/tmp/wp-codebox-inputs/0-wp-codebox-vendor-73845ca47d2f/autoload.php" ,
319+ "autoload-file-role=harness" ,
279320 "phpunit-xml=phpunit.xml.dist" ,
280321 "test-file=tests/unit/Models/OpenAiEmbeddingGenerationModelTest.php" ,
281322 ] ,
282323 } ,
283324} )
284- assert . ok ( capturedDefaultProjectCode . includes ( '$autoload_file = "";' ) )
285- assert . ok ( capturedDefaultProjectCode . includes ( "NOTICE:project bootstrap mode continuing without configured PHPUnit harness autoload" ) )
325+ assert . ok ( capturedCanonicalHarnessCode . includes ( '$autoload_file = "/tmp/wp-codebox-inputs/0-wp-codebox-vendor-73845ca47d2f/autoload.php ";' ) )
326+ assert . ok ( capturedCanonicalHarnessCode . includes ( '$autoload_file_role = " harness";' ) )
286327
287328const coreModeCode = corePhpunitRunCode ( {
288329 coreRoot : "/wordpress" ,
0 commit comments