import assert from "node:assert/strict"; import test from "node:test"; import { createPublicThinkingSanitizer, sanitizePublicThinkingText, } from "../src/lib/public-thinking.ts"; function chunksOf(text: string, size: number): string[] { const chunks: string[] = []; for (let index = 0; index < text.length; index += size) { chunks.push(text.slice(index, index + size)); } return chunks; } function feed(text: string, size: number): string { const sanitizer = createPublicThinkingSanitizer(); let released = ""; for (const chunk of chunksOf(text, size)) { released += sanitizer.push(chunk) ?? ""; } released += sanitizer.flush() ?? ""; return released; } const INCIDENT_ENGLISH = [ "The a for 2026-09-09 (, per). The is a - an, not a.", 'The be "" or "timing" - is a/trend.', 'Let me use: [""]. "timing"? Let me run-jyotish-.', ].join(" "); test("incident English salad fed in 3-6 character chunks never reaches the public channel", () => { const chinese = "今日宜推进合同细节。"; for (const size of [3, 4, 5, 6]) { const released = feed(`${INCIDENT_ENGLISH} ${chinese}`, size); assert.match(released, /今日宜推进合同细节/); assert.doesNotMatch(released, /[A-Za-z]{4,}/); assert.doesNotMatch(released, /run-jyotish/); } }); test("pure Chinese thinking is unchanged", () => { const chinese = "先对照今日过境。再分开适合推进的事。"; assert.equal(feed(chinese, 4), chinese); assert.equal(sanitizePublicThinkingText(chinese), chinese); }); test("CJK sentences keep Chinese and drop four-letter English words", () => { assert.equal( sanitizePublicThinkingText("今日趋势 timing 可以推进。"), "今日趋势 可以推进。", ); }); test("English-only process narration is dropped even without a terminator", () => { assert.equal(sanitizePublicThinkingText("The proposedKind value was rejected"), null); }); test("an unterminated English chunk does not glue onto the following Chinese sentence", () => { const sanitizer = createPublicThinkingSanitizer(); assert.equal(sanitizer.push("The proposedKind value was rejected"), null); assert.equal(sanitizer.push("先看事业宫的结构。"), "先看事业宫的结构。"); assert.equal(sanitizer.flush(), null); });