Skip to content

Commit 0b42631

Browse files
authored
test(codex): cover native image delivery path
Document trusted harness artifact provenance and cover the runner-to-dispatch bridge.\n\nRelease note: Codex-generated images now reach message-tool-only routes while normal source suppression remains intact.\n\nCo-authored-by: Omar Shahine <[email protected]>
1 parent 67def3c commit 0b42631

6 files changed

Lines changed: 93 additions & 33 deletions

File tree

‎docs/plugins/sdk-agent-harness.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ yourself.
435435
This keeps text, image, video, music, TTS, approval, and messaging-tool
436436
outputs on the same delivery path as OpenClaw-backed runs.
437437

438+
Set `AgentHarnessAttemptResult.hostOwnedToolMediaUrls` only for native artifacts
439+
that the trusted harness runtime created and persisted itself. Every entry must
440+
also appear in `toolMediaUrls`. Never include model-selected dynamic-tool or
441+
OpenClaw-tool media. On `message_tool_only` routes, this narrow provenance lets
442+
native runtime artifacts survive source-reply suppression; normal send policy
443+
and ambient-room admission still apply.
444+
438445
### Terminal tool outcomes
439446

440447
`AgentHarnessAttemptParams.observeToolTerminal` is the host-owned terminal

‎extensions/codex/src/app-server/run-attempt-test-harness.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ export function getMockRuntimeIdentity() {
281281

282282
export function mockClientRuntimeMethods() {
283283
return {
284+
getInstanceId: () => "test-client-1",
284285
getRuntimeIdentity: getMockRuntimeIdentity,
285286
getServerVersion: getMockServerVersion,
286287
};

‎extensions/codex/src/app-server/run-attempt.test.ts‎

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4123,42 +4123,40 @@ describe("runCodexAppServerAttempt", () => {
41234123
});
41244124

41254125
it("surfaces Codex-native image generation saved paths as reply media", async () => {
4126-
const harness = createStartedThreadHarness();
4127-
const params = createParams(
4128-
path.join(tempDir, "session.jsonl"),
4129-
path.join(tempDir, "workspace"),
4130-
);
4131-
4132-
const run = runCodexAppServerAttempt(params);
4133-
await harness.waitForMethod("turn/start");
4134-
await harness.notify({
4135-
method: "turn/completed",
4136-
params: {
4137-
threadId: "thread-1",
4138-
turnId: "turn-1",
4139-
turn: {
4140-
id: "turn-1",
4141-
status: "completed",
4142-
items: [
4143-
{
4144-
type: "imageGeneration",
4145-
id: "ig_123",
4146-
status: "completed",
4147-
revisedPrompt: "A tiny blue square",
4148-
result: "Zm9v",
4149-
savedPath: "/tmp/codex-home/generated_images/session-1/ig_123.png",
4150-
},
4151-
],
4152-
},
4153-
},
4126+
const savedPath = "/tmp/codex-home/generated_images/session-1/ig_123.png";
4127+
const harness = createAppServerHarness(async (method) => {
4128+
if (method === "thread/start") {
4129+
return threadStartResult();
4130+
}
4131+
if (method === "turn/start") {
4132+
return {
4133+
turn: {
4134+
id: "turn-1",
4135+
status: "completed",
4136+
items: [
4137+
{
4138+
type: "imageGeneration",
4139+
id: "ig_123",
4140+
status: "completed",
4141+
revisedPrompt: "A tiny blue square",
4142+
result: "Zm9v",
4143+
savedPath,
4144+
},
4145+
],
4146+
},
4147+
};
4148+
}
4149+
return {};
41544150
});
41554151

4156-
const result = await run;
4152+
const result = await runCodexAppServerAttempt(
4153+
createParams(path.join(tempDir, "session.jsonl"), path.join(tempDir, "workspace")),
4154+
);
4155+
4156+
expect(harness.requests.map((entry) => entry.method)).toContain("turn/start");
41574157
expect(result.assistantTexts).toEqual([]);
4158-
expect(result.toolMediaUrls).toEqual(["/tmp/codex-home/generated_images/session-1/ig_123.png"]);
4159-
expect(result.hostOwnedToolMediaUrls).toEqual([
4160-
"/tmp/codex-home/generated_images/session-1/ig_123.png",
4161-
]);
4158+
expect(result.toolMediaUrls).toEqual([savedPath]);
4159+
expect(result.hostOwnedToolMediaUrls).toEqual([savedPath]);
41624160
});
41634161

41644162
it("does not complete on unscoped turn/completed notifications", async () => {

‎src/agents/embedded-agent-runner.e2e.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const loggerWarnMock = vi.fn();
4343
let refreshRuntimeAuthOnFirstPromptError = false;
4444
let clearRuntimeConfigSnapshot: typeof import("../config/config.js").clearRuntimeConfigSnapshot;
4545
let setRuntimeConfigSnapshot: typeof import("../config/config.js").setRuntimeConfigSnapshot;
46+
let getReplyPayloadMetadata: typeof import("../auto-reply/reply-payload.js").getReplyPayloadMetadata;
4647

4748
vi.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"]);

‎src/agents/embedded-agent-runner/run/terminal-preparation.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ export function prepareEmbeddedRunTerminal(input: {
138138
const payloadsWithToolMedia = mergeAttemptToolMediaPayloads({
139139
payloads,
140140
toolMediaUrls: attempt.toolMediaUrls,
141+
// Preserve harness provenance through terminal delivery. Without it,
142+
// message-tool-only routes silently drop native runtime artifacts.
141143
hostOwnedToolMediaUrls: attempt.hostOwnedToolMediaUrls,
142144
toolAudioAsVoice: attempt.toolAudioAsVoice,
143145
toolTrustedLocalMedia: attempt.toolTrustedLocalMedia,

‎src/agents/embedded-agent-runner/run/tool-media-payloads.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ describe("mergeAttemptToolMediaPayloads", () => {
8484
expect(getReplyPayloadMetadata(mediaReply ?? {})).toBeUndefined();
8585
});
8686

87+
it("ignores host-owned provenance outside the delivered tool media set", () => {
88+
const [mediaReply] =
89+
mergeAttemptToolMediaPayloads({
90+
toolMediaUrls: ["/tmp/tool.png"],
91+
hostOwnedToolMediaUrls: ["/tmp/forged.png"],
92+
sourceReplyDeliveryMode: "message_tool_only",
93+
}) ?? [];
94+
95+
expect(mediaReply).toMatchObject({
96+
mediaUrls: ["/tmp/tool.png"],
97+
mediaUrl: "/tmp/tool.png",
98+
});
99+
expect(getReplyPayloadMetadata(mediaReply ?? {})).toBeUndefined();
100+
});
101+
87102
it("keeps generic and host-owned media in separate delivery payloads", () => {
88103
const [genericReply, hostOwnedReply] =
89104
mergeAttemptToolMediaPayloads({

0 commit comments

Comments
 (0)