// TestAIBrowserSmoke supplies a disposable API, random schema and fake providers. const {chromium}=require(process.env.PLAYWRIGHT_MODULE||'playwright'); const assert=require('node:assert/strict'); (async()=>{ const api=process.env.AI_E2E_API,token=process.env.AI_E2E_TOKEN,url=process.env.AI_E2E_URL; assert(api&&token&&url,'Use the disposable Go browser fixture'); const browser=await chromium.launch({headless:true,args:['--no-sandbox']}); try{ const page=await browser.newPage(),errors=[];page.setDefaultTimeout(15000);page.on('pageerror',e=>errors.push(e.message)); const headers={Authorization:`Bearer ${token}`}; await page.goto(url);await page.evaluate(t=>localStorage.setItem('speech_token',t),token);await page.reload(); await page.getByRole('button',{name:'Adminbereich',exact:true}).click(); const admin=page.getByRole('region',{name:'KI-Verwaltung'}); await admin.getByText('KI-Aufrufe sind gesperrt, bis ein positives Monatsbudget eingerichtet ist.',{exact:true}).waitFor(); await admin.getByLabel('Monatslimit in USD',{exact:true}).fill('1'); await admin.getByRole('button',{name:'Budget speichern',exact:true}).click();await admin.getByText('Budget gespeichert.',{exact:true}).waitFor(); await admin.getByLabel('Modell-ID',{exact:true}).fill('fixture-model'); await admin.getByLabel('Kontextbudget · Ein- und Ausgabe',{exact:true}).fill('131072'); await admin.getByLabel('Eingabe',{exact:true}).fill('1');await admin.getByLabel('Ausgabe',{exact:true}).fill('2'); await admin.getByLabel('Preise mit aktuellen Anbieterpreisen abgeglichen',{exact:true}).check(); await admin.getByRole('button',{name:'Modellprofil speichern',exact:true}).click(); await admin.getByText('Neue Profilversion gespeichert. Vor Freigabe mit richtigen und falschen Antworten testen.',{exact:true}).waitFor(); await admin.getByRole('button',{name:'Modellliste laden / Verbindung prüfen',exact:true}).click();await admin.getByText(/1 Modelle geladen/).waitFor(); await admin.getByRole('button',{name:'Bewertungsqualität prüfen · 2 kostenpflichtige Testfälle',exact:true}).click(); await admin.locator('pre').filter({hasText:'"passed": true'}).first().waitFor({timeout:15000}); assert.equal(await admin.getByRole('table').getByRole('row').count(),3); await admin.getByRole('button',{name:'Schreibbewertung prüfen · 2 kostenpflichtige Testfälle',exact:true}).click(); await admin.locator('pre').filter({hasText:'"suite": "writing"'}).first().waitFor(); const writingQuality=JSON.parse(await admin.locator('pre').filter({hasText:'"suite": "writing"'}).first().innerText());assert.equal(writingQuality.suite,'writing');assert.equal(writingQuality.passed,true); assert.equal(await admin.getByRole('table').getByRole('row').count(),5); const settings=await(await page.request.get(`${api}/admin/ai/settings`,{headers})).json(); for(const p of Object.values(settings.profiles)){ Object.assign(p,{enabled:true,model:'fixture-model',pricing_set:true,context_tokens:131072,input_microusd_per_million:1000000,cached_input_microusd_per_million:0,output_microusd_per_million:2000000}); const r=await page.request.put(`${api}/admin/ai/profiles/${p.action}`,{headers,data:p});assert.equal(r.status(),200); } await admin.getByRole('button',{name:'Anzeigen',exact:true}).first().click(); const details=admin.getByRole('region',{name:'KI-Aufrufdetails'});await details.waitFor(); await details.locator('pre').waitFor(); await page.waitForFunction(()=>{const el=document.querySelector('[aria-label="KI-Aufrufdetails"]');return el&&document.activeElement===el&&el.getBoundingClientRect().top>=-1&&el.getBoundingClientRect().topdocument.activeElement===el)); // A failed detail request must be visible at the same place as successful details. await page.route('**/admin/ai/calls/*',route=>route.fulfill({status:503,contentType:'application/json',body:JSON.stringify({error:'Details-Testfehler'})})); await admin.getByRole('button',{name:'Anzeigen',exact:true}).first().click(); await details.getByRole('alert').filter({hasText:'Der Dienst ist vorübergehend nicht verfügbar.'}).waitFor(); await details.getByRole('button',{name:'Schließen',exact:true}).click(); await page.unroute('**/admin/ai/calls/*'); await page.getByRole('button',{name:'A1-Kurs',exact:true}).click(); const modules=page.getByRole('navigation',{name:'A1-Module'}).getByRole('button');await modules.nth(6).waitFor();assert.equal(await modules.count(),7); await modules.nth(1).click();const areas=page.getByRole('group',{name:'Lernbereich'}); const exercise=page.getByRole('region',{name:'Aktuelle Kursaufgabe'}); async function generate(area){await areas.getByRole('button',{name:area,exact:true}).click();await page.getByRole('button',{name:'Nächste Aufgabe',exact:true}).click();await exercise.getByText('Mit KI erstellt',{exact:false}).waitFor({timeout:15000});await page.getByRole('button',{name:'Nächste Aufgabe',exact:true}).waitFor();} await generate('Grammatik');assert.equal(await exercise.getByText('Private Testlösung',{exact:true}).count(),0); await exercise.getByRole('radio').first().check();await exercise.getByRole('button',{name:'Antwort prüfen',exact:true}).click();await exercise.getByText('100 / 100 · Richtig',{exact:true}).waitFor(); await page.reload();await page.getByRole('button',{name:'A1-Kurs',exact:true}).click();await exercise.getByText('100 / 100 · Richtig',{exact:true}).waitFor(); await generate('Schreiben');await exercise.getByRole('textbox').fill('He has got a sister.');await exercise.getByRole('button',{name:'Antwort prüfen',exact:true}).click();await exercise.getByText('100 / 100 · Richtig',{exact:true}).waitFor({timeout:15000}); await modules.nth(6).click();await page.getByRole('button',{name:'Neuen A1-Test starten · 12 Aufgaben',exact:true}).click(); const exam=page.getByRole('region',{name:'A1-Test'});await exam.getByRole('button').nth(11).waitFor({timeout:15000});assert.equal(await exam.getByRole('button').count(),12); await exercise.getByText('Mit KI erstellt',{exact:false}).waitFor(); const catalog=await(await page.request.get(`${api}/course/catalog`,{headers})).json();const data=await(await page.request.get(`${api}/course/exams/${catalog.exams[0].id}`,{headers})).json(); for(const task of data.tasks){assert.equal(task.source,'ai');assert.equal(task.answer_key,undefined);assert.equal(task.audio_text,undefined)} await page.request.put(`${api}/admin/ai/budget`,{headers,data:{monthly_limit_microusd:0,daily_limit_microusd:0}}); await modules.nth(1).click();await areas.getByRole('button',{name:'Grammatik',exact:true}).click();await page.getByRole('button',{name:'Nächste Aufgabe',exact:true}).click(); await exercise.getByText('Geprüfte Ersatzaufgabe',{exact:false}).waitFor({timeout:15000}); const report=await(await page.request.get(`${api}/admin/ai/usage`,{headers})).json();assert(report.total>5);assert(report.input_tokens>0);assert(report.estimated_cost_microusd>0); assert.deepEqual(errors,[]); console.log('PASS: admin profiles/prices/budget/model list, quality tests, private details, direct author+reviewer, async grading, reload, AI exam privacy, budget-blocked seed fallback; no browser errors.'); }finally{await browser.close()} })().catch(e=>{console.error(e);process.exitCode=1});