mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(e2e): ignore embedded diagnostic reply json
This commit is contained in:
@@ -67,6 +67,19 @@ function parseJson(text) {
|
||||
}
|
||||
}
|
||||
|
||||
function isJsonObjectRecordStart(text, index) {
|
||||
for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
|
||||
const char = text[cursor];
|
||||
if (char === "\n" || char === "\r") {
|
||||
return true;
|
||||
}
|
||||
if (char !== " " && char !== "\t") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function parseJsonObjectsFromText(text) {
|
||||
const payloads = [];
|
||||
let start = -1;
|
||||
@@ -77,7 +90,7 @@ function parseJsonObjectsFromText(text) {
|
||||
for (let index = 0; index < text.length; index += 1) {
|
||||
const char = text[index];
|
||||
if (start === -1) {
|
||||
if (char === "{") {
|
||||
if (char === "{" && isJsonObjectRecordStart(text, index)) {
|
||||
start = index;
|
||||
depth = 1;
|
||||
inString = false;
|
||||
|
||||
@@ -80,6 +80,26 @@ describe("scripts/e2e/lib/agent-turn-output", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("does not accept reply-shaped JSON embedded in diagnostic lines", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "openclaw-e2e-agent-output-"));
|
||||
try {
|
||||
const outputPath = join(dir, "agent.log");
|
||||
writeFileSync(
|
||||
outputPath,
|
||||
[
|
||||
`echo ${JSON.stringify({ payloads: [{ text: "OPENCLAW_E2E_OK_DIAGNOSTIC" }] })}`,
|
||||
JSON.stringify({ payloads: [{ text: "real reply without marker" }] }),
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
expect(() =>
|
||||
assertAgentReplyContainsMarker("OPENCLAW_E2E_OK_DIAGNOSTIC", outputPath),
|
||||
).toThrow(/agent reply payload did not contain marker/u);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("does not accept markers that only appear in error payload text", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "openclaw-e2e-agent-output-"));
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user