@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises"
33import { resolve } from "node:path"
44import { commandArgValue , parseCommandJson , parseCommandJsonObject , RUNTIME_BACKED_FUZZ_SUITE_RUNNER_CAPABILITIES , runFuzzSuite , runtimeCheckpointUnsupportedDiagnostic , type ArtifactBundle , type ArtifactManifestFile , type ExecutionResult , type FuzzSuiteContract , type Runtime , type RuntimeCheckpointFailureDiagnostic , type RuntimeCheckpointOperation , type RuntimeCheckpointResult , type WorkspaceRecipe , type WorkspaceRecipeDistributionSetupArtifact , type WorkspaceRecipeDistributionStartupProbe , type WorkspaceRecipeProbe } from "@automattic/wp-codebox-core"
55import { stripUndefined } from "@automattic/wp-codebox-core/internals"
6+ import { createWordPressFuzzSuiteResetExecutor } from "@automattic/wp-codebox-playground/public"
67import { correlateObservedHostsToExternalServiceBoundaries , recipeExternalServiceBoundarySummaries } from "../recipe-external-services.js"
78import { recipeExecutionSpec , sandboxWorkspaceContract } from "../agent-sandbox.js"
89import { executeAgentFanoutFromArgs } from "../agent-fanout.js"
@@ -523,6 +524,7 @@ async function executeRunFuzzSuiteRecipeCommand(runtime: Runtime, args: string[]
523524 const result = await runFuzzSuite ( suite , {
524525 runnerCapabilities : RUNTIME_BACKED_FUZZ_SUITE_RUNNER_CAPABILITIES ,
525526 executor : async ( spec ) => executeRecipeWorkflowStep ( runtime , { phase : "steps" , index : 0 , step : workflowStepFromExecutionSpec ( spec ) } , recipeDirectory , sandboxWorkspace , undefined , undefined , inputMountPathMap ) ,
527+ resetExecutor : createWordPressFuzzSuiteResetExecutor ( recipeRuntimeFuzzSuiteResetEpisode ( runtime , recipeDirectory , sandboxWorkspace , inputMountPathMap ) ) ,
526528 runtimeWorkloadExecutor : async ( { suite, workload, case : fuzzCase } ) => {
527529 const workloadJson = JSON . stringify ( workload )
528530 const execution = await executeWordPressRunWorkloadJsonRecipeCommand ( runtime , [ `workload-json=${ workloadJson } ` ] , recipeDirectory , sandboxWorkspace , suite , fuzzCase , inputMountPathMap )
@@ -552,6 +554,37 @@ async function executeRunFuzzSuiteRecipeCommand(runtime: Runtime, args: string[]
552554 }
553555}
554556
557+ function recipeRuntimeFuzzSuiteResetEpisode ( runtime : Runtime , recipeDirectory : string , sandboxWorkspace : ReturnType < typeof sandboxWorkspaceContract > | undefined , inputMountPathMap : readonly InputMountPathMapping [ ] ) {
558+ let index = 0
559+ return {
560+ async step ( action : { command : string ; args ?: string [ ] ; metadata ?: Record < string , unknown > } ) {
561+ index += 1
562+ const id = `recipe-fuzz-reset-${ index } `
563+ const execution = await executeRecipeWorkflowStep ( runtime , {
564+ phase : "steps" ,
565+ index,
566+ step : { command : action . command , args : action . args , metadata : action . metadata } ,
567+ } , recipeDirectory , sandboxWorkspace , undefined , undefined , inputMountPathMap )
568+ return {
569+ id,
570+ index,
571+ action : {
572+ schema : "wp-codebox/runtime-episode-action/v1" as const ,
573+ id,
574+ kind : "command" as const ,
575+ command : action . command ,
576+ args : action . args ?? [ ] ,
577+ metadata : action . metadata ,
578+ digest : { algorithm : "sha256" as const , value : createHash ( "sha256" ) . update ( JSON . stringify ( action ) ) . digest ( "hex" ) } ,
579+ } ,
580+ actionRef : { kind : "action" , id } ,
581+ execution,
582+ executionRef : { kind : "execution" , id : execution . id } ,
583+ }
584+ } ,
585+ }
586+ }
587+
555588async function fuzzSuiteFromRecipeCommandArgs ( args : string [ ] , recipeDirectory : string ) : Promise < FuzzSuiteContract > {
556589 const inline = commandArgValue ( args , "input-json" ) ?? commandArgValue ( args , "suite-json" )
557590 if ( inline ) {
0 commit comments