fix: always compare draft identity, gate auto-send until checked
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
e7deca480a
commit
57761326fd
7 files changed
+161
-34
No files matched your search
@@ -99,3 +99,43 @@ test("draft action keeps the caret", () => {
|
||||
const s = reduce(createState(), { type: "draft", agent: "a", text: "hi", caret: 1 });
|
||||
assert.equal(s.carets.a, 1);
|
||||
});
|
||||
|
||||
const q3 = () => ({ type: "restore", agent: "t2", items: [
|
||||
{ id: "1", text: "a", state: "queued", createdAt: 1 },
|
||||
{ id: "2", text: "b", state: "sending", createdAt: 2 },
|
||||
{ id: "3", text: "c", state: "uncertain", createdAt: 3 },
|
||||
] });
|
||||
|
||||
test("restore_draft keepCurrent: mismatch holds the queue, keeps what the user typed", () => {
|
||||
let s = reduce(createState(), q3());
|
||||
s = reduce(s, { type: "draft", agent: "t2", text: "nowy tekst", caret: 4 });
|
||||
s = reduce(s, { type: "restore_draft", agent: "t2", draft: dr(5), identity: { created_ms: 9, app: null }, keepCurrent: true });
|
||||
assert.equal(s.drafts.t2, "nowy tekst");
|
||||
assert.equal(s.carets.t2, 4);
|
||||
assert.deepEqual(s.queue.t2.map((i) => i.state), ["held", "held", "uncertain"]);
|
||||
assert.equal(s.notice.text, "Szkic z poprzedniej sesji agenta");
|
||||
});
|
||||
|
||||
test("restore_draft: unknown live identity holds the queue; notice only when saved identity was known", () => {
|
||||
let s = reduce(createState(), q3());
|
||||
const live = reduce(s, { type: "restore_draft", agent: "t2", draft: dr(5), identity: { created_ms: null, app: null } });
|
||||
assert.deepEqual(live.queue.t2.map((i) => i.state), ["held", "held", "uncertain"]);
|
||||
assert.equal(live.notice.text, "Szkic z poprzedniej sesji agenta");
|
||||
|
||||
const both = reduce(s, { type: "restore_draft", agent: "t2", draft: dr(null), identity: { created_ms: null, app: null } });
|
||||
assert.deepEqual(both.queue.t2.map((i) => i.state), ["held", "held", "uncertain"]);
|
||||
assert.equal(both.notice, null);
|
||||
assert.equal(both.drafts.t2, "szkic");
|
||||
});
|
||||
|
||||
test("restore_draft without a draft: unknown live identity still holds the queue", () => {
|
||||
const s = reduce(createState(), q3());
|
||||
const out = reduce(s, { type: "restore_draft", agent: "t2", draft: null, identity: { created_ms: null, app: null } });
|
||||
assert.deepEqual(out.queue.t2.map((i) => i.state), ["held", "held", "uncertain"]);
|
||||
assert.equal(out.notice, null);
|
||||
});
|
||||
|
||||
test("hold_queue holds queued and sending, keeps uncertain", () => {
|
||||
const s = reduce(reduce(createState(), q3()), { type: "hold_queue", agent: "t2" });
|
||||
assert.deepEqual(s.queue.t2.map((i) => i.state), ["held", "held", "uncertain"]);
|
||||
});
|
||||
@@ -114,3 +114,14 @@ test("loadDraft: text-only draft still loads, with defaults", () => {
|
||||
text: "a", caret: 1, attachments: [], identity: { created_ms: null, app: null }, savedAt: 0,
|
||||
});
|
||||
});
|
||||
|
||||
test("saveDraft does not overwrite a known created_ms with null", () => {
|
||||
const store = memStore();
|
||||
saveDraft(store, "t2", draft());
|
||||
saveDraft(store, "t2", draft({ text: "nowy", identity: { created_ms: null, app: null } }));
|
||||
const out = loadDraft(store, "t2");
|
||||
assert.equal(out.text, "nowy");
|
||||
assert.equal(out.identity.created_ms, 1794818438639);
|
||||
saveDraft(store, "t2", draft({ text: "x", identity: { created_ms: 7, app: null } }));
|
||||
assert.equal(loadDraft(store, "t2").identity.created_ms, 7);
|
||||
});
|
||||
@@ -53,3 +53,11 @@ test("insertedNewline finds the index", () => {
|
||||
assert.deepEqual(insertedNewline("ab", "a\nb"), { index: 1 });
|
||||
assert.equal(insertedNewline("ab", "abc"), null);
|
||||
});
|
||||
|
||||
test("canAutoSend waits for the draft/identity check of the agent", async () => {
|
||||
const { canAutoSend } = await import("../mod/ovis-composer/view.js");
|
||||
assert.equal(canAutoSend(new Set(), "t2"), false);
|
||||
assert.equal(canAutoSend(new Set(["t2"]), "t2"), true);
|
||||
assert.equal(canAutoSend(new Set(["t3"]), "t2"), false);
|
||||
assert.equal(canAutoSend(null, "t2"), false);
|
||||
});
|
||||
Reference in new issue
Block a user