@@ -33,11 +33,13 @@ import { registerAgentHarness } from "../harness/registry.js";
3333import { makeAttemptResult } from "./run.overflow-compaction.fixture.js" ;
3434import {
3535 loadRunOverflowCompactionHarness ,
36+ mockedAcquireAgentRunPreparedModelRuntime ,
3637 mockedBuildEmbeddedRunPayloads ,
3738 mockedGlobalHookRunner ,
3839 mockedRunEmbeddedAttempt ,
3940 useOpenAIPlatformAuthFixture ,
4041} from "./run.overflow-compaction.harness.js" ;
42+ import type { RunEmbeddedAgentInternalParams } from "./run/internal-params.js" ;
4143import { buildEmbeddedSystemPrompt } from "./system-prompt.js" ;
4244
4345const runnerState = setupAgentRunnerExecutionTestState ( ) ;
@@ -428,4 +430,109 @@ describe("prepared harness source delivery", () => {
428430 ) ;
429431 }
430432 } ) ;
433+
434+ it ( "prepares a Codex primary without pinning a plugin-owned fallback" , async ( ) => {
435+ const { runEmbeddedAgent, registerPreparedAgentHarness } =
436+ await loadRunOverflowCompactionHarness ( ) ;
437+ registerPreparedAgentHarness ( {
438+ id : "fallback-owner" ,
439+ label : "Fallback owner" ,
440+ supports : ( { provider } ) =>
441+ provider === "custom" ? { supported : true } : { supported : false } ,
442+ runAttempt : vi . fn ( async ( ) => ( { } ) as never ) ,
443+ } ) ;
444+ mockedGlobalHookRunner . hasHooks . mockReturnValue ( false ) ;
445+ mockedBuildEmbeddedRunPayloads . mockReturnValue ( [ { text : "primary" } ] ) ;
446+ mockedRunEmbeddedAttempt . mockResolvedValueOnce (
447+ makeAttemptResult ( { assistantTexts : [ "primary" ] } ) ,
448+ ) ;
449+ useOpenAIPlatformAuthFixture ( ) ;
450+
451+ const runParams : RunEmbeddedAgentInternalParams = {
452+ agentId : "worker" ,
453+ sessionId : "runtime-preparation-hint" ,
454+ workspaceDir : "/tmp/workspace" ,
455+ prompt : "hello" ,
456+ runId : "runtime-preparation-hint" ,
457+ timeoutMs : 30_000 ,
458+ provider : "openai" ,
459+ model : "gpt-5.4" ,
460+ agentHarnessRuntimePreparationHint : "codex" ,
461+ modelFallbacksOverride : [ "fast" ] ,
462+ config : {
463+ agents : {
464+ list : [
465+ { id : "main" , default : true } ,
466+ {
467+ id : "worker" ,
468+ models : {
469+ "openai/gpt-5.4" : { agentRuntime : { id : "codex" } } ,
470+ "custom/plugin-fallback" : {
471+ alias : "fast" ,
472+ agentRuntime : { id : "fallback-owner" } ,
473+ } ,
474+ } ,
475+ } ,
476+ ] ,
477+ defaults : {
478+ models : {
479+ "custom/global-fallback" : { alias : "fast" } ,
480+ } ,
481+ } ,
482+ } ,
483+ } ,
484+ } ;
485+ await runEmbeddedAgent ( runParams ) ;
486+
487+ expect ( mockedAcquireAgentRunPreparedModelRuntime ) . toHaveBeenCalledWith (
488+ expect . objectContaining ( {
489+ runtimePluginSelections : [
490+ { provider : "openai" , modelId : "gpt-5.4" , runtime : "codex" , agentId : "worker" } ,
491+ { provider : "custom" , modelId : "plugin-fallback" , agentId : "worker" } ,
492+ ] ,
493+ } ) ,
494+ expect . any ( Object ) ,
495+ ) ;
496+ } ) ;
497+
498+ it . each ( [
499+ [ "agentHarnessId" , { agentHarnessId : "codex" } ] ,
500+ [ "agentHarnessRuntimeOverride" , { agentHarnessRuntimeOverride : "codex" } ] ,
501+ ] as const ) ( "keeps %s authoritative across fallback preparation" , async ( _label , override ) => {
502+ const { runEmbeddedAgent } = await loadRunOverflowCompactionHarness ( ) ;
503+ mockedGlobalHookRunner . hasHooks . mockReturnValue ( false ) ;
504+ mockedBuildEmbeddedRunPayloads . mockReturnValue ( [ { text : "primary" } ] ) ;
505+ mockedRunEmbeddedAttempt . mockResolvedValueOnce (
506+ makeAttemptResult ( { assistantTexts : [ "primary" ] } ) ,
507+ ) ;
508+ useOpenAIPlatformAuthFixture ( ) ;
509+
510+ await runEmbeddedAgent ( {
511+ agentId : "worker" ,
512+ sessionId : `authoritative-${ _label } ` ,
513+ workspaceDir : "/tmp/workspace" ,
514+ prompt : "hello" ,
515+ runId : `authoritative-${ _label } ` ,
516+ timeoutMs : 30_000 ,
517+ provider : "openai" ,
518+ model : "gpt-5.4" ,
519+ modelFallbacksOverride : [ "custom/plugin-fallback" ] ,
520+ ...override ,
521+ } ) ;
522+
523+ expect ( mockedAcquireAgentRunPreparedModelRuntime ) . toHaveBeenCalledWith (
524+ expect . objectContaining ( {
525+ runtimePluginSelections : [
526+ { provider : "openai" , modelId : "gpt-5.4" , runtime : "codex" , agentId : "worker" } ,
527+ {
528+ provider : "custom" ,
529+ modelId : "plugin-fallback" ,
530+ runtime : "codex" ,
531+ agentId : "worker" ,
532+ } ,
533+ ] ,
534+ } ) ,
535+ expect . any ( Object ) ,
536+ ) ;
537+ } ) ;
431538} ) ;
0 commit comments