test: specify prompt image path refs

This commit is contained in:
Shakker
2026-05-12 00:43:54 +01:00
parent 56c26c38be
commit f006e97caa

View File

@@ -50,24 +50,31 @@ describe("detectImageReferences", () => {
it("detects relative paths starting with ./", () => {
const ref = expectSingleImageReference("Look at ./images/photo.jpg");
expect(ref?.raw).toBe("./images/photo.jpg");
expect(ref?.type).toBe("path");
expect(ref).toStrictEqual({
raw: "./images/photo.jpg",
type: "path",
resolved: "./images/photo.jpg",
});
});
it("detects relative paths starting with ../", () => {
const ref = expectSingleImageReference("The file is at ../screenshots/test.jpeg");
expect(ref?.raw).toBe("../screenshots/test.jpeg");
expect(ref?.type).toBe("path");
expect(ref).toStrictEqual({
raw: "../screenshots/test.jpeg",
type: "path",
resolved: "../screenshots/test.jpeg",
});
});
it("detects home directory paths starting with ~/", () => {
const ref = expectSingleImageReference("My photo is at ~/Pictures/vacation.png");
expect(ref?.raw).toBe("~/Pictures/vacation.png");
expect(ref?.type).toBe("path");
// Resolved path should expand ~
expect(ref?.resolved?.startsWith("~")).toBe(false);
expect(ref).toStrictEqual({
raw: "~/Pictures/vacation.png",
type: "path",
resolved: path.join(process.env.HOME ?? os.homedir(), "Pictures/vacation.png"),
});
});
it("detects multiple image references in a prompt", () => {
@@ -80,7 +87,13 @@ describe("detectImageReferences", () => {
1,
);
expect(refs.map((ref) => ref.type)).toContain("path");
expect(refs).toStrictEqual([
{
raw: "/home/user/photo1.png",
type: "path",
resolved: "/home/user/photo1.png",
},
]);
});
it("does not leak parser state between calls", () => {