fix(chat): recover web approvals and questions across clients and reconnects
This commit is contained in:
@@ -107,8 +107,34 @@ try {
|
||||
await page.fill("#chatInput", "New message must scroll into view");
|
||||
await page.click("#chatSend");
|
||||
await eventually(() => page.evaluate("(() => { const t=document.querySelector('#chatTranscript'); return t.textContent.includes('New message must scroll into view') && t.scrollHeight-t.scrollTop-t.clientHeight<3; })()"));
|
||||
// These requests originate at the broker snapshot, not an injected browser
|
||||
// frame. A reload must recover all of them, and each control reaches Go.
|
||||
assert.equal((await fetch(`http://${target}/fixture-attention`,{method:'POST'})).status,204);
|
||||
await eventually(() => page.evaluate("document.querySelectorAll('.chat-approval-pending').length===2 && document.querySelectorAll('.chat-question').length===2"));
|
||||
await page.goto(`http://127.0.0.1:${port}/chat/${sessionId}`);
|
||||
try {
|
||||
await eventually(() => page.evaluate("document.querySelectorAll('.chat-approval-pending').length===2 && document.querySelectorAll('.chat-question').length===2"));
|
||||
} catch(error) {
|
||||
console.log(await page.evaluate("({approvals:document.querySelectorAll('.chat-approval-pending').length,questions:document.querySelectorAll('.chat-question').length,errors:window.__errors,text:document.body.innerText.slice(-2000)})"));
|
||||
throw error;
|
||||
}
|
||||
assert.equal(await page.evaluate("!!document.querySelector('.chat-approval-jump')"),true);
|
||||
await page.click('.chat-approval-jump');
|
||||
if(process.env.PIPELINES_CAPTURE_DIR) await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR,'mobile-pending-interactions.png'));
|
||||
await page.evaluate("document.querySelector('[data-request-id=per_first] .chat-approval-control').click()");
|
||||
await eventually(() => page.evaluate("document.querySelectorAll('.chat-approval-pending').length===1"));
|
||||
await page.evaluate("document.querySelector('[data-request-id=per_second] .chat-approval-control:last-child').click()");
|
||||
await eventually(() => page.evaluate("document.querySelectorAll('.chat-approval-pending').length===0"));
|
||||
for(const id of ['form_first','form_second']) {
|
||||
await page.fill(`[data-form-id=${id}] .chat-question-input`,'Browser answer');
|
||||
await emit({message_id:'msg_answer',kind:'text',part:{id:'draft-check',type:'text',text:'unrelated frame'}});
|
||||
await eventually(() => page.evaluate(`document.querySelector('[data-form-id=${id}] .chat-question-input')?.value==='Browser answer'`));
|
||||
await page.evaluate(`document.querySelector('[data-form-id=${id}] .chat-question-submit').click()`);
|
||||
await eventually(() => page.evaluate(`!document.querySelector('[data-form-id=${id}]')`));
|
||||
}
|
||||
await eventually(() => page.evaluate("!document.querySelector('.chat-approval-jump')"));
|
||||
assert.deepEqual(await page.evaluate("window.__errors"), []);
|
||||
console.log("Model dialog, stable activity mark, keyboard/caret, Back restoration and send-to-bottom passed.");
|
||||
console.log("Model dialog, stable activity mark, keyboard/caret, Back restoration, send-to-bottom and all recovered approvals/questions passed.");
|
||||
} finally {
|
||||
await browser?.close();
|
||||
serve.kill("SIGTERM");
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { applyChatForm, applyChatPermission, chatApprovalCards, chatPendingForms } from '../src/chat.js';
|
||||
|
||||
test('parallel approvals stay independently actionable and resolve by identity',()=>{
|
||||
let thread={};
|
||||
for(const id of ['a','b']) thread=applyChatPermission(thread,{session_id:'s',request_id:id,action:'shell'});
|
||||
assert.deepEqual(chatApprovalCards(thread).map(c=>c.requestId),['a','b']);
|
||||
thread=applyChatPermission(thread,{session_id:'s',request_id:'a',resolved:true});
|
||||
assert.deepEqual(chatApprovalCards(thread).map(c=>c.requestId),['b']);
|
||||
thread=applyChatPermission(thread,{session_id:'s',request_id:'b',resolved:true});
|
||||
assert.deepEqual(chatApprovalCards(thread),[]);
|
||||
});
|
||||
|
||||
test('parallel questions survive replies and cancellation of a different question',()=>{
|
||||
let thread={};
|
||||
for(const id of ['a','b']) thread=applyChatForm(thread,{id,session_id:'s',fields:[]});
|
||||
assert.deepEqual(chatPendingForms(thread).map(f=>f.id),['a','b']);
|
||||
thread=applyChatForm(thread,{id:'a',resolved:true});
|
||||
assert.deepEqual(chatPendingForms(thread).map(f=>f.id),['b']);
|
||||
thread=applyChatForm(thread,{id:'b',cancelled:true});
|
||||
assert.deepEqual(chatPendingForms(thread),[]);
|
||||
});
|
||||
Reference in New Issue
Block a user