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