Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Jay <air@live.ca> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: James Long <jlongster@users.noreply.github.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: 冯基魁 <56265583+fengjikui@users.noreply.github.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com> Co-authored-by: Victor Navarro <vn4varro@gmail.com> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Nabs <nabil@instafork.com> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: AidenGeunGeun <eastlandwyvern@gmail.com> Co-authored-by: Mark <geraint0923@users.noreply.github.com>
65 lines
2 KiB
TypeScript
65 lines
2 KiB
TypeScript
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")
|
|
})
|
|
})
|