mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 19:00:38 +09:00
25 lines
929 B
TypeScript
25 lines
929 B
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
import { compactRunLogChunk } from "../services/heartbeat.js";
|
||
|
|
|
||
|
|
describe("compactRunLogChunk", () => {
|
||
|
|
it("redacts inline base64 image data from structured log chunks", () => {
|
||
|
|
const base64 = "A".repeat(4096);
|
||
|
|
const chunk = `{"type":"user","message":{"content":[{"type":"image","source":{"type":"base64","data":"${base64}"}}]}}\n`;
|
||
|
|
|
||
|
|
const compacted = compactRunLogChunk(chunk);
|
||
|
|
|
||
|
|
expect(compacted).not.toContain(base64);
|
||
|
|
expect(compacted).toContain("[omitted base64 image data: 4096 chars]");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("truncates oversized chunks after sanitizing them", () => {
|
||
|
|
const chunk = `${"x".repeat(90_000)}tail`;
|
||
|
|
|
||
|
|
const compacted = compactRunLogChunk(chunk, 16_384);
|
||
|
|
|
||
|
|
expect(compacted.length).toBeLessThan(chunk.length);
|
||
|
|
expect(compacted).toContain("[paperclip truncated run log chunk:");
|
||
|
|
expect(compacted.endsWith("tail")).toBe(true);
|
||
|
|
});
|
||
|
|
});
|