feat: edit validated per-model engine start profiles (#1070)

This commit is contained in:
2026-11-17 15:08:41 +01:00
parent 51604eebf6
commit 8ec8d6af7f
22 changed files with 1404 additions and 16 deletions

View File

@ -26,12 +26,15 @@ try {
let id = 0;
const pending = new Map();
const requests = [];
const loaded = new Set();
socket.onmessage = event => {
const data = JSON.parse(event.data);
if (data.id) {
const call = pending.get(data.id);
pending.delete(data.id);
if (data.error) { call.reject(new Error(data.error.message)); } else { call.resolve(data.result); }
} else if (data.method === 'Page.lifecycleEvent' && data.params.name === 'load') {
loaded.add(data.params.loaderId);
} else if (data.method === 'Network.requestWillBeSent' && data.params.request.url.endsWith('/ui/chat/senden')) {
requests.push(JSON.parse(data.params.request.postData));
}
@ -48,7 +51,7 @@ try {
const page = (method, params) => call(method, params, sessionId);
const evaluate = async expression => {
const result = await page('Runtime.evaluate', { expression, returnByValue: true });
if (result.exceptionDetails) { throw new Error(result.exceptionDetails.text); }
if (result.exceptionDetails) { throw new Error(result.exceptionDetails.exception?.description || result.exceptionDetails.text); }
return result.result.value;
};
async function until(expression) {
@ -61,10 +64,47 @@ try {
}
await page('Network.enable');
await page('Page.enable');
await page('Page.setLifecycleEventsEnabled', { enabled: true });
async function navigate(url) {
const nav = await page('Page.navigate', { url });
const deadline = Date.now() + 15000;
while (!loaded.has(nav.loaderId)) {
if (Date.now() > deadline) { throw new Error('Browserseite lädt nicht vollständig'); }
await new Promise(resolve => setTimeout(resolve, 20));
}
}
const cookie = process.env.NEXUS_TEST_COOKIE.split('=');
await page('Network.setCookie', { name: cookie[0], value: cookie.slice(1).join('='),
url: `${process.env.NEXUS_TEST_BASE}/ui`, path: '/ui', httpOnly: true, sameSite: 'Strict' });
await page('Page.navigate', { url: `${process.env.NEXUS_TEST_BASE}/ui/chat` });
if (process.env.NEXUS_TEST_ADMIN === '1') {
const goModels = async () => {
await navigate(`${process.env.NEXUS_TEST_BASE}/ui/modelle`);
await until(`!!document.querySelector('button[title="Bearbeiten"]')`);
await evaluate(`document.querySelector('button[title="Bearbeiten"]').click(); Array.from(document.querySelectorAll('dialog[open] summary')).find(s=>s.textContent==='Startparameter').click()`);
await until(`!!document.querySelector('dialog[open] input[name="p.context"]')`);
};
await goModels();
await evaluate(`var input=document.querySelector('dialog[open] input[name="p.context"]'); input.value='511'; input.form.requestSubmit()`);
await until(`document.body.textContent.includes('Typ oder Wertebereich')`);
await goModels();
await evaluate(`var input=document.querySelector('dialog[open] input[name="p.context"]'); input.value='8192'; document.querySelector('dialog[open] input[name="p.slots"]').value='4'; input.form.requestSubmit()`);
await until(`location.search.includes('startprofil') && !!document.querySelector('button[title="Bearbeiten"]')`);
await goModels();
assert.equal(await evaluate(`document.querySelector('dialog[open] input[name="p.context"]').value`), '8192');
await evaluate(`document.querySelector('dialog[open] input[name="modus"][value="standard"]').form.requestSubmit()`);
await until(`location.search.includes('startprofil') && !!document.querySelector('button[title="Bearbeiten"]')`);
await goModels();
assert.equal(await evaluate(`document.querySelector('dialog[open] input[name="p.context"]').value`), '');
await navigate(`${process.env.NEXUS_TEST_BASE}/ui/logs?quelle=audit&q=model.profile`);
await until(`!!document.querySelector('table[data-filtern="logs"]') && !!document.querySelector('.tabellenleiste')`);
assert.ok(await evaluate(`document.querySelector('table[data-filtern="logs"]').textContent.includes('model.profile.rejected')`));
assert.ok(await evaluate(`document.querySelector('table[data-filtern="logs"]').textContent.includes('model.profile.set')`));
assert.ok(await evaluate(`document.querySelector('table[data-filtern="logs"]').textContent.includes('model.profile.restore')`));
await evaluate(`document.querySelector('.tabellenleiste input').value='model.profile.set'; document.querySelector('.tabellenleiste input').dispatchEvent(new Event('input'))`);
assert.ok(await evaluate(`Array.from(document.querySelectorAll('table[data-filtern="logs"] tbody tr')).filter(r=>!r.hidden).every(r=>r.textContent.includes('model.profile.set'))`));
console.log('Chromium: Startprofil bearbeiten, ungültige Eingabe, Standard wiederherstellen, Audit und vorhandene Tabellenfilter geprüft.');
} else {
await navigate(`${process.env.NEXUS_TEST_BASE}/ui/chat`);
await until('!!document.getElementById("chat-denkstufe")');
assert.equal(await evaluate('document.getElementById("chat-denkstufe").value'), 'medium');
for (const effort of ['medium', 'none', 'low', 'high', '']) {
@ -80,12 +120,18 @@ try {
await until('!document.getElementById("chat-senden").disabled && document.getElementById("chat-status").textContent.includes("Denkstufe nicht unterstützt")');
assert.equal(requests.at(-1).reasoning_effort, 'medium');
console.log('Chromium: Ladephase, alle Denkstufen, fehlendes Feld, eingeklappte Denkphase und Fallback geprüft.');
}
} finally {
socket?.close();
if (chrome.pid && chrome.exitCode === null && chrome.signalCode === null) {
const ended = new Promise(resolve => chrome.once('exit', resolve));
chrome.kill('SIGTERM');
// Chromium soll Profil-Schreiber zuerst selbst beenden und leeren.
if (socket?.readyState === WebSocket.OPEN) {
socket.send(JSON.stringify({ id: 0, method: 'Browser.close' }));
}
const fallback = setTimeout(() => chrome.kill('SIGTERM'), 3000);
await ended;
clearTimeout(fallback);
}
await rm(profile, { recursive: true, force: true });
socket?.close();
await rm(profile, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
}