Skip to content

Commit cfeed10

Browse files
committed
fix(e2e): bound live plugin agent output
1 parent 3006b85 commit cfeed10

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

‎scripts/e2e/lib/live-plugin-tool/assertions.mjs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const agentTurnTimeoutSeconds = readPositiveIntEnv(
2727
const SCAN_CHUNK_BYTES = 64 * 1024;
2828
const SCAN_CARRY_CHARS = 256;
2929
const ERROR_DETAIL_TAIL_BYTES = 16 * 1024;
30+
const AGENT_OUTPUT_MAX_BYTES = readPositiveIntEnv(
31+
"OPENCLAW_LIVE_PLUGIN_TOOL_AGENT_OUTPUT_MAX_BYTES",
32+
1024 * 1024,
33+
);
3034
const SESSION_FILE_LIST_LIMIT = 20;
3135

3236
function requireEnv(name) {
@@ -355,6 +359,14 @@ function assertAgentTurn() {
355359
const toolName = requireEnv("TOOL_NAME");
356360
const outputPath = agentOutputPath();
357361
const errorPath = agentErrorPath();
362+
const outputStat = fs.statSync(outputPath);
363+
if (outputStat.isFile() && outputStat.size > AGENT_OUTPUT_MAX_BYTES) {
364+
const stdoutTail = readTextFileTail(outputPath, ERROR_DETAIL_TAIL_BYTES);
365+
const stderrTail = readTextFileTail(errorPath, ERROR_DETAIL_TAIL_BYTES);
366+
throw new Error(
367+
`live agent output exceeded ${AGENT_OUTPUT_MAX_BYTES} bytes:\nstdout tail=${stdoutTail}\nstderr tail=${stderrTail}`,
368+
);
369+
}
358370
const stdout = fs.readFileSync(outputPath, "utf8");
359371
const response = JSON.parse(stdout);
360372
const text = extractAgentReplyTexts(JSON.stringify(response)).join("\n");

‎scripts/e2e/live-plugin-tool-docker.sh‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ DOCKER_TARGET="${OPENCLAW_LIVE_PLUGIN_TOOL_DOCKER_TARGET:-bare}"
1212
HOST_BUILD="${OPENCLAW_LIVE_PLUGIN_TOOL_HOST_BUILD:-1}"
1313
PACKAGE_TGZ="${OPENCLAW_CURRENT_PACKAGE_TGZ:-}"
1414
AGENT_TURN_TIMEOUT_SECONDS="${OPENCLAW_LIVE_PLUGIN_TOOL_TIMEOUT_SECONDS:-300}"
15+
AGENT_OUTPUT_MAX_BYTES="${OPENCLAW_LIVE_PLUGIN_TOOL_AGENT_OUTPUT_MAX_BYTES:-1048576}"
1516
PROFILE_FILE="${OPENCLAW_LIVE_PLUGIN_TOOL_PROFILE_FILE:-${OPENCLAW_TESTBOX_PROFILE_FILE:-$HOME/.openclaw-testbox-live.profile}}"
1617
run_log=""
1718

@@ -67,6 +68,7 @@ if ! docker_e2e_run_with_harness \
6768
-e OPENAI_API_KEY \
6869
-e OPENAI_BASE_URL \
6970
-e OPENCLAW_LIVE_PLUGIN_TOOL_MODEL="${OPENCLAW_LIVE_PLUGIN_TOOL_MODEL:-openai/gpt-5.5}" \
71+
-e "OPENCLAW_LIVE_PLUGIN_TOOL_AGENT_OUTPUT_MAX_BYTES=$AGENT_OUTPUT_MAX_BYTES" \
7072
-e "OPENCLAW_LIVE_PLUGIN_TOOL_TIMEOUT_SECONDS=$AGENT_TURN_TIMEOUT_SECONDS" \
7173
-e "OPENCLAW_TEST_STATE_SCRIPT_B64=$OPENCLAW_TEST_STATE_SCRIPT_B64" \
7274
"${DOCKER_E2E_PACKAGE_ARGS[@]}" \
@@ -112,14 +114,19 @@ export MODEL_REF PLUGIN_ID PLUGIN_NAME PLUGIN_VERSION TOOL_NAME SEED EXPECTED_SL
112114
113115
dump_debug_logs() {
114116
local status="$1"
117+
local agent_output_dump_bytes="${OPENCLAW_LIVE_PLUGIN_TOOL_AGENT_OUTPUT_DUMP_BYTES:-16384}"
115118
echo "Live plugin tool scenario failed with exit code $status" >&2
119+
if [ -f /tmp/openclaw-agent.json ]; then
120+
echo "--- /tmp/openclaw-agent.json (last ${agent_output_dump_bytes} bytes) ---" >&2
121+
tail -c "$agent_output_dump_bytes" /tmp/openclaw-agent.json >&2 || true
122+
echo >&2
123+
fi
116124
openclaw_e2e_dump_logs \
117125
/tmp/openclaw-install.log \
118126
/tmp/openclaw-plugin-install.log \
119127
/tmp/openclaw-plugin-enable.log \
120128
/tmp/openclaw-plugins-list.json \
121129
/tmp/openclaw-plugin-inspect.json \
122-
/tmp/openclaw-agent.json \
123130
/tmp/openclaw-agent.err
124131
}
125132
trap 'status=$?; dump_debug_logs "$status"; exit "$status"' ERR

‎test/scripts/docker-build-helper.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,22 @@ test -f "$TMPDIR/docker-cmd-seen"
17691769
}
17701770
});
17711771

1772+
it("threads the live plugin tool output cap into the Docker harness", () => {
1773+
const runner = readFileSync(LIVE_PLUGIN_TOOL_DOCKER_E2E_PATH, "utf8");
1774+
1775+
expect(runner).toContain(
1776+
'AGENT_OUTPUT_MAX_BYTES="${OPENCLAW_LIVE_PLUGIN_TOOL_AGENT_OUTPUT_MAX_BYTES:-1048576}"',
1777+
);
1778+
expect(runner).toContain(
1779+
'-e "OPENCLAW_LIVE_PLUGIN_TOOL_AGENT_OUTPUT_MAX_BYTES=$AGENT_OUTPUT_MAX_BYTES"',
1780+
);
1781+
expect(runner).toContain("OPENCLAW_LIVE_PLUGIN_TOOL_AGENT_OUTPUT_DUMP_BYTES");
1782+
expect(runner).toContain('tail -c "$agent_output_dump_bytes" /tmp/openclaw-agent.json');
1783+
const dumpLogsStart = runner.indexOf("openclaw_e2e_dump_logs \\");
1784+
const dumpLogsEnd = runner.indexOf("\n}", dumpLogsStart);
1785+
expect(runner.slice(dumpLogsStart, dumpLogsEnd)).not.toContain("/tmp/openclaw-agent.json");
1786+
});
1787+
17721788
it("cleans every prepared Docker package tarball on every runner exit path", () => {
17731789
const paths = packageBackedDockerRunnerPaths();
17741790

‎test/scripts/live-plugin-tool-assertions.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,31 @@ describe("live plugin tool assertions", () => {
212212
}
213213
});
214214

215+
it("rejects oversized agent output before parsing it", () => {
216+
const root = mkdtempSync(path.join(tmpdir(), "openclaw-live-plugin-tool-"));
217+
218+
try {
219+
writeFileSync(
220+
path.join(root, "agent.json"),
221+
`DO_NOT_DUMP_OLD_AGENT_OUTPUT${"x".repeat(70 * 1024)}\nrecent oversized stdout tail`,
222+
"utf8",
223+
);
224+
writeFileSync(path.join(root, "agent.err"), "recent stderr tail\n", "utf8");
225+
226+
const result = runAssertion(root, {
227+
OPENCLAW_LIVE_PLUGIN_TOOL_AGENT_OUTPUT_MAX_BYTES: "1024",
228+
});
229+
230+
expect(result.status).not.toBe(0);
231+
expect(result.stderr).toContain("live agent output exceeded 1024 bytes");
232+
expect(result.stderr).toContain("recent oversized stdout tail");
233+
expect(result.stderr).toContain("recent stderr tail");
234+
expect(result.stderr).not.toContain("DO_NOT_DUMP_OLD_AGENT_OUTPUT");
235+
} finally {
236+
rmSync(root, { force: true, recursive: true });
237+
}
238+
});
239+
215240
it("does not dump session transcript contents when a transcript check fails", () => {
216241
const root = mkdtempSync(path.join(tmpdir(), "openclaw-live-plugin-tool-"));
217242
const sessionsDir = path.join(root, "state", "agents", "main", "sessions");

0 commit comments

Comments
 (0)