|
2 | 2 | import fs from "node:fs/promises"; |
3 | 3 | import os from "node:os"; |
4 | 4 | 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"; |
7 | 10 | import { |
8 | 11 | buildCodexWorkspaceBootstrapContext, |
9 | 12 | buildCodexSystemPromptReport, |
10 | 13 | readContextEngineThreadBootstrapProjection, |
| 14 | + readMirroredSessionHistoryMessages, |
11 | 15 | remapCodexContextFilePath, |
12 | 16 | resolveContextEngineBootstrapProjectionDecision, |
13 | 17 | } from "./attempt-context.js"; |
14 | 18 | import type { CodexDynamicToolSpec } from "./protocol.js"; |
15 | 19 | import type { CodexAppServerContextEngineBinding } from "./session-binding.js"; |
16 | 20 |
|
| 21 | +afterEach(() => { |
| 22 | + vi.restoreAllMocks(); |
| 23 | +}); |
| 24 | + |
17 | 25 | 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 | + |
18 | 67 | it("returns a run context report without deferred Codex dynamic tool schemas", () => { |
19 | 68 | const tools = [ |
20 | 69 | { |
|
0 commit comments