import { chromium, expect } from '@playwright/test'; import fs from 'node:fs'; import assert from 'node:assert/strict'; import { login, call } from './role-permissions-live.mjs'; const dir='reports/bridge-scripted-tasks-20260913', session=await login('root'); const tasks=JSON.parse(fs.readFileSync(`${dir}/registered.json`,'utf8')), checks=[], writes=[]; const browser=await chromium.launch({channel:'msedge',headless:true,args:['--enable-unsafe-swiftshader']}); try { const page=await browser.newPage({viewport:{width:1600,height:1000}}); await page.addInitScript(s=>sessionStorage.setItem('unreal-tran:web:access-token:v1',s.accessToken),session); page.on('request',r=>{if(r.method()!=='GET'&&new URL(r.url()).pathname.startsWith('/api/tran/'))writes.push(new URL(r.url()).pathname)}); for(const task of tasks){ await page.goto('http://127.0.0.1:6180'+task.previewUrl); const procedure=task.presentation==='procedure'; if(procedure)await expect(page.locator('.bridge-procedure h2')).toHaveText(task.name); else await expect(page.locator('[data-role="loading"]')).toHaveClass(/is-hidden/,{timeout:120000}); const response=page.waitForResponse(r=>r.url().includes(`/assignments/${task.id}/preview/validate`)); await (procedure?page.getByRole('button',{name:'完成本步并保存',exact:true}):page.locator('[data-role="part-label"]')).click(); assert.equal((await response).status(),200); const runs=await call(`tran/v1/teaching/runs?channel=VIRTUAL&assignmentKind=TRAINING&assignmentId=${task.id}&size=100`,session.accessToken); assert.equal(runs.status,200);assert.equal(runs.data.total,0); checks.push(`${task.code} 教员预览使用服务端校验,未创建训练运行`); } assert.ok(writes.every(path=>path.endsWith('/preview/validate'))); fs.writeFileSync(`${dir}/normal-preview.json`,JSON.stringify({pass:true,checks,writes},null,2)); console.log('PASS: four previews validate without writing learner progress or scores'); } finally {await browser.close()}