diff --git a/README.md b/README.md index b4279fb..9dfbaa5 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ ## 验证 ```sh -node --test --test-isolation=none sansheng/test/*.test.js # 155 tests +node --test --test-isolation=none sansheng/test/*.test.js # 156 tests node --check sansheng/client.js && node --check sansheng/index.js ``` diff --git a/docs/verification/02-test-matrix.md b/docs/verification/02-test-matrix.md index 3d329e8..c865914 100644 --- a/docs/verification/02-test-matrix.md +++ b/docs/verification/02-test-matrix.md @@ -1,7 +1,7 @@ # 验收矩阵与证据状态(候选版本 v0.2.5) 日期:2026-11-14 -结论:**候选版本**。仓库内自动化回归 **155/155 通过**;已在隔离测试 profile(独立 DSH_HOME,宿主 0.2.2-rc.3)完成真实宿主冒烟:原生项目树、原生聊天、右栏三卡与 Bot 切换,DS-Bot 全局 shell 未接管,控制台无 DS-Bot 重挂/设置冲突警告,证据见 `03-host-smoke.md`。真实模型 E2E(E01–E04)、长消息/连续工具流仍缺失;用户日常 desktop profile 未修改。 +结论:**候选版本**。仓库内自动化回归 **156/156 通过**;已在隔离测试 profile(独立 DSH_HOME,宿主 0.2.2-rc.3)完成真实宿主冒烟:原生项目树、原生聊天、右栏三卡与 Bot 切换,DS-Bot 全局 shell 未接管,控制台无 DS-Bot 重挂/设置冲突警告,证据见 `03-host-smoke.md`。真实模型 E2E(E01–E04)、长消息/连续工具流仍缺失;用户日常 desktop profile 未修改。 ## 1. 自动化测试入口 @@ -19,7 +19,7 @@ node --check sansheng/index.js - `api-v3.test.js`:状态投影与历史折叠 - `gate-install.test.js`:F01、unknown 身份、治理损坏、跨项目 - `client.test.js`:右栏/入口/项目上下文(见 UI 工作包报告) -- 审查修复回归:Q01/Q01b/Q01c(store+apply)、Q02/Q02b(governance+gate 双故障)、Q03(unknown 工具)、Q04(governance + 真实 memory install + peer stub)、Q05/Q05b/Q05c(observer)、Q06/G06(draft+最终复核)、Q07(artifact/gate)、Q08/Q08b/Q08c(提交租约+真实写根+junction)、Q09(store+HTTP route)、Q10(records)、Q11/Q11b/Q11c/Q11d(config 回滚+并发+recovery sidecar)、Q12/Q12b(Hook+超时)、Q13(needsKey 服务端+前端)。 +- 审查修复回归:Q01/Q01b/Q01c(store+apply)、Q02/Q02b(governance+gate 双故障)、Q03(unknown 工具)、Q04(governance + 真实 memory install + peer stub)、Q05/Q05b/Q05c(observer)、Q06/G06(draft+最终复核)、Q07(artifact/gate)、Q08/Q08b/Q08c(提交租约+真实写根+junction)、Q09(store+HTTP route)、Q10(records)、Q11/Q11b/Q11c/Q11d(config 回滚+并发+recovery sidecar)、Q12/Q12b/Q12c(Hook+超时+真实 useSanshengState)、Q13(needsKey 服务端+前端)。 ## 2. 入口与布局 @@ -104,7 +104,7 @@ node --check sansheng/index.js | Q09 | 已修 | `store.test.js` Q09 + `route.test.js` Q09:跨项目核实 409 且不写事件;事件与状态同事务 | | Q10 | 已修 | `records.test.js` Q10:重复 draft/start 拒绝,新建/启动确认 | | Q11 | 部分修 | Q11/Q11b/Q11c:失败角色也补偿、保留 model/appliedModel、整段配置按项目串行、sidecar recovery;真实 session selectModel 故障和 DS-Bot 并发外部写未测 | -| Q12 | 部分修 | Q12/Q12b:跨项目失败清空、切换立即刷新、节流 trailing、12s 超时、Hook 保留 loading;真实 React 浏览器时间线未自动化 | +| Q12 | 已修(真实 Hook 级) | `client.test.js` Q12c 用 mini React hooks 挂载真实 `useSanshengState`:切项目先 loading、旧数据清空、B 失败后显示 B 错误;真实浏览器像素时间线仍未自动化 | | Q13 | 已修 | 服务端 `availabilityOf` 拒绝 needsKey/不在目录模型;前端选项禁用并标注 | ## 8. 发布门核对 diff --git a/docs/verification/04-release.md b/docs/verification/04-release.md index f6fc67c..2f0ede7 100644 --- a/docs/verification/04-release.md +++ b/docs/verification/04-release.md @@ -83,7 +83,7 @@ node pack --pack-destination ..\dist - Q04 记忆边界有真实 memory.js 集成测试(peer stub loader),覆盖群快照/显式 recall;真实模型/宿主记忆注入仍未做。 - Q08 已覆盖已知写工具、同根/junction 别名、提交与写工具共用根锁;后台 job 返回后仍会释放租约,第三方工具若绕过这些入口仍可能不受根租约约束;进程崩溃后的租约只能等过期。 - Q11 真实 `selectModel`/忙碌会话故障注入未执行;补偿失败 sidecar `config-recovery.jsonl` 在 Store 完全不可写时也可能失败。 -- Q12 的真实 React 浏览器时间线未自动化;已用提取的 poller/Hook helper + 真实宿主浅色冒烟覆盖。 +- Q12 有真实 `useSanshengState` Hook 级测试(mini React hooks);真实浏览器像素时间线仍未自动化。 - UI01–UI03 在隔离测试 profile 的浅色 1440×900、深色 1440×900、窄屏 900×700 验证;Bot 详情/终端/文件交叉打开、DS-Bot 先加载顺序仍未操作。 - 真实模型 E2E(E01–E04)、长消息/连续工具流仍缺;不把 154 项单测写成真实 DSH E2E 全通过。 - `workspace-groups-remote` 项目树右键菜单未在真实测试 profile 复现(DS Bot 页面占据左栏);组件级 contextMenus 测试通过。用户日常环境若项目树可见,右键「三省六部」应可用;若不可用,用左栏底部「三省」入口。 diff --git a/docs/verification/05-delivery-note.md b/docs/verification/05-delivery-note.md index 18b0dcd..d3437a0 100644 --- a/docs/verification/05-delivery-note.md +++ b/docs/verification/05-delivery-note.md @@ -12,7 +12,7 @@ https://git.qyhhh.top/DeepsSeekHarness/dsh-sansheng-liubu/releases/tag/v0.2.2-sansheng - 发布产物:`dist/dsh-sansheng-sansheng-0.2.2.tgz`、`dist/ds-bot-0.3.2-sansheng.2.tgz` - 审查修复 v0.2.3:本地提交(当前 HEAD)(`dsh-sansheng-sansheng@0.2.3` / `ds-bot@0.3.2-sansheng.3`),144/144 回归;按审查“不授权推送/发布”暂未推 Gitea,tarball 只在 `dist/`。 -- 第三轮审查修复 v0.2.5:`dsh-sansheng-sansheng@0.2.5` / `ds-bot@0.3.2-sansheng.5`,155/155 回归;UI01–UI03 原生共存、Q01/Q02 启动保护、Q11–Q13 补强;仍未推送/发布。 +- 第三轮审查修复 v0.2.5:`dsh-sansheng-sansheng@0.2.5` / `ds-bot@0.3.2-sansheng.5`,156/156 回归;UI01–UI03 原生共存、Q01/Q02 启动保护、Q11–Q13 补强;仍未推送/发布。 - 当前状态:候选版本,真实模型 E2E(E01–E04)未执行;日常 desktop profile 未修改。 > 说明:仓库的 `master` 分支仍是旧版结构(工作台/panel 目录),与 `feat/dsbot` 不在同一历史线。 diff --git a/sansheng/client.js b/sansheng/client.js index 65e1449..57e7351 100644 --- a/sansheng/client.js +++ b/sansheng/client.js @@ -1219,6 +1219,8 @@ window.__ModuleLoader__.load({ workspaceContextOf, workspaceIdOf, createStatePoller, + useSanshengState, + React, mergePollState, createWakeGate, normalizeModels, diff --git a/sansheng/test/client.test.js b/sansheng/test/client.test.js index 9b1fe06..4d7088f 100644 --- a/sansheng/test/client.test.js +++ b/sansheng/test/client.test.js @@ -47,18 +47,16 @@ function domStub() { return { document, styles } } -async function loadClient({ fetch: customFetch } = {}) { +async function loadClient({ fetch: customFetch, react: customReact } = {}) { const source = await readFile(new URL('../client.js', import.meta.url), 'utf8') const { document, styles } = domStub() let captured + const reactImpl = customReact ?? reactStub() const window = { __ModuleLoader__: { load(options) { captured = options - return options.factory((name) => { - if (name === 'react') return reactStub() - throw new Error(`未知模块 ${name}`) - }) + return { exports: {} } }, }, localStorage: { @@ -72,7 +70,7 @@ async function loadClient({ fetch: customFetch } = {}) { : () => Promise.reject(new Error('测试里不联网')) const run = new Function('window', 'document', 'fetch', 'nextTick', source) run(window, document, fetchImpl, () => {}) - return { module: captured.factory((name) => (name === 'react' ? reactStub() : (() => { throw new Error(name) })())), captured, document, styles, window } + return { module: captured.factory((name) => (name === 'react' ? reactImpl : (() => { throw new Error(name) })())), captured, document, styles, window } } function fakeCtx(options = {}) { @@ -666,3 +664,122 @@ test('Q12b:悬挂请求超时后进入错误状态,不永久卡住轮询', a assert.match(states.at(-1).error, /超时/) poller.stop() }) + +function hookReact() { + let cells = [] + let cursor = 0 + let pending = [] + let scheduled = null + let hookFn + let current + let setCalls = 0 + let effectCalls = 0 + const depsChanged = (a, b) => !a || !b || a.length !== b.length || a.some((value, index) => value !== b[index]) + const render = () => { + cursor = 0 + pending = [] + current = hookFn() + for (const run of pending) run() + return current + } + const schedule = () => { + if (scheduled) return + scheduled = setTimeout(() => { scheduled = null; render() }, 0) + } + const React = { + __id: 'custom-hook-react', + createElement: () => null, + Fragment: 'Fragment', + useMemo: fn => fn(), + useCallback: fn => fn(), + useRef: value => ({ current: value }), + useState(initial) { + const index = cursor++ + if (!(index in cells)) cells[index] = typeof initial === 'function' ? initial() : initial + return [cells[index], value => { + setCalls += 1 + cells[index] = typeof value === 'function' ? value(cells[index]) : value + schedule() + }] + }, + useEffect(fn, deps) { + effectCalls += 1 + const index = cursor++ + const previous = cells[index] + if (!previous || depsChanged(previous.deps, deps)) { + cells[index] = { deps, cleanup: undefined } + pending.push(() => { cells[index].cleanup = fn() }) + } + }, + useLayoutEffect: () => {}, + } + return { + React, + mount(fn) { hookFn = fn; return render() }, + get state() { return current }, + get setCalls() { return setCalls }, + get effectCalls() { return effectCalls }, + stop() { + if (scheduled) clearTimeout(scheduled) + scheduled = null + for (const cell of cells) { + if (cell && typeof cell.cleanup === 'function') { + try { cell.cleanup() } catch { /* ignore */ } + } + } + }, + } +} + +test('Q12c:真实 useSanshengState Hook 切换项目保留 loading 并清空旧数据', async () => { + let selection = { sessionId: 'sess-a' } + const workspaceItems = [ + { workspaceId: 'wa', sessionIds: ['sess-a'] }, + { workspaceId: 'wb', sessionIds: ['sess-b'] }, + ] + const sessionRows = { + byId: { + 'sess-a': { id: 'sess-a', retainedBy: { mainView: 1 } }, + 'sess-b': { id: 'sess-b', retainedBy: { mainView: 0 } }, + }, + } + const workspaceListeners = [] + const workspaces = { list: { getSnapshot: () => ({ items: workspaceItems }), subscribe: fn => { workspaceListeners.push(fn); return () => {} } } } + const sessions = { list: { getSnapshot: () => sessionRows, subscribe: fn => { return () => {} } } } + let fetchCalls = 0 + const fetch = async url => { + fetchCalls += 1 + if (url.includes('workspaceId=wa')) { + return { ok: true, status: 200, json: async () => ({ current: { id: 'A', name: 'A' }, projects: [] }) } + } + await new Promise(resolve => setTimeout(resolve, 50)) + throw new Error('B 网络断了') + } + const ctx = fakeCtx({ + uiWorkspace: { selection: { getSnapshot: () => selection } }, + workspaces, + sessions, + }) + const hook = hookReact() + const { module } = await loadClient({ fetch, react: hook.React }) + hook.mount(() => module.__test.useSanshengState(ctx, '')) + await new Promise(resolve => setTimeout(resolve, 20)) + assert.ok(hook.effectCalls >= 1, 'effect calls=' + hook.effectCalls + ' fetch=' + fetchCalls) + assert.equal(hook.state.data && hook.state.data.current && hook.state.data.current.id, 'A', JSON.stringify(hook.state)) + + selection = { sessionId: 'sess-b' } + sessionRows.byId['sess-a'].retainedBy.mainView = 0 + sessionRows.byId['sess-b'].retainedBy.mainView = 1 + assert.equal(module.__test.workspaceContextOf(ctx).workspaceId, 'wb') + for (const listener of workspaceListeners) listener() + await new Promise(resolve => setTimeout(resolve, 15)) + assert.equal(hook.state.context.workspaceId, 'wb') + assert.equal(hook.state.loading, true, '切换后先进入 loading') + assert.equal(hook.state.data, null, '旧项目数据立即清空') + + await new Promise(resolve => setTimeout(resolve, 60)) + assert.equal(hook.state.context.workspaceId, 'wb') + assert.match(hook.state.error, /B 网络断了/) + assert.equal(hook.state.data, null) + hook.stop() +})