Skip to content

Commit fb7c53c

Browse files
committed
test(codex): prove missing mirrored history stays quiet
1 parent 6cc823a commit fb7c53c

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

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

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,68 @@
22
import fs from "node:fs/promises";
33
import os from "node:os";
44
import path from "node:path";
5-
import type { EmbeddedRunAttemptParams } from "openclaw/plugin-sdk/agent-harness-runtime";
6-
import { describe, expect, it } from "vitest";
5+
import {
6+
embeddedAgentLog,
7+
type EmbeddedRunAttemptParams,
8+
} from "openclaw/plugin-sdk/agent-harness-runtime";
9+
import { afterEach, describe, expect, it, vi } from "vitest";
710
import {
811
buildCodexWorkspaceBootstrapContext,
912
buildCodexSystemPromptReport,
1013
readContextEngineThreadBootstrapProjection,
14+
readMirroredSessionHistoryMessages,
1115
remapCodexContextFilePath,
1216
resolveContextEngineBootstrapProjectionDecision,
1317
} from "./attempt-context.js";
1418
import type { CodexDynamicToolSpec } from "./protocol.js";
1519
import type { CodexAppServerContextEngineBinding } from "./session-binding.js";
1620

21+
afterEach(() => {
22+
vi.restoreAllMocks();
23+
});
24+
1725
describe("Codex app-server attempt context", () => {
26+
it("treats missing mirrored session history as empty without hook warning", async () => {
27+
const warn = vi.spyOn(embeddedAgentLog, "warn").mockImplementation(() => undefined);
28+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "codex-attempt-context-history-"));
29+
const sessionFile = path.join(dir, "session.jsonl");
30+
try {
31+
await expect(
32+
readMirroredSessionHistoryMessages({
33+
sessionFile,
34+
sessionId: "codex-session",
35+
sessionKey: "codex-session",
36+
}),
37+
).resolves.toEqual([]);
38+
expect(warn).not.toHaveBeenCalled();
39+
} finally {
40+
await fs.rm(dir, { recursive: true, force: true });
41+
}
42+
});
43+
44+
it("keeps malformed mirrored session history on the hook warning path", async () => {
45+
const warn = vi.spyOn(embeddedAgentLog, "warn").mockImplementation(() => undefined);
46+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "codex-attempt-context-history-"));
47+
const sessionFile = path.join(dir, "session.jsonl");
48+
try {
49+
await fs.writeFile(sessionFile, JSON.stringify({ type: "message", id: "orphan" }) + "\n");
50+
51+
await expect(
52+
readMirroredSessionHistoryMessages({
53+
sessionFile,
54+
sessionId: "codex-session",
55+
sessionKey: "codex-session",
56+
}),
57+
).resolves.toBeUndefined();
58+
expect(warn).toHaveBeenCalledWith(
59+
"failed to read mirrored session history for codex harness hooks",
60+
{ sessionFile },
61+
);
62+
} finally {
63+
await fs.rm(dir, { recursive: true, force: true });
64+
}
65+
});
66+
1867
it("returns a run context report without deferred Codex dynamic tool schemas", () => {
1968
const tools = [
2069
{

0 commit comments

Comments
 (0)