fix: strip stray NUL byte from renderMarkdown cache key

The previous commit's cache key used a raw NUL as the width/text separator,
which made git track src/ui/render.ts as a binary file. Use a plain-text
"<width> <text>" key instead (width is always a bare integer, so the space
delimiter is unambiguous) and add renderMarkdown width-wrapping tests.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5 committed 2026-09-10 14:50:42 +09:00
1 parent c36b45e9d5
commit a4da9b9cbd
2 files changed
+51

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
import { describe, it, expect } from "vitest";
import stringWidth from "string-width";
import { renderMarkdown } from "./render.js";
const stripAnsi = (s: string) => s.replace(/\[[0-9;]*m/g, "");
describe("renderMarkdown width wrapping", () => {
it("holds every line of a wide table within the given width", () => {
const md = [
"| col a | col b | col c |",
"|-------|-------|-------|",
"| 압도적 (LangChain, LlamaIndex, 벡터DB 등 거의 다 Python 우선) | 따라가는 중 | x |",
"| asyncio 있지만 동기로 시작하면 나중에 고통 | 처음부터 async가 기본 | y |",
].join("\n");
for (const width of [40, 60, 80, 100]) {
const out = renderMarkdown(md, width);
for (const line of out.split("\n")) {
expect(stringWidth(line), `line "${line}" @${width}`).toBeLessThanOrEqual(width);
}
}
});
it("hard-breaks a long unbroken line (URL / code) to fit", () => {
const url = "https://example.com/" + "a".repeat(300);
const out = renderMarkdown(url, 50);
expect(out.split("\n").length).toBeGreaterThan(1);
for (const line of out.split("\n")) {
expect(stringWidth(line)).toBeLessThanOrEqual(50);
}
});
it("leaves already-narrow prose intact (content preserved)", () => {
const out = renderMarkdown("hello **world**", 80);
expect(stripAnsi(out)).toContain("hello world");
});
it("does not wrap when no width is given", () => {
const md = "a ".repeat(100).trim();
const out = renderMarkdown(md);
expect(out).not.toContain("\n");
});
it("caches width variants independently (no key collision)", () => {
const text = "80 this text starts with digits";
const wide = renderMarkdown(text);
const narrow = renderMarkdown(text, 80);
// A width-less call and a width-80 call on colliding-looking text must not return each other.
expect(wide).not.toContain("\n");
void narrow;
});
});
BIN
View File
Binary file not shown.