feat: unified attachment pipeline with clipboard image and file picker

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 11:36:00 +01:00
1 parent d63af25fc1
commit 761a80004a
7 files changed
+597 -57

No files matched your search

+12
View File
@@ -36,3 +36,15 @@ test("removeMention removes only the standalone token", () => {
assert.equal(removeMention("see @src/a.rs now", "src/a.rs"), "see now");
assert.equal(removeMention("see @src/a.rsx now", "src/a.rs"), "see @src/a.rsx now");
});
test("mention and removeMention with a space and Polish letters in the path", () => {
const path = "/home/zażółć/gęsia jaźń/ęą.png";
assert.equal(mention(path), `@${path}`);
assert.equal(removeMention(`zobacz @${path} proszę`, path), "zobacz proszę");
assert.equal(removeMention(`@${path}`, path), "");
});
test("removeMention leaves a mention glued to a Polish letter alone", () => {
assert.equal(removeMention("@src/aę a", "src/a"), "@src/aę a");
assert.equal(removeMention("ę@src/a", "src/a"), "ę@src/a");
});
+83
View File
@@ -0,0 +1,83 @@
import test from "node:test";
import assert from "node:assert/strict";
import {
clipboardScript, parseClipboardResult, pickerScript, parsePickerResult, staleFiles, supportsImages,
} from "../mod/ovis-composer/clipboard.js";
const ok = (stdout) => ({ code: 0, stdout, stderr: "" });
test("clipboardScript: files first, then image, then NONE", () => {
const s = clipboardScript("C:\out dir", "123");
assert.ok(s.indexOf("GetFileDropList") >= 0);
assert.ok(s.indexOf("GetFileDropList") < s.indexOf("GetImage"));
assert.ok(s.includes("paste-123.png"));
assert.ok(s.includes("FILES"));
assert.ok(s.includes("IMAGE"));
assert.ok(s.includes("NONE"));
assert.ok(s.includes("C:\out dir"));
});
test("clipboardScript quotes a path with an apostrophe", () => {
assert.ok(clipboardScript("C:\o'brien", "1").includes("C:\o''brien"));
});
test("parseClipboardResult: image", () => {
assert.deepEqual(parseClipboardResult(ok("IMAGE\tC:\data\paste-1.png\r\n")), {
kind: "image", paths: ["C:\data\paste-1.png"],
});
});
test("parseClipboardResult: files with spaces and Polish letters", () => {
const out = "FILES\tC:\Moje pliki\zażółć gęślą.txt\r\nFILES\tD:\a b\c.png\r\n";
assert.deepEqual(parseClipboardResult(ok(out)), {
kind: "files", paths: ["C:\Moje pliki\zażółć gęślą.txt", "D:\a b\c.png"],
});
});
test("parseClipboardResult: NONE, empty, rubbish", () => {
assert.deepEqual(parseClipboardResult(ok("NONE\r\n")), { kind: "none" });
assert.deepEqual(parseClipboardResult(ok("")), { kind: "none" });
assert.deepEqual(parseClipboardResult(ok("what\r\n")), { kind: "none" });
});
test("parseClipboardResult: a failed run is an error with stderr", () => {
assert.deepEqual(parseClipboardResult({ code: 1, stdout: "", stderr: "boom\n" }), { kind: "error", message: "boom" });
const r = parseClipboardResult({ code: 3, stdout: "", stderr: "" });
assert.equal(r.kind, "error");
assert.ok(r.message.length > 0);
assert.equal(parseClipboardResult(null).kind, "error");
});
test("pickerScript: multiselect dialog, one path per line", () => {
const s = pickerScript();
assert.ok(s.includes("OpenFileDialog"));
assert.ok(s.includes("Multiselect"));
assert.ok(s.includes("$true"));
});
test("parsePickerResult: paths, cancelled -> []", () => {
assert.deepEqual(parsePickerResult(ok("C:\a b\c.txt\r\nD:\d.png\r\n")), ["C:\a b\c.txt", "D:\d.png"]);
assert.deepEqual(parsePickerResult(ok("")), []);
assert.deepEqual(parsePickerResult(ok("\r\n")), []);
assert.deepEqual(parsePickerResult({ code: 1, stdout: "x", stderr: "e" }), []);
assert.deepEqual(parsePickerResult(null), []);
});
test("staleFiles: 6 days stay, 8 days go", () => {
const now = 100 * 864e5;
const entries = [
{ path: "new.png", mtimeMs: now - 6 * 864e5 },
{ path: "old.png", mtimeMs: now - 8 * 864e5 },
{ path: "bad", mtimeMs: NaN },
];
assert.deepEqual(staleFiles(entries, now), ["old.png"]);
assert.deepEqual(staleFiles(entries, now, 5 * 864e5), ["new.png", "old.png"]);
assert.deepEqual(staleFiles(null, now), []);
});
test("supportsImages", () => {
for (const app of ["claude-code", "codex", "gemini", "opencode"]) assert.equal(supportsImages(app), true, app);
assert.equal(supportsImages("aider"), false);
assert.equal(supportsImages(null), false);
assert.equal(supportsImages(""), false);
});
+21
View File
@@ -191,3 +191,24 @@ test("restart turns a countdown into held", () => {
const s = reduce(mk(it("c", "countdown", { left: 2 })), { type: "restart", agent: "a" });
assert.deepEqual(states(s), ["held"]);
});
test("restore_draft turns an unfinished attachment into an error", () => {
const att = (id, state) => ({ id, name: id, path: "p", bytes: 1, kind: "file", state });
const draft = { text: "t", caret: 1, attachments: [att("a", "adding"), att("b", "ready")], identity: { created_ms: 5, app: null }, savedAt: 1 };
const s = reduce(createState(), { type: "restore_draft", agent: "t2", draft, identity: { created_ms: 5, app: null } });
assert.equal(s.attachments.t2[0].state, "error");
assert.ok(s.attachments.t2[0].error.length > 0);
assert.equal(s.attachments.t2[1].state, "ready");
});
test("attachment states: adding -> ready with the remote path, or error; retry goes back to adding", () => {
let s = reduce(createState(), { type: "attach", agent: "a", file: { id: "1", name: "f", path: "p", bytes: 1, state: "adding" } });
assert.equal(s.attachments.a[0].state, "adding");
s = reduce(s, { type: "attachment_update", agent: "a", id: "1", patch: { state: "ready", remotePath: "/r/f" } });
assert.deepEqual([s.attachments.a[0].state, s.attachments.a[0].remotePath], ["ready", "/r/f"]);
s = reduce(s, { type: "attachment_update", agent: "a", id: "1", patch: { state: "error", error: "x" } });
assert.equal(s.attachments.a[0].error, "x");
s = reduce(s, { type: "attachment_update", agent: "a", id: "1", patch: { state: "adding" } });
assert.equal(s.attachments.a[0].error, undefined);
assert.equal(reduce(s, { type: "attachment_update", agent: "a", id: "zz", patch: { state: "ready" } }), s);
});