[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
92
infrastructure/ai/requestPayloadCompression.test.ts
Normal file
92
infrastructure/ai/requestPayloadCompression.test.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import type { ModelMessage } from "ai";
|
||||
|
||||
import {
|
||||
compressMessagesForRequestTooLargeRetry,
|
||||
compressVerboseText,
|
||||
truncateTextWithHeadAndTail,
|
||||
} from "./requestPayloadCompression.ts";
|
||||
|
||||
test("compressVerboseText collapses repeated blank lines and duplicate runs", () => {
|
||||
const input = "line1\n\n\n\n\nline2\nsame\nsame\nsame\nsame\nline3";
|
||||
const output = compressVerboseText(input);
|
||||
assert.match(output, /line1\n\n\nline2/);
|
||||
assert.ok(output.split("\nsame\n").length <= 3);
|
||||
});
|
||||
|
||||
test("compressVerboseText normalizes terminal control noise and huge payload lines", () => {
|
||||
const ansiProgress = "\u001b[31mstarting\u001b[0m\r10%\r20%\r100%\n";
|
||||
const longLine = "x".repeat(8_000);
|
||||
const base64 = "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=".repeat(100);
|
||||
const output = compressVerboseText(`${ansiProgress}${longLine}\n${base64}`);
|
||||
|
||||
assert.equal(output.includes("\u001b["), false);
|
||||
assert.doesNotMatch(output, /10%|20%/);
|
||||
assert.match(output, /100%/);
|
||||
assert.match(output, /long line shortened/);
|
||||
assert.match(output, /base64-like payload omitted/);
|
||||
assert.ok(output.length < 5_000);
|
||||
});
|
||||
|
||||
test("compressVerboseText preserves CRLF-delimited lines", () => {
|
||||
assert.equal(compressVerboseText("alpha\r\nbeta\r\n"), "alpha\nbeta\n");
|
||||
});
|
||||
|
||||
test("truncateTextWithHeadAndTail keeps both ends of long terminal output", () => {
|
||||
const value = `${"A".repeat(500)}${"B".repeat(20_000)}${"C".repeat(500)}`;
|
||||
const truncated = truncateTextWithHeadAndTail(value, 2_000);
|
||||
assert.ok(truncated.startsWith("AAA"));
|
||||
assert.ok(truncated.includes("[... output truncated for request size ...]"));
|
||||
assert.ok(truncated.endsWith("CCC"));
|
||||
assert.ok(truncated.length <= 2_000);
|
||||
});
|
||||
|
||||
test("compressMessagesForRequestTooLargeRetry compresses messages without enforcing a byte budget", () => {
|
||||
const messages: ModelMessage[] = [
|
||||
{ role: "user", content: "run build" },
|
||||
{
|
||||
role: "tool",
|
||||
content: [{
|
||||
type: "tool-result",
|
||||
toolCallId: "call-1",
|
||||
toolName: "terminal_execute",
|
||||
output: { type: "text", value: "X".repeat(200_000) },
|
||||
}],
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "text", text: "please inspect this image" },
|
||||
{ type: "image", image: "A".repeat(1_000_000), mediaType: "image/png" },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const result = compressMessagesForRequestTooLargeRetry(messages);
|
||||
|
||||
assert.equal(result.didAdjust, true);
|
||||
assert.deepEqual(Object.keys(result).sort(), ["didAdjust", "messages"]);
|
||||
assert.equal(result.messages.length, messages.length);
|
||||
|
||||
const toolContent = result.messages[1].content;
|
||||
assert.ok(Array.isArray(toolContent));
|
||||
const toolPart = toolContent[0] as { output?: { value?: string } };
|
||||
assert.ok((toolPart.output?.value?.length ?? 0) < 5_000);
|
||||
|
||||
const userContent = result.messages[2].content;
|
||||
assert.ok(Array.isArray(userContent));
|
||||
assert.deepEqual(userContent[1], {
|
||||
type: "text",
|
||||
text: "[image attachment omitted to keep the AI request small: mediaType=image/png, 1000000 chars]",
|
||||
});
|
||||
});
|
||||
|
||||
test("compressMessagesForRequestTooLargeRetry reports no adjustment for compact messages", () => {
|
||||
const messages: ModelMessage[] = [{ role: "user", content: "hello" }];
|
||||
|
||||
const result = compressMessagesForRequestTooLargeRetry(messages);
|
||||
|
||||
assert.equal(result.didAdjust, false);
|
||||
assert.deepEqual(result.messages, messages);
|
||||
});
|
||||
Reference in New Issue
Block a user