mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-10 16:21:22 +00:00
New Chat wrote an empty composer-only draft, which the text-only equality treated as identical to the previous typed draft. The panel skipped re-render, so the uncontrolled textarea kept the old string and send could still submit it. Treat emptying draft text as a lifecycle change so listeners wake, and commit the live box on ChatInput unmount so mid-IME hide still flushes.
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import { createEmptyDraft } from './aiDraftState.ts';
|
|
import { aiSessionsStore } from './aiSessionsStore.ts';
|
|
|
|
test('AI sessions store does not notify listeners when only composer text changes', () => {
|
|
const previous = aiSessionsStore.getSnapshot();
|
|
const draft = createEmptyDraft('catty');
|
|
const base = {
|
|
sessions: Object.freeze([]),
|
|
activeSessionIdMap: Object.freeze({}),
|
|
draftsByScope: { 'terminal:1': draft },
|
|
panelViewByScope: {},
|
|
};
|
|
|
|
try {
|
|
aiSessionsStore.setSnapshot(base);
|
|
|
|
let notified = 0;
|
|
const unsubscribe = aiSessionsStore.subscribe(() => {
|
|
notified += 1;
|
|
});
|
|
|
|
aiSessionsStore.setSnapshot({
|
|
...base,
|
|
draftsByScope: {
|
|
'terminal:1': { ...draft, text: 'hello', updatedAt: draft.updatedAt + 1 },
|
|
},
|
|
});
|
|
assert.equal(notified, 0);
|
|
assert.equal(aiSessionsStore.getSnapshot().draftsByScope['terminal:1']?.text, 'hello');
|
|
|
|
aiSessionsStore.setSnapshot({
|
|
...base,
|
|
draftsByScope: {},
|
|
});
|
|
notified = 0;
|
|
aiSessionsStore.setSnapshot({
|
|
...base,
|
|
draftsByScope: {
|
|
'terminal:1': { ...draft, text: '你好' },
|
|
},
|
|
});
|
|
assert.equal(notified, 0);
|
|
|
|
notified = 0;
|
|
aiSessionsStore.setSnapshot({
|
|
...base,
|
|
draftsByScope: {
|
|
'terminal:1': { ...draft, text: '' },
|
|
},
|
|
});
|
|
assert.equal(notified, 1);
|
|
|
|
notified = 0;
|
|
aiSessionsStore.setSnapshot({
|
|
...base,
|
|
draftsByScope: {
|
|
'terminal:1': { ...draft, text: 'hello', attachments: [{ id: 'a' } as never] },
|
|
},
|
|
});
|
|
assert.equal(notified, 1);
|
|
unsubscribe();
|
|
} finally {
|
|
aiSessionsStore.setSnapshot(previous);
|
|
}
|
|
});
|