diff --git a/scripts/e2e/lib/agent-turn-output.mjs b/scripts/e2e/lib/agent-turn-output.mjs index d3a6b14231ec..14d6bc70a358 100644 --- a/scripts/e2e/lib/agent-turn-output.mjs +++ b/scripts/e2e/lib/agent-turn-output.mjs @@ -2,16 +2,13 @@ import fs from "node:fs"; import { readTextFileTail, tailText } from "./text-file-utils.mjs"; const ERROR_DETAIL_TAIL_BYTES = 64 * 1024; +const OUTPUT_SCAN_TAIL_BYTES = 2 * 1024 * 1024; const REPLY_TEXT_PREVIEW_BYTES = 8 * 1024; const REPLY_TEXT_PREVIEW_COUNT = 5; const REQUEST_LOG_SCAN_CHUNK_BYTES = 64 * 1024; const REQUEST_LOG_SCAN_CARRY_CHARS = 256; const OPENAI_REQUEST_PATH_PATTERN = /\/v1\/(responses|chat\/completions)/u; -function readTextFile(file) { - return fs.readFileSync(file, "utf8"); -} - function textByteLength(text) { return Buffer.byteLength(text, "utf8"); } @@ -164,7 +161,7 @@ export function extractAgentReplyTexts(text) { } export function assertAgentReplyContainsMarker(marker, outputPath) { - const output = readTextFile(outputPath); + const output = readTextFileTail(outputPath, OUTPUT_SCAN_TAIL_BYTES); const replyTexts = extractAgentReplyTexts(output); if (replyTexts.some((text) => text.includes(marker))) { return; diff --git a/test/scripts/e2e-agent-turn-output.test.ts b/test/scripts/e2e-agent-turn-output.test.ts index 42608307da5a..868205983ce6 100644 --- a/test/scripts/e2e-agent-turn-output.test.ts +++ b/test/scripts/e2e-agent-turn-output.test.ts @@ -79,6 +79,27 @@ describe("scripts/e2e/lib/agent-turn-output", () => { } }); + it("ignores stale reply markers outside the recent output tail", () => { + const dir = mkdtempSync(join(tmpdir(), "openclaw-e2e-agent-output-")); + try { + const outputPath = join(dir, "agent.log"); + writeFileSync( + outputPath, + [ + JSON.stringify({ payloads: [{ text: "OPENCLAW_E2E_OK_STALE" }] }), + "x".repeat(2_200_000), + JSON.stringify({ payloads: [{ text: "current reply without marker" }] }), + ].join("\n"), + ); + + expect(() => assertAgentReplyContainsMarker("OPENCLAW_E2E_OK_STALE", outputPath)).toThrow( + /agent reply payload did not contain marker/u, + ); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + }); + it("bounds missing marker diagnostics to the recent output tail", () => { const dir = mkdtempSync(join(tmpdir(), "openclaw-e2e-agent-output-")); try {