fix(client): 模块 id 改为包名修正重复注册;补隔离测试 DSH 真机验收

This commit is contained in:
qyh15 2026-11-14 23:35:46 +08:00
parent 5256a58505
commit 2bbafe7ab1
8 changed files with 125 additions and 5 deletions

View File

@ -8,8 +8,8 @@
| 步骤 | 内容 | 状态 |
|---|---|---|
| 1 | 对照 Web / dsh-go 两份样式确认第一版范围 | ✅ 已完成(见 v1-plan、preview) |
| 2 | 项目内身份及十席会话绑定(创建/恢复/失败重试/跨项目隔离) | ✅ 代码 + 测试完成(隔离环境验证) |
| 3 | Web 导航入口 + 右侧工作台 | 🟡 源码就位,宿主接口待真机核验 |
| 2 | 项目内身份及十席会话绑定(创建/恢复/失败重试/跨项目隔离) | ✅ fake ctx 测试 + 隔离测试 DSH 真机建席验证 |
| 3 | Web 导航入口 + 右侧工作台 | ✅ 已在隔离测试 DSH 真机验证(见下) |
| 4 | dsh-go 原生面板 | 🟡 源码就位,触摸/返回/会话跳转待真机核验 |
| 5 | 双项目联调、打包发布 | ⬜ 未开始 |
@ -44,6 +44,24 @@ HTTP 处理器端到端;systemPrompt 只注入十席;Web 纯视图模型(
- dsh-go:面板入口位置、会话跳转 effect(现有 effect 无 navigation)、由 sessionId 反查项目、原生模型选择持久化、触摸面积与深浅色由宿主渲染。
- 打包:`client.js` 需 `npm run build`(依赖 esbuild devDependency)生成;当前环境未安装 esbuild,故未产出 `client.js`。
## 真实 DSH 真机验收(隔离环境,不触碰日常 DSH)
方式:用本机 dsh CLI 在独立 `DSH_HOME=.dsh-test-b` 新建 `sansheng-test` profile(由 web 模板生成),把插件装入该 profile 的 node_modules,起独立 web 服务(127.0.0.1:5988),无头 Edge 经 CDP 驱动。
结果(截图 `preview/live-01-entry.png`、`live-02-workbench.png`、`live-03-enabled.png`;脚本 `preview/check-live.mjs` 可复现):
- 左侧出现「三省六部」入口(追加型 `sidebar.footer.action`,未替换工作区/项目树)。✅
- 点击后工作台渲染十席,顺序与两字名正确:丞相/中书/尚书/门下/吏部/户部/礼部/兵部/刑部/工部;丞相居中、三省一排、六部两排。✅
- 当前项目 default-workspace 正确识别,显示「10 个角色 · 0 个会话」「启用此项目的十席」。✅
- 点「启用此项目的十席」→ 宿主真实建成 10 个独立 root session:项目 ready、10 席 bound、failed=0、无报错。✅
- 重启 DSH 进程后重开:仍「10 个角色 · 10 个会话」、无「启用」按钮、10 个会话 ID 互不相同 → 持久化与幂等通过,重启不重复建会话。✅
真机发现并已修复:客户端 bundle 模块 id 原写 `sansheng`,与包名 `dsh-sansheng` 不一致导致重复注册(duplicate factory)使入口未激活;改为 `dsh-sansheng` 后正常。
真机遗留:右侧标签页 API 报 `no tab type is registered as "sansheng-workbench"`,当前自动降级为右侧浮动面板(功能可用);正式对接标签页类型注册需再核验。
仍未验证(不能宣称完成):dsh-go 手机 App 原生面板(第 4 步,需真实客户端/设备);运行中改模型即时生效;双真实项目联调;第 5 步打包发布。
## 未改动
未安装到任何 DSH profile,未修改用户日常 DSH、node_modules 或全局默认模型。

102
preview/check-live.mjs Normal file
View File

@ -0,0 +1,102 @@
// 真机检查:无头 Edge 打开独立测试 DSH,确认入口出现、点击后工作台渲染十席。
import { spawn } from 'node:child_process'
import { mkdtemp, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
const url = process.argv[2]
if (!url) { console.error('usage: check-live.mjs <url>'); process.exit(2) }
const EDGE = process.env.EDGE ?? 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'
const dir = dirname(fileURLToPath(import.meta.url))
const profile = await mkdtemp(join(tmpdir(), 'sansheng-live-'))
const errors = []
const result = { url, entry: null, workbench: null, consoleErrors: errors }
let browser, ws
const sleep = ms => new Promise(r => setTimeout(r, ms))
async function main() {
browser = spawn(EDGE, ['--headless=new', '--disable-gpu', '--no-first-run', '--no-default-browser-check', '--remote-debugging-port=0', '--user-data-dir=' + profile, 'about:blank'], { stdio: ['ignore', 'ignore', 'pipe'] })
const endpoint = await new Promise((resolve, reject) => {
let log = ''
const timer = setTimeout(() => reject(new Error('browser startup timeout')), 20000)
browser.stderr.on('data', b => { log += b; const m = log.match(/DevTools listening on (.+)/); if (m) { clearTimeout(timer); resolve(m[1].trim()) } })
browser.on('error', reject)
})
ws = new WebSocket(endpoint)
await new Promise((resolve, reject) => { ws.onopen = resolve; ws.onerror = reject })
let n = 0
const pending = new Map()
ws.onmessage = e => {
const m = JSON.parse(e.data)
if (m.id) { const p = pending.get(m.id); pending.delete(m.id); if (m.error) p.reject(Error(JSON.stringify(m.error))); else p.resolve(m.result) }
else if (m.method === 'Runtime.exceptionThrown') errors.push('exception: ' + (m.params.exceptionDetails.exception?.description || m.params.exceptionDetails.text))
else if (m.method === 'Runtime.consoleAPICalled' && ['error', 'warning'].includes(m.params.type)) {
const text = (m.params.args || []).map(a => a.value ?? a.description ?? '').join(' ')
if (/sansheng|error|failed|did not activate|duplicate/i.test(text)) errors.push(m.params.type + ': ' + text.slice(0, 400))
}
}
const cdp = (method, params = {}, sessionId) => new Promise((resolve, reject) => { const id = ++n; pending.set(id, { resolve, reject }); ws.send(JSON.stringify({ id, method, params, ...(sessionId ? { sessionId } : {}) })) })
const { targetId } = await cdp('Target.createTarget', { url: 'about:blank' })
const { sessionId } = await cdp('Target.attachToTarget', { targetId, flatten: true })
const call = (m, p = {}) => cdp(m, p, sessionId)
await call('Page.enable'); await call('Runtime.enable')
const evaluate = async expression => {
const r = await call('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true })
if (r.exceptionDetails) throw Error(r.exceptionDetails.exception?.description || r.exceptionDetails.text)
return r.result.value
}
const waitFor = async (expr, timeout = 45000, step = 250) => { const end = Date.now() + timeout; while (Date.now() < end) { try { if (await evaluate(expr)) return true } catch {} await sleep(step) } return false }
const shot = async name => { const r = await call('Page.captureScreenshot', { format: 'png', captureBeyondViewport: false }); await writeFile(join(dir, name), Buffer.from(r.data, 'base64')) }
await call('Emulation.setDeviceMetricsOverride', { width: 1440, height: 900, deviceScaleFactor: 1, mobile: false })
await call('Page.navigate', { url })
await waitFor("document.readyState === 'complete'", 30000)
const foundEntry = await waitFor("!!document.querySelector('.ssw-entry')", 60000)
result.entry = await evaluate(`(() => ({ found: !!document.querySelector('.ssw-entry'), text: document.querySelector('.ssw-entry')?.innerText?.trim() ?? null, title: document.title }))()`)
await shot('live-01-entry.png')
if (foundEntry) {
await evaluate("document.querySelector('.ssw-entry').click(); true")
const foundRoot = await waitFor("!!(document.querySelector('.ssw-root') || document.querySelector('.ssw-float'))", 15000)
await sleep(3000)
result.workbench = await evaluate(`(() => {
const root = document.querySelector('.ssw-root') || document.querySelector('.ssw-float')
const seats = document.querySelectorAll('.ssw-seat')
return {
found: !!root,
rootClass: root ? root.className : null,
headTitle: document.querySelector('.ssw-head-title')?.innerText?.trim() ?? null,
seatCount: seats.length,
seatNames: Array.from(seats).map(s => s.querySelector('.ssw-role-name')?.innerText?.trim()).filter(Boolean),
countLabel: document.querySelector('.ssw-count')?.innerText?.trim() ?? null,
enableText: document.querySelector('.ssw-enable .ssw-primary')?.innerText?.trim() ?? null,
currentName: document.querySelector('.ssw-current-name')?.innerText?.trim() ?? null,
error: document.querySelector('.ssw-error')?.innerText?.trim() ?? null,
empty: document.querySelector('.ssw-empty')?.innerText?.replace(/\\s+/g, ' ').trim() ?? null,
loading: !!document.querySelector('.ssw-loading'),
rootText: root ? root.innerText.replace(/\\s+/g, ' ').trim().slice(0, 700) : null,
}
})()`)
await shot('live-02-workbench.png')
if (process.argv.includes('--enable') && await evaluate("!!document.querySelector('.ssw-enable .ssw-primary')")) {
await evaluate("document.querySelector('.ssw-enable .ssw-primary').click(); true")
const done = await waitFor("(() => { const c = document.querySelector('.ssw-count'); return c && /10 个会话/.test(c.innerText) })()", 60000)
await sleep(1500)
result.enable = await evaluate(`(() => ({
done: !!done_placeholder,
count: document.querySelector('.ssw-count')?.innerText?.trim() ?? null,
bound: document.querySelectorAll('.ssw-dot[data-status=bound]').length,
failed: document.querySelectorAll('.ssw-dot[data-status=failed]').length,
error: document.querySelector('.ssw-error')?.innerText?.trim() ?? null,
notice: document.querySelector('.ssw-notice')?.innerText?.trim() ?? null,
}))()`.replace('done_placeholder', String(done)))
await shot('live-03-enabled.png')
}
}
result.pass = !!(result.entry?.found && result.workbench?.found && (result.workbench?.seatCount === 10 || result.workbench?.enableText))
}
try { await main() } catch (error) { result.fatal = String(error?.stack ?? error) } finally { try { ws?.close() } catch {}; try { browser?.kill() } catch {} }
console.log(JSON.stringify(result, null, 2))

BIN
preview/live-01-entry.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

BIN
preview/live-03-enabled.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

View File

@ -6,7 +6,7 @@
当前进度(对应 `docs/v1-plan.md` §7 实施顺序):
- ✅ 第 2 步:项目内身份与十席会话绑定(宿主服务 + 严格创建/恢复/失败重试/跨项目隔离,`npm test` 用 fake ctx 验证)。
- 🟡 第 3 步:Web 入口与右侧工作台(源代码就位,导航/侧栏/会话跳转的原生接口仍需真机核验,见 docs)。
- ✅ 第 3 步:Web 入口与右侧工作台(已在隔离测试 DSH 真机验证:入口、十席工作台、真实建十个会话、重启幂等)。
- 🟡 第 4 步:dsh-go 原生面板(源代码就位,触摸/返回/会话跳转需真机核验)。
- ⬜ 第 5 步:双项目联调后打包发布。

View File

@ -1,6 +1,6 @@
// Generated from src/client by `npm run build` (scripts/build-client.mjs). Do not edit by hand.
window.__ModuleLoader__.load({
id: 'sansheng',
id: 'dsh-sansheng',
factory: (require) => {
const module = { exports: {} }
var __defProp = Object.defineProperty;

View File

@ -32,7 +32,7 @@ export async function bundleClient() {
return [
'// Generated from src/client by `npm run build` (scripts/build-client.mjs). Do not edit by hand.',
'window.__ModuleLoader__.load({',
" id: 'sansheng',",
" id: 'dsh-sansheng',",
' factory: (require) => {',
'const module = { exports: {} }',
result.outputFiles[0].text.trimEnd(),