/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/session-ui/src/components/message-file.test.ts
65 строк
2 KB
Aarav Sareen
feat(app): redesign attachment cards (#35945)
13 июл 2026, 13:04
Не верифицирован
13 июл 2026, 13:04
b4e49d5
Код
Авторство
О чём код?
import { describe, expect, test } from "bun:test" import type { FilePart } from "@opencode-ai/sdk/v2" import { attached, inline, kind, typeLabel } from "./message-file" function file(part: Partial<FilePart> = {}): FilePart { return { id: "part_1", sessionID: "ses_1", messageID: "msg_1", type: "file", mime: "text/plain", url: "file:///repo/README.txt", filename: "README.txt", ...part, } } describe("message-file", () => { test("treats data URLs as attachments", () => { expect(attached(file({ url: "data:text/plain;base64,SGVsbG8=" }))).toBe(true) expect(attached(file())).toBe(false) }) test("treats only non-attachment source ranges as inline references", () => { expect( inline( file({ source: { type: "file", path: "/repo/README.txt", text: { value: "@README.txt", start: 0, end: 11 }, }, }), ), ).toBe(true) expect( inline( file({ url: "data:text/plain;base64,SGVsbG8=", source: { type: "file", path: "/repo/README.txt", text: { value: "@README.txt", start: 0, end: 11 }, }, }), ), ).toBe(false) }) test("separates image and file attachment kinds", () => { expect(kind(file({ mime: "image/png" }))).toBe("image") expect(kind(file({ mime: "application/pdf" }))).toBe("file") }) test("labels attachment types from the basename extension", () => { expect(typeLabel("list.md", "text/plain")).toBe("Markdown") expect(typeLabel("/repo/src/main.ts", "text/plain")).toBe("TypeScript") expect(typeLabel("/tmp/report.pdf", "application/pdf")).toBe("PDF") expect(typeLabel("notes.xyz", "text/plain")).toBe("XYZ") expect(typeLabel("/home/user/my.project/Makefile", "text/plain")).toBe("File") expect(typeLabel(".gitignore", "text/plain")).toBe("File") expect(typeLabel("/repo/.env", "text/plain")).toBe("File") }) })