Files
paseo/packages/app/src/utils/assistant-image-source.test.ts
T
Mohamed BoudraandGitHub 811f52395e Fix Windows image previews (#1811)
* fix(images): preserve Windows preview paths

Provider image markdown used escaped backslash paths on Windows, which markdown parsing could turn into encoded drive paths that the app treated as workspace-relative. Emit drive-letter paths as file URIs and normalize existing encoded local paths before file preview.

* test(server): accept file URI image sources

Windows provider image output now renders drive-letter paths as file URIs. Decode those markdown sources before filesystem assertions so the image rendering tests keep checking the materialized file.

* fix(images): keep plain local paths literal

Limit legacy URI decoding to markdown-encoded Windows drive paths so ordinary local paths with percent sequences remain unchanged. Document why provider image markdown matching still accepts old doubled-backslash history.
2026-06-29 20:49:13 +00:00

108 lines
3.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { resolveAssistantImageSource } from "./assistant-image-source";
describe("resolveAssistantImageSource", () => {
it("passes through direct image URIs", () => {
expect(resolveAssistantImageSource({ source: "https://example.com/image.png" })).toEqual({
kind: "direct",
uri: "https://example.com/image.png",
});
expect(resolveAssistantImageSource({ source: "data:image/png;base64,abc" })).toEqual({
kind: "direct",
uri: "data:image/png;base64,abc",
});
});
it("uses the workspace root for relative paths", () => {
expect(
resolveAssistantImageSource({
source: "screenshots/output.png",
workspaceRoot: "/Users/test/project",
}),
).toEqual({
kind: "file_rpc",
cwd: "/Users/test/project",
path: "screenshots/output.png",
});
});
it("uses the workspace root for absolute paths inside the workspace", () => {
expect(
resolveAssistantImageSource({
source: "/Users/test/project/screenshots/output.png",
workspaceRoot: "/Users/test/project",
}),
).toEqual({
kind: "file_rpc",
cwd: "/Users/test/project",
path: "/Users/test/project/screenshots/output.png",
});
});
it("falls back to filesystem root for absolute paths outside the workspace", () => {
expect(
resolveAssistantImageSource({
source: "/tmp/paseo-codex-screenshot.png",
workspaceRoot: "/Users/test/project",
}),
).toEqual({
kind: "file_rpc",
cwd: "/",
path: "/tmp/paseo-codex-screenshot.png",
});
});
it("uses the same home-root target as file previews for tilde paths", () => {
expect(
resolveAssistantImageSource({
source: "~/.paseo/screenshots/output.png",
workspaceRoot: "/Users/test/project",
}),
).toEqual({
kind: "file_rpc",
cwd: "~",
path: "~/.paseo/screenshots/output.png",
});
});
it("normalizes file URIs into file RPC requests", () => {
expect(
resolveAssistantImageSource({
source: "file:///tmp/paseo-codex-screenshot.png",
workspaceRoot: "/Users/test/project",
}),
).toEqual({
kind: "file_rpc",
cwd: "/",
path: "/tmp/paseo-codex-screenshot.png",
});
});
it("normalizes markdown-encoded Windows paths into file RPC requests", () => {
expect(
resolveAssistantImageSource({
source: "C:%5CUsers%5Chanse%5CAppData%5CLocal%5CTemp%5Cpaseo-attachments%5Cimage.png",
workspaceRoot: "C:/Users/hanse/eatingkat",
}),
).toEqual({
kind: "file_rpc",
cwd: "C:/",
path: "C:/Users/hanse/AppData/Local/Temp/paseo-attachments/image.png",
});
});
it("falls back to the drive root for Windows absolute paths", () => {
expect(
resolveAssistantImageSource({
source: "C:/Users/test/Desktop/screenshot.png",
workspaceRoot: "D:/repo",
}),
).toEqual({
kind: "file_rpc",
cwd: "C:/",
path: "C:/Users/test/Desktop/screenshot.png",
});
});
});