feat: embed native Harness assistant and verify live task model
This commit is contained in:
1 parent
9c508333bb
commit
96227eed2e
29 files changed
+11110
-582
No files matched your search
@@ -0,0 +1,14 @@
|
||||
param()
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$dshRepoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$dshRuntimeRoot = Join-Path $dshRepoRoot 'integration/dsh'
|
||||
$dshNodeCommand = Get-Command node -ErrorAction Stop
|
||||
$dshNodeVersion = & $dshNodeCommand.Source -p 'process.versions.node'
|
||||
if ([version]$dshNodeVersion -lt [version]'24.9.0') { throw 'DSH requires Node.js 24.9.0 or later.' }
|
||||
Push-Location -LiteralPath $dshRuntimeRoot
|
||||
try {
|
||||
& npm.cmd ci --ignore-scripts --no-audit --no-fund
|
||||
if ($LASTEXITCODE -ne 0) { throw 'DSH installation failed.' }
|
||||
& $dshNodeCommand.Source start.mjs --doctor
|
||||
if ($LASTEXITCODE -ne 0) { throw 'DSH runtime verification failed.' }
|
||||
} finally { Pop-Location }
|
||||
@@ -0,0 +1,144 @@
|
||||
"""Click the real task-center menus, then test its embedded official page."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
|
||||
REPO = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(REPO / 'src'))
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--output', type=Path, default=REPO / 'build/dsh-native-desktop-verification')
|
||||
parser.add_argument('--port', type=int, default=9227)
|
||||
parser.add_argument('--provider-config', type=Path)
|
||||
parser.add_argument('--live-model', action='store_true')
|
||||
args = parser.parse_args()
|
||||
output = args.output.resolve()
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
data = output / ('data-' + time.strftime('%Y%m%d-%H%M%S'))
|
||||
if args.provider_config:
|
||||
(data / 'dsh').mkdir(parents=True, exist_ok=True)
|
||||
for name in ('provider.json', 'provider-key.dpapi'):
|
||||
shutil.copy2(args.provider_config / name, data / 'dsh' / name)
|
||||
os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = f'127.0.0.1:{args.port}'
|
||||
os.environ.pop('QT_QPA_PLATFORM', None)
|
||||
from PySide6.QtCore import QTimer, Qt
|
||||
from PySide6.QtTest import QTest
|
||||
from PySide6.QtWidgets import QApplication, QMessageBox
|
||||
from dx_productivity.trial_task_center import application
|
||||
from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow
|
||||
|
||||
report = {'driver': 'Qt QTest mouse clicks + Chromium CDP Input events', 'checks': []}
|
||||
state = {'phase': 'select', 'child': None, 'deadline': time.monotonic() + (240 if args.live_model else 150)}
|
||||
|
||||
def build_window(service):
|
||||
service.create_task('DSH接入验收任务')
|
||||
window = TrialTaskCenterWindow(service)
|
||||
window.resize(1380, 860)
|
||||
|
||||
def click_menu(action):
|
||||
window.activateWindow()
|
||||
bar = window.menuBar()
|
||||
top = bar.actions()[0]
|
||||
menu = top.menu()
|
||||
QTest.mouseClick(bar, Qt.MouseButton.LeftButton, pos=bar.actionGeometry(top).center())
|
||||
QApplication.processEvents()
|
||||
if not menu.isVisible():
|
||||
raise AssertionError('The tool menu did not open after mouse click')
|
||||
QTest.mouseClick(menu, Qt.MouseButton.LeftButton, pos=menu.actionGeometry(action).center())
|
||||
QApplication.processEvents()
|
||||
|
||||
def failed(error):
|
||||
report.update(status='failed', error=type(error).__name__ + ': ' + str(error))
|
||||
(output / 'desktop-report.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf8')
|
||||
child = state['child']
|
||||
if child and child.poll() is None:
|
||||
child.terminate()
|
||||
timer.stop()
|
||||
window.close()
|
||||
|
||||
def tick():
|
||||
try:
|
||||
if time.monotonic() > state['deadline']:
|
||||
raise TimeoutError('Native desktop acceptance timed out')
|
||||
modal = QApplication.activeModalWidget()
|
||||
if isinstance(modal, QMessageBox) and modal.windowTitle().startswith('DSH助手'):
|
||||
button = modal.button(QMessageBox.StandardButton.No)
|
||||
QTest.mouseClick(button, Qt.MouseButton.LeftButton)
|
||||
report['checks'].append('clicked No in the actual Qt confirmation dialog')
|
||||
if state['phase'] == 'select' and window.task_list.list.count() and not window._task_query.busy:
|
||||
item = window.task_list.list.item(0)
|
||||
QTest.mouseClick(window.task_list.list.viewport(), Qt.MouseButton.LeftButton,
|
||||
pos=window.task_list.list.visualItemRect(item).center())
|
||||
state['phase'] = 'menu'
|
||||
elif state['phase'] == 'menu' and window._context is not None and not window._loading:
|
||||
click_menu(window.dsh_action)
|
||||
assert window.content_stack.currentWidget() is window._dsh_view
|
||||
report['checks'].append('clicked task row and Tools > DSH assistant in the real main window')
|
||||
state['phase'] = 'ready'
|
||||
elif state['phase'] == 'ready' and window._dsh_view._started:
|
||||
command = ['node', str(REPO / 'tools/verify_dsh_native_ui.mjs'), str(output), str(args.port), '--confirm-cancel']
|
||||
if args.live_model:
|
||||
command.append('--live-model')
|
||||
state['child'] = subprocess.Popen(command, cwd=REPO, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
creationflags=subprocess.CREATE_NO_WINDOW if os.name == 'nt' else 0)
|
||||
state['phase'] = 'web'
|
||||
elif state['phase'] == 'web' and state['child'].poll() is not None:
|
||||
stdout, stderr = state['child'].communicate()
|
||||
if state['child'].returncode:
|
||||
raise RuntimeError(stderr.decode('utf8', 'replace'))
|
||||
report['web'] = json.loads((output / 'report.json').read_text(encoding='utf8'))
|
||||
click_menu(window.task_center_action)
|
||||
assert window.content_stack.currentIndex() == 0
|
||||
click_menu(window.dsh_action)
|
||||
assert window.content_stack.currentWidget() is window._dsh_view
|
||||
report['checks'].append('clicked back to task center and returned to the same native page')
|
||||
state['phase'] = 'check-preserved'
|
||||
def preserved(text):
|
||||
if '请分析当前任务' not in (text or ''):
|
||||
failed(AssertionError('Composer draft was lost when switching tool menus'))
|
||||
return
|
||||
report['checks'].append('native composer draft survived tool-menu navigation')
|
||||
window.grab().save(str(output / 'dsh-in-tool.png'))
|
||||
report['status'] = 'passed'
|
||||
(output / 'desktop-report.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf8')
|
||||
timer.stop()
|
||||
window.close()
|
||||
window._dsh_view.web.page().runJavaScript("document.querySelector('[contenteditable=true]')?.textContent", preserved)
|
||||
except Exception as error:
|
||||
failed(error)
|
||||
|
||||
timer = QTimer(window)
|
||||
timer.setInterval(150)
|
||||
timer.timeout.connect(tick)
|
||||
timer.start()
|
||||
return window
|
||||
|
||||
application._load_window = lambda: build_window
|
||||
code = application.main(['--data-root', str(data)])
|
||||
if code or report.get('status') != 'passed':
|
||||
print(json.dumps(report, ensure_ascii=False))
|
||||
return 1
|
||||
log = (data / 'logs/application.log').read_text(encoding='utf8')
|
||||
report['cleanShutdown'] = 'application_clean_shutdown exit_code=0' in log
|
||||
report['uncaughtErrors'] = 'uncaught_main_thread' in log
|
||||
if args.live_model:
|
||||
audit_file = data / 'dsh/harness-home/task-tool-audit.jsonl'
|
||||
audit = [json.loads(line) for line in audit_file.read_text(encoding='utf8').splitlines()] if audit_file.is_file() else []
|
||||
report['modelToolCalls'] = audit
|
||||
report['modelToolSucceeded'] = any(row['name'] == 'dx_task_snapshot' and row['is_error'] is False for row in audit)
|
||||
(output / 'desktop-report.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf8')
|
||||
print(json.dumps(report, ensure_ascii=True))
|
||||
return 0 if report['cleanShutdown'] and not report['uncaughtErrors'] and (not args.live_model or report['modelToolSucceeded']) else 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,58 @@
|
||||
/** Tiny CDP driver for the real Qt Chromium page; no browser mocks. */
|
||||
import {writeFile} from 'node:fs/promises';
|
||||
|
||||
export async function connect(port=9226) {
|
||||
const targets=await fetch(`http://127.0.0.1:${port}/json`).then(r=>r.json());
|
||||
const target=targets.find(x=>x.type==='page');
|
||||
if(!target) throw Error('The embedded DSH page has not opened');
|
||||
const socket=new WebSocket(target.webSocketDebuggerUrl);
|
||||
await new Promise((resolve,reject)=>{socket.onopen=resolve;socket.onerror=reject;});
|
||||
let sequence=0;
|
||||
const pending=new Map();
|
||||
socket.onmessage=event=>{
|
||||
const result=JSON.parse(event.data);
|
||||
const item=pending.get(result.id);
|
||||
if(!item) return;
|
||||
pending.delete(result.id);clearTimeout(item.timer);
|
||||
if(result.error)item.reject(Error(result.error.message));else item.resolve(result.result);
|
||||
};
|
||||
const call=(method,params={})=>new Promise((resolve,reject)=>{
|
||||
const id=++sequence;
|
||||
const timer=setTimeout(()=>{pending.delete(id);reject(Error('CDP timeout: '+method));},10000);
|
||||
pending.set(id,{resolve,reject,timer});
|
||||
socket.send(JSON.stringify({id,method,params}));
|
||||
});
|
||||
const evaluate=async expression=>{
|
||||
const result=await call('Runtime.evaluate',{expression,returnByValue:true,awaitPromise:true});
|
||||
if(result.exceptionDetails)throw Error(result.exceptionDetails.text+': '+result.exceptionDetails.exception?.description);
|
||||
return result.result.value;
|
||||
};
|
||||
return {call,evaluate,
|
||||
async click(expression) {
|
||||
let rect;
|
||||
const end=Date.now()+4000;
|
||||
while(Date.now()<end) {
|
||||
rect=await evaluate(`(()=>{const e=${expression};if(!e)throw Error('Missing click target');const r=e.getBoundingClientRect();return {x:r.x+r.width/2,y:r.y+r.height/2};})()`);
|
||||
await call('Input.dispatchMouseEvent',{type:'mouseMoved',...rect});
|
||||
await evaluate('new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve)))');
|
||||
const ready=await evaluate(`(()=>{const e=${expression};if(!e)return false;const r=e.getBoundingClientRect(),top=document.elementFromPoint(r.x+r.width/2,r.y+r.height/2);return r.width>0 && r.height>0 && (e===top || e.contains(top));})()`);
|
||||
if(ready)break;
|
||||
await new Promise(resolve=>setTimeout(resolve,80));
|
||||
}
|
||||
await call('Input.dispatchMouseEvent',{type:'mousePressed',button:'left',clickCount:1,...rect});
|
||||
await call('Input.dispatchMouseEvent',{type:'mouseReleased',button:'left',clickCount:1,...rect});
|
||||
},
|
||||
async screenshot(file) {const {data}=await call('Page.captureScreenshot',{format:'png'});await writeFile(file,Buffer.from(data,'base64'));},
|
||||
close:()=>socket.close(),
|
||||
};
|
||||
}
|
||||
|
||||
if(process.argv[1]?.endsWith('dsh_cdp.mjs')) {
|
||||
const client=await connect(Number(process.argv[2] || 9226));
|
||||
try {
|
||||
console.log(JSON.stringify(await client.evaluate(`({title:document.title,text:document.body.innerText,
|
||||
buttons:[...document.querySelectorAll('button')].map(x=>({text:x.innerText,label:x.getAttribute('aria-label'),title:x.title})),
|
||||
svg:document.querySelectorAll('svg').length,animations:document.getAnimations().length,
|
||||
animatedSvg:document.querySelectorAll('animate,animateTransform,animateMotion').length,canvas:document.querySelectorAll('canvas').length})`)));
|
||||
}finally{client.close();}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
"""Launch or render the actual DSH panel without opening CAD or a task database."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'src'))
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--screenshot', type=Path)
|
||||
parser.add_argument('--width', type=int, default=1320)
|
||||
parser.add_argument('--height', type=int, default=820)
|
||||
args = parser.parse_args()
|
||||
if args.screenshot:
|
||||
os.environ['QT_QPA_PLATFORM'] = 'offscreen'
|
||||
from PySide6.QtGui import QFont, QFontDatabase
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from dx_productivity.dsh.client import DshConfig, OpenAICompatibleClient
|
||||
from dx_productivity.trial_task_center.ui.dsh_panel import DshPanel
|
||||
|
||||
app = QApplication([])
|
||||
# Offscreen Qt does not discover the Windows system font collection itself.
|
||||
font_path = Path('C:/Windows/Fonts/msyh.ttc')
|
||||
if args.screenshot and font_path.exists():
|
||||
QFontDatabase.addApplicationFont(str(font_path))
|
||||
app.setFont(QFont('Microsoft YaHei', 10))
|
||||
panel = DshPanel(None, client=OpenAICompatibleClient(DshConfig(
|
||||
base_url=os.getenv('DSH_API_BASE', ''), model=os.getenv('DSH_MODEL', ''),
|
||||
api_key=os.getenv('DSH_API_KEY', ''))))
|
||||
panel.resize(args.width, args.height)
|
||||
panel.show()
|
||||
if args.screenshot:
|
||||
app.processEvents()
|
||||
args.screenshot.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not panel.grab().save(str(args.screenshot)):
|
||||
raise RuntimeError('Could not save screenshot')
|
||||
print(args.screenshot.resolve())
|
||||
panel.close()
|
||||
return 0
|
||||
return app.exec()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,110 @@
|
||||
/** Click the actual embedded Chromium UI and record native SVG/animation evidence. */
|
||||
import assert from 'node:assert/strict';
|
||||
import {mkdir,writeFile} from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {connect} from './dsh_cdp.mjs';
|
||||
|
||||
const output=path.resolve(process.argv[2] || 'build/dsh-native-acceptance/ui');
|
||||
await mkdir(output,{recursive:true});
|
||||
const c=await connect(Number(process.argv[3] || 9226));
|
||||
const report={driver:'Qt Chromium CDP Input events',checks:[]};
|
||||
const liveModel=process.argv.includes('--live-model');
|
||||
async function wait(expression,timeout=15000) {
|
||||
const end=Date.now()+timeout;
|
||||
while(Date.now()<end){if(await c.evaluate(expression))return;await new Promise(r=>setTimeout(r,100));}
|
||||
throw Error('UI condition timed out: '+expression);
|
||||
}
|
||||
async function dismissOnboarding() {
|
||||
const end=Date.now()+12000;
|
||||
let quiet=Date.now();
|
||||
while(Date.now()<end) {
|
||||
const modal=await c.evaluate(`({preview:!![...document.querySelectorAll('button')].find(e=>e.textContent.trim()==='继续'),start:document.body.innerText.includes('开始使用')})`);
|
||||
if(modal.preview) {
|
||||
await c.click(`[...document.querySelectorAll('button')].find(e=>e.textContent.trim()==='继续')`);
|
||||
quiet=Date.now();
|
||||
}else if(modal.start) {
|
||||
await c.click(`[...document.querySelectorAll('button[aria-label="关闭"]')].at(-1)`);
|
||||
quiet=Date.now();
|
||||
}else if(Date.now()-quiet>1000) return;
|
||||
await new Promise(resolve=>setTimeout(resolve,150));
|
||||
}
|
||||
throw Error('The native onboarding dialog could not be dismissed');
|
||||
}
|
||||
try {
|
||||
await wait(`!!document.querySelector('svg[class*="fish"]')`,45000);
|
||||
await dismissOnboarding();
|
||||
for(let attempt=0;attempt<10 && !await c.evaluate(`document.body.innerText.includes('DSH助手')`);attempt++) {
|
||||
if(await c.evaluate(`!!document.querySelector('button[aria-label="打开侧边栏"]')`))
|
||||
await c.click(`document.querySelector('button[aria-label="打开侧边栏"]')`);
|
||||
await new Promise(resolve=>setTimeout(resolve,150));
|
||||
}
|
||||
await wait(`document.body.innerText.includes('DSH助手')`);
|
||||
await wait(`!!document.querySelector('[data-testid="dx-task-panel"]')`);
|
||||
report.checks.push('official frontend and native right dock loaded');
|
||||
const context=await c.evaluate(`fetch('/dx/context').then(r=>r.json())`);
|
||||
assert.ok(context.task_id,'Select a task in the task center before running this test.');
|
||||
report.checks.push('current task received from task center');
|
||||
await c.click(`[...document.querySelectorAll('button')].find(e=>e.textContent.trim()==='刷新任务上下文')`);
|
||||
await wait(`fetch('/dx/context').then(r=>r.json()).then(d=>d.revision!==${JSON.stringify(context.revision)})`);
|
||||
report.checks.push('refresh clicked and confirmed through Qt task bridge');
|
||||
await c.click(`document.querySelectorAll('button[aria-label="新建会话"]')[1]`);
|
||||
await wait(`!!document.querySelector('[data-testid="dx-task-panel"]')`);
|
||||
report.checks.push('native new conversation retains task dock');
|
||||
if(!liveModel) {
|
||||
await c.click(`document.querySelector('button[aria-label="收起侧边栏"]')`);
|
||||
await wait(`!!document.querySelector('button[aria-label="打开侧边栏"]')`);
|
||||
await c.click(`document.querySelector('button[aria-label="打开侧边栏"]')`);
|
||||
await wait(`!!document.querySelector('button[aria-label="收起侧边栏"]')`);
|
||||
report.checks.push('native sidebar collapsed and expanded');
|
||||
}
|
||||
const fish=await c.evaluate(`(()=>{const r=document.querySelector('svg[class*="fish"]').getBoundingClientRect();return {x:r.x+r.width/2,y:r.y+r.height/2};})()`);
|
||||
await c.call('Input.dispatchMouseEvent',{type:'mouseMoved',...fish});
|
||||
await wait(`document.getAnimations().length>0 || document.querySelectorAll('svg animate').length>0`);
|
||||
report.nativeSvgCount=await c.evaluate(`document.querySelectorAll('svg').length`);
|
||||
report.nativeAnimations=await c.evaluate(`({css:document.getAnimations().length,svg:document.querySelectorAll('svg animate').length})`);
|
||||
assert.ok(report.nativeSvgCount>=15);
|
||||
for(let i=0;i<8;i++) {
|
||||
await c.screenshot(path.join(output,`hover-${i}.png`));
|
||||
await new Promise(resolve=>setTimeout(resolve,120));
|
||||
}
|
||||
report.checks.push('upstream whale SVG hover animation runs in Qt Chromium');
|
||||
const transforms=await c.evaluate(`document.getAnimations().map(a=>({name:a.animationName,time:a.currentTime}))`);
|
||||
report.animationState=transforms;
|
||||
const modelButton=`[...document.querySelectorAll('button')].find(e=>e.getBoundingClientRect().width>0 && (e.getAttribute('aria-label')==='请选择模型' || /skyworth-deepseek/.test(e.title+' '+e.getAttribute('aria-label'))))`;
|
||||
await c.click(modelButton);
|
||||
await wait(`document.querySelector('[role="dialog"],[role="menu"],[role="listbox"]')!==null`);
|
||||
report.modelPickerEntries=await c.evaluate(`[...new Set((document.body.innerText.match(/skyworth-deepseek[\\w.-]*/g)||[]))]`);
|
||||
report.checks.push('native model picker opened');
|
||||
await c.call('Input.dispatchKeyEvent',{type:'keyDown',key:'Escape',code:'Escape'});
|
||||
await c.call('Input.dispatchKeyEvent',{type:'keyUp',key:'Escape',code:'Escape'});
|
||||
await c.click(`document.querySelector('[contenteditable="true"]')`);
|
||||
await c.call('Input.insertText',{text:liveModel ? '请分析当前任务:先调用 dx_task_snapshot 获取真实任务快照,然后用中文告诉我任务名称、当前状态和允许的下一步。不要修改工程。' : '请分析当前任务的异常,并说明允许的处理方式。'});
|
||||
await wait(`document.querySelector('[contenteditable="true"]').textContent.includes('请分析当前任务')`);
|
||||
report.checks.push('typed into official composer with native keyboard input');
|
||||
report.liveModelReplyTested=false;
|
||||
if(liveModel) {
|
||||
await c.click(`document.querySelector('button[aria-label="发送消息"]')`);
|
||||
const replies=`[...document.querySelectorAll('[data-chat-group-part="response"]')].map(e=>e.innerText).join('\\n')`;
|
||||
await wait(`(${replies}).length>30 && /任务|状态/.test(${replies})`,100000);
|
||||
await wait(`![...document.querySelectorAll('button[aria-label="停止生成"]')].some(e=>e.getBoundingClientRect().width>0)`,100000);
|
||||
report.reply=await c.evaluate(replies);
|
||||
report.liveModelReplyTested=true;
|
||||
report.liveTurnCompleted=true;
|
||||
report.checks.push('real API reply rendered through the official Harness conversation');
|
||||
await c.click(`document.querySelector('[contenteditable="true"]')`);
|
||||
await c.call('Input.insertText',{text:'请分析当前任务的下一步。'});
|
||||
} else report.reason='No model credential configured in this isolated acceptance profile.';
|
||||
await c.screenshot(path.join(output,'dsh-native-final.png'));
|
||||
if(process.argv.includes('--confirm-cancel')) {
|
||||
await c.click(`[...document.querySelectorAll('button')].find(e=>e.textContent.trim()==='准备失败项重试')`);
|
||||
await wait(`fetch('/dx/context').then(r=>r.json()).then(d=>d.action_result.includes('已取消'))`,20000);
|
||||
report.checks.push('sensitive action required Qt confirmation and was cancelled');
|
||||
}
|
||||
report.status='passed';
|
||||
await writeFile(path.join(output,'report.json'),JSON.stringify(report,null,2));
|
||||
console.log(JSON.stringify(report));
|
||||
} catch(error) {
|
||||
await c.screenshot(path.join(output,'failure.png')).catch(()=>{});
|
||||
await writeFile(path.join(output,'report.json'),JSON.stringify({...report,status:'failed',error:error.message},null,2));
|
||||
throw error;
|
||||
} finally {c.close();}
|
||||
@@ -0,0 +1,66 @@
|
||||
/** Exercise the real official runtime and policy pipeline without CAD or a model. */
|
||||
import assert from 'node:assert/strict';
|
||||
import {mkdir,writeFile} from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {fileURLToPath,pathToFileURL} from 'node:url';
|
||||
import {createRequire} from 'node:module';
|
||||
import {bootRuntime} from '../integration/dsh/start.mjs';
|
||||
|
||||
const repo=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
||||
const output=path.join(repo,'build/dsh-native-cli-verification');
|
||||
await mkdir(output,{recursive:true});
|
||||
process.env.DX_DSH_HOME=path.join(output,'home');
|
||||
process.env.DX_DSH_CONTEXT_FILE=path.join(output,'context.json');
|
||||
await writeFile(process.env.DX_DSH_CONTEXT_FILE,JSON.stringify({task_id:'cli-verification',status:'paused',
|
||||
revision:'cli-revision',rules_count:2,progress:{},issue:'',issue_code:'',events:[]}));
|
||||
const {ctx,shutdown}=await bootRuntime({announce:false});
|
||||
const report={};
|
||||
try {
|
||||
const schemas=ctx.tools.schemas();
|
||||
report.tools=schemas.map(x=>x.name);
|
||||
assert.deepEqual(report.tools,['dx_task_snapshot']);
|
||||
const presets=await ctx.agentPresets.list();
|
||||
report.presets=presets.map(x=>x.id);
|
||||
assert.deepEqual(report.presets,['dx-task']);
|
||||
if(process.env.DSH_MODEL) {
|
||||
report.configuredModels=(await ctx.llm.listModels('dx')).map(model=>model.id);
|
||||
assert.ok(report.configuredModels.includes(process.env.DSH_MODEL));
|
||||
}
|
||||
const snapshot=await ctx.tools.execute({callId:'verify-read',name:'dx_task_snapshot',arguments:{},signal:new AbortController().signal});
|
||||
assert.equal(snapshot.isError,false,JSON.stringify(snapshot));
|
||||
report.snapshotRead=true;
|
||||
const require=createRequire(path.join(repo,'integration/dsh/package.json'));
|
||||
const {defineTool}=await import(pathToFileURL(require.resolve('@deepseek-ai/dsh-tools')).href);
|
||||
let bodyRan=false;
|
||||
const release=ctx.tools.register(defineTool({name:'forbidden_probe',description:'Never executes',parameters:{},
|
||||
output:{schema:{type:'boolean'},render:()=>[{type:'text',text:'probe'}]},execute:async()=>{bodyRan=true;return true;}}));
|
||||
const denial=await ctx.tools.execute({callId:'verify-denial',name:'forbidden_probe',arguments:{},signal:new AbortController().signal});
|
||||
release();
|
||||
assert.equal(denial.isError,true);
|
||||
assert.equal(bodyRan,false);
|
||||
report.forbiddenToolDenied=true;
|
||||
const base=`http://127.0.0.1:${ctx.webServer.port}`;
|
||||
const unauth=await fetch(base+'/dx/context');
|
||||
assert.equal(unauth.status,401);
|
||||
report.unauthenticatedContextDenied=true;
|
||||
const login=await fetch(ctx.connection.authenticatedUrl(base+'/'),{redirect:'manual'});
|
||||
const cookie=login.headers.getSetCookie().map(x=>x.split(';')[0]).join('; ');
|
||||
assert.ok(cookie);
|
||||
const auth={Cookie:cookie};
|
||||
const visible=await fetch(base+'/dx/context',{headers:auth});
|
||||
assert.equal(visible.status,200);
|
||||
assert.equal((await visible.json()).task_id,'cli-verification');
|
||||
report.authenticatedContextRead=true;
|
||||
for (const payload of [
|
||||
{action:'shell',task_id:'cli-verification',revision:'cli-revision'},
|
||||
{action:'retry_failed',task_id:'another-task',revision:'cli-revision'},
|
||||
{action:'refresh_snapshot',task_id:'cli-verification',revision:'stale-revision'},
|
||||
]) {
|
||||
const response=await fetch(base+'/dx/action',{method:'POST',headers:{...auth,'Content-Type':'application/json'},body:JSON.stringify(payload)});
|
||||
assert.equal(response.status,409);
|
||||
}
|
||||
report.invalidActionsDenied=true;
|
||||
report.status='passed';
|
||||
await writeFile(path.join(output,'report.json'),JSON.stringify(report,null,2));
|
||||
console.log(JSON.stringify(report));
|
||||
} finally {await shutdown.shutdown(0);}
|
||||
Reference in new issue
Block a user