Files
OmniRoute/tests/unit/streamingPiiInitialization.test.ts
Hernan Javier Ardila Sanchez fd26e601a2 fix(dashboard): use lightweight ping endpoint for MaintenanceBanner (fixes #3040) (#3043)
Integrated into release/v3.8.8. Applied review fixes: moved the SELECT 1 into a pingDb() db helper (no raw SQL in route, Hard Rule #5) + the 503 catch no longer leaks err.message (Hard Rule #12). Thanks @herjarsa!
2026-06-01 14:30:17 -03:00

33 lines
1.2 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { createPiiSseTransform } from "../../src/lib/streamingPiiTransform";
test("First chunk is stop signal", async () => {
const transform = createPiiSseTransform({ windowSize: 3 });
const writer = transform.writable.getWriter();
const chunks: string[] = [];
const reader = transform.readable.getReader();
const readPromise = (async () => {
while (true) {
const { value, done } = await reader.read();
if (done) break;
chunks.push(new TextDecoder().decode(value));
}
})();
const encoder = new TextEncoder();
const payload = JSON.stringify({ choices: [{ delta: { content: "Hello" }, finish_reason: "stop" }] });
await writer.write(encoder.encode(`data: ${payload}\n`));
await writer.close();
await readPromise;
const fullOutput = chunks.join("");
console.log("FULL OUTPUT:", JSON.stringify(fullOutput));
assert.ok(fullOutput.includes("Hello"), "Should contain the full buffered text");
// It should be valid JSON
const lines = fullOutput.split("\n").filter(l => l.startsWith("data: ") && !l.includes("[DONE]"));
const parsed = JSON.parse(lines[0].replace("data: ", ""));
assert.equal(parsed.choices[0].delta.content, "Hello");
});