@@ -13,7 +13,9 @@ import {
1313 QA_TEST_RUNNER_DEFAULTS ,
1414 createScenarioRunnerTestHarness ,
1515 makeDockerE2eScenario ,
16+ makeTestFileScenario ,
1617 writeDockerCandidateManifest ,
18+ writeScriptProducerEvidence ,
1719} from "./test-file-scenario-runner.test-support.js" ;
1820
1921const harness = createScenarioRunnerTestHarness ( ) ;
@@ -232,6 +234,102 @@ describe("qa test file scenario runner", () => {
232234 expect ( result . evidence . entries [ 0 ] ?. result . status ) . toBe ( "pass" ) ;
233235 } ) ;
234236
237+ it ( "prioritizes serial native work while preserving catalog-ordered mixed evidence" , async ( ) => {
238+ const repoRoot = await makeTempRepo ( "qa-script-docker-priority-" ) ;
239+ const outputDir = path . join ( repoRoot , ".artifacts" , "qa-e2e" , "native-priority" ) ;
240+ const makeScriptScenario = ( id : string , timeoutMs : number ) => {
241+ const scenario = makeTestFileScenario ( "script" , `scripts/${ id } .ts` ) ;
242+ if ( scenario . execution . kind !== "script" ) {
243+ throw new Error ( "expected script scenario" ) ;
244+ }
245+ return { ...scenario , id, execution : { ...scenario . execution , timeoutMs } } ;
246+ } ;
247+ const dockerScenario = makeDockerE2eScenario ( "long-docker" , "gateway-network" ) ;
248+ if ( dockerScenario . execution . kind !== "script" ) {
249+ throw new Error ( "expected Docker script scenario" ) ;
250+ }
251+ const scenarios = [
252+ makeScriptScenario ( "short-script" , 1_000 ) ,
253+ { ...dockerScenario , execution : { ...dockerScenario . execution , timeoutMs : 3_000 } } ,
254+ makeScriptScenario ( "long-script-a" , 3_000 ) ,
255+ makeScriptScenario ( "long-script-b" , 3_000 ) ,
256+ ] ;
257+ const executionOrder : string [ ] = [ ] ;
258+ const output : string [ ] = [ ] ;
259+ const progress : string [ ] = [ ] ;
260+ let activeCommands = 0 ;
261+ let maximumActiveCommands = 0 ;
262+
263+ const result = await runQaTestFileScenarios ( {
264+ repoRoot,
265+ outputDir,
266+ ...QA_TEST_RUNNER_DEFAULTS ,
267+ scenarios,
268+ onCommandOutput : ( stream , chunk ) => output . push ( `${ stream } :${ chunk . toString ( "utf8" ) } ` ) ,
269+ progress : ( message ) => progress . push ( message ) ,
270+ runCommand : async ( command ) => {
271+ const isDocker = command . args [ 0 ] === "scripts/test-docker-all.mjs" ;
272+ let scenarioId = "long-docker" ;
273+ if ( ! isDocker ) {
274+ const scriptPath = command . args [ 2 ] ;
275+ if ( ! scriptPath ) {
276+ throw new Error ( "missing script scenario path" ) ;
277+ }
278+ scenarioId = path . basename ( scriptPath , ".ts" ) ;
279+ }
280+ executionOrder . push ( scenarioId ) ;
281+ activeCommands += 1 ;
282+ maximumActiveCommands = Math . max ( maximumActiveCommands , activeCommands ) ;
283+ try {
284+ command . onOutput ?.( "stdout" , Buffer . from ( scenarioId ) ) ;
285+ if ( isDocker ) {
286+ const logDir = command . env . OPENCLAW_DOCKER_ALL_LOG_DIR ;
287+ if ( ! logDir ) {
288+ throw new Error ( "missing Docker scheduler log dir" ) ;
289+ }
290+ await fs . mkdir ( logDir , { recursive : true } ) ;
291+ await fs . writeFile (
292+ path . join ( logDir , "summary.json" ) ,
293+ JSON . stringify ( {
294+ failures : [ ] ,
295+ lanes : [ { elapsedSeconds : 1 , name : "gateway-network" , status : 0 } ] ,
296+ selectedLanes : [ "gateway-network" ] ,
297+ } ) ,
298+ ) ;
299+ } else {
300+ await writeScriptProducerEvidence ( {
301+ outputDir,
302+ producerId : scenarioId ,
303+ scenarioId,
304+ status : "pass" ,
305+ } ) ;
306+ }
307+ return { exitCode : 0 , stdout : `${ scenarioId } passed\n` , stderr : "" } ;
308+ } finally {
309+ activeCommands -= 1 ;
310+ }
311+ } ,
312+ } ) ;
313+
314+ expect ( executionOrder ) . toEqual ( [
315+ "long-docker" ,
316+ "long-script-a" ,
317+ "long-script-b" ,
318+ "short-script" ,
319+ ] ) ;
320+ expect ( maximumActiveCommands ) . toBe ( 1 ) ;
321+ expect ( output ) . toEqual ( executionOrder . map ( ( scenarioId ) => `stdout:${ scenarioId } ` ) ) ;
322+ expect ( progress . filter ( ( message ) => message . includes ( " start " ) ) ) . toEqual ( [
323+ "native docker-batch start scenarios=1 timeoutMs=3000" ,
324+ "native script start scenario=long-script-a timeoutMs=3000" ,
325+ "native script start scenario=long-script-b timeoutMs=3000" ,
326+ "native script start scenario=short-script timeoutMs=1000" ,
327+ ] ) ;
328+ const catalogOrder = scenarios . map ( ( scenario ) => scenario . id ) ;
329+ expect ( result . results . map ( ( entry ) => entry . scenario . id ) ) . toEqual ( catalogOrder ) ;
330+ expect ( result . evidence . entries . map ( ( entry ) => entry . test . id ) ) . toEqual ( catalogOrder ) ;
331+ } ) ;
332+
235333 it ( "runs Docker script scenarios through one aggregate scheduler invocation" , async ( ) => {
236334 const repoRoot = await makeTempRepo ( "qa-script-docker-batch-" ) ;
237335 const outputDir = path . join ( repoRoot , ".artifacts" , "qa-e2e" , "docker-batch" ) ;
0 commit comments