fix(agent): stabilize large tool results
Generic Container CI/CD / test-build-publish (push) Successful in 1m53s
Agent CI/CD v2 / build-test-publish-and-deploy (push) Successful in 1m53s

This commit is contained in:
2026-08-25 12:02:48 +08:00
parent 774f39cbbe
commit 004c9bb72d
17 changed files with 721 additions and 62 deletions
+65 -2
View File
@@ -104,7 +104,11 @@ async function startJsonServer(responseData) {
url: req.url,
});
res.setHeader("content-type", "application/json");
res.end(JSON.stringify(responseData));
res.end(
JSON.stringify(
typeof responseData === "function" ? responseData(req) : responseData,
),
);
});
await new Promise((resolveListen, reject) => {
@@ -138,7 +142,20 @@ function normalizeSeenRequest(request) {
};
}
async function runAgainstServer(name, runner, args, auth, responseData = { accepted: true }) {
function defaultContractResponse(req) {
const url = new URL(req.url, "http://127.0.0.1");
if (["/api/v1/pipes", "/api/v1/reservoirs", "/api/v1/tanks", "/api/v1/pumps", "/api/v1/valves"].includes(url.pathname)) {
return {
items: [],
limit: Number(url.searchParams.get("limit")),
offset: Number(url.searchParams.get("offset")),
total: 0,
};
}
return { accepted: true };
}
async function runAgainstServer(name, runner, args, auth, responseData = defaultContractResponse) {
const server = await startJsonServer(responseData);
try {
const result = await runner(["--auth-stdin", ...args], { ...auth, server: server.url });
@@ -232,6 +249,52 @@ test("sends auth headers and simulation body through the backend API contract",
}
});
test("get-all network commands collect every backend page", async () => {
const items = Array.from({ length: 2_005 }, (_, index) => ({
id: `P${index + 1}`,
node1: `N${index + 1}`,
node2: `N${index + 2}`,
}));
const server = await startJsonServer((req) => {
const url = new URL(req.url, "http://127.0.0.1");
const limit = Number(url.searchParams.get("limit") ?? 100);
const offset = Number(url.searchParams.get("offset") ?? 0);
return {
items: items.slice(offset, offset + limit),
limit,
offset,
total: items.length,
};
});
try {
const result = await runCli(
["--auth-stdin", "network", "get-all-pipes-properties"],
{
server: server.url,
access_token: "token-1",
project_id: "project-1",
},
);
assert.equal(result.exitCode, 0, result.stderr);
const payload = parseJsonResult(result);
assert.equal(payload.data.length, items.length);
assert.deepEqual(payload.data[0], items[0]);
assert.deepEqual(payload.data.at(-1), items.at(-1));
assert.deepEqual(
server.seen.map((request) => normalizeSeenRequest(request).query),
[
{ limit: "1000", offset: "0" },
{ limit: "1000", offset: "1000" },
{ limit: "1000", offset: "2000" },
],
);
} finally {
await server.close();
}
});
test("uses project scoped headers for realtime data commands", async () => {
const server = await startJsonServer([{ id: "P1" }]);
try {