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

+41
View File
@@ -58,3 +58,44 @@ test("notice sets and clears", () => {
s = reduce(s, { type: "notice", notice: null });
assert.equal(s.notice, null);
});
const dr = (created_ms, text = "szkic") => ({
text, caret: 2, attachments: [], identity: { created_ms, app: "codex" }, savedAt: 1,
});
test("restore_draft with the same identity restores silently", () => {
const s = reduce(createState(), { type: "restore_draft", agent: "t2", draft: dr(5), identity: { created_ms: 5, app: "codex" } });
assert.equal(s.drafts.t2, "szkic");
assert.equal(s.carets.t2, 2);
assert.equal(s.notice, null);
});
test("restore_draft with other created_ms holds the whole queue and warns", () => {
let s = reduce(createState(), { type: "restore", agent: "t2", items: [
{ id: "1", text: "a", state: "queued", createdAt: 1 },
{ id: "2", text: "b", state: "held", createdAt: 2 },
{ id: "3", text: "c", state: "uncertain", createdAt: 3 },
] });
s = reduce(s, { type: "restore_draft", agent: "t2", draft: dr(5), identity: { created_ms: 9, app: "codex" } });
assert.equal(s.drafts.t2, "szkic");
assert.deepEqual(s.notice, { text: "Szkic z poprzedniej sesji agenta", level: "warn" });
assert.deepEqual(s.queue.t2.map((i) => i.state), ["held", "held", "uncertain"]);
});
test("restore_draft restores attachments and never mutates", () => {
const before = createState();
const att = { id: "a", name: "f", path: "p", bytes: 1, kind: "file", state: "ready" };
const s = reduce(before, { type: "restore_draft", agent: "t2", draft: { ...dr(5), attachments: [att] }, identity: { created_ms: 5, app: null } });
assert.deepEqual(s.attachments.t2, [att]);
assert.deepEqual(before.drafts, {});
});
test("restore_draft without a draft changes nothing", () => {
const s = createState();
assert.equal(reduce(s, { type: "restore_draft", agent: "t2", draft: null, identity: { created_ms: 1, app: null } }), s);
});
test("draft action keeps the caret", () => {
const s = reduce(createState(), { type: "draft", agent: "a", text: "hi", caret: 1 });
assert.equal(s.carets.a, 1);
});