|
1 | 1 | import fs from "node:fs/promises"; |
2 | 2 | import os from "node:os"; |
3 | 3 | import path from "node:path"; |
| 4 | +import { pathToFileURL } from "node:url"; |
4 | 5 | import { describe, expect, it, vi } from "vitest"; |
5 | 6 | import { createHostSandboxFsBridge } from "../../test-helpers/host-sandbox-fs-bridge.js"; |
6 | 7 | import { createUnsafeMountedSandbox } from "../../test-helpers/unsafe-mounted-sandbox.js"; |
@@ -103,8 +104,10 @@ describe("detectImageReferences", () => { |
103 | 104 | expect(detectImageReferences("[Image: source: /tmp/second.jpg]")).toStrictEqual([ |
104 | 105 | { raw: "/tmp/second.jpg", type: "path", resolved: "/tmp/second.jpg" }, |
105 | 106 | ]); |
106 | | - expect(detectImageReferences("See file:///tmp/third.webp")).toStrictEqual([ |
107 | | - { raw: "file:///tmp/third.webp", type: "path", resolved: "/tmp/third.webp" }, |
| 107 | + const thirdPath = path.join(os.tmpdir(), "third.webp"); |
| 108 | + const thirdUrl = pathToFileURL(thirdPath).href; |
| 109 | + expect(detectImageReferences(`See ${thirdUrl}`)).toStrictEqual([ |
| 110 | + { raw: thirdUrl, type: "path", resolved: thirdPath }, |
108 | 111 | ]); |
109 | 112 | expect(detectImageReferences("See ./fourth.jpeg")).toStrictEqual([ |
110 | 113 | { raw: "./fourth.jpeg", type: "path", resolved: "./fourth.jpeg" }, |
@@ -192,6 +195,18 @@ describe("detectImageReferences", () => { |
192 | 195 | }); |
193 | 196 | }); |
194 | 197 |
|
| 198 | + it("detects Windows drive image paths in plain prompts", () => { |
| 199 | + const ref = expectSingleImageReference( |
| 200 | + String.raw`Look at C:\Users\Ada\Pictures\screenshot.png`, |
| 201 | + ); |
| 202 | + |
| 203 | + expect(ref).toStrictEqual({ |
| 204 | + raw: String.raw`C:\Users\Ada\Pictures\screenshot.png`, |
| 205 | + type: "path", |
| 206 | + resolved: String.raw`C:\Users\Ada\Pictures\screenshot.png`, |
| 207 | + }); |
| 208 | + }); |
| 209 | + |
195 | 210 | it("detects [Image: source: ...] format from messaging systems", () => { |
196 | 211 | const ref = expectSingleImageReference(`What does this image show? |
197 | 212 | [Image: source: /Users/tyleryust/Library/Messages/Attachments/IMG_0043.jpeg]`); |
|
0 commit comments