verify-development-fallback.mjs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {chromium} from 'file:///C:/Users/JSHY/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright/index.mjs';
  2. import fs from 'node:fs/promises';
  3. import assert from 'node:assert/strict';
  4. const base='http://127.0.0.1:4183';
  5. const out='docs/development-board-20261108';
  6. const browser=await chromium.launch({executablePath:'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',headless:true});
  7. const report={ok:false,checkedAt:new Date().toISOString(),responseOverrides:0,productionWrites:0,paidCalls:0,checks:[]};
  8. try{
  9. const context=await browser.newContext({viewport:{width:390,height:844},isMobile:true,hasTouch:true});
  10. const p=await context.newPage();
  11. await p.goto(base+'/industry?tab=development');await p.locator('[data-development-copy]').waitFor();
  12. const cdp=await context.newCDPSession(p),info=await cdp.send('Target.getTargetInfo');
  13. await cdp.send('Browser.setPermission',{permission:{name:'clipboard-write'},setting:'denied',origin:base,browserContextId:info.targetInfo.browserContextId});
  14. assert.equal(await p.evaluate(()=>navigator.permissions.query({name:'clipboard-write'}).then(r=>r.state)),'denied');
  15. await p.locator('[data-development-copy]').click();
  16. await p.locator('.dr-copy[open]').waitFor();
  17. const copy=await p.locator('.dr-copy textarea').inputValue();
  18. assert.ok(copy.includes('KfMaterial/')&&copy.includes('KfSource/')&&copy.includes('待验证设想'));
  19. await p.locator('.dr-copy>button').click();
  20. const range=await p.locator('.dr-copy textarea').evaluate(e=>({start:e.selectionStart,end:e.selectionEnd,length:e.value.length}));
  21. assert.equal(range.start,0);assert.equal(range.end,range.length);
  22. report.checks.push('real clipboard permission denial opens complete selectable brief');
  23. await p.screenshot({path:out+'/copy-fallback-390.png'});
  24. await p.keyboard.press('Escape');assert.equal(await p.locator('.dr-copy[open]').count(),0);
  25. report.checks.push('native Escape closes text dialog');
  26. await p.locator('.dr-reference').first().click();await p.locator('.dr-detail[open]').waitFor();
  27. await p.keyboard.press('Escape');assert.equal(await p.locator('.dr-detail[open]').count(),0);
  28. report.checks.push('native Escape closes source dialog');
  29. for(const [tab,selector]of [['insights','.workshop-analysis'],['policies','.policy-applications'],['rankings','.ranking-research']]){
  30. await p.goto(base+'/industry?tab='+tab);
  31. await p.waitForFunction(async tab=>{const el=document.querySelector('kf-app')?.renderRoot.querySelector('view-industry');if(!el)return false;await el.updateComplete;return el._tab===tab&&!el._loading&&!!el._data?.generation&&!el._error;},tab);
  32. await p.locator('view-industry').evaluate(async e=>{await e.updateComplete;return true;});
  33. await p.waitForFunction(()=>{const el=document.querySelector('kf-app')?.renderRoot.querySelector('view-industry');return !el?false:!el._loading&&!!el._data;});
  34. const state=await p.locator('view-industry').evaluate(e=>({tab:e._tab,ok:!!e._data&&!e._error,generation:e._data?.generation||null,loading:e._loading,error:e._error}));
  35. assert.equal(state.tab,tab);assert.ok(state.ok,JSON.stringify(state));report.checks.push('existing '+tab+' loads actual data');
  36. }
  37. await p.goto(base+'/industry?tab=insights');await p.locator('.sf-filters').waitFor();
  38. await p.setViewportSize({width:1440,height:900});
  39. await p.locator('view-industry .p-actions a').filter({hasText:'研发参考'}).click();
  40. await p.waitForURL(/tab=development/);await p.locator('industry-development .dr-intro').waitFor();
  41. report.checks.push('existing innovation page links to development references');
  42. report.ok=true;
  43. }catch(e){report.error=e.stack;process.exitCode=1;console.error(e);}
  44. finally{await browser.close();await fs.writeFile(out+'/supplement-acceptance.json',JSON.stringify(report,null,2)+'\n');console.log(JSON.stringify(report));}