skillhub/plugins/dsh/test/integration/search-catalog-navigation-probe.mjs
XiaoSeS 3560679793
Some checks failed
Deploy Docs / build (push) Has been cancelled
Security / Dependency Review (push) Has been cancelled
Security / CodeQL (java-kotlin) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Deploy Docs / Deploy (push) Has been cancelled
feat(dsh): add native SkillHub plugin for DeepSeek Harness (#956)
Add the native SkillHub plugin for DeepSeek Harness with a scoped skill center, conversation search/install tools, exact-version installation and protected lifecycle management. Prepare the independently versioned 0.1.0 npm candidate with an empty default Registry and documented compatibility limits.

Keep formal specifications and executable regression tests; remove archived development screenshots and runtime reports from the final tree. Review fixes cover independent scopes, installed references, pre-staging recovery and idempotent discovery.

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-10-16 19:22:26 +08:00

77 lines
6 KiB
JavaScript

import { chromium } from 'playwright';
import {writeFile} from 'node:fs/promises';
const r={title:process.env.DSH_SEARCH_SESSION_TITLE,project:process.env.DSH_SEARCH_WORKSPACE};
if(!r.title||!r.project)throw Error('Search session title and workspace are required');
const b=await chromium.launch({headless:true,executablePath:process.env.DSH_PROBE_CHROMIUM});
const page=await b.newPage({viewport:{width:1440,height:1000},locale:'en-US'});let writes=0;const errors=[];
page.on('request',req=>{if(new URL(req.url()).pathname.endsWith('/startInstall'))writes++;});
page.on('pageerror',()=>errors.push('pageerror'));
try{
for(const name of ['Continue','Configure later'])await page.addLocatorHandler(page.getByRole('button',{name,exact:true}),async l=>{await l.click();});
await page.goto(process.env.DSH_PROBE_URL,{waitUntil:'domcontentloaded'});
const title=page.getByText(r.title,{exact:true});
if(!await title.waitFor({timeout:5000}).then(()=>true,()=>false))await page.getByText(r.project.split('/').at(-1),{exact:true}).click();
await title.click();
const card=page.getByRole('region',{name:'SkillHub 搜索结果'});
if(!await card.isVisible()){const p=page.locator('button[data-turn-process="1"]');await p.waitFor();if(await p.getAttribute('aria-expanded')==='false')await p.click();}
if(!await card.isVisible())await page.getByText('Called tools',{exact:true}).click();
await card.waitFor();
const found=(await card.innerText()).includes('document-helper');
const candidate=card.getByRole('button',{name:'查看技能详情',exact:true}).first();
const headingBox=await candidate.locator('xpath=ancestor::*[contains(concat(" ", normalize-space(@class), " "), " astron-sh-skill-card ")]').getByRole('heading').boundingBox();
if(!headingBox)throw Error('Candidate heading is not visible');
await page.mouse.click(headingBox.x+headingBox.width/2,headingBox.y+headingBox.height/2);
const detail=page.getByRole('dialog',{name:'技能详情',exact:true});
await detail.waitFor();
await page.keyboard.press('Escape');
await detail.waitFor({state:'hidden'});
if(!await candidate.evaluate(element=>element===document.activeElement))throw Error('Candidate focus not restored');
await page.keyboard.press('Enter');
await detail.waitFor();
await detail.getByRole('button',{name:'关闭技能详情',exact:true}).click();
await detail.waitFor({state:'hidden'});
if(!await candidate.evaluate(element=>element===document.activeElement))throw Error('Keyboard candidate focus not restored');
if ((await page.locator('body').innerText()).includes('selectionRef')) throw Error('Internal reference visible');
await page.screenshot({path:process.env.DSH_PROBE_OUTPUT+'/real-model-search.png'});
await page.setViewportSize({width:390,height:844});
await candidate.scrollIntoViewIfNeeded();
if(!await candidate.evaluate(element=>{const card=element.closest('.astron-sh-skill-card');return card.scrollWidth<=card.clientWidth+1;}))throw Error('Candidate content overflows narrow width');
await candidate.press('Enter');
await detail.waitFor();
if(!await detail.evaluate(element=>element.scrollWidth<=element.clientWidth+1))throw Error('Detail overflows narrow width');
await page.keyboard.press('Escape');
await detail.waitFor({state:'hidden'});
if(!await candidate.evaluate(element=>element===document.activeElement))throw Error('Narrow candidate focus not restored');
await page.screenshot({path:process.env.DSH_PROBE_OUTPUT+'/real-model-search-mobile.png'});
await page.setViewportSize({width:1440,height:1000});
await card.getByRole('button',{name:'打开技能广场',exact:true}).click();
const catalog=page.getByRole('region',{name:'SkillHub 技能广场',exact:true});
await catalog.waitFor();
const query=await catalog.getByRole('textbox',{name:'搜索技能',exact:true}).inputValue();
if(query!=='document')throw Error('Search query not preserved');
await catalog.getByRole('button',{name:/@demo\/document-helper/}).waitFor();
await page.screenshot({path:process.env.DSH_PROBE_OUTPUT+'/search-catalog-navigation.png'});
await catalog.getByRole('button',{name:'返回会话',exact:true}).click();
const processButton=page.locator('button[data-turn-process="1"]');
if(await processButton.isVisible()&&await processButton.getAttribute('aria-expanded')==='false')await processButton.click();
if(!await card.isVisible())await page.getByText('Called tools',{exact:true}).click();
await card.waitFor();
await card.getByRole('button',{name:'打开技能广场',exact:true}).click();
await catalog.waitFor();
if(await catalog.getByRole('textbox',{name:'搜索技能',exact:true}).inputValue()!=='document')throw Error('Reopened query changed');
await catalog.getByRole('button',{name:'返回会话',exact:true}).click();
if(await processButton.isVisible()&&await processButton.getAttribute('aria-expanded')==='false')await processButton.click();
if(!await card.isVisible())await page.getByText('Called tools',{exact:true}).click();
await card.waitFor();
await page.route('**/getContext',async route=>{
const response=await route.fetch();
const body=await response.text();
await route.fulfill({response,body:body.replaceAll('http://127.0.0.1:43219','http://127.0.0.1:43220')});
});
await card.getByRole('button',{name:'打开技能广场',exact:true}).click();
await card.getByRole('alert').waitFor();
if(await catalog.isVisible())throw Error('Changed source opened catalog');
await writeFile(process.env.DSH_PROBE_OUTPUT+'/navigation-result.json',JSON.stringify({wholeCandidateClick:true,keyboardCandidateOpen:true,closeRestoresCandidateFocus:true,narrowCandidateAndDetailNoOverflow:true,narrowKeyboardOpenAndClose:true,catalogOpened:true,queryPreserved:query,returnedToConversation:true,reopened:true,changedSourceRejected:true,installSubmissions:writes,pageErrors:errors,modelReplayOnly:true},null,2));
await writeFile(process.env.DSH_PROBE_OUTPUT+'/result.json' ,JSON.stringify({cardVisible:true,documentHelper:found,installSubmissions:writes,pageErrors:errors,modelReplayOnly:true}));
if(!found||writes||errors.length)throw Error('Browser assertion failed');
}finally{await b.close();}