@@ -43,6 +43,7 @@ const loggerWarnMock = vi.fn();
4343let refreshRuntimeAuthOnFirstPromptError = false ;
4444let clearRuntimeConfigSnapshot : typeof import ( "../config/config.js" ) . clearRuntimeConfigSnapshot ;
4545let setRuntimeConfigSnapshot : typeof import ( "../config/config.js" ) . setRuntimeConfigSnapshot ;
46+ let getReplyPayloadMetadata : typeof import ( "../auto-reply/reply-payload.js" ) . getReplyPayloadMetadata ;
4647
4748vi . mock ( "openclaw/plugin-sdk/llm" , async ( ) => {
4849 const actual =
@@ -180,6 +181,7 @@ beforeAll(async () => {
180181 vi . useRealTimers ( ) ;
181182 vi . resetModules ( ) ;
182183 installRunEmbeddedMocks ( ) ;
184+ ( { getReplyPayloadMetadata } = await import ( "../auto-reply/reply-payload.js" ) ) ;
183185 ( { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } = await import ( "../config/config.js" ) ) ;
184186 ( { runEmbeddedAgent } = await import ( "./embedded-agent-runner/run.js" ) ) ;
185187 const { SessionManager : LoadedSessionManager } =
@@ -1123,6 +1125,41 @@ describe("runEmbeddedAgent", () => {
11231125 ) ;
11241126 } ) ;
11251127
1128+ it ( "preserves harness-owned media provenance through terminal preparation" , async ( ) => {
1129+ const sessionFile = nextSessionFile ( ) ;
1130+ const cfg = createEmbeddedAgentRunnerOpenAiConfig ( [ "mock-1" ] ) ;
1131+ runEmbeddedAttemptMock . mockResolvedValueOnce (
1132+ makeEmbeddedRunnerAttempt ( {
1133+ toolMediaUrls : [ "/tmp/generated.png" ] ,
1134+ hostOwnedToolMediaUrls : [ "/tmp/generated.png" ] ,
1135+ } ) ,
1136+ ) ;
1137+
1138+ const result = await runEmbeddedAgent ( {
1139+ sessionId : "session:test" ,
1140+ sessionFile,
1141+ workspaceDir,
1142+ config : cfg ,
1143+ prompt : "generate an image" ,
1144+ provider : "openai" ,
1145+ model : "mock-1" ,
1146+ timeoutMs : 5_000 ,
1147+ agentDir,
1148+ runId : nextRunId ( "host-owned-media" ) ,
1149+ sourceReplyDeliveryMode : "message_tool_only" ,
1150+ enqueue : immediateEnqueue ,
1151+ } ) ;
1152+
1153+ expect ( result . payloads ) . toHaveLength ( 1 ) ;
1154+ expect ( result . payloads ?. [ 0 ] ) . toMatchObject ( {
1155+ mediaUrls : [ "/tmp/generated.png" ] ,
1156+ mediaUrl : "/tmp/generated.png" ,
1157+ } ) ;
1158+ expect ( getReplyPayloadMetadata ( result . payloads ?. [ 0 ] ?? { } ) ) . toMatchObject ( {
1159+ deliverDespiteSourceReplySuppression : true ,
1160+ } ) ;
1161+ } ) ;
1162+
11261163 it ( "handles prompt error paths without dropping user state" , async ( ) => {
11271164 const sessionFile = nextSessionFile ( ) ;
11281165 const cfg = createEmbeddedAgentRunnerOpenAiConfig ( [ "mock-error" ] ) ;
0 commit comments