Skip to content

Commit 8ddc5a7

Browse files
committed
Cover unique path mentions next to pending clipboard images
1 parent 5a72273 commit 8ddc5a7

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/tui/prompt-attachments.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ describe("ingestPathMentions", () => {
6060
expect(result.attachments[0]?.name).toBe("shot.png");
6161
expect(result.text).toBe("see [Attached image: shot.png] and [Attached image: shot.png]");
6262
});
63+
64+
test("pending plus a unique mention and a duplicate mention returns only the unique as new", async () => {
65+
const pending = attachment("clipboard.png");
66+
const load = async (path: string): Promise<AttachImageResult> => {
67+
if (path.endsWith("dup.png")) {
68+
return {
69+
ok: true,
70+
attachment: { ...attachment("dup.png"), path, contentHash: pending.contentHash },
71+
};
72+
}
73+
return { ok: true, attachment: { ...attachment("unique.png"), path } };
74+
};
75+
const result = await ingestPathMentions(
76+
"see ./unique.png and ./dup.png",
77+
"/repo",
78+
load,
79+
[pending],
80+
);
81+
expect(result.attachments).toHaveLength(1);
82+
expect(result.attachments[0]?.name).toBe("unique.png");
83+
expect(result.text).toBe(
84+
"see [Attached image: unique.png] and [Attached image: clipboard.png]",
85+
);
86+
});
6387
});
6488

6589
describe("ingestOperatorPrompt", () => {
@@ -97,6 +121,19 @@ describe("ingestOperatorPrompt", () => {
97121
expect(result.attachments[0]).toEqual(pending);
98122
expect(result.text).toBe("see [Attached image: clipboard.png]");
99123
});
124+
125+
test("a path mention of different bytes keeps pending and appends the new attachment", async () => {
126+
const pending = attachment("clipboard.png");
127+
const load = async (path: string): Promise<AttachImageResult> => ({
128+
ok: true,
129+
attachment: { ...attachment("shot.png"), path },
130+
});
131+
const result = await ingestOperatorPrompt("see ./shot.png", "/repo", load, [pending]);
132+
expect(result.attachments).toHaveLength(2);
133+
expect(result.attachments[0]).toEqual(pending);
134+
expect(result.attachments[1]?.name).toBe("shot.png");
135+
expect(result.text).toBe("see [Attached image: shot.png]");
136+
});
100137
});
101138

102139
describe("spliceMentionCompletion", () => {

0 commit comments

Comments
 (0)