Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
import assert from "node:assert/strict";
import test from "node:test";
import { DOMParser } from "@xmldom/xmldom";
import { strToU8, zipSync } from "fflate";
import { formatNumber, readDelimited, readPptx, readXlsx } from "../src/components/file-viewer/office.ts";
import { registerBundlerResolver } from "./helpers/kit.ts";
registerBundlerResolver();
{
const proto = Object.getPrototypeOf(new DOMParser().parseFromString("<a/>", "application/xml").documentElement);
const element = (node: Node | null): Element | null => {
while (node && node.nodeType !== 1) node = node.nextSibling;
return node as Element | null;
};
Object.defineProperties(proto, {
firstElementChild: { get: function (this: Element) { return element(this.firstChild); } },
nextElementSibling: { get: function (this: Element) { return element(this.nextSibling); } },
parentElement: { get: function (this: Element) { return this.parentNode?.nodeType === 1 ? this.parentNode : null; } },
children: {
get: function (this: Element) {
const out: Element[] = [];
for (let node = this.firstElementChild; node; node = node.nextElementSibling) out.push(node);
return out;
},
},
});
(globalThis as { DOMParser?: unknown }).DOMParser = DOMParser;
}
const MAIN = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
const REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
const PKG = "http://schemas.openxmlformats.org/package/2006/relationships";
const rels = (items: string) => strToU8(`<Relationships xmlns="${PKG}">${items}</Relationships>`);
function workbook(sheet: string, extra: Record<string, Uint8Array> = {}): Uint8Array {
return zipSync({
"xl/workbook.xml": strToU8(
`<workbook xmlns="${MAIN}" xmlns:r="${REL}"><sheets><sheet name="One" sheetId="1" r:id="rId1"/></sheets></workbook>`,
),
"xl/_rels/workbook.xml.rels": rels(`<Relationship Id="rId1" Type="${REL}/worksheet" Target="worksheets/sheet1.xml"/>`),
"xl/worksheets/sheet1.xml": strToU8(sheet),
...extra,
});
}
function declareHuge(zip: Uint8Array, name: string): Uint8Array {
const view = new DataView(zip.buffer, zip.byteOffset, zip.byteLength);
for (let i = 0; i < zip.length - 46; i++) {
if (view.getUint32(i, true) !== 0x02014b50) continue;
if (new TextDecoder().decode(zip.subarray(i + 46, i + 46 + view.getUint16(i + 28, true))) === name) {
view.setUint32(i + 24, 0xfffffff0, true);
return zip;
}
}
throw new Error(`no entry ${name}`);
}
test("number formats", () => {
const cases: [number, string, string][] = [
[1234567.891, "#,##0.00", "1,234,567.89"],
[-5, "#,##0.00;(#,##0.00)", "(5.00)"],
[1.5, "# ?/?", "1 1/2"],
[-1.5, "# ?/?;(# ?/?)", "(1 1/2)"],
[45000, "yyyy-mm-dd", "2023-03-15"],
[12.5, '0.00 "kg; net"', "12.50 kg; net"],
[1, '"A_B"0', "A_B1"],
[1234, '0.00E+00 "kg"', "1.23E+03 kg"],
[-1234, "0.00E+00;(0.00E+00)", "(1.23E+03)"],
[0.0123, "0.00E+00%", "1.23E+00%"],
[1.5 / 86400, "[h]:mm:ss.00", "0:00:01.50"],
[1 / 24, '[h]:mm "hours"', "1:00 hours"],
[1 / 24, "[h]:m:s", "1:0:0"],
[0.125, "# ?/?%", "12 1/2%"],
[125000, "# ?/?,", "125"],
[1.5, '0 "0/0"', "2 0/0"],
[0.01, "0%%", "100%%"],
[12345, "##0.0E+0", "12.3E+3"],
[0.00123, "##0.0E+0", "1.2E-3"],
[12.345, ".00", "12.35"],
[0.5, ".00", ".50"],
[3.5, '"$".00', "$3.50"],
];
for (const [value, format, expected] of cases) assert.equal(formatNumber(value, format), expected, format);
});
test("xlsx: reads only the parts and rows it keeps", () => {
let rows = "";
for (let r = 1; r <= 5200; r++) {
rows += `<x:row r="${r}"><x:c r="A${r}"><x:v>${r}</x:v></x:c><x:c r="B${r}" t="inlineStr"><x:is><x:t>${"x".repeat(200)}</x:t></x:is></x:c></x:row>`;
}
const zip = workbook(`<x:worksheet xmlns:x="${MAIN}"><x:sheetData>${rows}</x:sheetData></x:worksheet>`, {
"customXml/item1.xml": strToU8("<x/>"),
});
const [sheet] = readXlsx(declareHuge(zip, "customXml/item1.xml"));
assert.equal(sheet?.rows.length, 5000);
assert.equal(sheet?.truncated, true);
});
test("xlsx: sheet XML read as text", () => {
const [sheet] = readXlsx(
workbook(`<worksheet xmlns="${MAIN}"><cols><col min='2' max='2' hidden='1'/></cols><sheetData>
<row r="1"><c r="A1" t="inlineStr"><is><r><t>a & B</t></r><r><t><![CDATA[<c></row>]]></t></r><rPh><t>ruby</t></rPh></is></c><c r="B1"><v>9</v></c></row>
<row r="2"><c r="A2"><f t="shared" ref="A2:A3" si="0">SUM(b2,C:C,2:2)*2+$C$1+'A1'!A1+T[[#This Row],[Q1]]</f><v>7</v></c></row>
<row r="3"><c r="A3"><f t="shared" si="0"/></c></row>
</sheetData></worksheet>`),
);
assert.deepEqual(
sheet?.rows.map((row) => row.map((cell) => cell?.text)),
[["a & B<c></row>"], ["7"], ["=SUM(B3,C:C,3:3)*2+$C$1+'A1'!A2+T[[#This Row],[Q1]]"]],
);
});
test("xlsx: decodes escaped text in shared, inline and cached formula strings", () => {
for (const [encoded, expected] of [
["First_x000D_\nSecond_x0009_End", "First\r\nSecond\tEnd"],
["_xD83D__xDE00_", "\u{1f600}"],
["_x005F_x000D_", "_x000D_"],
["_x005F_x005F_x000D_", "_x005F_x000D_"],
["&_x0041_ _xZZZZ_", "&A _xZZZZ_"],
["_X0041_ _X000D_ _x004a_", "_X0041_ _X000D_ J"],
]) {
const [sheet] = readXlsx(workbook(
`<worksheet xmlns="${MAIN}"><sheetData><row r="1">
<c r="A1" t="s"><v>0</v></c>
<c r="B1" t="inlineStr"><is><t>${encoded}</t></is></c>
<c r="C1" t="str"><f>A1</f><v>${encoded}</v></c>
</row></sheetData></worksheet>`,
{ "xl/sharedStrings.xml": strToU8(`<sst xmlns="${MAIN}"><si><t>${encoded}</t></si></sst>`) },
));
assert.deepEqual(sheet?.rows[0]?.map((cell) => cell?.text), [expected, expected, expected], encoded);
}
});
test("xlsx: decodes rich text runs independently", () => {
const rich = "<r><t>_x00</t></r><r><t>0D_</t></r><r><t>_x000A_end</t></r>";
const [sheet] = readXlsx(workbook(
`<worksheet xmlns="${MAIN}"><sheetData><row r="1">
<c r="A1" t="s"><v>0</v></c>
<c r="B1" t="inlineStr"><is>${rich}</is></c>
</row></sheetData></worksheet>`,
{ "xl/sharedStrings.xml": strToU8(`<sst xmlns="${MAIN}"><si>${rich}</si></sst>`) },
));
assert.deepEqual(sheet?.rows[0]?.map((cell) => cell?.text), ["_x000D_\nend", "_x000D_\nend"]);
});
test("xlsx: lowercase cell references land in their columns", () => {
const [sheet] = readXlsx(
workbook(`<worksheet xmlns="${MAIN}"><sheetData><row r="1"><c r="a1"><v>1</v></c><c r="c1"><v>3</v></c></row></sheetData></worksheet>`),
);
assert.deepEqual(sheet?.rows.map((row) => Array.from(row, (cell) => cell?.text)), [["1", undefined, "3"]]);
});
test("pptx: tables capped, SmartArt read, pictures as Blobs", () => {
const P = "http://schemas.openxmlformats.org/presentationml/2006/main";
const A = "http://schemas.openxmlformats.org/drawingml/2006/main";
const DGM = "http://schemas.openxmlformats.org/drawingml/2006/diagram";
const tc = "<a:tc><a:txBody><a:p><a:r><a:t>v</a:t></a:r></a:p></a:txBody></a:tc>";
const text = (t: string) => `<dgm:t><a:p><a:r><a:t>${t}</a:t></a:r></a:p></dgm:t>`;
const zip = zipSync({
"ppt/presentation.xml": strToU8(
`<p:presentation xmlns:p="${P}" xmlns:r="${REL}"><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst></p:presentation>`,
),
"ppt/_rels/presentation.xml.rels": rels(`<Relationship Id="rId1" Type="${REL}/slide" Target="slides/slide1.xml"/>`),
"ppt/slides/slide1.xml": strToU8(
`<p:sld xmlns:p="${P}" xmlns:a="${A}" xmlns:r="${REL}" xmlns:dgm="${DGM}"><p:cSld><p:spTree>` +
`<p:graphicFrame><a:graphic><a:graphicData><a:tbl>${`<a:tr>${tc.repeat(10)}</a:tr>`.repeat(1000)}</a:tbl></a:graphicData></a:graphic></p:graphicFrame>` +
`<p:graphicFrame><a:graphic><a:graphicData><dgm:relIds r:dm="rId2"/></a:graphicData></a:graphic></p:graphicFrame>` +
`<p:pic><p:blipFill><a:blip r:embed="rId3"/><a:srcRect l="25000" b="-10000"/></p:blipFill></p:pic>` +
`</p:spTree></p:cSld></p:sld>`,
),
"ppt/slides/_rels/slide1.xml.rels": rels(
`<Relationship Id="rId2" Type="${REL}/diagramData" Target="../diagrams/data1.xml"/><Relationship Id="rId3" Type="${REL}/image" Target="../media/image1.png"/>`,
),
"ppt/diagrams/data1.xml": strToU8(
`<dgm:dataModel xmlns:dgm="${DGM}" xmlns:a="${A}"><dgm:ptLst><dgm:pt type="doc">${text("Doc")}</dgm:pt><dgm:pt>${text("Plan")}</dgm:pt></dgm:ptLst></dgm:dataModel>`,
),
"ppt/media/image1.png": new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1]),
"ppt/media/clip.mp4": new Uint8Array(8),
});
const [table, diagram, image] = readPptx(declareHuge(zip, "ppt/media/clip.mp4")).slides[0]!.boxes;
assert.equal(image?.image?.type, "image/png");
assert.deepEqual(image?.crop, { l: 0.25, t: 0, r: 0, b: -0.1 });
assert.equal(table?.table?.length, 501);
assert.deepEqual(table?.table?.at(-1), ["…"]);
assert.deepEqual(diagram?.paragraphs?.map((p) => p.text), ["Plan"]);
});
for (const cache of ["<v></v>", "<v/>", "<s:v xmlns:s=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" />"]) {
test(`xlsx: preserves a cached empty string formula result (${cache})`, () => {
const [sheet] = readXlsx(workbook(
`<worksheet xmlns="${MAIN}"><sheetData><row r="1">
<c r="A1" t="str"><f>IF(1=1,"",42)</f>${cache}</c>
<c r="B1" t="str"><f>IF(1=1,"ready",42)</f><v>ready</v></c>
<c r="C1"><f>1-1</f><v>0</v></c>
</row></sheetData></worksheet>`,
));
assert.equal(sheet?.rows[0]?.[0]?.text ?? "", "");
assert.equal(sheet?.rows[0]?.[1]?.text, "ready");
assert.equal(sheet?.rows[0]?.[2]?.text, "0");
});
}
test("xlsx: preserves formula fallback for uncalculated cells and shared followers", () => {
const [sheet] = readXlsx(workbook(
`<worksheet xmlns="${MAIN}"><sheetData><row r="1">
<c r="A1"><f>SUM(1,2)</f><v></v></c>
<c r="B1" t="n"><f>SUM(1,2)</f><v/></c>
<c r="C1"><f>SUM(1,2)</f></c>
<c r="D1" t="str"><f>IF(1=1,"",42)</f></c>
<c r="E1" t="str"><f t="shared" si="0" ref="E1:G1">IF(A1=0,"",A1)</f><v/></c>
<c r="F1" t="str"><f t="shared" si="0"/><v/></c>
<c r="G1"><f t="shared" si="0"/><v/></c>
</row></sheetData></worksheet>`,
));
const row = sheet?.rows[0];
for (const col of [0, 1, 2]) assert.equal(row?.[col]?.text, "=SUM(1,2)");
assert.equal(row?.[3]?.text, '=IF(1=1,"",42)');
assert.equal(row?.[4]?.text ?? "", "");
assert.equal(row?.[5]?.text ?? "", "");
assert.equal(row?.[6]?.text, '=IF(C1=0,"",C1)');
});
test("xlsx: out-of-range date values do not prevent reading the workbook", () => {
for (const date1904 of [false, true]) {
for (const value of [1700000000, -1700000000]) {
assert.equal(formatNumber(value, "mmm-yy", date1904), String(value));
assert.equal(formatNumber(value, "mmmmm", date1904), String(value));
}
}
assert.equal(formatNumber(45000, "mmm-yy"), "Mar-23");
const [sheet] = readXlsx(workbook(
`<worksheet xmlns="${MAIN}"><sheetData><row r="1">
<c r="A1" s="1"><v>1700000000</v></c>
<c r="B1" s="1"><v>45000</v></c>
<c r="C1"><v>42</v></c>
</row></sheetData></worksheet>`,
{
"xl/styles.xml": strToU8(`<styleSheet xmlns="${MAIN}">
<numFmts count="1"><numFmt numFmtId="164" formatCode="mmm-yy"/></numFmts>
<cellXfs count="2"><xf numFmtId="0"/><xf numFmtId="164"/></cellXfs>
</styleSheet>`),
},
));
assert.deepEqual(sheet?.rows[0]?.map((cell) => cell?.text), ["1700000000", "Mar-23", "42"]);
});
test("xlsx: a chat attachment keeps the rows, columns and sheets the viewer hides", async () => {
const { extractOfficeAttachmentText } = await import("../src/features/chat/attachment-content.ts");
const zip = zipSync({
"xl/workbook.xml": strToU8(
`<workbook xmlns="${MAIN}" xmlns:r="${REL}"><sheets><sheet name="Sales" sheetId="1" r:id="rId1"/><sheet name="Notes" sheetId="2" state="hidden" r:id="rId2"/></sheets></workbook>`,
),
"xl/_rels/workbook.xml.rels": rels(
`<Relationship Id="rId1" Type="${REL}/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="${REL}/worksheet" Target="worksheets/sheet2.xml"/>`,
),
"xl/worksheets/sheet1.xml": strToU8(`<worksheet xmlns="${MAIN}"><cols><col min="3" max="3" hidden="1"/></cols><sheetData>
<row r="1"><c r="A1" t="inlineStr"><is><t>Region</t></is></c><c r="B1" t="inlineStr"><is><t>Q3</t></is></c><c r="C1" t="inlineStr"><is><t>Owner</t></is></c></row>
<row r="2"><c r="A2" t="inlineStr"><is><t>North</t></is></c><c r="B2"><v>100</v></c><c r="C2" t="inlineStr"><is><t>Ann</t></is></c></row>
<row r="3" hidden="1"><c r="A3" t="inlineStr"><is><t>West</t></is></c><c r="B3"><v>300</v></c><c r="C3" t="inlineStr"><is><t>Bo</t></is></c></row>
</sheetData></worksheet>`),
"xl/worksheets/sheet2.xml": strToU8(
`<worksheet xmlns="${MAIN}"><sheetData><row r="1"><c r="A1" t="inlineStr"><is><t>adjust</t></is></c></row></sheetData></worksheet>`,
),
});
const viewer = readXlsx(zip);
assert.deepEqual(viewer.map((sheet) => sheet.name), ["Sales"]);
assert.deepEqual(viewer[0]!.rows.filter(Boolean).map((row) => row.map((cell) => cell?.text)), [
["Region", "Q3"],
["North", "100"],
]);
const file = new File([zip], "q3.xlsx", { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
assert.equal(
await extractOfficeAttachmentText(file, "XLSX"),
"Sheet: Sales\nRegion\tQ3\tOwner\nNorth\t100\tAnn\nWest\t300\tBo\n\nSheet: Notes\nadjust",
);
});
test("xlsx: kept hidden sheets come after visible ones so they cannot use up the sheet budget", () => {
const zip = zipSync({
"xl/workbook.xml": strToU8(
`<workbook xmlns="${MAIN}" xmlns:r="${REL}"><sheets><sheet name="Lookup" sheetId="1" state="veryHidden" r:id="rId1"/><sheet name="Sales" sheetId="2" r:id="rId2"/></sheets></workbook>`,
),
"xl/_rels/workbook.xml.rels": rels(
`<Relationship Id="rId1" Type="${REL}/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="${REL}/worksheet" Target="worksheets/sheet2.xml"/>`,
),
"xl/worksheets/sheet1.xml": strToU8(
`<worksheet xmlns="${MAIN}"><sheetData><row r="1"><c r="A1" t="inlineStr"><is><t>code</t></is></c></row></sheetData></worksheet>`,
),
"xl/worksheets/sheet2.xml": strToU8(
`<worksheet xmlns="${MAIN}"><sheetData><row r="1"><c r="A1" t="inlineStr"><is><t>North</t></is></c></row></sheetData></worksheet>`,
),
});
const limits = { sheets: 1, rows: 10, columns: 10 };
assert.deepEqual(readXlsx(zip, limits, { keepHidden: true }).map((sheet) => sheet.name), ["Sales"]);
assert.deepEqual(readXlsx(zip, undefined, { keepHidden: true }).map((sheet) => sheet.name), ["Sales", "Lookup"]);
});
test("pptx: maxSlides stops reading after that many slides", () => {
const P = "http://schemas.openxmlformats.org/presentationml/2006/main";
const A = "http://schemas.openxmlformats.org/drawingml/2006/main";
const ids = [1, 2, 3].map((n) => `<p:sldId id="${255 + n}" r:id="rId${n}"/>`).join("");
const links = [1, 2, 3].map((n) => `<Relationship Id="rId${n}" Type="${REL}/slide" Target="slides/slide${n}.xml"/>`).join("");
const slide = (t: string) =>
strToU8(`<p:sld xmlns:p="${P}" xmlns:a="${A}"><p:cSld><p:spTree><p:sp><p:txBody><a:p><a:r><a:t>${t}</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>`);
const zip = zipSync({
"ppt/presentation.xml": strToU8(`<p:presentation xmlns:p="${P}" xmlns:r="${REL}"><p:sldIdLst>${ids}</p:sldIdLst></p:presentation>`),
"ppt/_rels/presentation.xml.rels": rels(links),
"ppt/slides/slide1.xml": slide("one"),
"ppt/slides/slide2.xml": slide("two"),
"ppt/slides/slide3.xml": slide("three"),
});
assert.equal(readPptx(zip).slides.length, 3);
const first = readPptx(zip, { maxSlides: 1 });
assert.equal(first.slides.length, 1);
assert.equal(first.truncated, true);
assert.equal(first.slides[0]!.boxes[0]?.paragraphs?.[0]?.text, "one");
});
test("pptx attachments keep speaker notes without the slide number", async () => {
const { extractOfficeAttachmentText } = await import("../src/features/chat/attachment-content.ts");
const P = "http://schemas.openxmlformats.org/presentationml/2006/main";
const A = "http://schemas.openxmlformats.org/drawingml/2006/main";
const sp = (ph: string, body: string) =>
`<p:sp><p:nvSpPr><p:nvPr><p:ph type="${ph}"/></p:nvPr></p:nvSpPr><p:txBody>${body}</p:txBody></p:sp>`;
const zip = zipSync({
"ppt/presentation.xml": strToU8(
`<p:presentation xmlns:p="${P}" xmlns:r="${REL}"><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst></p:presentation>`,
),
"ppt/_rels/presentation.xml.rels": rels(`<Relationship Id="rId1" Type="${REL}/slide" Target="slides/slide1.xml"/>`),
"ppt/slides/slide1.xml": strToU8(
`<p:sld xmlns:p="${P}" xmlns:a="${A}"><p:cSld><p:spTree>${sp("title", "<a:p><a:r><a:t>Quarterly plan</a:t></a:r></a:p>")}</p:spTree></p:cSld></p:sld>`,
),
"ppt/slides/_rels/slide1.xml.rels": rels(
`<Relationship Id="rId2" Type="${REL}/notesSlide" Target="../notesSlides/notesSlide1.xml"/>`,
),
"ppt/notesSlides/notesSlide1.xml": strToU8(
`<p:notes xmlns:p="${P}" xmlns:a="${A}"><p:cSld><p:spTree>` +
sp("sldImg", "") +
sp("body", "<a:p><a:r><a:t>Budget is 42 dollars</a:t></a:r></a:p><a:p><a:r><a:t>Ask about Q3</a:t></a:r></a:p>") +
sp("sldNum", '<a:p><a:fld type="slidenum"><a:t>1</a:t></a:fld></a:p>') +
`</p:spTree></p:cSld></p:notes>`,
),
});
const file = new File([zip], "deck.pptx");
assert.equal(
await extractOfficeAttachmentText(file, "PPTX"),
"Slide 1\nQuarterly plan\nNotes:\nBudget is 42 dollars\nAsk about Q3",
);
assert.deepEqual(
readPptx(zip).slides[0]?.boxes.flatMap((box) => box.paragraphs?.map((p) => p.text) ?? []),
["Quarterly plan"],
);
});
test("sheet limits cap rows, columns and parsed sheets", () => {
const cells = (r: number) => Array.from({ length: 5 }, (_, c) => `<c r="${"ABCDE"[c]}${r}"><v>${r}</v></c>`).join("");
const rows = Array.from({ length: 10 }, (_, i) => `<row r="${i + 1}">${cells(i + 1)}</row>`).join("");
const sheet = strToU8(`<worksheet xmlns="${MAIN}"><sheetData>${rows}</sheetData></worksheet>`);
const zip = zipSync({
"xl/workbook.xml": strToU8(
`<workbook xmlns="${MAIN}" xmlns:r="${REL}"><sheets><sheet name="One" sheetId="1" r:id="rId1"/><sheet name="Two" sheetId="2" r:id="rId2"/></sheets></workbook>`,
),
"xl/_rels/workbook.xml.rels": rels(
`<Relationship Id="rId1" Type="${REL}/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="${REL}/worksheet" Target="worksheets/sheet2.xml"/>`,
),
"xl/worksheets/sheet1.xml": sheet,
"xl/worksheets/sheet2.xml": sheet,
});
const full = readXlsx(zip);
assert.deepEqual([full.length, full[1]!.rows.length], [2, 10]);
const [first, second] = readXlsx(zip, { sheets: 1, rows: 3, columns: 2, extraNames: 1 });
assert.equal(readXlsx(zip, { sheets: 1, rows: 3, columns: 2, extraNames: 0 }).length, 1);
assert.equal(first!.rows.length, 3);
assert.ok(first!.rows.every((row) => row.length <= 2));
assert.equal(first!.truncated, true);
assert.deepEqual([second!.name, second!.rows.length], ["Two", 0]);
const csv = readDelimited("a,b,c\n1,2,3\n4,5,6\n7,8,9\n", ",", "x.csv", { sheets: 1, rows: 2, columns: 2 });
assert.deepEqual(csv.rows.map((row) => row.map((cell) => cell?.text)), [["a", "b"], ["1", "2"]]);
});
test("thumbnails render no nested controls: sheet tabs as labels, Word links without href", async () => {
const { readFileSync } = await import("node:fs");
const view = readFileSync(new URL("../src/components/file-viewer/office-view.tsx", import.meta.url), "utf8");
assert.match(view, /return thumbnail \? \(\n\s*<span key=\{index\} className=\{className\}>/);
assert.match(view, /sanitizeDocxHtml\(value, THUMBNAIL_DOCX_ELEMENTS, \{ links: false \}\)/);
assert.match(view, /attr\.name === "href" && \(!links \|\|/);
assert.match(view, /thumbnail=\{thumbnail\}\n\s*\/>/);
});