feat: persistent per-agent drafts with identity check

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 11:14:54 +01:00
1 parent 187a385f6f
commit 2ce1b45ee4
5 files changed
+367 -10

No files matched your search

+58
View File
@@ -2,6 +2,7 @@ import test from "node:test";
import assert from "node:assert/strict";
import {
HISTORY_LIMIT, queueKey, loadHistory, saveHistory, loadQueue, saveQueue, loadUsage, saveUsage,
KEYS, draftKey, loadDraft, saveDraft,
} from "../mod/ovis-composer/storage.js";
const memStore = () => {
@@ -56,3 +57,60 @@ test("rubbish list does not wipe stored history", () => {
saveHistory(store, [{ nope: 1 }]);
assert.equal(loadHistory(store).length, 1);
});
const draft = (over = {}) => ({
text: "hello", caret: 3, attachments: [],
identity: { created_ms: 1794818438639, app: "claude-code" }, savedAt: 10, ...over,
});
test("draftKey is per agent", () => {
assert.equal(KEYS.draft, "ovis-composer.draft");
assert.equal(draftKey("t2"), "ovis-composer.draft:t2");
});
test("draft roundtrip", () => {
const store = memStore();
const d = draft({ attachments: [{ id: "a", name: "f.txt", path: "C:/f.txt", bytes: 3, kind: "file", state: "ready" }] });
saveDraft(store, "t2", d);
assert.deepEqual(loadDraft(store, "t2"), d);
assert.equal(loadDraft(store, "t3"), null);
});
test("loadDraft: rubbish in store gives null", () => {
const store = memStore();
for (const bad of ["x", [], 5, { text: 1 }]) {
store.set(draftKey("t2"), bad);
assert.equal(loadDraft(store, "t2"), null);
}
});
test("draft keeps text over 20000 chars whole", () => {
const store = memStore();
const text = "a".repeat(25000);
saveDraft(store, "t2", draft({ text, caret: 25000 }));
assert.equal(loadDraft(store, "t2").text.length, 25000);
});
test("saveDraft ignores rubbish and empty agent", () => {
const store = memStore();
saveDraft(store, "t2", draft());
saveDraft(store, "t2", "x");
saveDraft(store, "", draft());
assert.equal(loadDraft(store, "t2").text, "hello");
assert.equal(store.get("ovis-composer.draft:"), undefined);
});
test("empty draft overwrites the old one", () => {
const store = memStore();
saveDraft(store, "t2", draft());
saveDraft(store, "t2", draft({ text: "", caret: 0 }));
assert.equal(loadDraft(store, "t2").text, "");
});
test("loadDraft: text-only draft still loads, with defaults", () => {
const store = memStore();
store.set(draftKey("t2"), { text: "a" });
assert.deepEqual(loadDraft(store, "t2"), {
text: "a", caret: 1, attachments: [], identity: { created_ms: null, app: null }, savedAt: 0,
});
});