@@ -3,6 +3,7 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises"
33import { tmpdir } from "node:os"
44import { join } from "node:path"
55
6+ import { recipeExecutionSpec } from "../packages/cli/src/agent-sandbox.js"
67import { applyRecipeRuntimeSetup , assertResolvedInputMountPathArgs , recipeInputMountPathMap , rewriteInputMountPathArgs , type PreparedRecipeRuntimeSetup } from "../packages/cli/src/commands/recipe-runtime-setup.js"
78import { executeRecipeWorkflowStep } from "../packages/cli/src/commands/recipe-run-workflow-evidence.js"
89import type { ExecutionSpec , Runtime , WorkspaceRecipe } from "../packages/runtime-core/src/public.js"
@@ -201,17 +202,43 @@ assert.throws(
201202 / s t i l l r e f e r e n c e s o r i g i n a l i n p u t m o u n t t a r g e t .* \/ h o m e \/ w p c o m \/ p u b l i c _ h t m l / s,
202203)
203204
204- await assert . rejects (
205- ( ) => executeRecipeWorkflowStep ( workflowRuntime , {
206- phase : "steps" ,
207- index : 1 ,
208- step : {
209- command : "wordpress.run-php" ,
210- args : [ "code=require '/home/wpcom/public_html/bin/tests/i18n-tools/bootstrap.php';" ] ,
211- } ,
212- } , process . cwd ( ) , undefined , undefined , undefined , wpcomPathMap ) ,
213- / s t i l l r e f e r e n c e s o r i g i n a l i n p u t m o u n t t a r g e t .* \/ h o m e \/ w p c o m \/ p u b l i c _ h t m l / s,
214- )
205+ const agentMountPathMap = recipeInputMountPathMap ( {
206+ schema : "wp-codebox/workspace-recipe/v1" ,
207+ inputs : {
208+ mounts : [ { source : "/workspace/example" , target : "/workspace/example" , mode : "readonly" } ] ,
209+ } ,
210+ workflow : { steps : [ ] } ,
211+ } )
212+ const agentRuntimeTask = {
213+ bootstrap : "require '/workspace/example/bootstrap.php';" ,
214+ nested : { source : "/workspace/example/task.json" } ,
215+ }
216+ const rewrittenAgentTaskArg = rewriteInputMountPathArgs ( [ `runtime-task-json=${ JSON . stringify ( agentRuntimeTask ) } ` ] , agentMountPathMap ) [ 0 ]
217+ assert . deepEqual ( JSON . parse ( rewrittenAgentTaskArg . slice ( "runtime-task-json=" . length ) ) , {
218+ bootstrap : `require '${ agentMountPathMap [ 0 ] . canonicalTarget } /bootstrap.php';` ,
219+ nested : { source : `${ agentMountPathMap [ 0 ] . canonicalTarget } /task.json` } ,
220+ } , "serialized agent task payloads rewrite embedded input mount references" )
221+
222+ const agentSandboxSpec = await recipeExecutionSpec ( {
223+ command : "wp-codebox.agent-sandbox-run" ,
224+ args : [
225+ "task=Inspect /workspace/example/task.json" ,
226+ "code=require '/workspace/example/bootstrap.php';" ,
227+ rewrittenAgentTaskArg ,
228+ ] ,
229+ } , process . cwd ( ) , undefined , { inputMountPathMap : agentMountPathMap } )
230+ assert . equal ( agentSandboxSpec . args ?. some ( ( arg ) => arg . includes ( "/workspace/example" ) ) , false , "generated agent sandbox bootstrap uses canonical input mount paths" )
231+ assert . match ( agentSandboxSpec . args ?. [ 0 ] ?? "" , new RegExp ( agentMountPathMap [ 0 ] . canonicalTarget . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ) )
232+
233+ const embeddedPhpExecution = await executeRecipeWorkflowStep ( workflowRuntime , {
234+ phase : "steps" ,
235+ index : 1 ,
236+ step : {
237+ command : "wordpress.run-php" ,
238+ args : [ "code=require '/home/wpcom/public_html/bin/tests/i18n-tools/bootstrap.php';" ] ,
239+ } ,
240+ } , process . cwd ( ) , undefined , undefined , undefined , wpcomPathMap )
241+ assert . deepEqual ( embeddedPhpExecution . args , [ `code=require '${ wpcomPathMap [ 0 ] . canonicalTarget } /bin/tests/i18n-tools/bootstrap.php';` ] )
215242
216243executedWorkflowSpecs . length = 0
217244const nestedWorkloadExecution = await executeRecipeWorkflowStep ( workflowRuntime , {
0 commit comments