skillhub/plugins/dsh/test/integration/change-upgrade-browser.mjs
XiaoSeS e99c2ce44e
feat(dsh): compact workbench and file browser (#1080)
Apply the reviewed compact DSH workbench, bounded file tree preview and lifecycle navigation fixes.

Preserve registry/session boundaries and managed installation semantics.

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-11-10 14:35:47 +08:00

25 lines
5.9 KiB
JavaScript

// Full sequential upgrade against an actual isolated Host. No model calls.
import assert from 'node:assert/strict';
import {readFile,writeFile} from 'node:fs/promises';
import {join} from 'node:path';
import {chromium} from 'playwright';
const {DSH_PROBE_URL_FILE:entryFile,DSH_PROBE_OUTPUT:output,DSH_CHANGE_RESULT:resultFile}=process.env;assert(entryFile&&output&&resultFile);
const fixture=JSON.parse(await readFile(resultFile,'utf8'));assert(fixture.passed&&fixture.manualPreview);
const browser=await chromium.launch({headless:true,...(process.env.DSH_PROBE_CHROMIUM?{executablePath:process.env.DSH_PROBE_CHROMIUM}:{})});
const p=await browser.newPage({viewport:{width:1440,height:1000}});const errors=[];p.on('pageerror',e=>errors.push(e.message));let stage='boot';
try{
await p.goto((await readFile(entryFile,'utf8')).trim());
for(const name of [/^(Continue|继续)$/,/^(Configure later|稍后配置)$/])await p.addLocatorHandler(p.getByRole('button',{name}),async l=>l.click());
const d=p.getByRole('dialog',{name:/^(Get started|开始使用)$/});await p.addLocatorHandler(d,async l=>l.getByRole('button',{name:/^(Close|关闭)$/}).click());
await p.getByText('New Session',{exact:true}).last().click();await p.getByRole('button',{name:'技能中心',exact:true}).click();await p.getByRole('tab',{name:'已安装',exact:true}).click();await p.getByRole('button',{name:/查看 .*@change-demo\/document-helper 详情/}).click();
stage='local-inspection';await p.getByRole('button',{name:/^本地修改 · \d+$/}).waitFor();await p.getByRole('button',{name:/^本地修改 · \d+$/}).click();await p.locator('.astron-sh-changes summary').first().focus();await p.keyboard.press('Enter');await p.locator('.changes-code').waitFor();
await p.getByRole('button',{name:/^撤销 .* 的修改$/}).click();await p.waitForFunction(()=>document.activeElement?.textContent==='取消');await p.keyboard.press('Tab');assert.equal(await p.evaluate(()=>document.activeElement?.textContent),'确认撤销');await p.keyboard.press('Shift+Tab');await p.keyboard.press('Escape');await p.waitForFunction(()=>document.activeElement?.textContent==='撤销');
await p.getByText(/^(More|更多)$/,{exact:true}).first().click();await p.getByText('Settings',{exact:true}).last().click();await p.getByRole('button',{name:'Light',exact:true}).click();await p.getByRole('button',{name:'Close',exact:true}).click();
const metrics=[];for(const width of [1440,390]){await p.setViewportSize({width,height:1000});const metric=await p.locator('.changes-code').evaluate(e=>({height:e.clientHeight,scroll:e.scrollHeight}));assert(metric.height<=(width===390?240:320));assert(metric.scroll>metric.height);metrics.push({width,...metric});assert(await p.evaluate(()=>document.documentElement.scrollWidth)<=width);await p.screenshot({path:join(output,`real-${width}-expanded-light.png`),fullPage:true});}
stage='dark-theme';await p.setViewportSize({width:1440,height:1000});await p.getByText(/^(More|更多)$/,{exact:true}).first().click();await p.getByText('Settings',{exact:true}).last().click();await p.getByRole('button',{name:'Dark',exact:true}).click();await p.getByRole('button',{name:'Close',exact:true}).click();
const dark=await p.locator('.astron-sh-changes').evaluate(e=>({background:getComputedStyle(e.closest('.skillhub-installed')).backgroundColor,text:getComputedStyle(e).color}));assert(Number(dark.text.match(/\d+/)?.[0])>150);for(const width of [1440,390]){await p.setViewportSize({width,height:1000});await p.screenshot({path:join(output,`real-${width}-expanded-dark.png`),fullPage:true});}
stage='upgrade-entry';await p.setViewportSize({width:1440,height:1000});await p.getByRole('button',{name:'返回详情',exact:true}).click();const management=p.getByRole('region',{name:'安装管理',exact:true});await management.getByRole('button',{name:'更多操作',exact:true}).click();await p.getByRole('menuitem',{name:'检查更新',exact:true}).click();await management.getByRole('button',{name:'更新',exact:true}).click();await p.getByRole('heading',{name:'处理本地修改',exact:true}).waitFor();
const before=await readFile(join(fixture.directory,'SKILL.md'),'utf8');await p.getByRole('button',{name:'备份修改并继续',exact:true}).click();await p.getByRole('heading',{name:'版本变化',exact:true}).waitFor();assert.equal(await readFile(join(fixture.directory,'SKILL.md'),'utf8'),before);await p.getByRole('button',{name:'复制路径',exact:true}).waitFor();assert.equal(await p.getByRole('tab',{name:'本地修改',exact:true}).count(),0);await p.screenshot({path:join(output,'real-version-preview.png'),fullPage:true});
stage='final-upgrade';await p.getByRole('button',{name:'确认升级',exact:true}).click();await p.getByText('升级完成。',{exact:true}).waitFor();assert.equal(JSON.parse(await readFile(join(fixture.directory,'.skillhub/metadata.json'),'utf8')).version,'1.3.0');assert(!(await readFile(join(fixture.directory,'SKILL.md'),'utf8')).includes('人工验收'));await p.screenshot({path:join(output,'real-upgrade-completed.png'),fullPage:true});await p.getByRole('button',{name:'返回详情',exact:true}).click();await p.getByRole('region',{name:'已安装技能详情',exact:true}).waitFor();await p.getByRole('region',{name:'已安装技能详情',exact:true}).getByText(/v1\.3\.0/).first().waitFor();assert.equal(await p.getByRole('region',{name:'升级变化预览',exact:true}).count(),0);assert.deepEqual(errors,[]);
await writeFile(join(output,'upgrade-browser-result.json'),JSON.stringify({passed:true,realHost:true,modelCalled:false,metrics,dark,sequentialBackupPreviewConfirmation:true,backupDidNotModifyInstallation:true,backupLocationVisible:true,keyboardCancelFocus:true,successReturnsToUpgradedDetail:true,upgradedVersion:'1.3.0',browser:browser.version()},null,2));
}catch(e){await p.screenshot({path:join(output,'upgrade-browser-failure.png'),fullPage:true}).catch(()=>{});await writeFile(join(output,'upgrade-browser-result.json'),JSON.stringify({passed:false,stage,error:e.message,errors},null,2));throw e;}finally{await browser.close();}