feat(headroom): report effective payload savings

Break out tool schema and tool-history bytes in the size snapshot and
add an effective byte-savings percentage so token-saved logs reflect
the actual outbound payload reduction, not just processed content.
This commit is contained in:
minhnhat166
2026-08-05 11:29:07 +07:00
committed by decolua
parent 13ed14568d
commit da8691f866
2 changed files with 20 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import { describe, it, expect, vi, afterEach } from "vitest";
import { compressWithHeadroom, formatHeadroomLog } from "../../open-sse/rtk/headroom.js";
import { compressWithHeadroom, formatHeadroomLog, formatHeadroomSizeLog } from "../../open-sse/rtk/headroom.js";
afterEach(() => {
vi.restoreAllMocks();
@@ -209,4 +209,11 @@ describe("formatHeadroomLog", () => {
expect(formatHeadroomLog({ tokens_before: 100, tokens_after: 25, tokens_saved: 75 }))
.toBe("reported token delta=75 before=100 after=25 (75.0%)");
});
it("reports effective payload, tool-schema, and tool-history sizes", () => {
expect(formatHeadroomSizeLog({
before: { bodyBytes: 1000, messageBytes: 800, toolSchemaBytes: 100, toolHistoryBytes: 500 },
after: { bodyBytes: 900, messageBytes: 700, toolSchemaBytes: 100, toolHistoryBytes: 400 },
})).toContain("tools=100B→100B toolHistory=500B→400B effective=10.0%");
});
});