Files
pipelines/web/test/chatInteractions.test.mjs
T

40 lines
2.1 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { applyChatForm, applyChatPermission, chatApprovalCards, chatPendingForms, approvalCard, applyChatEvent } 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('native turn identity rejects late completion and resync preserves queued intent',()=>{
let thread=applyChatEvent({messages:[],queued:true},{kind:'step',step:{status:'started',turn_id:'new'}},1);
thread={...thread,queued:true};
assert.equal(applyChatEvent(thread,{kind:'resync'}),thread);
thread=applyChatEvent(thread,{kind:'step',step:{status:'ended',turn_id:'old'}},2);
assert.equal(thread.running,true);
assert.equal(thread.queued,true);
thread=applyChatEvent(thread,{kind:'step',step:{status:'ended',turn_id:'new'}},3);
assert.equal(thread.running,false);
});
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:[]});
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),[]);
});