fix(dsh): preserve acrylic and restore durable native model settings
Core regression / Python core and release configuration (push) Successful in 15s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 15s
Core regression / JavaScript syntax (pull_request) Successful in 3s
Core regression / Python core and release configuration (push) Successful in 15s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 15s
Core regression / JavaScript syntax (pull_request) Successful in 3s
This commit is contained in:
1 parent
3cec9adc5f
commit
374e1cd5bf
11 files changed
+262
-17
No files matched your search
@@ -26,7 +26,7 @@ DSH助手围绕真实任务中心工作,支持:
|
||||
|
||||
AI 不能直接写入 CAD、运行 Shell、访问任意文件或绕过确认门禁。自动异常诊断为只读;不确定执行不会自动重放,恢复必须重新核对冻结计划、检查点和业务证据。未配置模型时仍可使用任务监管和本地恢复功能,但不会产生真实模型回复。
|
||||
|
||||
模型配置保存在本机任务中心数据目录,密钥使用 Windows DPAPI 保护,不写入仓库或环境变量。首次接入可在 **工具设置 → DSH工具** 中配置 OpenAI 兼容端点和模型;开发环境也可通过 `DSH_API_BASE`、`DSH_MODEL`、`DSH_API_KEY` 临时提供配置。不要把 API key、Git 凭据或 `integration/dsh/issue-bootstrap.json` 提交到 Git。
|
||||
首次接入打开 **工具设置 → 模型 → 添加模型提供商 → 自定义模型 API**,填写 API 地址、协议和密钥,点击 **获取可用模型** 并选择需要的模型,也可手动填写模型 ID。保存后在输入框下方选择模型。设置保存在任务中心数据目录的专用 Harness profile,重启会保留;主工具预配置的密钥继续由 Windows DPAPI 保护,模型设置页新增的密钥使用 Harness 本地凭据存储。开发环境也可通过 `DSH_API_BASE`、`DSH_MODEL`、`DSH_API_KEY` 临时提供配置。不要把数据目录、API key 或 Git 凭据提交到 Git。
|
||||
|
||||
详细的能力边界、异常介入、证据链、排期和工单说明见 [DSH助手使用与监管说明](docs/user/dsh-ai-supervision.md)。源码环境可用下面的命令检查运行时门禁:
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# 工单 #16:DSH 切换材质与模型设置
|
||||
|
||||
基线:`main@3cec9ad`。工单:[切换DSH工具遇到的一些问题](https://git.simgreek.com/Skyworth_Digital_Hardware/dxdesigner-part-replacement/issues/16)。
|
||||
|
||||
## 修复内容
|
||||
|
||||
首次展示 WebEngine 时,Qt 将透明主窗口重建为 RHI 图形合成表面。返回任务中心后,重新调用 Acrylic API 或预设 alpha buffer 均不能恢复玻璃效果。DSH 现在通过 `WA_DontCreateNativeAncestors` 和 `WA_NativeWindow` 独立承载 Chromium 原生表面,保留任务中心的原 HWND 与 Acrylic。未改变系统透明度策略及“减少透明度”回退。
|
||||
|
||||
恢复官方 `ui-settings-models` 插件,提供模型提供商、自定义模型 API、手动模型列表和“获取可用模型”。通过上游公开的配置项关闭凭据引导,并使用固定 Harness 版本对应的欢迎说明配置,保留无账户/充值入口的任务工具界面。
|
||||
|
||||
重启验收发现旧启动脚本还会覆盖原生用户 `cordis.patch.yml`。应用配置现放在独立 `@dx/dsh-policy` bundle 中,原生用户配置作为上层保留。识别到旧应用生成的 overlay 时,先保存包含 SHA256 的逐字节备份,再迁移提供商与默认模型配置。原生模型页新增密钥使用 Harness 本地凭据存储,主工具预配置继续使用 DPAPI,文档分别说明。
|
||||
|
||||
## Windows 实际显示与点击
|
||||
|
||||
- 修复前屏幕截图:进入 DSH 再返回后,侧栏和右侧摘要对两种自有底图的差异均为 **0**;Acrylic 属性仍显示 true,因此属性不能作为显示成功证明。
|
||||
- 最终材质验收:`build/dsh-issue16-acrylic-final/acceptance.json`。主 HWND 全程相同,切换前后侧栏差异均为 **21.82**,右侧摘要差异均约 **9.30**;数据表差异为 **0**,保持实色。减少透明度、紧凑布局和正常关闭通过。
|
||||
- 模型页面实际输入/点击:`build/dsh-issue16-model-final/desktop-report.json`。添加自定义 API、调用自有本机测试服务器的 `GET /v1/models`、选择模型、保存提供商、重新打开编辑器读回模型均通过。未调用真实模型生成、CAD 或远端工单接口。
|
||||
- 独立新进程重启报告:`build/dsh-issue16-model-final/restart-report.json`。重启真实 Harness 后读取到页面创建的 `issue16-fixture-model`,未发起模型请求。
|
||||
- 同轮桌面验收还通过无登录/首次引导、官方页面、侧栏、SVG 动画、模型选择器、原生取消确认、导航后草稿保留及清洁退出。
|
||||
|
||||
## 回归
|
||||
|
||||
- DSH、UI、打包、队列与安全停止:412 passed(在原生子窗口修复后运行)。
|
||||
- `node tools/verify_dsh_profile_settings.mjs`:原生设置重复初始化不改写、真实提供方加载、旧配置迁移与原字节备份通过。
|
||||
- 官方 runtime CLI 门禁、模型结果裁剪与 dock 启动检查通过。
|
||||
- 独立代码审查未发现新增阻断问题。
|
||||
|
||||
本轮没有构建冻结 EXE;发布包须从修复分支重新构建,源码验收不替代发布包验收。
|
||||
@@ -6,7 +6,13 @@
|
||||
|
||||
这里直接运行 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 的官方前端与运行时,固定 npm 版本 `0.2.1-rc.5`,通过 Qt WebEngine 嵌入主窗口。官方三栏框架、原生 SVG、鲸鱼悬停动画、输入编辑器、模型选择、侧栏与停靠交互均由上游代码提供。项目增加任务监管插件和“DSH助手”名称,不再使用 Qt 控件重画聊天页面。上游许可见 `licenses/DeepSeek-Harness-MIT.txt`。
|
||||
|
||||
不显示上游账户登录、注册、充值和首次产品引导,也不注册其账户模型提供方。左下角 **工具设置** 单击打开原生设置页中的“DSH工具”说明;首页提示和任务监管面板围绕器件替换任务。输入框下方仍可选择主工具已经配置的模型。
|
||||
不显示上游账户登录、注册、充值和首次产品引导,也不注册其账户模型提供方。左下角 **工具设置** 单击打开原生设置页,包含“DSH工具”“通用设置”和“模型”;首页提示和任务监管面板围绕器件替换任务。输入框下方选择已配置的模型。
|
||||
|
||||
在 **模型 → 添加模型提供商 → 自定义模型 API** 中填写 Provider ID、API 地址、协议及可选密钥,点击 **获取可用模型**,勾选后点 **添加所选**,最后 **创建提供商**。也可手动添加模型 ID。获取失败会保留表单,便于修正地址或手动填写。已有提供方点击 **编辑** 可修改其模型目录;保存后即时生效。
|
||||
|
||||
模型页面使用官方 Harness 设置与凭据服务:用户设置保存在 `dsh/harness-home/profiles/dx-task/cordis.patch.yml`,新增的密钥通过官方本地凭据服务保存在 `dsh/harness-home/.credentials.yaml`;此文件不使用主工具的 DPAPI 格式。主工具预配置的 `provider.json` 和 DPAPI 密钥仍可加载。应用固定策略作为独立 bundle 提供,不会在启动时覆盖用户模型设置。旧版应用生成的配置升级时先逐字节备份,再保留提供方和默认模型设置;请一并备份整个数据目录,不要将凭据文件分发或提交到仓库。
|
||||
|
||||
DSH 使用独立原生子窗口承载 WebEngine,切回任务中心后保留原有 Acrylic 玻璃材质;“减少透明度”与系统高对比度等回退规则继续生效。
|
||||
|
||||
模型由本机保存的主工具配置加载;也支持启动进程的 `DSH_API_BASE`、`DSH_MODEL`、`DSH_API_KEY`。未配置模型时可查看任务上下文和操作面板,不能获得真实模型回复。
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/** Application-owned composition around the unmodified official Harness web UI. */
|
||||
import {createRequire} from 'node:module';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {mkdir, writeFile, readFile, cp} from 'node:fs/promises';
|
||||
import {mkdir, writeFile, readFile, cp, rename} from 'node:fs/promises';
|
||||
import {createHash,randomUUID} from 'node:crypto';
|
||||
import path from 'node:path';
|
||||
import {createInterface} from 'node:readline';
|
||||
|
||||
@@ -28,12 +29,14 @@ export const DISABLED = [
|
||||
// This embedded tool uses its application-owned API configuration, without
|
||||
// upstream accounts, billing, credential onboarding or product feedback.
|
||||
'ui-settings-account','account-controller','deepseek-account','llm-deepseek-account',
|
||||
'ui-settings-models','ui-message-feedback','message-feedback','command-feedback',
|
||||
'ui-message-feedback','message-feedback','command-feedback',
|
||||
];
|
||||
|
||||
export function overlay() {
|
||||
const rows = DISABLED.map(id => ({id, disabled:true}));
|
||||
rows.push({id:'agent-preset-registry',config:{default:'dx-task'}});
|
||||
rows.push({id:'ui-settings-general',config:{welcomeNoticeVersion:'2026-09-28.1'}});
|
||||
rows.push({id:'ui-settings-models',config:{credentialOnboarding:false}});
|
||||
rows.push({id:'web-runtime',config:{openBrowser:false,printUrl:false,surfaceContext:false}});
|
||||
rows.push({id:'sandbox-policy',config:{mode:'read-only',workspaceRoot:process.env.DX_DSH_WORKSPACE}});
|
||||
rows.push({id:'permission',config:{presets:{'read-only':{sandbox:'read-only',approval:'ask'}}}});
|
||||
@@ -55,6 +58,48 @@ export function overlay() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
async function replaceJson(filename,value) {
|
||||
const temporary=filename+'.'+randomUUID()+'.tmp';
|
||||
const {unlink}=await import('node:fs/promises');
|
||||
try{await writeFile(temporary,JSON.stringify(value,null,2));await rename(temporary,filename);}
|
||||
finally{await unlink(temporary).catch(error=>{if(error.code!=='ENOENT')throw error;});}
|
||||
}
|
||||
|
||||
export async function prepareProfileDirectory(dir) {
|
||||
// The official settings page writes the user patch. Application defaults
|
||||
// belong to a bundle below that patch, so rebooting must never overwrite it.
|
||||
await mkdir(dir,{recursive:true});
|
||||
const userPatch=path.join(dir,'cordis.patch.yml');
|
||||
let prior;
|
||||
try{prior=await readFile(userPatch,'utf8');}catch(error){if(error.code!=='ENOENT')throw error;}
|
||||
if(prior!==undefined){
|
||||
const {load}=require('js-yaml');
|
||||
const rows=load(prior);
|
||||
const legacy=Array.isArray(rows)&&rows.some(row=>Array.isArray(row?.insert)
|
||||
&&row.insert.some(entry=>entry.id==='dx-task'&&entry.name==='@dx/dsh-task')
|
||||
&&row.insert.some(entry=>entry.id==='preset-dx-task'));
|
||||
if(legacy){
|
||||
const digest=createHash('sha256').update(prior).digest('hex');
|
||||
const backup=userPatch+'.legacy-'+digest+'.bak';
|
||||
try{await writeFile(backup,prior,{flag:'wx'});}catch(error){
|
||||
if(error.code!=='EEXIST'||await readFile(backup,'utf8')!==prior)throw error;
|
||||
}
|
||||
const editable=new Set(['llm-pi-ai','llm-deepseek','agent-default-model']);
|
||||
await replaceJson(userPatch,rows.filter(row=>editable.has(row?.id)&&row.config)
|
||||
.map(({id,config})=>({id,config})));
|
||||
}
|
||||
}
|
||||
const policyDir=path.join(dir,'node_modules','@dx','dsh-policy');
|
||||
await mkdir(policyDir,{recursive:true});
|
||||
await cp(path.join(root,'task-plugin'),path.join(dir,'node_modules','@dx','dsh-task'),{recursive:true});
|
||||
await replaceJson(path.join(policyDir,'package.json'),{name:'@dx/dsh-policy',version:VERSION,
|
||||
private:true,dsh:{bundle:{patch:'./cordis.patch.yml'}}});
|
||||
await replaceJson(path.join(policyDir,'cordis.patch.yml'),overlay());
|
||||
await replaceJson(path.join(dir,'package.json'),{private:true,type:'module',
|
||||
dependencies:{'@dx/dsh-task':'file:'+path.join(root,'task-plugin'),'@dx/dsh-policy':'file:'+policyDir},
|
||||
dsh:{profile:{bundles:['@deepseek-ai/dsh-base','@deepseek-ai/dsh-web-app','@dx/dsh-policy']}}});
|
||||
}
|
||||
|
||||
export async function bootRuntime({announce=true} = {}) {
|
||||
const installed = require('@deepseek-ai/dsh/package.json');
|
||||
if (installed.version !== VERSION) throw Error('Unsupported Harness version: ' + installed.version);
|
||||
@@ -73,12 +118,7 @@ export async function bootRuntime({announce=true} = {}) {
|
||||
process.env.DX_DSH_WORKSPACE = path.join(process.env.DX_DSH_HOME,'workspace');
|
||||
await mkdir(process.env.DX_DSH_WORKSPACE,{recursive:true});
|
||||
const dir = path.join(process.env.DX_DSH_HOME,'profiles','dx-task');
|
||||
await mkdir(path.join(dir,'node_modules','@dx'),{recursive:true});
|
||||
await cp(path.join(root,'task-plugin'),path.join(dir,'node_modules','@dx','dsh-task'),{recursive:true});
|
||||
await writeFile(path.join(dir,'package.json'), JSON.stringify({private:true,type:'module',
|
||||
dependencies:{'@dx/dsh-task':'file:'+path.join(root,'task-plugin')},
|
||||
dsh:{profile:{bundles:['@deepseek-ai/dsh-base','@deepseek-ai/dsh-web-app']}}}));
|
||||
await writeFile(path.join(dir,'cordis.patch.yml'),JSON.stringify(overlay(),null,2));
|
||||
await prepareProfileDirectory(dir);
|
||||
const {runProfile, INSTALL_ANCHOR} = await import('@deepseek-ai/dsh/profile-boot');
|
||||
const {loadProfileDirectory,composeEntries} = await import('@deepseek-ai/dsh-app-boot');
|
||||
const {createLaunchEnvironmentSnapshot} = await import('@deepseek-ai/dsh-launch-environment');
|
||||
|
||||
@@ -13,7 +13,7 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
|
||||
h('h3',null,'任务能力'),
|
||||
h('ul',null,...['在对话中创建和修改任务;具体工程与执行范围由原生窗口确认','实时监管当前执行、阶段、耗时与保存/失败/未命中计数','保存执行回执,重启后核对原队列并手动确认恢复','预览精确位号影响;仅有料号映射时明确标记未知匹配数量','检索历史异常经验,仅将持久化核验通过的记录标为已验证','只读同步已有 Git 工单状态与评论,查看本地证据','查看会话 Token、耗时与超时状态,配置响应时限并停止模型生成','设置任务优先级、执行时间与依赖,通过原生窗口确认排期'].map(text=>h('li',{key:text},text))),
|
||||
h('h3',null,'模型与数据'),
|
||||
h('p',null,'使用主工具配置的模型,在输入框下方选择。会话保存在本机任务中心数据目录。'),
|
||||
h('p',null,'在“模型”设置页添加模型提供商或自定义模型 API,填写地址后可获取可用模型,也可手动填写模型 ID。保存后在输入框下方选择,模型设置和会话在重启后保留。'),
|
||||
h('h3',null,'异常工单'),
|
||||
h('p',null,'随工具预置专用工单上报身份,无需安装 Git 或登录。未解决的异常自动提交项目工单,并上传脱敏诊断证据。'),
|
||||
h('p',null,'工程修改与执行核验由任务中心完成。模型不直接访问工程文件或执行命令。'));
|
||||
|
||||
@@ -5,7 +5,7 @@ import json
|
||||
import codecs
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import QProcess, QProcessEnvironment, QTimer, QUrl, Signal
|
||||
from PySide6.QtCore import QProcess, QProcessEnvironment, QTimer, QUrl, Signal, Qt
|
||||
from PySide6.QtWebEngineCore import QWebEnginePage, QWebEngineProfile, QWebEngineSettings
|
||||
from PySide6.QtWebEngineWidgets import QWebEngineView
|
||||
from PySide6.QtWidgets import QLabel, QPushButton, QVBoxLayout, QWidget
|
||||
@@ -37,6 +37,11 @@ class NativeHarnessView(QWidget):
|
||||
|
||||
def __init__(self, data_root: Path, parent=None):
|
||||
super().__init__(parent)
|
||||
# Isolate Chromium's RHI surface in this child HWND. Otherwise showing
|
||||
# WebEngine recreates the translucent task-center HWND as an opaque
|
||||
# graphics surface and Acrylic stays white after the view is hidden.
|
||||
self.setAttribute(Qt.WidgetAttribute.WA_DontCreateNativeAncestors)
|
||||
self.setAttribute(Qt.WidgetAttribute.WA_NativeWindow)
|
||||
self.setObjectName('dshNativeWorkspace')
|
||||
self.setStyleSheet('QWidget#dshNativeWorkspace {background:white;}')
|
||||
self.data_root = Path(data_root)
|
||||
|
||||
@@ -29,6 +29,7 @@ from dx_productivity.trial_task_center.target_plan import ComponentTarget,Target
|
||||
def main():
|
||||
parser=argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--output',type=Path,default=Path('build/acrylic-acceptance'))
|
||||
parser.add_argument('--dsh-switch',action='store_true',help='Measure live Acrylic after entering the actual DSH WebEngine page')
|
||||
args=parser.parse_args();out=args.output.resolve();out.mkdir(parents=True,exist_ok=True)
|
||||
app=QApplication([]);app.setFont(QFont('Microsoft YaHei UI',9))
|
||||
def settle(seconds=.2):
|
||||
@@ -80,6 +81,9 @@ def main():
|
||||
assert window.property('acrylicEnabled'),'Native Acrylic not available under current system policy'
|
||||
report['native_enabled']=True
|
||||
def capture(name):
|
||||
report.setdefault('surfaces',{})[name]={
|
||||
'hwnd':int(window.winId()),'translucent':window.testAttribute(Qt.WidgetAttribute.WA_TranslucentBackground),
|
||||
'alpha':window.windowHandle().format().alphaBufferSize(),'acrylic':window.property('acrylicEnabled')}
|
||||
settle(.7)
|
||||
QToolTip.hideText();settle(.12)
|
||||
geo=window.geometry();scale=screen.devicePixelRatio()
|
||||
@@ -121,6 +125,40 @@ def main():
|
||||
assert report['right_header_backdrop_difference']>2,report
|
||||
assert report['right_execution_backdrop_difference']>2,report
|
||||
assert report['opaque_table_backdrop_difference']<1.5,report
|
||||
if args.dsh_switch:
|
||||
from PySide6.QtTest import QTest
|
||||
QTest.mouseClick(window.dsh_navigation,Qt.MouseButton.LeftButton)
|
||||
deadline=time.monotonic()+120
|
||||
while time.monotonic()<deadline:
|
||||
settle(.1)
|
||||
if window._dsh_view is not None and window._dsh_view._started:break
|
||||
assert window._dsh_view is not None and window._dsh_view._started,'DSH did not start'
|
||||
# READY precedes the Chromium load; require the real visible page.
|
||||
loaded=[]
|
||||
window._dsh_view.web.page().runJavaScript("document.body?.innerText?.includes('DSH助手')",loaded.append)
|
||||
deadline=time.monotonic()+60
|
||||
while time.monotonic()<deadline:
|
||||
settle(.1)
|
||||
if loaded and loaded[-1]:break
|
||||
if loaded:
|
||||
loaded.clear()
|
||||
window._dsh_view.web.page().runJavaScript("document.body?.innerText?.includes('DSH助手')",loaded.append)
|
||||
assert loaded and loaded[-1],'Official DSH UI did not load'
|
||||
capture('dsh-before-return')
|
||||
QTest.mouseClick(window.task_center_navigation,Qt.MouseButton.LeftButton)
|
||||
settle(.5)
|
||||
background.phase=0;background.update();capture('returned-backdrop-a')
|
||||
background.phase=1;background.update();capture('returned-backdrop-b')
|
||||
returned=ImageChops.difference(captures['returned-backdrop-a'],captures['returned-backdrop-b'])
|
||||
assert report['surfaces']['native-app-backdrop-a']['hwnd']==report['surfaces']['returned-backdrop-a']['hwnd'],report
|
||||
report['after_dsh_sidebar_difference']=mean(returned.crop(sidebar))
|
||||
report['after_dsh_header_difference']=mean(returned.crop(header))
|
||||
report['after_dsh_table_difference']=mean(returned.crop(table))
|
||||
(out/'surface-probe.json').write_text(json.dumps(report,indent=2),encoding='utf8')
|
||||
assert report['after_dsh_sidebar_difference']>2,report
|
||||
assert report['after_dsh_header_difference']>2,report
|
||||
assert report['after_dsh_table_difference']<1.5,report
|
||||
report['real_dsh_switch_restored_acrylic']=True
|
||||
window.plan_panel.find_text.setText('RV');window.plan_panel.find()
|
||||
report['visible_search_feedback']=window.plan_panel.find_result.isVisible()
|
||||
assert '2 / 6'in window.plan_panel.find_result.text()
|
||||
@@ -158,7 +196,11 @@ def main():
|
||||
window._finish_run();window._update_gates()
|
||||
window.project_options_button.setChecked(True);settle(.2)
|
||||
report['options_exposed']=window.run_panel.copy_value_check.isVisible()
|
||||
window.plan_panel.discard_all();window.close();settle(.3);store.close();logging.shutdown()
|
||||
window.plan_panel.discard_all();window.close()
|
||||
deadline=time.monotonic()+15
|
||||
while window.isVisible() and time.monotonic()<deadline:settle(.1)
|
||||
assert not window.isVisible(),'Window did not finish shutdown'
|
||||
settle(.3);store.close();logging.shutdown()
|
||||
background.close();app.processEvents()
|
||||
(out/'acceptance.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
|
||||
print(json.dumps(report,ensure_ascii=True))
|
||||
|
||||
@@ -32,6 +32,7 @@ def main():
|
||||
parser.add_argument('--port', type=int, default=9227)
|
||||
parser.add_argument('--provider-config', type=Path)
|
||||
parser.add_argument('--live-model', action='store_true')
|
||||
parser.add_argument('--model-settings-check', action='store_true', help='Create an isolated custom provider using a local model-list fixture')
|
||||
parser.add_argument('--incident', action='store_true', help='Inject a read-only controlled failure and verify automatic diagnosis and Git escalation')
|
||||
parser.add_argument('--outbox-only', action='store_true', help='Verify failed publication stays in local outbox without creating another real issue')
|
||||
parser.add_argument('--without-git', action='store_true', help='Simulate a client with no Git credentials or executable')
|
||||
@@ -146,6 +147,8 @@ def main():
|
||||
command = ['node', str(REPO / 'tools' / script), str(output), str(args.port), '--confirm-cancel']
|
||||
if args.live_model:
|
||||
command.append('--live-model')
|
||||
if args.model_settings_check:
|
||||
command.append('--model-settings-check')
|
||||
if args.outbox_only:
|
||||
command.append('--outbox-only')
|
||||
state['child'] = subprocess.Popen(command, cwd=REPO, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/** Real settings form, provider discovery and persistence against an owned fixture. */
|
||||
import assert from 'node:assert/strict';
|
||||
import {createServer} from 'node:http';
|
||||
import path from 'node:path';
|
||||
|
||||
export async function verifyModelSettings(c, output) {
|
||||
const requests=[];
|
||||
const server=createServer((req,res)=>{
|
||||
requests.push({method:req.method,path:req.url});
|
||||
res.writeHead(req.url==='/v1/models'?200:404,{'Content-Type':'application/json'});
|
||||
res.end(JSON.stringify({object:'list',data:[{id:'issue16-fixture-model',object:'model',owned_by:'acceptance'}]}));
|
||||
});
|
||||
await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));
|
||||
const endpoint=`http://127.0.0.1:${server.address().port}/v1`;
|
||||
const visible=selector=>`[...document.querySelectorAll(${JSON.stringify(selector)})].find(e=>e.getBoundingClientRect().width>0)`;
|
||||
const button=text=>`[...document.querySelectorAll('button')].find(e=>e.getBoundingClientRect().width>0&&e.textContent.trim()===${JSON.stringify(text)})`;
|
||||
async function wait(expression){
|
||||
const end=Date.now()+20000;
|
||||
while(Date.now()<end){if(await c.evaluate(expression))return;await new Promise(r=>setTimeout(r,100));}
|
||||
throw Error('Models acceptance timed out: '+expression);
|
||||
}
|
||||
async function type(selector,text){
|
||||
await c.click(visible(selector));
|
||||
await c.call('Input.insertText',{text});
|
||||
await wait(`(${visible(selector)})?.value===${JSON.stringify(text)}`);
|
||||
}
|
||||
try{
|
||||
// The caller has reached the actual upstream Custom model API form.
|
||||
await type('input[aria-label="Provider ID"]','issue16-fixture');
|
||||
await type('input[aria-label="API 地址"]',endpoint);
|
||||
const protocol='select[aria-label="API 协议"]';
|
||||
// This is a native keyboard selection, not a direct settings RPC.
|
||||
const choices=await c.evaluate(`[...(${visible(protocol)}).options].map(x=>x.value)`);
|
||||
const target=choices.indexOf('openai-completions');
|
||||
assert.ok(target>=0);
|
||||
await c.click(visible(protocol));
|
||||
await c.call('Input.dispatchKeyEvent',{type:'keyDown',key:'Home',code:'Home',windowsVirtualKeyCode:36});
|
||||
await c.call('Input.dispatchKeyEvent',{type:'keyUp',key:'Home',code:'Home',windowsVirtualKeyCode:36});
|
||||
for(let i=0;i<target;i++){
|
||||
await c.call('Input.dispatchKeyEvent',{type:'keyDown',key:'ArrowDown',code:'ArrowDown',windowsVirtualKeyCode:40});
|
||||
await c.call('Input.dispatchKeyEvent',{type:'keyUp',key:'ArrowDown',code:'ArrowDown',windowsVirtualKeyCode:40});
|
||||
}
|
||||
await c.call('Input.dispatchKeyEvent',{type:'keyDown',key:'Enter',code:'Enter',windowsVirtualKeyCode:13});
|
||||
await c.call('Input.dispatchKeyEvent',{type:'keyUp',key:'Enter',code:'Enter',windowsVirtualKeyCode:13});
|
||||
await wait(`(${visible(protocol)}).value==='openai-completions'`);
|
||||
await c.click(button('获取可用模型'));
|
||||
await wait(`document.body.innerText.includes('issue16-fixture-model')`);
|
||||
assert.deepEqual(requests,[{method:'GET',path:'/v1/models'}]);
|
||||
const candidate=`[...document.querySelectorAll('[role="dialog"] label')].find(e=>e.textContent.includes('issue16-fixture-model'))?.querySelector('input[type="checkbox"]')`;
|
||||
if(!await c.evaluate(`(${candidate})?.checked`))await c.click(candidate);
|
||||
assert.equal(await c.evaluate(`(${candidate})?.checked`),true);
|
||||
await c.click(button('添加所选'));
|
||||
await wait(`!![...document.querySelectorAll('input')].find(x=>x.value==='issue16-fixture-model')`);
|
||||
await c.screenshot(path.join(output,'custom-model-discovery.png'));
|
||||
await c.click(button('创建提供商'));
|
||||
await wait(`!document.querySelector('input[aria-label="Provider ID"]')`);
|
||||
await wait(`document.body.innerText.includes('issue16-fixture')`);
|
||||
// Reopen the real editor to read committed fields, not the submitted draft.
|
||||
await c.click(`[...document.querySelectorAll('li')].find(e=>e.textContent.includes('issue16-fixture'))?.querySelector('button')`);
|
||||
await wait(`document.body.innerText.includes('自定义设置')`);
|
||||
await c.click(`[...document.querySelectorAll('summary')].find(e=>e.textContent.includes('自定义设置'))`);
|
||||
await wait(`!![...document.querySelectorAll('input')].find(x=>x.value==='issue16-fixture-model')`);
|
||||
await c.screenshot(path.join(output,'custom-model-persisted.png'));
|
||||
return {status:'passed',provider:'issue16-fixture',model:'issue16-fixture-model',requests,
|
||||
credentialsUsed:false,remoteModelCalls:false};
|
||||
}finally{
|
||||
server.closeAllConnections();await new Promise(resolve=>server.close(resolve));
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,21 @@ try {
|
||||
assert.equal(await c.evaluate(`${accountEntries}.length`),0);
|
||||
report.checks.push('one click opens native tool settings with DSH capabilities and no account entry');
|
||||
await c.screenshot(path.join(output,'dsh-tool-settings.png'));
|
||||
await c.call('Input.dispatchKeyEvent',{type:'keyDown',key:'Escape',code:'Escape'});
|
||||
await c.call('Input.dispatchKeyEvent',{type:'keyUp',key:'Escape',code:'Escape'});
|
||||
await wait(`!document.querySelector('[data-testid="dx-tool-settings-panel"]')`);
|
||||
await c.click(`[...document.querySelectorAll('[data-shortcut-modal="settings"] nav button')].find(e=>e.textContent.trim()==='模型')`);
|
||||
await wait(`document.body.innerText.includes('自定义模型 API')||document.body.innerText.includes('添加模型提供商')`);
|
||||
if(!await c.evaluate(`document.body.innerText.includes('自定义模型 API')`))
|
||||
await c.click(`[...document.querySelectorAll('button')].find(e=>e.textContent.includes('添加模型提供商'))`);
|
||||
await wait(`document.body.innerText.includes('自定义模型 API')`);
|
||||
await c.click(`[...document.querySelectorAll('button')].find(e=>e.textContent.trim()==='自定义模型 API')`);
|
||||
await wait(`!!document.querySelector('input[aria-label="Provider ID"]')&&document.body.innerText.includes('获取可用模型')`);
|
||||
report.checks.push('actual model settings clicks reveal custom API and fetch-model controls');
|
||||
await c.screenshot(path.join(output,'dsh-custom-model-settings.png'));
|
||||
if(process.argv.includes('--model-settings-check')){
|
||||
const {verifyModelSettings}=await import('./verify_dsh_model_settings.mjs');
|
||||
report.modelSettings=await verifyModelSettings(c,output);
|
||||
}
|
||||
await c.click(`[...document.querySelectorAll('[data-shortcut-modal="settings"] button')].find(e=>e.textContent.trim()==='关闭')`);
|
||||
await wait(`!document.querySelector('[role="dialog"]')`);
|
||||
await c.screenshot(path.join(output,'dsh-tool-home.png'));
|
||||
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.');
|
||||
@@ -92,7 +104,7 @@ try {
|
||||
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.';
|
||||
} else report.reason='Live model generation was not requested for this acceptance run.';
|
||||
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()==='准备失败项重试')`);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/** Boot the actual Harness over native user settings and a legacy profile. */
|
||||
import assert from 'node:assert/strict';
|
||||
import {mkdtemp,mkdir,readFile,writeFile,readdir} from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {bootRuntime,overlay,prepareProfileDirectory} from '../integration/dsh/start.mjs';
|
||||
|
||||
const output=path.resolve('build/dsh-profile-settings-verification');
|
||||
await mkdir(output,{recursive:true});
|
||||
const base=await mkdtemp(path.join(output,'run-'));
|
||||
process.env.DX_DSH_HOME=path.join(base,'home');
|
||||
process.env.DX_DSH_CONTEXT_FILE=path.join(base,'context.json');
|
||||
await writeFile(process.env.DX_DSH_CONTEXT_FILE,JSON.stringify({task_id:'',revision:'settings-test',status:'observe'}));
|
||||
const dir=path.join(process.env.DX_DSH_HOME,'profiles/dx-task');
|
||||
await mkdir(dir,{recursive:true});
|
||||
const profile=[{id:'llm-pi-ai',config:{providers:{'profile-fixture':{
|
||||
api:'openai-completions',baseURL:'http://127.0.0.1:1/v1',models:[{id:'persisted-fixture-model'}]}}}}];
|
||||
const patch=path.join(dir,'cordis.patch.yml');
|
||||
const original='# Native user settings\n'+JSON.stringify(profile,null,2)+'\n';
|
||||
await writeFile(patch,original);
|
||||
await prepareProfileDirectory(dir);await prepareProfileDirectory(dir);
|
||||
assert.equal(await readFile(patch,'utf8'),original,'application preparation must not rewrite a native user layer');
|
||||
const legacyDir=path.join(base,'legacy');
|
||||
await mkdir(legacyDir,{recursive:true});
|
||||
const old=JSON.stringify([...overlay(),...profile],null,2);
|
||||
await writeFile(path.join(legacyDir,'cordis.patch.yml'),old);
|
||||
await prepareProfileDirectory(legacyDir);
|
||||
const migrated=await readFile(path.join(legacyDir,'cordis.patch.yml'),'utf8');
|
||||
assert.ok(JSON.parse(migrated).some(x=>x.id==='llm-pi-ai'&&x.config.providers['profile-fixture']));
|
||||
const backups=(await readdir(legacyDir)).filter(x=>x.includes('.legacy-'));
|
||||
assert.equal(backups.length,1);
|
||||
assert.equal(await readFile(path.join(legacyDir,backups[0]),'utf8'),old);
|
||||
await prepareProfileDirectory(legacyDir);
|
||||
assert.equal(await readFile(path.join(legacyDir,'cordis.patch.yml'),'utf8'),migrated);
|
||||
const {ctx,shutdown}=await bootRuntime({announce:false});
|
||||
try{
|
||||
assert.deepEqual((await ctx.llm.listModels('profile-fixture')).map(x=>x.id),['persisted-fixture-model']);
|
||||
assert.equal(ctx.tools.schemas().length,7);
|
||||
console.log(JSON.stringify({status:'passed',nativeSettingsPreserved:true,actualProviderRestored:true,
|
||||
legacyMigrationPreservedModels:true,byteBackup:true,modelRequests:0}));
|
||||
}finally{await shutdown.shutdown(0);}
|
||||
Reference in new issue
Block a user