GHHG10/CodeServer / opencode /packages /ui /src /components /message-file.test.ts
GHHG10's picture
download
raw
1.44 kB
import { describe, expect, test } from "bun:test"
import type { FilePart } from "@opencode-ai/sdk/v2"
import { attached, inline, kind } 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")
})
})

Xet Storage Details

Size:
1.44 kB
·
Xet hash:
736d2c3c877c7a1e00d699d50bc5718e199974ba79df8d95b7fa077011e963b7

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.