feat(chat): broker Codex approvals and complete typed tool interactions

This commit is contained in:
2026-10-20 17:41:35 +01:00
parent f31806cfcb
commit 35329e4022
21 changed files with 879 additions and 84 deletions
+13
View File
@@ -127,12 +127,25 @@ try {
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');
if(id==='form_second') {
await page.evaluate("(()=>{const s=document.querySelector('[data-form-id=form_second] select');s.value='true';s.dispatchEvent(new Event('change',{bubbles:true}));})()");
await page.fill('[data-form-id=form_second] input[aria-label="Only when enabled"]','must not leak');
await page.evaluate("(()=>{const s=document.querySelector('[data-form-id=form_second] select');s.value='false';s.dispatchEvent(new Event('change',{bubbles:true}));})()");
await page.fill('[data-form-id=form_second] input[type=number]','0');
assert.equal(await page.evaluate("document.querySelector('[data-form-id=form_second] input[aria-label=\"Only when enabled\"]').closest('.chat-question-field').getBoundingClientRect().height"),0);
assert.equal(await page.evaluate("document.querySelector('[data-form-id=form_second] input[aria-label=Secret]').type"),'password');
if(process.env.PIPELINES_CAPTURE_DIR) await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR,'typed-question-controls.png'));
}
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.equal((await fetch(`http://${target}/fixture-cancel`,{method:'POST'})).status,204);
await page.waitForSelector('[data-form-id=form_cancel]');
await page.evaluate("[...document.querySelectorAll('[data-form-id=form_cancel] button')].find(button=>button.textContent==='Cancel question').click()");
await eventually(()=>page.evaluate("!document.querySelector('[data-form-id=form_cancel]')"));
assert.deepEqual(await page.evaluate("window.__errors"), []);
console.log("Model dialog, stable activity mark, keyboard/caret, Back restoration, send-to-bottom and all recovered approvals/questions passed.");
} finally {
+26
View File
@@ -0,0 +1,26 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {formFieldValue,formAnswerError,visibleFormAnswers,safeFormURL} from '../src/chatForms.js';
test('typed questions preserve false and zero, and reject invalid numeric answers',()=>{
const fields=[{key:'yes',type:'boolean',required:true},{key:'count',type:'integer',required:true,minimum:0,maximum:5}];
const answers={yes:formFieldValue(fields[0],'false'),count:formFieldValue(fields[1],'0')};
assert.deepEqual(answers,{yes:false,count:0});
assert.equal(formAnswerError(fields,answers),'');
assert.match(formAnswerError(fields,{...answers,count:1.5}),/integer/);
assert.match(formAnswerError(fields,{...answers,count:6}),/at most/);
assert.match(formAnswerError(fields,{...answers,count:NaN}),/valid/);
});
test('conditional and hidden fields never send stale answers',()=>{
const fields=[{key:'yes',type:'boolean'},{key:'extra',type:'string',required:true,when:[{key:'yes',op:'eq',value:true}]},{key:'hidden',hidden:true}];
const answers={yes:false,extra:'stale',hidden:'hidden'};
assert.deepEqual(visibleFormAnswers(fields,answers),{yes:false});
assert.equal(formAnswerError(fields,answers),'');
assert.match(formAnswerError(fields,{yes:true}),/extra/);
});
test('external question links accept only explicit HTTP(S) URLs',()=>{
assert.equal(safeFormURL('https://example.test/form'),'https://example.test/form');
for(const value of ['javascript:alert(1)','file:///etc/passwd','//example.test','bad'])assert.equal(safeFormURL(value),null);
});
+6 -1
View File
@@ -1,6 +1,6 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { applyChatForm, applyChatPermission, chatApprovalCards, chatPendingForms } from '../src/chat.js';
import { applyChatForm, applyChatPermission, chatApprovalCards, chatPendingForms, approvalCard } from '../src/chat.js';
test('parallel approvals stay independently actionable and resolve by identity',()=>{
let thread={};
@@ -12,6 +12,11 @@ test('parallel approvals stay independently actionable and resolve by identity',
assert.deepEqual(chatApprovalCards(thread),[]);
});
test('Codex session-scoped approval is never described as a permanent grant',()=>{
const card=approvalCard({request_id:'a',always_label:'Allow for session',resolved:true,decision:'always'},'');
assert.equal(card.headline,'Allowed for session');
});
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:[]});