test: Versuch zur Engine-Oberfläche: Sandbox dicht, Oberfläche läuft darin nicht; Entscheidung #1241 offen (#1101)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
48
scripts/ui-pruefung/engine-oberflaeche.mjs
Normal file
48
scripts/ui-pruefung/engine-oberflaeche.mjs
Normal file
@ -0,0 +1,48 @@
|
||||
// admin2engineoberflaeche.2 und .3 (#1101): Die Oberfläche von llama.cpp über das Gateway im Chromium öffnen (Knopf auf
|
||||
// der Karte), Sandbox prüfen (leere Herkunft, kein Cookie, kein Zugriff auf die Seiten des Gateways), eine Antwort streamen.
|
||||
// Aufruf: node engine-oberflaeche.mjs <Testpasswort> <API-Key> (Benutzer `claude`, `NEXUS_BASE`, Standard http://127.0.0.1:18127;
|
||||
// `NEXUS_MODELL` Standard `qwen-klein`; Testinstanz mit echtem llama.cpp und einem kleinen Modell). Nicht gegen die Produktion.
|
||||
import * as cdp from './lib.mjs';
|
||||
const BASE = process.env.NEXUS_BASE || 'http://127.0.0.1:18127', pw = process.argv[2], key = process.argv[3];
|
||||
const MODELL = process.env.NEXUS_MODELL || 'qwen-klein';
|
||||
const AUS = process.env.NEXUS_AUS || '/tmp';
|
||||
const b = await cdp.start({ port: 9379 });
|
||||
const ergebnisse = [];
|
||||
const pruefe = (name, ok, extra = '') => { ergebnisse.push(ok); console.log(ok ? 'OK ' : 'FEHL', name, extra); };
|
||||
const warte = ms => new Promise(r => setTimeout(r, ms));
|
||||
try {
|
||||
await b.login(BASE, 'claude', pw);
|
||||
// Modell laden (eine Anfrage), damit die Engine eine Instanz hat.
|
||||
const geladen = await b.eval(`fetch(${JSON.stringify(BASE + '/v1/chat/completions')},{method:'POST',headers:{'content-type':'application/json',authorization:'Bearer ${key}'},body:JSON.stringify({model:${JSON.stringify(MODELL)},max_tokens:4,messages:[{role:'user',content:'Hallo'}]})}).then(r=>r.status)`);
|
||||
pruefe('Modell geladen (Anfrage 200)', geladen === 200, `(${geladen})`);
|
||||
await warte(5500);
|
||||
await b.goto(BASE + '/ui/engines');
|
||||
const hat = await b.eval(`!!document.querySelector('form[action="/ui/engine/llama.cpp/oeffnen"] button')`);
|
||||
pruefe('Karte llama.cpp hat den Knopf „Oberfläche öffnen“', hat);
|
||||
const hinweis = await b.eval(`/ohne Warteschlange, am Scheduler vorbei und ohne Eintrag im Anfrage-Protokoll/.test(document.body.innerText)`);
|
||||
pruefe('Hinweis auf den direkten Weg steht auf der Karte', hinweis);
|
||||
await b.eval(`(()=>{const f=document.querySelector('form[action="/ui/engine/llama.cpp/oeffnen"]'); f.target='_self'; f.submit();})()`);
|
||||
await warte(5000);
|
||||
const ort = await b.eval(`JSON.stringify({pfad:location.pathname, herkunft:window.origin, titel:document.title, text:document.body?document.body.innerText.slice(0,200):''})`);
|
||||
console.log('Seite:', ort);
|
||||
for (const ev of b.events) { if (ev.method === 'Runtime.exceptionThrown') console.log('Ausnahme:', (ev.params.exceptionDetails.exception?.description || ev.params.exceptionDetails.text || '').slice(0, 300)); if (ev.method === 'Runtime.consoleAPICalled' && ['error','warning'].includes(ev.params.type)) console.log('Konsole', ev.params.type + ':', ev.params.args.map(a => a.value ?? a.description ?? '').join(' ').slice(0, 300)); if (ev.method === 'Log.entryAdded' && ev.params.entry.level==='error') console.log('Log:', ev.params.entry.text.slice(0,200), ev.params.entry.url||''); }
|
||||
const o = JSON.parse(ort);
|
||||
pruefe('Adresse hat das Token im Pfad', /^\/ui\/engine\/llama\.cpp\/t\/[0-9a-f]{64}\/$/.test(o.pfad), o.pfad.replace(/[0-9a-f]{64}/, '<token>'));
|
||||
pruefe('Die Seite läuft in einer Sandbox (leere Herkunft)', o.herkunft === 'null', `(${o.herkunft})`);
|
||||
await b.shot(`${AUS}/engine-oberflaeche-1.png`);
|
||||
const eig = await b.eval(`(async()=>{const r={};
|
||||
try { r.cookie = document.cookie; } catch(e) { r.cookie = ''; r.cookieFehler = e.name; }
|
||||
try { await fetch('/ui/engines'); r.zugriff='gelesen'; } catch(e) { r.zugriff='blockiert'; }
|
||||
try { localStorage.setItem('x','1'); r.speicher='ok'; } catch(e) { r.speicher='gesperrt: '+e.name; }
|
||||
try { r.api = (await fetch('/props')).status; } catch(e) { r.api='Fehler'; }
|
||||
return JSON.stringify(r); })()`);
|
||||
console.log('Eigenschaften:', eig);
|
||||
const e = JSON.parse(eig);
|
||||
pruefe('Kein Cookie in der Seite', e.cookie === '');
|
||||
pruefe('Kein Lesezugriff auf die Seiten des Gateways', e.zugriff === 'blockiert');
|
||||
const bild = await b.eval(`document.querySelectorAll('textarea,input,button').length`);
|
||||
pruefe('Die Oberfläche hat Bedienelemente (nicht leer)', bild > 0, `(${bild})`);
|
||||
} finally { b.close(); }
|
||||
const fehl = ergebnisse.filter(x => !x).length;
|
||||
console.log(fehl ? `${fehl} Prüfung(en) fehlgeschlagen` : `Alle ${ergebnisse.length} Prüfungen bestanden`);
|
||||
process.exit(fehl ? 1 : 0);
|
||||
Reference in New Issue
Block a user