






















@@ -50,24 +50,31 @@ describe("detectImageReferences", () => {
5050it("detects relative paths starting with ./", () => {
5151const ref = expectSingleImageReference("Look at ./images/photo.jpg");
525253-expect(ref?.raw).toBe("./images/photo.jpg");
54-expect(ref?.type).toBe("path");
53+expect(ref).toStrictEqual({
54+raw: "./images/photo.jpg",
55+type: "path",
56+resolved: "./images/photo.jpg",
57+});
5558});
56595760it("detects relative paths starting with ../", () => {
5861const ref = expectSingleImageReference("The file is at ../screenshots/test.jpeg");
596260-expect(ref?.raw).toBe("../screenshots/test.jpeg");
61-expect(ref?.type).toBe("path");
63+expect(ref).toStrictEqual({
64+raw: "../screenshots/test.jpeg",
65+type: "path",
66+resolved: "../screenshots/test.jpeg",
67+});
6268});
63696470it("detects home directory paths starting with ~/", () => {
6571const ref = expectSingleImageReference("My photo is at ~/Pictures/vacation.png");
667267-expect(ref?.raw).toBe("~/Pictures/vacation.png");
68-expect(ref?.type).toBe("path");
69-// Resolved path should expand ~
70-expect(ref?.resolved?.startsWith("~")).toBe(false);
73+expect(ref).toStrictEqual({
74+raw: "~/Pictures/vacation.png",
75+type: "path",
76+resolved: path.join(process.env.HOME ?? os.homedir(), "Pictures/vacation.png"),
77+});
7178});
72797380it("detects multiple image references in a prompt", () => {
@@ -80,7 +87,13 @@ describe("detectImageReferences", () => {
80871,
8188);
828983-expect(refs.map((ref) => ref.type)).toContain("path");
90+expect(refs).toStrictEqual([
91+{
92+raw: "/home/user/photo1.png",
93+type: "path",
94+resolved: "/home/user/photo1.png",
95+},
96+]);
8497});
85988699it("does not leak parser state between calls", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。