Files
nexus/scripts/ui-pruefung/chat-umbenennen.mjs

42 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Chat in der Seitenleiste umbenennen: Name bleibt nach weiterer Frage und Neuladen, Escape und leerer Name ändern nichts.
// Aufruf: node chat-umbenennen.mjs <Passwort> (Testinstanz mit Modell chat und fake_llama_lang.py, NEXUS_BASE)
import * as cdp from './lib.mjs';
const BASE=process.env.NEXUS_BASE||'http://127.0.0.1:18123', pw=process.argv[2];
const b=await cdp.start({port:9371});
const ok=(n,c,d='')=>{console.log(`${c?'ok ':'FEHLER'} ${n}${d?' – '+d:''}`); if(!c) process.exitCode=1;};
const warte=ms=>new Promise(r=>setTimeout(r,ms));
const titel=()=>b.eval(`[...document.querySelectorAll('#chat-liste li .titel, #chat-liste li .titel-eingabe')].map(x=>x.tagName==='INPUT'?x.value:x.textContent).join('|')`);
const frage=async t=>{ await b.eval(`document.getElementById('chat-text').value=${JSON.stringify(t)}`); await b.eval(`document.getElementById('chat-senden').click()`);
for(let i=0;i<400;i++){ await warte(500); if(await b.eval(`!document.getElementById('chat-senden').disabled && document.querySelectorAll('.blase.assistant').length>0`)) break; } await warte(1500); };
const tippe=async t=>{ await b.eval(`(()=>{const f=document.querySelector('.titel-eingabe'); f.value=${JSON.stringify(t)};})()`); };
const taste=async k=>{ await b.send('Input.dispatchKeyEvent',{type:'keyDown',key:k,code:k,windowsVirtualKeyCode:k==='Enter'?13:27}); await b.send('Input.dispatchKeyEvent',{type:'keyUp',key:k,code:k,windowsVirtualKeyCode:k==='Enter'?13:27}); await warte(600); };
try{
await b.login(BASE,'claude',pw);
await b.goto(BASE+'/ui/chat'); await warte(1000);
await frage('Erste Frage zum Scheduler');
ok('Titel kommt zunächst aus der ersten Frage', /Erste Frage/.test(await titel()), await titel());
const knopf=()=>b.eval(`(()=>{const k=[...document.querySelectorAll('#chat-liste li button')].find(x=>x.textContent==='Umbenennen'); if(!k) return false; k.click(); return true;})()`);
ok('Knopf „Umbenennen“ vorhanden', await knopf());
await tippe('Nexus Architektur'); await taste('Enter');
ok('Neuer Name steht in der Liste', (await titel())==='Nexus Architektur', await titel());
// Escape ändert nichts
await knopf(); await tippe('Wird verworfen'); await taste('Escape');
ok('Escape verwirft', (await titel())==='Nexus Architektur', await titel());
// leerer Name ändert nichts
await knopf(); await tippe(' '); await taste('Enter');
ok('Leerer Name ändert nichts', (await titel())==='Nexus Architektur', await titel());
// weitere Frage: Name bleibt
await frage('Zweite Frage dazu');
ok('Name bleibt nach der nächsten Frage', (await titel())==='Nexus Architektur', await titel());
// Neuladen: vom Server
await warte(1500); await b.goto(BASE+'/ui/chat'); await warte(1500);
ok('Name bleibt nach Neuladen (Server)', /Nexus Architektur/.test(await titel()), await titel());
const json=await b.eval(`fetch('/ui/chat/verlauf').then(r=>r.json()).then(l=>l.map(c=>({titel:c.titel,manuell:!!c.titelManuell,n:c.nachrichten.length})))`);
console.log(' Server:', JSON.stringify(json));
ok('Server hat Namen und Marke', json.length===1 && json[0].titel==='Nexus Architektur' && json[0].manuell && json[0].n>=4);
// Suche findet den neuen Namen
await b.eval(`(()=>{const s=document.getElementById('chat-suche'); s.value='architektur'; s.dispatchEvent(new Event('input',{bubbles:true}));})()`); await warte(500);
ok('Suche findet den neuen Namen', /Nexus Architektur/.test(await titel()));
await b.shot('/tmp/umbenennen.png');
}catch(e){console.log('Fehler im Lauf:',e.message); process.exitCode=1;} finally{b.close();}