fix(webui): preserve room refusal and recover session controls (#1843)
This commit is contained in:
1 parent
5558fe0204
commit
a1ba9cd566
5 files changed
+53
-1
No files matched your search
@@ -282,7 +282,7 @@
|
||||
const signal = controller.signal, g = ++generation;
|
||||
const match = /^\/chat\/rooms\/([0-9a-f-]+)$/i.exec(path), id = match?.[1];
|
||||
current = { kind: 'room', id, key: 'room:' + id, path, container, canSend, user, tester,
|
||||
projects: [], threads: [], members: [], roomReady: false, refused: false, error: '' };
|
||||
projects: [], threads: [], members: [], roomReady: false, channelDisabled: current?.channelDisabled ?? false, refused: false, error: '' };
|
||||
if (!UUID.test(id ?? '') || !roomOwner()) {
|
||||
current.error = UUID.test(id ?? '') ? 'Rooms require the business owner.' : 'Invalid room route.';
|
||||
current.refused = true; paint(navigated); return;
|
||||
@@ -302,6 +302,7 @@
|
||||
const page = await request(`rooms/${id}/messages?limit=100${after ? '&after=' + after : ''}`, undefined, signal);
|
||||
if (g !== generation || out()) return;
|
||||
if (typeof page.hasMore !== 'boolean' || !(page.after === null || UUID.test(page.after)) || page.rows.some(m => !UUID.test(m?.id) || !Array.isArray(m.ids) || !m.ids.every(id => UUID.test(id)) || !Array.isArray(m.to))) throw new ChatError('invalid-response');
|
||||
current.channelDisabled = false;
|
||||
s.rows = [...new Map((after ? [...s.rows, ...page.rows] : page.rows).map(m => [m.id, m])).values()].slice(-200);
|
||||
s.after = page.after ?? s.after; s.more = page.hasMore; s.loaded = true;
|
||||
current.roomReady = current.members.length > 0;
|
||||
@@ -506,6 +507,7 @@
|
||||
}
|
||||
if (s) {
|
||||
if (typeof page.hasMore !== 'boolean' || !(page.after === null || UUID.test(page.after))) throw new ChatError('invalid-response');
|
||||
if (catalog) current.legacyDefault = false;
|
||||
const rows = after ? [...s.rows, ...page.rows] : page.rows;
|
||||
s.rows = [...new Map(rows.map(m => [m.id, m])).values()].slice(-200);
|
||||
s.after = page.after ?? s.after; s.more = page.hasMore; s.loaded = true;
|
||||
|
||||
@@ -191,6 +191,27 @@ test('chat browser: a refused share explains the disabled channel without exposi
|
||||
assert.equal(await b.evaluate('document.querySelector("#chat-share-target").value'), 'user:reader');
|
||||
assert.equal(await b.evaluate('window.__writes.length'), 1);
|
||||
});
|
||||
test('chat browser: session catalog recovery restores controls and scopes drafts and messages', async t => {
|
||||
const { b, wait, set, click, route, refresh } = await setup(t);
|
||||
await b.evaluate('window.__failurePath="/sessions";window.__readFailure="access-refused";true');
|
||||
await route(A);
|
||||
assert.match(await b.evaluate('document.querySelector(".chat-area").textContent'), /sessions.*not.*available/i);
|
||||
await set('#chat-body', 'legacy draft');
|
||||
await b.evaluate(`window.__readFailure=null;window.__sessions['${A}']=[{id:'${B}',name:'default',default:true,state:'active',revision:2}];window.__pages.push({rows:[{id:'${M}',body:'session history',from_role:'assistant',at:'2026-10-18T00:00:00Z'}],after:'${M}',hasMore:false});true`);
|
||||
await refresh();
|
||||
assert.equal(await b.evaluate('document.querySelector("#chat-session")?.value'), B);
|
||||
assert.equal(await b.evaluate('!!document.querySelector("#chat-session-form") && !!document.querySelector("#chat-clear")'), true);
|
||||
assert.match(await b.evaluate('document.querySelector(".chat-log").textContent'), /session history/);
|
||||
assert.equal(await b.evaluate('document.querySelector("#chat-body").value'), '', 'legacy draft is not copied into another session');
|
||||
await set('#chat-body', 'session draft');
|
||||
await b.evaluate(`window.__answers.push({body:{id:'${P}'}}),true`);
|
||||
await click('#chat-send-form button');
|
||||
await wait('document.querySelector("#chat-receipt").textContent.includes("Accepted")');
|
||||
assert.deepEqual(await b.evaluate('window.__writes[0].body'), { body: 'session draft', session: B });
|
||||
await b.evaluate('window.__readFailure="access-refused";true');
|
||||
await refresh();
|
||||
assert.equal(await b.evaluate('document.querySelector("#chat-body").value'), 'legacy draft');
|
||||
});
|
||||
test('chat browser: list/create named projects and threads, hostile labels inert and no implicit writes', async t => {
|
||||
const { b, wait, set, click } = await setup(t);
|
||||
assert.equal(await b.evaluate('window.__writes.length'), 0);
|
||||
|
||||
@@ -40,6 +40,7 @@ const stub = `(() => {
|
||||
if(path==='/api/library/revert'){window.__writes.push({path,body:JSON.parse(init.body)});return answer({project:'books',path:'Notes/One.md',reverted:'${SHA}',commit:'${LAST}'});}
|
||||
if(!path.startsWith('/api/chat/'))return real(url,init);
|
||||
if(method==='GET')window.__reads.push(path);
|
||||
if(method==='GET' && window.__chatOffline)throw new TypeError('offline');
|
||||
if(path==='/api/chat/projects')return answer({rows:window.__projects});
|
||||
if(path==='/api/chat/instances')return answer({rows:window.__instances});
|
||||
if(path.includes('/rooms/')){
|
||||
@@ -84,6 +85,29 @@ test('disabled room read shows unavailable history and disables opening', async
|
||||
assert.equal(await b.evaluate('document.querySelector("#chat-room-open").disabled'), true);
|
||||
assert.equal(await b.evaluate('window.__writes.length'), 0);
|
||||
});
|
||||
test('room keeps a known disabled channel through a failed refresh and recovers on a successful read', async t => {
|
||||
const { b, wait, text } = await setup(t);
|
||||
const refresh = async () => {
|
||||
await wait('!document.querySelector("#refresh").disabled');
|
||||
await b.evaluate('document.querySelector(".chat-area").dataset.beforeRefresh="yes";document.querySelector("#refresh").click();true');
|
||||
await wait('!document.querySelector(".chat-area")?.dataset.beforeRefresh');
|
||||
};
|
||||
assert.match(await text('.chat-room-log'), /Broadcast once/);
|
||||
await b.evaluate('window.__readError="channel-disabled";true');
|
||||
await refresh();
|
||||
assert.match(await text('.chat-error'), /channel.*disabled/i);
|
||||
assert.equal(await b.evaluate('document.querySelector("#chat-room-open").disabled'), true);
|
||||
await b.evaluate('window.__readError=null;window.__chatOffline=true;true');
|
||||
await refresh();
|
||||
assert.equal(await b.evaluate('document.querySelector("#chat-room-open").disabled'), true);
|
||||
await b.evaluate('document.querySelector("#chat-room-open").dispatchEvent(new MouseEvent("click",{bubbles:true}));true');
|
||||
assert.equal(await b.evaluate('window.__writes.length'), 0, 'the write guard also refuses a synthetic click');
|
||||
assert.match(await text('.chat-room-log'), /Broadcast once/);
|
||||
await b.evaluate('window.__chatOffline=false;true');
|
||||
await refresh();
|
||||
assert.equal(await b.evaluate('document.querySelector("#chat-room-open").disabled'), false);
|
||||
assert.equal(await b.evaluate('window.__writes.length'), 0, 'recovery reads never open a room');
|
||||
});
|
||||
test('C2-10c room merges members, shows a broadcast once, reuses cited renderer and suppresses checked notice forgery', async t => {
|
||||
const { b, wait, text } = await setup(t);
|
||||
await wait('document.querySelector(".chat-cites")');
|
||||
|
||||
Reference in new issue
Block a user