const assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path') const {chromium,frontend,backend,username,password}=require('./vue3-test-runtime.cjs') ;(async()=>{ const login=await(await fetch(backend+'/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username,password})})).json();assert.equal(login.code,200) const browser=await chromium.launch(),writes=[],errors=[];let project=null,saveAttempts=0,detailFailed=true,genFailed=true const out=path.resolve('.codex-tmp/full-flow-audit');fs.mkdirSync(out,{recursive:true}) try { const context=await browser.newContext({viewport:{width:1366,height:768}});await context.addCookies([{name:'Admin-Token',value:login.token,url:frontend}]);const page=await context.newPage();page.setDefaultTimeout(12000);page.on('pageerror',e=>errors.push(e.message)) await page.route('**/dev-api/**',async route=>{ const r=route.request(),p=new URL(r.url()).pathname.replace('/dev-api',''),m=r.method(),ok=data=>route.fulfill({json:{code:200,data}}) if(p==='/project/workspace/capabilities')return ok({supported:false}); if(p==='/project/info/list')return route.fulfill({json:{code:200,rows:project?[project]:[],total:project?1:0}}) if(p==='/project/info'&&['POST','PUT'].includes(m)){writes.push({path:p,method:m,data:r.postDataJSON()});saveAttempts++;await new Promise(r=>setTimeout(r,120));if(saveAttempts===1)return route.fulfill({json:{code:500,msg:'模拟保存失败,请重试'}});project={...r.postDataJSON(),id:910001,projectCode:'XM26100001',version:saveAttempts,spentAmount:0,availableAmount:r.postDataJSON().totalAmount};return ok(1)} if(p==='/project/info/910001')return detailFailed?route.fulfill({json:{code:500,msg:'模拟项目加载失败'}}):ok(project) if(p==='/production/tasks/overview/910001')return ok({pendingPurchases:2,pendingReceipts:1,openTasks:1,outstandingLoans:1,remainingStocks:3}) if(p==='/project/info/options')return ok(project?[project]:[]) if(p==='/tool/gen/990003')return genFailed?route.fulfill({json:{code:500,msg:'生成配置不存在或已删除,请返回列表刷新'}}):ok({info:{tableId:990003,tableName:'fixture',tableComment:'测试表',className:'Fixture',functionAuthor:'测试',tplCategory:'crud',packageName:'com.fixture',moduleName:'fixture',businessName:'fixture',functionName:'测试',genType:'0'},tables:[],rows:[]}) if(!['GET','HEAD'].includes(m))throw Error('Unexpected real write blocked: '+m+' '+p) return route.continue() }) await page.goto(frontend+'/project/info');await page.getByRole('button',{name:'新增项目',exact:true}).click() let dialog=page.locator('.el-dialog:visible').last() await dialog.getByRole('button',{name:'确定',exact:true}).click();await dialog.locator('.el-form-item__error').first().waitFor();assert.equal(writes.length,0) await dialog.locator('.el-form-item').filter({hasText:'项目编号'}).locator('input').fill('AUDIT-PROJECT-20261027');await dialog.locator('.el-form-item').filter({hasText:'项目名称'}).locator('input').fill('完整流程模拟项目') await dialog.locator('.el-form-item').filter({hasText:'总金额'}).locator('input').fill('12000') await dialog.getByRole('button',{name:'确定',exact:true}).click();await page.getByText('模拟保存失败,请重试',{exact:true}).waitFor();assert.equal(await dialog.locator('.el-form-item').filter({hasText:'项目名称'}).locator('input').inputValue(),'完整流程模拟项目') await dialog.getByRole('button',{name:'确定',exact:true}).click();await dialog.waitFor({state:'hidden'});assert.equal(saveAttempts,2);assert.equal(project.totalAmount,12000) console.log('PASS project required fields, failed-save retention, immediate retry and explicit project code') await page.getByText('完整流程模拟项目',{exact:true}).click();await page.getByText('模拟项目加载失败',{exact:true}).last().waitFor();detailFailed=false;await page.getByRole('button',{name:'重试',exact:true}).click();await page.getByText('未到齐采购 2 条',{exact:true}).waitFor() await page.locator('.el-message').last().waitFor({state:'hidden'});await page.screenshot({path:path.join(out,'project-overview.png')});assert.equal(await page.getByRole('tab',{name:'分类预算',exact:true}).count(),1) await page.getByRole('button',{name:'返回列表',exact:true}).click();await page.locator('.el-table__body .el-button').filter({hasText:'更多'}).click();await page.getByRole('menuitem',{name:'修改',exact:true}).click() dialog=page.locator('.el-dialog:visible').last();assert.equal(await dialog.locator('.el-form-item').filter({hasText:'项目状态'}).locator('input').isDisabled(),true) await dialog.locator('.el-form-item').filter({hasText:'备注'}).locator('textarea').fill('超级管理员维护无经理历史项目') await dialog.getByRole('button',{name:'确定',exact:true}).click();await dialog.waitFor({state:'hidden'});assert.equal(saveAttempts,3);assert.equal(project.projectStatus,0);assert.equal(project.remark,'超级管理员维护无经理历史项目') console.log('PASS root administrator edits a managerless project; ordinary edit keeps lifecycle status read-only') await page.evaluate(async()=>{const r=document.querySelector('#app').__vue_app__.config.globalProperties.$router,{default:Layout}=await import('/src/layout/index.vue'),{default:Edit}=await import('/src/views/tool/gen/editTable.vue');r.addRoute({path:'/_project-flow',component:Layout,children:[{path:'gen/:tableId',component:Edit}]});await r.push('/_project-flow/gen/990003')}) await page.locator('.gen-edit-page .el-alert').waitFor();assert.equal(await page.getByRole('button',{name:'提交',exact:true}).isDisabled(),true);genFailed=false;await page.getByRole('button',{name:'重试',exact:true}).click();await page.locator('.gen-edit-page .el-alert').waitFor({state:'hidden'});await page.locator('.gen-edit-footer button:not([disabled])').filter({hasText:'提交'}).waitFor();assert.equal(await page.getByRole('button',{name:'提交',exact:true}).isEnabled(),true) console.log('PASS missing generation config shows retry and blocks empty submission') assert.deepEqual(errors,[]);fs.writeFileSync(path.join(out,'project-flow.json'),JSON.stringify({result:'PASS',scenarios:4,mockedWrites:writes.length,errors},null,2)) }finally{await browser.close()} })().catch(e=>{console.error(e);process.exitCode=1})