源码快照 @ 2026-09-02 (source-only, 剔除非源码素材)
This commit is contained in:
commit
04bac1f6e2
2200 files changed
+489415
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import {
|
||||
getMediaBadge,
|
||||
getSafeFileDownloadUrl,
|
||||
getSafeFileRevealPath,
|
||||
} from "../src/components/chat/utils";
|
||||
import { getArtifactsFromMessages } from "../src/lib/artifacts";
|
||||
|
||||
const DOCX_MIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
||||
const PPTX_MIME = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
||||
const XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
|
||||
describe("Office attachment UI affordances", () => {
|
||||
test("uses compact Office badges instead of exposing MIME subtypes", () => {
|
||||
expect(getMediaBadge({ filename: "QuarterlyBrief.docx", mediaType: DOCX_MIME })).toBe("DOCX");
|
||||
expect(getMediaBadge({ filename: "LaunchRoadmap.PPTX", mediaType: PPTX_MIME })).toBe("PPTX");
|
||||
expect(getMediaBadge({ filename: "LaunchRoadmap.PPTX", mediaType: "application/octet-stream" })).toBe("PPTX");
|
||||
expect(getMediaBadge({ filename: "RevenueWorkbook.XLSX", mediaType: XLSX_MIME })).toBe("XLSX");
|
||||
expect(getMediaBadge({ filename: "RevenueWorkbook.XLSX", mediaType: "" })).toBe("XLSX");
|
||||
});
|
||||
|
||||
test("only exposes download actions for browser-managed file URLs", () => {
|
||||
expect(getSafeFileDownloadUrl({ url: `data:${DOCX_MIME};base64,UEsDBA==` })).toBe(`data:${DOCX_MIME};base64,UEsDBA==`);
|
||||
expect(getSafeFileDownloadUrl({ url: "blob:http://localhost/office-download" })).toBe("blob:http://localhost/office-download");
|
||||
expect(getSafeFileDownloadUrl({ url: "file:///workspace/artifacts/QuarterlyBrief.docx" })).toBeNull();
|
||||
expect(getSafeFileDownloadUrl({ url: "https://example.com/QuarterlyBrief.docx" })).toBeNull();
|
||||
expect(getSafeFileDownloadUrl({ url: "javascript:alert(1)" })).toBeNull();
|
||||
});
|
||||
|
||||
test("only exposes reveal actions for local file URLs", () => {
|
||||
expect(getSafeFileRevealPath({ url: "file:///workspace/artifacts/Quarterly%20Brief.docx" })).toBe("/workspace/artifacts/Quarterly Brief.docx");
|
||||
expect(getSafeFileRevealPath({ url: "file:///C:/Users/Jalil/Quarterly%20Brief.docx" })).toBe("C:/Users/Jalil/Quarterly Brief.docx");
|
||||
expect(getSafeFileRevealPath({ url: "blob:http://localhost/office-download" })).toBeNull();
|
||||
expect(getSafeFileRevealPath({ url: "https://example.com/QuarterlyBrief.docx" })).toBeNull();
|
||||
expect(getSafeFileRevealPath({ url: "javascript:alert(1)" })).toBeNull();
|
||||
});
|
||||
|
||||
test("collects DOCX artifacts as document previews", () => {
|
||||
const artifacts = getArtifactsFromMessages([
|
||||
{
|
||||
id: "msg_1",
|
||||
role: "assistant",
|
||||
parts: [{ type: "text", text: "Created artifacts/QuarterlyBrief.docx and artifacts/LaunchRoadmap.pptx." }],
|
||||
},
|
||||
]);
|
||||
|
||||
const docx = artifacts.find((artifact) => artifact.path === "artifacts/quarterlybrief.docx");
|
||||
const pptx = artifacts.find((artifact) => artifact.path === "artifacts/launchroadmap.pptx");
|
||||
|
||||
expect(docx?.type).toBe("document");
|
||||
expect(docx?.legacy_target.preview).toBe("document");
|
||||
expect(pptx?.type).toBe("slides");
|
||||
expect(pptx?.legacy_target.preview).toBe("slides");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user