feat: Personas-Seite mit Übersicht, Editor, Wiederherstellen, Dirty-State und Testen-Verweis, Version 0.1.33 (#1199)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-29 16:04:29 +01:00
parent 56741a46b9
commit e0a70aeb11
9 changed files with 406 additions and 49 deletions

View File

@ -0,0 +1,53 @@
import * as cdp from './lib.mjs';
// Personas-Seite (#1199, R1): Übersicht, Suche, Editor, Dirty-State, Wiederherstellen, Breiten 1280/768/390/320 hell und dunkel.
// Aufruf: node personas-seite.mjs <Testpasswort> <Ausgabeordner>; Testinstanz mit leerer Datenbank (NEXUS_BASE, Standard http://127.0.0.1:18141), Benutzer claude (admin).
const BASE=process.env.NEXUS_BASE||'http://127.0.0.1:18141', pw=process.argv[2], AUS=process.argv[3]||'/tmp';
const b=await cdp.start({port:9411});
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 ev=x=>b.eval(x);
try{
await b.login(BASE,'claude',pw);
await b.goto(BASE+'/ui/personas'); await warte(500);
ok('leere Übersicht', /Noch keine Persona/.test(await ev('document.body.innerText')));
const lang='Zeile\n'.repeat(1500);
for(const [n,t,v] of [['Luna',lang,'Du bist Luna.'],['Karl','Sachlich.','']]){
await ev(`fetch('/ui/personas/speichern',{method:'POST',headers:{'content-type':'application/x-www-form-urlencoded'},body:new URLSearchParams({csrf:document.body.getAttribute('data-csrf'),id:'',name:${JSON.stringify(n)},systemprompt:${JSON.stringify(t||v)},stil:'',stimme:'',standard:${n==='Karl'?"'1'":"''"}})}).then(r=>r.status)`); }
const luna=await ev(`fetch('/ui/personas').then(r=>r.text()).then(t=>t.match(/personas\\?id=(\\d+)">Bearbeiten/g).join('|'))`);
console.log(luna);
for(const theme of ['light','dark']){
for(const [w,h] of [[1280,900],[768,900],[390,844],[320,568]]){
await b.viewport(w,h,{mobile:w<500});
await ev(`document.documentElement.setAttribute('data-theme','${theme}'); try{localStorage.setItem('theme','${theme}')}catch(e){}`);
for(const [name,url] of [['uebersicht','/ui/personas'],['editor','/ui/personas?id=1']]){
await b.goto(BASE+url); await ev(`document.documentElement.setAttribute('data-theme','${theme}')`); await warte(300);
const m=await ev(`({ueberlauf:document.documentElement.scrollWidth>document.documentElement.clientWidth+1, sw:document.documentElement.scrollWidth, cw:document.documentElement.clientWidth})`);
ok(`${name} ${w}px ${theme}: kein seitliches Scrollen`, !m.ueberlauf, JSON.stringify(m));
if(w===1280||w===390) await b.shot(`${AUS}/personas-${name}-${w}-${theme}.png`,{full:true});
}
}
}
await b.viewport(1280,900,{mobile:false});
// Suche
await b.goto(BASE+'/ui/personas'); await warte(300);
const n0=await ev(`document.querySelectorAll('.persona-karte:not([hidden])').length`);
await ev(`(()=>{const s=document.getElementById('persona-suche'); s.value='kar'; s.dispatchEvent(new Event('input',{bubbles:true}));})()`);
ok('Suche filtert Karten', n0===2 && (await ev(`document.querySelectorAll('.persona-karte:not([hidden])').length`))===1);
await ev(`(()=>{const s=document.getElementById('persona-suche'); s.value='xyz'; s.dispatchEvent(new Event('input',{bubbles:true}));})()`);
ok('Suche ohne Treffer zeigt Hinweis', await ev(`!document.getElementById('persona-leer').hidden`));
// Editor: Dirty-State
await b.goto(BASE+'/ui/personas?id=1'); await warte(300);
ok('Dirty zunächst verborgen', await ev(`document.querySelector('.persona-dirty').hidden`));
await ev(`(()=>{const f=document.querySelector('.persona-form').elements.name; f.value=f.value+'x'; f.dispatchEvent(new Event('input',{bubbles:true}));})()`);
ok('Dirty nach Änderung sichtbar', await ev(`!document.querySelector('.persona-dirty').hidden`));
await ev(`(()=>{const f=document.querySelector('.persona-form').elements.name; f.value=f.value.slice(0,-1); f.dispatchEvent(new Event('input',{bubbles:true}));})()`);
ok('Dirty verschwindet bei Rückgängig', await ev(`document.querySelector('.persona-dirty').hidden`));
ok('Zähler zeigt Zeichen', /von 32000 Zeichen/.test(await ev(`document.querySelector('.zeichenzahl').textContent`)));
// Speichern, dann Wiederherstellen
await ev(`(()=>{const f=document.querySelector('.persona-form'); f.elements.systemprompt.value='Neu'; f.elements.systemprompt.dispatchEvent(new Event('input',{bubbles:true})); f.requestSubmit();})()`); await warte(1200);
ok('Version 2 gespeichert', /Version 2/.test(await ev('document.body.innerText')));
await ev(`[...document.querySelectorAll('button')].find(x=>x.textContent.trim()==='Als neue Version wiederherstellen').click()`); await warte(1200);
const t=await ev('document.body.innerText');
ok('Wiederherstellen legt Version 3 an', /Version 3/.test(t) && /Das ist die aktuelle Version/.test(await ev('document.body.textContent')));
await b.goto(BASE+'/ui/personas'); ok('Testen-Verweis zeigt auf den Chat', await ev("[...document.querySelectorAll('.persona-karte a')].some(a=>a.textContent==='Testen' && a.getAttribute('href')==='/ui/chat?persona=1')"));
const kons=b.events.filter(e=>e.method==='Runtime.exceptionThrown'); ok('keine Skriptfehler', kons.length===0, JSON.stringify(kons.slice(0,2)));
}catch(e){console.log('FEHLER',e.message); process.exitCode=1;} finally{b.close();}