This commit is contained in:
Eason Goodale
2025-04-19 22:55:37 -07:00
parent 2bcc15a839
commit 1e0a7cc313
7 changed files with 168 additions and 39 deletions

View File

@@ -5,7 +5,15 @@ import { renderTui } from "./ui-test-helpers.js";
import TerminalInlineImage from "../src/components/chat/terminal-inline-image.js";
import TerminalChatResponseItem from "../src/components/chat/terminal-chat-response-item.js";
import { imageFilenameByDataUrl } from "../src/utils/input-utils.js";
import { imageFilenameByDataUrl, createInputItem } from "../src/utils/input-utils.js";
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
import path from "node:path";
import fs from "node:fs";
describe("TerminalInlineImage fallback", () => {
it("renders alt text in test env", () => {
@@ -16,10 +24,11 @@ describe("TerminalInlineImage fallback", () => {
});
});
function fakeImageMessage(filename) {
function fakeImageMessage(filename: string) {
const url = "data:image/png;base64,AAA";
imageFilenameByDataUrl.set(url, filename);
return {
id: "test-id",
type: "message",
role: "user",
content: [
@@ -33,8 +42,36 @@ describe("TerminalChatResponseItem image label", () => {
it("shows filename", () => {
const msg = fakeImageMessage("sample.png");
const { lastFrameStripped } = renderTui(
<TerminalChatResponseItem item={msg} />
<TerminalChatResponseItem item={msg as any} />
);
expect(lastFrameStripped()).toContain("sample.png");
});
});
// ---------------------------------------------------------------------------
// New tests ensure createInputItem gracefully skips missing images.
// ---------------------------------------------------------------------------
describe("createInputItem missing images", () => {
it("ignores images that never existed on disk (conversation start)", async () => {
const item = await createInputItem("hello", ["ghost.png"]);
expect(item.content.some((c) => c.type === "input_image")).toBe(false);
});
it("ignores images deleted before submit (midconversation)", async () => {
const tmpDir = fs.mkdtempSync(path.join(process.cwd(), "missing-img-"));
const imgPath = path.join(tmpDir, "temp.png");
fs.writeFileSync(imgPath, "dummy");
// Remove the file before we construct the message.
fs.rmSync(imgPath);
const item = await createInputItem("", [imgPath]);
expect(item.content.some((c) => c.type === "input_image")).toBe(false);
fs.rmSync(tmpDir, { recursive: true, force: true });
});
// Additional integration tests for the systemlevel warning are covered in
// higherlevel suites. This unit file focuses on createInputItem behaviour.
});