2026-10-12 16:41:42 +08:00
const assert = require ( 'node:assert/strict' ) , path = require ( 'node:path' ) , fs = require ( 'node:fs' )
const { chromium } = require ( 'C:/Users/Administrator/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright' )
; ( async ( ) => {
const login = await ( await fetch ( 'http://127.0.0.1:8080/login' , { method : 'POST' , headers : { 'Content-Type' : 'application/json' } , body : JSON . stringify ( { username : 'admin' , password : 'admin123' , code : '' , uuid : '' } ) } ) ) . json ( )
assert . equal ( login . code , 200 )
const headers = { Authorization : 'Bearer ' + login . token }
const menus = await ( await fetch ( 'http://127.0.0.1:8080/getRouters' , { headers } ) ) . json ( )
const routes = [ ]
function collect ( nodes , parent = '' ) { for ( const r of nodes || [ ] ) { const url = r . path . startsWith ( '/' ) ? r . path : ( parent + '/' + r . path ) . replace ( /\/+/g , '/' ) ; if ( r . children ? . length ) collect ( r . children , url ) ; else if ( r . component && ! r . hidden && ! /^https?:/ . test ( url ) ) routes . push ( { url , title : r . meta ? . title || r . name } ) } }
collect ( menus . data )
const browser = await chromium . launch ( { channel : 'chrome' , headless : true , args : [ '--disable-gpu' , '--js-flags=--max-old-space-size=256' ] } )
const out = path . resolve ( _ _dirname , '../../.codex-tmp/desktop-workbench-check' ) ; fs . mkdirSync ( out , { recursive : true } )
let page , context
try {
const errors = [ ] , apiFailures = [ ]
async function freshPage ( ) {
if ( context ) await context . close ( )
context = await browser . newContext ( { viewport : { width : 1440 , height : 900 } } )
await context . addCookies ( [ { name : 'Admin-Token' , value : login . token , url : 'http://127.0.0.1:8088' } ] )
page = await context . newPage ( ) ; page . setDefaultTimeout ( 15000 )
page . on ( 'pageerror' , e => errors . push ( e . message ) )
page . on ( 'response' , async r => { if ( r . url ( ) . includes ( '/dev-api/' ) && r . status ( ) >= 400 ) apiFailures . push ( r . status ( ) + ' ' + new URL ( r . url ( ) ) . pathname ) } )
await page . route ( '**/dev-api/**' , async route => { if ( ! [ 'GET' , 'HEAD' ] . includes ( route . request ( ) . method ( ) ) ) throw Error ( 'Unexpected business write in read-only UI regression: ' + route . request ( ) . url ( ) ) ; await route . continue ( ) } )
await page . goto ( 'http://127.0.0.1:8088/index' , { waitUntil : 'domcontentloaded' } )
await page . waitForFunction ( ( ) => { const vm = document . querySelector ( '.business-home' ) ? . _ _vue _ _ ; return vm ? . loadedOnce && ! vm . loading } )
}
await freshPage ( )
await page . waitForTimeout ( 450 )
assert . equal ( await page . locator ( '.home-todo' ) . count ( ) , 5 )
assert . equal ( await page . locator ( '.business-grid' ) . count ( ) , 0 )
const stats = await page . evaluate ( ( ) => { const vm = document . querySelector ( '.business-home' ) . _ _vue _ _ ; return { failures : vm . failures , counts : Object . fromEntries ( vm . queues . map ( q => [ q . key , q . rows . length ] ) ) } } )
const projectId = await page . evaluate ( ( ) => document . querySelector ( '.business-home' ) . _ _vue _ _ . projects [ 0 ] ? . id )
assert . deepEqual ( stats . failures , [ ] )
await page . screenshot ( { path : path . join ( out , 'home.png' ) } )
const checked = [ ]
async function navigate ( url ) { await page . evaluate ( async url => { await document . querySelector ( '#app' ) . _ _vue _ _ . $router . push ( url ) . catch ( e => { if ( e . name !== 'NavigationDuplicated' ) throw e } ) } , url ) ; await page . waitForFunction ( url => location . pathname === url . split ( '?' ) [ 0 ] , url ) ; await page . waitForTimeout ( 600 ) }
async function geometry ( label ) {
await page . waitForFunction ( ( ) => ! document . querySelector ( '.desktop-viewport .el-loading-mask:not([style*="display: none"])' ) , null , { timeout : 15000 } ) . catch ( ( ) => { } )
await page . waitForTimeout ( 200 )
const state = await page . evaluate ( ( ) => {
const main = document . querySelector ( '.app-main' ) , stage = document . querySelector ( '.desktop-viewport' ) , root = stage . firstElementChild , s = stage . getBoundingClientRect ( )
const visible = el => el . getClientRects ( ) . length && getComputedStyle ( el ) . visibility !== 'hidden'
const tables = [ ... root . querySelectorAll ( '.el-table' ) ] . filter ( el => el . _ _vue _ _ ? . $options . name === 'ElTable' && visible ( el ) && ! el . closest ( '.el-dialog,.el-drawer,.viewport-natural' ) ) . map ( el => { const r = el . getBoundingClientRect ( ) , body = el . querySelector ( '.el-table__body-wrapper' ) ; return { top : r . top , bottom : r . bottom , height : r . height , fit : el . hasAttribute ( 'data-viewport-table' ) , vm : el . _ _vue _ _ ? . $options . name , classes : el . className , scroll : body . scrollHeight > body . clientHeight , bodyHeight : body . clientHeight } } )
const footers = [ ... root . querySelectorAll ( '.pagination-container,.sheet-footer' ) ] . filter ( visible ) . map ( el => el . getBoundingClientRect ( ) . bottom )
return { page : location . pathname , stageBottom : s . bottom , doc : document . documentElement . scrollHeight - document . documentElement . clientHeight , main : main . scrollHeight - main . clientHeight , rootOverflow : root . scrollHeight - root . clientHeight , tables , footers }
} )
assert . ok ( state . doc <= 2 , label + ': document scroll ' + JSON . stringify ( state ) )
assert . ok ( state . main <= 2 , label + ': app main scroll ' + JSON . stringify ( state ) )
for ( const t of state . tables ) { assert . ok ( t . fit , label + ': table not fitted ' + JSON . stringify ( state ) ) ; assert . ok ( t . bottom <= state . stageBottom + 2 && t . bodyHeight >= 35 , label + ': table escaped screen ' + JSON . stringify ( state ) ) }
for ( const bottom of state . footers ) assert . ok ( bottom <= state . stageBottom + 2 , label + ': footer escaped screen ' + JSON . stringify ( state ) )
if ( state . tables . length ) assert . ok ( state . rootOverflow <= 2 , label + ': outer page scroll ' + JSON . stringify ( state ) )
return state
}
await geometry ( '首页' )
for ( const r of process . env . WORKBENCH _INTERACTIONS _ONLY ? [ ] : routes ) {
if ( checked . length && checked . length % 8 === 0 ) await freshPage ( )
await navigate ( r . url )
assert . equal ( await page . locator ( '.error-page' ) . count ( ) , 0 , r . title + ' unexpectedly rendered error page' )
const state = await geometry ( r . title ) ; checked . push ( { ... r , tables : state . tables . length } )
// Narrow laptop size must keep all bottom actions in screen too.
await page . setViewportSize ( { width : 1366 , height : 768 } ) ; await page . waitForTimeout ( 250 ) ; await geometry ( r . title + ' 1366x768' )
await page . setViewportSize ( { width : 1440 , height : 900 } )
await page . screenshot ( { path : path . join ( out , r . url . replace ( /[^a-zA-Z0-9]/g , '_' ) + '.png' ) } )
console . log ( 'PASS page:' , r . title , r . url )
}
await freshPage ( )
if ( projectId ) {
await navigate ( '/project/detail/' + projectId )
for ( const tab of [ '总览' , '分类预算' , '产品与BOM' , '采购' , '库存' , '借用与归还' , '生产' , '成本与损耗' ] ) {
await page . locator ( '.desktop-viewport .el-tabs__item' ) . filter ( { hasText : new RegExp ( '^' + tab + '$' ) } ) . first ( ) . click ( )
await page . waitForTimeout ( 600 ) ; await geometry ( '项目详情 ' + tab )
if ( tab === '成本与损耗' ) {
await page . locator ( '.desktop-viewport .el-tabs__item' ) . filter ( { hasText : '领退料、报废及交付追溯' } ) . click ( )
await page . waitForTimeout ( 600 ) ; await geometry ( '项目成本追溯' )
}
}
console . log ( 'PASS: 8 project workspace tabs and cost history sub-tab' )
}
await navigate ( '/system/dict' )
for ( const tab of [ '物品类别' , '物品单位' , '费用分类' ] ) { await page . locator ( '.desktop-viewport .el-tabs__item' ) . filter ( { hasText : tab } ) . click ( ) ; await page . waitForTimeout ( 300 ) ; await geometry ( '字典 ' + tab ) }
// Open, inspect and cancel forms only. Nothing is submitted.
for ( const [ url , label ] of [ [ '/project/info' , '新增项目' ] , [ '/businessBasics/product' , '新增' ] , [ '/businessBasics/suppliers' , '新增供应商' ] , [ '/businessBasics/area' , '新增' ] , [ '/production/tasks' , '新建生产任务' ] ] ) {
await navigate ( url )
const add = page . locator ( '.desktop-viewport button' ) . filter ( { hasText : new RegExp ( '^\\s*' + label + '\\s*$' ) } ) . first ( )
if ( ! await add . count ( ) ) continue
await add . click ( ) ; const dialog = page . locator ( '.el-dialog:visible' ) . last ( ) ; await dialog . waitFor ( )
await page . waitForTimeout ( 250 )
const box = await dialog . evaluate ( el => { const r = el . getBoundingClientRect ( ) , f = el . querySelector ( '.el-dialog__footer' ) ? . getBoundingClientRect ( ) ; return { top : r . top , bottom : r . bottom , footer : f ? . bottom , height : window . innerHeight } } )
assert . ok ( box . top >= 0 && box . bottom <= box . height + 1 && ( ! box . footer || box . footer <= box . height + 1 ) , url + ' dialog escaped screen ' + JSON . stringify ( box ) )
await dialog . getByRole ( 'button' , { name : /取\s*消/ } ) . click ( )
console . log ( 'PASS form open/cancel:' , url )
}
await freshPage ( )
// Large row counts scroll in the body; search/toolbars/header/footer do not move.
for ( const [ url , key ] of [ [ '/warehouse/stock' , 'stockList' ] , [ '/businessBasics/product' , 'productList' ] , [ '/procurement/details' , 'batches' ] ] ) {
console . log ( 'CHECK large rows:' , url )
await navigate ( url )
await page . waitForFunction ( key => { const find = vm => vm ? . $data ? . [ key ] ? . length ? vm : ( vm ? . $children || [ ] ) . map ( find ) . find ( Boolean ) ; const vm = find ( document . querySelector ( '.desktop-viewport' ) . firstElementChild . _ _vue _ _ ) ; return vm && ! vm . loading && ( key !== 'batches' || vm . _routeStamp === location . pathname + location . search ) } , key )
const seeded = await page . evaluate ( key => {
const root = document . querySelector ( '.desktop-viewport' ) . firstElementChild
const find = vm => vm ? . $data ? . [ key ] ? . length ? vm : ( vm ? . $children || [ ] ) . map ( find ) . find ( Boolean )
const vm = find ( root . _ _vue _ _ ) ; if ( ! vm ) return false
const first = vm [ key ] [ 0 ] ; vm [ key ] = Array . from ( { length : 80 } , ( _ , i ) => ( { ... first , id : 900000 + i } ) ) ; return true
} , key )
if ( ! seeded ) continue
await page . waitForTimeout ( 300 )
const before = await geometry ( 'large rows ' + url )
const body = page . locator ( '.desktop-viewport [data-viewport-table]>.el-table__body-wrapper' ) . first ( )
assert . ok ( await body . evaluate ( el => el . scrollHeight > el . clientHeight ) , 'large list must scroll internally' )
await body . hover ( ) ; await page . mouse . wheel ( 0 , 1800 ) ; await page . waitForTimeout ( 150 )
assert . ok ( await body . evaluate ( el => el . scrollTop > 0 ) )
const after = await geometry ( 'scrolled ' + url )
assert . equal ( before . tables [ 0 ] . top , after . tables [ 0 ] . top )
assert . equal ( before . tables [ 0 ] . bottom , after . tables [ 0 ] . bottom )
const check = page . locator ( '.desktop-viewport [data-viewport-table]>.el-table__header-wrapper .el-checkbox' ) . first ( )
if ( await check . count ( ) ) { await check . click ( ) ; await page . waitForTimeout ( 100 ) ; await check . click ( ) }
}
await navigate ( '/index' )
console . log ( 'CHECK home deep links, error handling, filtering, pagination and permissions' )
// Home deep links must land on the specific batch/record, not a generic menu.
const dest = await page . evaluate ( ( ) => { const vm = document . querySelector ( '.business-home' ) . _ _vue _ _ , queue = vm . todoQueues . find ( q => q . rows . length ) ; if ( ! queue ) return null ; vm . selectQueue ( queue . key ) ; return { key : queue . key , record : queue . rows [ 0 ] } } )
if ( dest ) { await page . locator ( '.home-record-action' ) . first ( ) . click ( ) ; await page . waitForTimeout ( 700 ) ; await geometry ( 'home deep link' ) }
await navigate ( '/index' )
// A failed business source must show unknown, never a reassuring zero.
2026-10-13 09:41:46 +08:00
await page . route ( '**/business/home*' , route => route . fulfill ( { json : { code : 500 , msg : 'Intentional read-failure fixture' } } ) )
2026-10-12 16:41:42 +08:00
await page . evaluate ( async ( ) => { await document . querySelector ( '.business-home' ) . _ _vue _ _ . reload ( ) } )
2026-10-13 09:41:46 +08:00
const failed = await page . evaluate ( ( ) => { const vm = document . querySelector ( '.business-home' ) . _ _vue _ _ ; return { failures : vm . failures , purchase : vm . serverQueues , counts : vm . queues . filter ( q => [ 'quote' , 'confirm' , 'arrival' , 'acceptance' ] . includes ( q . key ) ) . map ( q => q . rows ) } } )
assert . deepEqual ( failed . failures , [ '概览数据加载失败' ] ) ; assert . ok ( failed . counts . every ( r => r === null ) )
await page . unroute ( '**/business/home*' )
2026-10-12 16:41:42 +08:00
await page . evaluate ( async ( ) => { await document . querySelector ( '.business-home' ) . _ _vue _ _ . reload ( ) } )
2026-10-13 09:41:46 +08:00
const scoped = await page . evaluate ( async projectId => { const vm = document . querySelector ( '.business-home' ) . _ _vue _ _ ; vm . projectId = projectId ; await vm . reload ( ) ; return { projects : vm . scopedProjects . map ( p => p . id ) , purchases : vm . queues . filter ( q => [ 'quote' , 'confirm' , 'acceptance' , 'arrival' ] . includes ( q . key ) ) . flatMap ( q => q . rows || [ ] ) . map ( p => p . projectId ) } } , projectId )
2026-10-12 16:41:42 +08:00
if ( projectId ) { assert . deepEqual ( scoped . projects , [ projectId ] ) ; assert . ok ( scoped . purchases . every ( id => id === projectId ) ) }
await page . evaluate ( async ( ) => { const vm = document . querySelector ( '.business-home' ) . _ _vue _ _ ; vm . projectId = undefined ; await vm . reload ( ) } )
assert . equal ( await page . locator ( '.business-home .el-table' ) . count ( ) , 0 , 'homepage is a dashboard, not a detailed list page' )
assert . ok ( await page . locator ( '.home-todo-row' ) . count ( ) <= 6 , 'homepage must limit its preview' )
assert . ok ( await page . locator ( '.home-stat' ) . count ( ) > 0 ) ; assert . ok ( await page . locator ( '.home-shortcut' ) . count ( ) > 0 )
const calls = [ ] ; const reads = r => { if ( r . url ( ) . includes ( '/dev-api/' ) ) calls . push ( new URL ( r . url ( ) ) . pathname ) }
page . on ( 'request' , reads )
await page . evaluate ( async ( ) => { const vm = document . querySelector ( '.business-home' ) . _ _vue _ _ ; vm . $store . commit ( 'SET_PERMISSIONS' , [ 'warehouse:purchase:list' ] ) ; await vm . $nextTick ( ) ; await vm . reload ( ) } )
assert . equal ( await page . locator ( '.home-todo' ) . count ( ) , 3 ) ; assert . equal ( await page . locator ( '.home-projects' ) . count ( ) , 0 )
2026-10-13 09:41:46 +08:00
assert . ok ( calls . every ( url => url . endsWith ( '/business/home' ) ) , 'restricted home requested unrelated sources ' + calls . join ( ',' ) )
2026-10-12 16:41:42 +08:00
page . off ( 'request' , reads )
await page . evaluate ( async ( ) => { const vm = document . querySelector ( '.business-home' ) . _ _vue _ _ ; vm . $store . commit ( 'SET_PERMISSIONS' , [ '*:*:*' ] ) ; await vm . $nextTick ( ) ; await vm . reload ( ) } )
await page . screenshot ( { path : path . join ( out , 'home-final.png' ) } )
await freshPage ( ) ; await page . setViewportSize ( { width : 390 , height : 844 } ) ; await navigate ( '/mobile' )
assert . equal ( await page . locator ( '.desktop-viewport' ) . count ( ) , 0 , 'standalone mobile app must not inherit desktop canvas' )
for ( const tab of [ 'stock' , 'purchase' , 'in' , 'out' , 'check' , 'product' , 'area' , 'production' ] ) {
await page . evaluate ( tab => document . querySelector ( '.mobile-app' ) . _ _vue _ _ . switchTab ( tab ) , tab )
await page . waitForTimeout ( 350 )
assert . equal ( await page . evaluate ( ( ) => document . querySelector ( '.mobile-app' ) . _ _vue _ _ . activeTab ) , tab )
await page . getByRole ( 'button' , { name : '返回上一页' } ) . click ( )
await page . waitForTimeout ( 150 )
assert . equal ( await page . evaluate ( ( ) => document . querySelector ( '.mobile-app' ) . _ _vue _ _ . activeTab ) , 'home' )
}
console . log ( 'PASS: mobile web 8 sections and back navigation; Android device gestures not tested' )
assert . deepEqual ( errors , [ ] , 'browser exceptions' )
assert . deepEqual ( apiFailures , [ ] , 'failed read APIs' )
console . log ( 'PASS:' , checked . length , 'menu pages, 2 desktop sizes, internal table scrolling, footer visibility, home counts/deep link; no business writes. Home counts:' , JSON . stringify ( stats . counts ) )
} finally { if ( page ) await page . screenshot ( { path : path . join ( out , 'last.png' ) , timeout : 5000 } ) . catch ( ( ) => { } ) ; await browser . close ( ) }
} ) ( ) . catch ( e => { console . error ( e ) ; process . exitCode = 1 } )