11import assert from "node:assert/strict"
2+ import { mkdtemp , readFile , rm , writeFile } from "node:fs/promises"
23import { createServer } from "node:net"
4+ import { tmpdir } from "node:os"
5+ import { join } from "node:path"
6+ import { runRecipeBuildCommand } from "../packages/cli/src/commands/recipe-build.ts"
37import { parseLoopbackPort , provisionRuntimeServices , provisionRuntimeServicesForRecipe , RuntimeServiceProvisionError , runtimeServiceEvidenceFromError , runtimeServicePlan , waitForMysqlProtocol , type RuntimeServiceDependencies } from "../packages/cli/src/runtime-services.ts"
48import { planWorkspaceRecipe } from "../packages/cli/src/recipe-dry-run.ts"
59import { validateWorkspaceRecipeSemantics } from "../packages/cli/src/recipe-validation.ts"
@@ -19,6 +23,22 @@ assert.equal(unsafe.valid, false)
1923const emptyRootService = { ...service , configuration : { rootAuthentication : "empty-password" as const } }
2024assert . equal ( validateWorkspaceRecipeJsonSchema ( { schema : "wp-codebox/workspace-recipe/v1" , inputs : { services : [ emptyRootService ] } , workflow : { steps : [ { command : "wordpress.run-php" } ] } } ) . valid , true )
2125assert . deepEqual ( buildWordPressPhpunitRecipe ( { pluginSlug : "example" , services : [ emptyRootService ] } ) . inputs ?. services , [ emptyRootService ] )
26+ const builderDirectory = await mkdtemp ( join ( tmpdir ( ) , "wp-codebox-phpunit-builder-" ) )
27+ try {
28+ const optionsPath = join ( builderDirectory , "options.json" )
29+ const recipePath = join ( builderDirectory , "recipe.json" )
30+ await writeFile ( optionsPath , JSON . stringify ( {
31+ pluginSlug : "example" ,
32+ testRoot : "/home/example/bin/tests/core" ,
33+ phpunitXml : "/home/example/bin/tests/core/phpunit.xml" ,
34+ } ) )
35+ assert . equal ( await runRecipeBuildCommand ( [ "phpunit" , "--options" , optionsPath , "--output" , recipePath ] ) , 0 )
36+ const builtRecipe = JSON . parse ( await readFile ( recipePath , "utf8" ) ) as WorkspaceRecipe
37+ assert . ok ( builtRecipe . workflow . steps [ 0 ] . args ?. includes ( "test-root=/home/example/bin/tests/core" ) )
38+ assert . ok ( builtRecipe . workflow . steps [ 0 ] . args ?. includes ( "phpunit-xml=/home/example/bin/tests/core/phpunit.xml" ) )
39+ } finally {
40+ await rm ( builderDirectory , { recursive : true , force : true } )
41+ }
2242const recipe : WorkspaceRecipe = { schema : "wp-codebox/workspace-recipe/v1" , inputs : { services : [ service ] } , workflow : { steps : [ { command : "wordpress.run-php" , args : [ "code=echo 'ok';" ] } ] } }
2343assert . deepEqual ( await validateWorkspaceRecipeSemantics ( recipe , "recipe.json" ) , [ ] )
2444const dryRun = await planWorkspaceRecipe ( recipe , process . cwd ( ) , { recipePath : "recipe.json" } , {
0 commit comments