fix(e2e): ignore stale agent output markers

This commit is contained in:
Vincent Koc
2026-06-04 10:28:01 +02:00
parent 6de517cbcb
commit d77d231507
2 changed files with 23 additions and 5 deletions

View File

@@ -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;

View File

@@ -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 {