@sanqianx/project-knowledge 5.0.33 → 5.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +9 -0
  3. package/_site/_test/chat-claudecodeui-match-test.js +22 -3
  4. package/_site/_test/fresh-product-data-test.js +1 -1
  5. package/_site/_test/glm-ui-refresh-review-test.js +1 -1
  6. package/_site/_test/harness-isolation-test.js +1 -1
  7. package/_site/_test/home-overview-test.js +64 -0
  8. package/_site/_test/index-error-display-contract-test.js +23 -1
  9. package/_site/_test/knowledge-engine-client-test.js +1 -1
  10. package/_site/_test/memory-groups-ui-test.js +149 -0
  11. package/_site/_test/module-terminal-restart-test.js +1 -1
  12. package/_site/_test/packaged-ui-smoke-test.js +40 -2
  13. package/_site/_test/parallel-capture-safety-r5-mem005-health-test.js +94 -33
  14. package/_site/_test/parallel-knowledge-client-error-code-test.js +11 -1
  15. package/_site/_test/parallel-logging-acceptance-log008-test.js +23 -11
  16. package/_site/_test/parallel-memory-candidate-test.js +134 -84
  17. package/_site/_test/parallel-memory-capture-r3-mem005-persistence-test.js +100 -38
  18. package/_site/_test/parallel-memory-capture-r4-mem005-health-test.js +92 -32
  19. package/_site/_test/parallel-memory-manual-test.js +140 -34
  20. package/_site/_test/parallel-memory-scope-test.js +91 -23
  21. package/_site/_test/parallel-memory-source-test.js +54 -25
  22. package/_site/_test/parallel-memory-sync-test.js +102 -75
  23. package/_site/_test/parallel-nav-failure-test.js +36 -16
  24. package/_site/_test/parallel-nav-offline-test.js +37 -9
  25. package/_site/_test/parallel-nav-operability-test.js +12 -1
  26. package/_site/_test/parallel-nav-switch-test.js +65 -19
  27. package/_site/_test/parallel-nav-theme-test.js +52 -7
  28. package/_site/_test/parallel-nav-viewport-test.js +13 -4
  29. package/_site/_test/product-diagnostics-ui-test.js +15 -3
  30. package/_site/_test/product-empty-state-test.js +81 -15
  31. package/_site/_test/product-import-ui-test.js +35 -9
  32. package/_site/_test/product-navigation-test.js +78 -17
  33. package/_site/_test/product-progress-status-test.js +21 -5
  34. package/_site/_test/project-module-partial-recovery-test.js +22 -7
  35. package/_site/_test/project-unbind-late-read-ui-test.js +45 -14
  36. package/_site/_test/workspace-ui-contract-test.js +38 -5
  37. package/_site/lib/engine-connection.js +1 -1
  38. package/_site/lib/engine-knowledge-client.js +1 -1
  39. package/_site/lib/server-app.js +23 -0
  40. package/_site/scripts/refresh-runtime-manifest.js +108 -0
  41. package/module-runtime-manifest.json +17 -15
  42. package/package.json +2 -2
  43. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  44. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  45. package/plugins/project-knowledge/.mcp.json +1 -1
  46. package/ui/index.html +14 -11
  47. package/ui/product.css +42 -0
  48. package/ui/product.js +830 -212
@@ -1,6 +1,20 @@
1
1
  'use strict';
2
2
  // NAV-003 — 空项目。
3
3
  //
4
+ // 迁移说明(五页简化 UI):
5
+ // - 首页空项目态保留:成功读取登记且零项目时显示「从第一个项目开始 /
6
+ // 导入第一个项目」。新首页该态依赖 /api/engine/overview 成功,因此本
7
+ // 测试实例接入真实 vendored 知识引擎(无项目、零数据),失败注入仍只
8
+ // 针对 /api/projects/projection 的首次读取(HTTP 503)。
9
+ // - work 空态已删除:改为断言导航恰好五页不含 work、#view-work 永远
10
+ // hidden、#workFrame 服务挂载仍在、'#work' hash 回落 home。
11
+ // - 检索页空态:#searchEmpty 已删除,检索页空态是 #searchContent 的
12
+ // 「输入关键词…」引导文案。
13
+ // - 记忆页空态:记忆库列表为空时显示「没有匹配的记忆。」(引擎可用、
14
+ // 零记忆)。
15
+ // - 项目页空态:#projectTree/#projectDetail 已删除,改为 #projectsContent
16
+ // 的「没有匹配的项目。」且无 .project-row。
17
+ //
4
18
  // A brand new data directory must show real empty states, a failed registry
5
19
  // read must not be presented as an empty library, and nothing may create a
6
20
  // placeholder project on the way.
@@ -17,6 +31,7 @@
17
31
  const fs = require('node:fs');
18
32
  const os = require('node:os');
19
33
  const path = require('node:path');
34
+ const crypto = require('node:crypto');
20
35
  const assert = require('node:assert/strict');
21
36
 
22
37
  // One temp root per run, resolved from the caller's environment: the batch
@@ -29,10 +44,11 @@ const { spawnServer } = require('./helpers/spawn-server');
29
44
  const { findChrome } = require('./helpers/find-chrome');
30
45
  const { launchCdpBrowser, waitFor } = require('./helpers/cdp-browser');
31
46
  const { attachNetworkCapture } = require('./helpers/cdp-network-capture');
32
- const { createProductProxy } = require('./helpers/module-fixture');
47
+ const { createProductProxy, createUpstreamProxy } = require('./helpers/module-fixture');
33
48
  const freePort = require('./helpers/free-port');
34
49
 
35
50
  const ROOT = path.resolve(__dirname, '../..');
51
+ const ENGINE_ENTRY = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [ROOT] })), 'src', 'server.js');
36
52
 
37
53
  async function main() {
38
54
  const fixture = fs.mkdtempSync(path.join(TEMP_ROOT, 'pk-product-empty-state-'));
@@ -40,12 +56,34 @@ async function main() {
40
56
  fs.mkdirSync(evidenceDir, { recursive: true });
41
57
  const port = await freePort();
42
58
  const base = `http://127.0.0.1:${port}`;
59
+ // The new home page renders its empty-project state only after the engine
60
+ // overview answered, so this instance runs the real vendored engine with
61
+ // its own empty data directory (and dead vector/bridge endpoints, so it
62
+ // can never reach a real desktop hub). The engine sits behind the shared
63
+ // upstream proxy so the product's per-instance runtime token is rewritten
64
+ // into the engine's own token, exactly like the parallel-nav harness.
65
+ const { createEngineServer } = require(ENGINE_ENTRY);
66
+ const engineToken = crypto.randomBytes(24).toString('hex');
67
+ const engine = createEngineServer({
68
+ dataDir: path.join(fixture, 'engine'),
69
+ runtimeToken: engineToken,
70
+ consume: false,
71
+ debug: true,
72
+ vectorUrl: 'http://127.0.0.1:0',
73
+ bridgeUrl: 'http://127.0.0.1:0',
74
+ });
75
+ await engine.ready;
76
+ await new Promise(resolve => engine.server.listen(0, '127.0.0.1', resolve));
77
+ const engineUrl = `http://127.0.0.1:${engine.server.address().port}`;
78
+ const engineProxy = createUpstreamProxy({ target: engineUrl, token: engineToken, tag: 'engine' });
79
+ await engineProxy.start();
43
80
  const server = spawnServer({
44
81
  root: ROOT,
45
82
  port,
46
83
  dataDir: path.join(fixture, 'data'),
47
84
  tag: 'product-empty-state',
48
85
  analysisOwner: 'engine',
86
+ extraEnv: { KB_KNOWLEDGE_ENGINE_URL: engineProxy.url },
49
87
  });
50
88
  const proxy = createProductProxy({ target: base, tag: 'product-empty-state' });
51
89
  let browser;
@@ -90,36 +128,62 @@ async function main() {
90
128
  // The retry reads the registry for real; now the empty state is a fact.
91
129
  await run("document.querySelector('#homeContent [data-action=\"refresh\"]').click()");
92
130
  await waitFor(() => run("document.getElementById('homeContent').textContent.includes('从第一个项目开始')"), 'the real empty home', 20000);
131
+ assert.equal(await run("document.getElementById('homeContent').textContent.includes('导入第一个项目')"), true, 'the empty home keeps its real import entry point');
93
132
  assert.equal(await run("document.getElementById('homeContent').textContent.includes('项目登记读取失败')"), false, 'the recovered read clears the failure');
94
133
  await browser.screenshot(path.join(evidenceDir, 'empty-state-home.png'));
95
134
 
96
- // NAV-003 expected 1: work, search, domains and projects show empty
97
- // states.
98
- await run("document.querySelector('[data-view=\"work\"]').click()");
99
- await waitFor(() => run("document.getElementById('view-work').classList.contains('active')"), 'the work view');
100
- assert.equal(await run("document.getElementById('workEmpty').hidden"), false, 'the work view shows its empty state');
101
- assert.equal(await run("document.getElementById('workEmpty').textContent.includes('导入项目后')"), true, 'the work empty state explains what is missing');
102
- assert.equal(await run("document.getElementById('workLayout').hidden"), true, 'the work layout stays hidden without a project');
103
- await browser.screenshot(path.join(evidenceDir, 'empty-state-work.png'));
135
+ // NAV-003 expected 1 (work): the workbench page is gone from the
136
+ // navigation, keeps no empty state of its own, and survives only as the
137
+ // hidden service mount.
138
+ assert.deepEqual(
139
+ await run("[...document.querySelectorAll('nav [data-view]')].map(button => button.dataset.view)"),
140
+ ['home', 'memory', 'projects', 'search', 'activity'],
141
+ 'the navigation offers exactly the five pages',
142
+ );
143
+ assert.equal(await run("document.querySelector('[data-view=\"work\"]') === null"), true, 'the work navigation button is removed');
144
+ assert.equal(await run("document.getElementById('view-work') !== null"), true, 'the work section survives in the DOM');
145
+ assert.equal(await run("document.getElementById('view-work').hidden"), true, 'the work section stays hidden');
146
+ assert.equal(await run("document.getElementById('workFrame') !== null"), true, 'the workbench service mount (workFrame) survives');
147
+ assert.equal(await run("document.getElementById('workEmpty') === null"), true, 'the retired work empty state is really gone');
148
+ await run("location.hash = '#work'");
149
+ await waitFor(
150
+ async () => (await run("document.getElementById('view-home').classList.contains('active')"))
151
+ && (await run("location.hash")) === '#home',
152
+ 'the #work hash falls back to home',
153
+ 10000,
154
+ );
155
+ assert.equal(await run("document.getElementById('view-work').hidden"), true, 'the fallback never reveals the work section');
156
+ await browser.screenshot(path.join(evidenceDir, 'empty-state-nav-contract.png'));
104
157
 
158
+ // NAV-003 expected 1 (search): the search page shows its real empty
159
+ // guidance instead of an embedded module.
105
160
  await run("document.querySelector('[data-view=\"search\"]').click()");
106
161
  await waitFor(() => run("document.getElementById('view-search').classList.contains('active')"), 'the search view');
107
- assert.equal(await run("document.getElementById('searchEmpty').hidden"), false, 'the search view shows its empty state');
108
- assert.equal(await run("document.getElementById('searchEmpty').textContent.includes('尚未导入项目')"), true, 'the search empty state explains what is missing');
162
+ assert.equal(await run("document.getElementById('searchContent').textContent.includes('输入关键词')"), true, 'the search view shows its empty guidance');
163
+ assert.equal(await run("document.getElementById('searchForm') !== null"), true, 'the search view offers the real search form');
164
+ assert.equal(await run("document.getElementById('searchEmpty') === null"), true, 'the retired search empty element is really gone');
109
165
  await browser.screenshot(path.join(evidenceDir, 'empty-state-search.png'));
110
166
 
167
+ // NAV-003 expected 1 (memory): an empty memory library is a fact of the
168
+ // engine, not a placeholder list.
169
+ await run("document.querySelector('[data-view=\"memory\"]').click()");
170
+ await waitFor(() => run("document.getElementById('view-memory').classList.contains('active')"), 'the memory view');
171
+ await waitFor(() => run("document.getElementById('memoryContent').textContent.includes('没有匹配的记忆')"), 'the real empty memory library', 20000);
172
+ assert.equal(await run("document.querySelectorAll('#memoryContent .memory-item').length"), 0, 'the memory library lists no memory');
173
+ await browser.screenshot(path.join(evidenceDir, 'empty-state-memory.png'));
174
+
175
+ // NAV-003 expected 1 (projects): the project page shows its real empty
176
+ // state.
111
177
  await run("document.querySelector('[data-view=\"projects\"]').click()");
112
178
  await waitFor(() => run("document.getElementById('view-projects').classList.contains('active')"), 'the projects view');
113
- assert.equal(await run("document.getElementById('projectTree').textContent.includes('暂无项目')"), true, 'the project tree shows the empty group');
114
- assert.equal(await run("document.getElementById('projectTree').textContent.includes('未分组')"), true, 'the empty project tree still shows the ungrouped domain');
115
- assert.equal(await run("document.getElementById('projectDetail').textContent.includes('尚未导入项目')"), true, 'the project detail shows the empty state');
179
+ await waitFor(() => run("document.getElementById('projectsContent').textContent.includes('没有匹配的项目')"), 'the real empty project list', 20000);
180
+ assert.equal(await run("document.querySelectorAll('#projectsContent .project-row').length"), 0, 'the project page lists no project');
116
181
  await browser.screenshot(path.join(evidenceDir, 'empty-state-projects.png'));
117
182
 
118
183
  const brain = await (await fetch(base + '/api/brain')).json();
119
184
  assert.equal((brain.brain.domains || []).length, 0, 'a fresh instance owns no domain');
120
185
 
121
186
  // NAV-003 expected 3: nothing created a placeholder project.
122
- assert.equal(await run("document.querySelectorAll('#projectTree [data-select-project]').length"), 0, 'the project tree offers no project');
123
187
  assert.equal(await run("document.getElementById('projectSelect').disabled"), true, 'the project selector stays disabled');
124
188
  assert.equal(await run("document.getElementById('projectSelect').value"), '', 'no project is selected');
125
189
  assert.equal(await run("localStorage.getItem('kb.project')"), null, 'no project id is remembered');
@@ -141,6 +205,8 @@ async function main() {
141
205
  await browser?.close();
142
206
  await proxy.close();
143
207
  await server.cleanup();
208
+ await engineProxy.close();
209
+ await engine.close().catch(() => {});
144
210
  fs.rmSync(fixture, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
145
211
  }
146
212
  }
@@ -1,4 +1,20 @@
1
1
  'use strict';
2
+ // 迁移说明(五页简化 UI):
3
+ // - #importDialog 导入流程、预检(preflight/HOOK_CONFLICT/重复导入)、知识
4
+ // 根目录往返(#setupImportRoot → #saveBrainSettings)与领域创建
5
+ // (#createDomain → #domainForm)全部保持原断言。
6
+ // - work 不再是导航页:桌面视图遍历改为五页(memory/search/projects/
7
+ // activity/home)。
8
+ // - 首页不再罗列项目:启动等待改为「首页读取状态落定」(本实例引擎离线,
9
+ // 落定文案是全局状态读取失败——同样是真实的非空库状态)。
10
+ // - 领域落库可见性:#projectTree 已删除,改为项目页领域筛选
11
+ // #projectDomainFilter 的选项包含新领域。
12
+ // - 导入成功跳转项目页:#projectDetail 已删除,改为 #projectsContent 的
13
+ // .project-row 列表(项目名按钮 [data-action="project-detail"])。
14
+ // - PRJ-012 失败读取不被当作刷新结果:旧 #projectTree 从登记快照渲染,
15
+ // 新 UI 中登记快照驱动顶栏 #projectSelect——断言失败读取期间选择器
16
+ // 保持旧状态、恢复读取后出现第二个项目;项目页 .project-row 走独立的
17
+ // /api/projects/page 分页端点,不受该故障影响。
2
18
  const assert = require('node:assert/strict');
3
19
  const fs = require('node:fs');
4
20
  const os = require('node:os');
@@ -51,8 +67,11 @@ async function main() {
51
67
  const run = expression => browser.evaluate(expression);
52
68
  const click = selector => run(`document.querySelector(${JSON.stringify(selector)}).click()`);
53
69
  const fill = (selector, value) => run(`(() => { const field=document.querySelector(${JSON.stringify(selector)}); field.value=${JSON.stringify(value)}; field.dispatchEvent(new Event('input',{bubbles:true})); })()`);
54
- await waitFor(() => run("document.getElementById('homeContent').textContent.includes('第一个项目')"), 'real empty state');
55
- for (const view of ['work', 'search', 'memory', 'projects', 'activity', 'home']) {
70
+ // The shell's boot reads settle: this instance's engine module answers
71
+ // 503, so the settled home state is the reported overview failure (a real
72
+ // non-empty-library state), never a fabricated empty library.
73
+ await waitFor(() => run("(() => { const text = document.getElementById('homeContent').textContent; return text.trim().length > 0 && !text.includes('正在读取'); })()"), 'real settled home state');
74
+ for (const view of ['memory', 'search', 'projects', 'activity', 'home']) {
56
75
  await click(`[data-view="${view}"]`);
57
76
  assert.equal(await run(`document.getElementById('view-${view}').classList.contains('active')`), true);
58
77
  assert.equal(await run('document.documentElement.scrollWidth > innerWidth'), false, `desktop overflow in ${view}`);
@@ -69,7 +88,7 @@ async function main() {
69
88
  assert.equal(capture.find(entry => entry.method === 'POST' && entry.url.endsWith('/api/domains')).length, 0, 'an empty domain name must not reach the product');
70
89
  assert.equal(((await api('/api/settings')).settings.brain.domains || []).length, 0, 'an empty domain name must not persist a domain');
71
90
  await fill('#domainForm input[name="name"]', '回归领域'); await click('#domainForm button[type="submit"]');
72
- await waitFor(() => run("!document.getElementById('domainDialog').open && document.getElementById('projectTree').textContent.includes('回归领域')"), 'domain persisted from UI');
91
+ await waitFor(() => run("!document.getElementById('domainDialog').open && [...document.getElementById('projectDomainFilter').options].some(option => option.textContent === '回归领域')"), 'domain persisted from UI');
73
92
  const domainsOnDisk = JSON.parse(fs.readFileSync(path.join(dataDir, 'settings.json'), 'utf8')).brain.domains || [];
74
93
  assert.ok(domainsOnDisk.some(domain => domain.name === '回归领域'), 'the domain is persisted on disk');
75
94
  assert.equal(capture.find(entry => entry.method === 'POST' && entry.url.endsWith('/api/domains')).length, 1, 'only the named domain reached the product');
@@ -106,7 +125,11 @@ async function main() {
106
125
  assert.ok(await run(`document.getElementById('preflightStatus').textContent.includes(${JSON.stringify(failureLogs[0].operationId)})`), 'UI operation ID resolves to the persisted failure');
107
126
  fs.unlinkSync(racedHook);
108
127
  await click('#confirmImport');
109
- await waitFor(() => run("!document.getElementById('importDialog').open && document.getElementById('projectDetail').textContent.includes('回归项目')"), 'import feedback', 30000);
128
+ await waitFor(() => run("!document.getElementById('importDialog').open && document.getElementById('view-projects').classList.contains('active') && document.getElementById('projectsContent').textContent.includes('回归项目')"), 'import feedback', 30000);
129
+ // The import now lands on the projects page: the new list renders one
130
+ // .project-row per registered project, with the name as its detail button.
131
+ assert.equal(await run("document.querySelectorAll('#projectsContent .project-row').length"), 1, 'the imported project is listed as one project row');
132
+ assert.equal(await run("document.querySelectorAll('#projectsContent .project-row [data-action=\"project-detail\"]').length"), 1, 'the project row carries the project detail button');
110
133
  const selected = await run("document.getElementById('projectSelect').value");
111
134
  const project = (await api('/api/projects/aggregated')).projects.find(p => p.projectId === selected);
112
135
  assert.ok(project && Object.values(project.modules).every(module => !module.registered));
@@ -190,9 +213,11 @@ async function main() {
190
213
  const registered = (await api('/api/projects/aggregated')).projects;
191
214
  assert.equal(registered.length, 2, 'the successful import registers exactly one more project');
192
215
  assert.ok(registered.some(project => project.name === '第二个项目'), 'the second project is registered');
193
- // The page does not present the failed read as fresh state.
194
- assert.equal(await run("document.querySelectorAll('#projectTree [data-select-project]').length"), 1, 'the failed read leaves the project tree on the previous state');
195
- assert.equal(await run("document.getElementById('projectTree').textContent.includes('第二个项目')"), false, 'the failed read is not shown as a refreshed list');
216
+ // The page does not present the failed read as fresh state: the registry
217
+ // snapshot drives the top-bar selector, which stays on the previous
218
+ // state until a later read really succeeds.
219
+ assert.equal(await run("[...document.getElementById('projectSelect').options].filter(option => option.value).length"), 1, 'the failed read leaves the registry selector on the previous state');
220
+ assert.equal(await run("document.getElementById('projectSelect').textContent.includes('第二个项目')"), false, 'the failed read is not shown as a refreshed registry');
196
221
  // A later read succeeds: the same import is not registered a second time.
197
222
  fetchFaults.armed = false;
198
223
  const laterRead = () => capture.find(entry => entry.method === 'GET' && entry.url.includes('/api/projects/projection') && entry.status === 200 && requests.indexOf(entry) > importIndex).length > 0;
@@ -202,8 +227,9 @@ async function main() {
202
227
  await new Promise(resolve => setTimeout(resolve, 300));
203
228
  }
204
229
  assert.ok(laterRead(), 'the later registry read succeeds');
205
- await waitFor(() => run("document.getElementById('projectTree').textContent.includes('第二个项目')"), 'the refreshed project tree', 20000);
206
- assert.equal(await run("document.querySelectorAll('#projectTree [data-select-project]').length"), 2, 'the retry reads the same two projects and creates no third');
230
+ await waitFor(() => run("document.getElementById('projectSelect').textContent.includes('第二个项目')"), 'the refreshed registry selector', 20000);
231
+ assert.equal(await run("[...document.getElementById('projectSelect').options].filter(option => option.value).length"), 2, 'the retry reads the same two projects and creates no third');
232
+ await waitFor(() => run("document.querySelectorAll('#projectsContent .project-row').length === 2"), 'the refreshed project rows', 20000);
207
233
  assert.equal((await api('/api/projects/aggregated')).projects.length, 2, 'the product registry still holds exactly two projects');
208
234
  assert.ok(fs.existsSync(knowledge2), 'the second project keeps its knowledge directory');
209
235
  await browser.send('Fetch.disable');
@@ -1,10 +1,27 @@
1
1
  'use strict';
2
- // NAV-001 — 六页导航。
2
+ // NAV-001 — 五页导航。
3
3
  //
4
- // The shell owns the six-page navigation: exactly one active navigation
4
+ // The shell owns the five-page navigation: exactly one active navigation
5
5
  // entry, exactly one visible page, and a title/hash pair that matches the
6
6
  // active view — both after a click and after the same page is restored from
7
- // its hash. Moving around must not write anything into the product.
7
+ // its hash. The retired `work` page must fall back to home from its hash
8
+ // while its hidden service mount stays in the DOM. Moving around must not
9
+ // write anything into the product.
10
+ //
11
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md):
12
+ // - 导航从六页改为五页:home/memory/projects/search/activity;`work` 导航
13
+ // 按钮已删除,`nav [data-view]` 数量 6 → 5。
14
+ // - `#view-work` section 仍在 DOM(Workbench 隐藏服务挂载点,`#workFrame`
15
+ // 保留),`.view` 总数仍为 6,但 work 永远 hidden、永无 active。
16
+ // - 页面标题映射:home「智脑首页」→「首页」、projects「领域与项目」→「项目」;
17
+ // 其余不变(memory 长期记忆 / search 知识检索 / activity 活动记录)。
18
+ // - `#work` 回落:hash `#work` 经 setView 未知视图回落 home 并改写为
19
+ // `#home`;载入时(boot)同样回落。原 work 页的点击/重载断言由
20
+ // 「#work hash 回落 + work 挂载点保持 hidden」取代。
21
+ // - 新首页空项目态依赖 /api/engine/overview 成功,因此测试实例接入真实
22
+ // vendored 知识引擎(独立空数据目录、vector/bridge 指向死端口),经
23
+ // createUpstreamProxy 改写 per-instance runtime token(与已迁移的
24
+ // product-empty-state-test 相同模式)。
8
25
  //
9
26
  // The regression drives the real product UI in a real browser against an
10
27
  // isolated instance (own port, own data dir, own knowledge dir, own Bridge
@@ -15,6 +32,7 @@
15
32
  const fs = require('node:fs');
16
33
  const os = require('node:os');
17
34
  const path = require('node:path');
35
+ const crypto = require('node:crypto');
18
36
  const assert = require('node:assert/strict');
19
37
 
20
38
  // One temp root per run, resolved from the caller's environment: the batch
@@ -27,17 +45,18 @@ const { spawnServer } = require('./helpers/spawn-server');
27
45
  const { findChrome } = require('./helpers/find-chrome');
28
46
  const { launchCdpBrowser, waitFor } = require('./helpers/cdp-browser');
29
47
  const { attachNetworkCapture } = require('./helpers/cdp-network-capture');
48
+ const { createUpstreamProxy } = require('./helpers/module-fixture');
30
49
  const freePort = require('./helpers/free-port');
31
50
 
32
51
  const ROOT = path.resolve(__dirname, '../..');
52
+ const ENGINE_ENTRY = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [ROOT] })), 'src', 'server.js');
33
53
 
34
- const VIEWS = ['home', 'work', 'search', 'memory', 'projects', 'activity'];
54
+ const VIEWS = ['home', 'memory', 'projects', 'search', 'activity'];
35
55
  const TITLES = {
36
- home: '智脑首页',
37
- work: '开始工作',
38
- search: '知识检索',
56
+ home: '首页',
39
57
  memory: '长期记忆',
40
- projects: '领域与项目',
58
+ projects: '项目',
59
+ search: '知识检索',
41
60
  activity: '活动记录',
42
61
  };
43
62
 
@@ -47,12 +66,34 @@ async function main() {
47
66
  fs.mkdirSync(evidenceDir, { recursive: true });
48
67
  const port = await freePort();
49
68
  const base = `http://127.0.0.1:${port}`;
69
+ // The five-page home renders its empty-project state only after the engine
70
+ // overview answered, so this instance runs the real vendored engine with
71
+ // its own empty data directory (and dead vector/bridge endpoints, so it
72
+ // can never reach a real desktop hub). The engine sits behind the shared
73
+ // upstream proxy so the product's per-instance runtime token is rewritten
74
+ // into the engine's own token.
75
+ const { createEngineServer } = require(ENGINE_ENTRY);
76
+ const engineToken = crypto.randomBytes(24).toString('hex');
77
+ const engine = createEngineServer({
78
+ dataDir: path.join(fixture, 'engine'),
79
+ runtimeToken: engineToken,
80
+ consume: false,
81
+ debug: true,
82
+ vectorUrl: 'http://127.0.0.1:0',
83
+ bridgeUrl: 'http://127.0.0.1:0',
84
+ });
85
+ await engine.ready;
86
+ await new Promise(resolve => engine.server.listen(0, '127.0.0.1', resolve));
87
+ const engineUrl = `http://127.0.0.1:${engine.server.address().port}`;
88
+ const engineProxy = createUpstreamProxy({ target: engineUrl, token: engineToken, tag: 'engine' });
89
+ await engineProxy.start();
50
90
  const server = spawnServer({
51
91
  root: ROOT,
52
92
  port,
53
93
  dataDir: path.join(fixture, 'data'),
54
94
  tag: 'product-navigation',
55
95
  analysisOwner: 'engine',
96
+ extraEnv: { KB_KNOWLEDGE_ENGINE_URL: engineProxy.url },
56
97
  });
57
98
  let browser;
58
99
  try {
@@ -73,8 +114,9 @@ async function main() {
73
114
  const run = expression => browser.evaluate(expression);
74
115
 
75
116
  await waitFor(() => run("document.getElementById('homeContent').textContent.includes('第一个项目')"), 'the real empty home', 20000);
76
- assert.equal(await run("document.querySelectorAll('nav [data-view]').length"), 6, 'the shell exposes six navigation entries');
77
- assert.equal(await run("document.querySelectorAll('.view').length"), 6, 'the shell owns six pages');
117
+ assert.equal(await run("document.querySelectorAll('nav [data-view]').length"), 5, 'the shell exposes five navigation entries');
118
+ assert.equal(await run("document.querySelector('[data-view=\"work\"]')"), null, 'the retired work page no longer has a navigation entry');
119
+ assert.equal(await run("document.querySelectorAll('.view').length"), 6, 'five pages plus the hidden work service mount');
78
120
 
79
121
  const readShell = () => run(`(() => ({
80
122
  marker: window.__navMarker === undefined ? null : String(window.__navMarker),
@@ -85,15 +127,20 @@ async function main() {
85
127
  href: location.href,
86
128
  navCount: document.querySelectorAll('[data-view]').length,
87
129
  documentTitle: document.title,
88
- scopeActive: document.querySelectorAll('[data-scope].active').length,
130
+ workHidden: document.getElementById('view-work').hidden,
131
+ workActive: document.getElementById('view-work').classList.contains('active'),
132
+ workFrameKept: Boolean(document.getElementById('workFrame')),
89
133
  }))()`);
90
134
 
91
135
  const assertShell = (shell, view, phase) => {
92
- const where = `${phase} (href=${shell.href}, nav=${shell.navCount}, title=${shell.documentTitle}, scopeActive=${shell.scopeActive}, exceptions=${JSON.stringify(browser.exceptions)})`;
136
+ const where = `${phase} (href=${shell.href}, nav=${shell.navCount}, title=${shell.documentTitle}, exceptions=${JSON.stringify(browser.exceptions)})`;
93
137
  assert.deepEqual(shell.activeNav, [view], `${where}: only ${view} is the active navigation entry`);
94
138
  assert.deepEqual(shell.activeView, [`view-${view}`], `${where}: only view-${view} is the visible page`);
95
139
  assert.equal(shell.title, TITLES[view], `${where}: the page title matches ${view}`);
96
140
  assert.equal(shell.hash, `#${view}`, `${where}: the hash matches ${view}`);
141
+ assert.equal(shell.workHidden, true, `${where}: the hidden work service mount never becomes a page`);
142
+ assert.equal(shell.workActive, false, `${where}: view-work is never the active page`);
143
+ assert.equal(shell.workFrameKept, true, `${where}: the workbench service mount iframe survives without a work page`);
97
144
  };
98
145
 
99
146
  // NAV-001 expected 1 + 2: one active entry, and title/hash/selection in
@@ -106,6 +153,10 @@ async function main() {
106
153
  }
107
154
 
108
155
  // The same four properties after the hash alone restores the page.
156
+ const bootedInto = view => shell => shell && shell.marker === null
157
+ && shell.activeNav.length === 1 && shell.activeNav[0] === view
158
+ && shell.activeView.length === 1 && shell.activeView[0] === `view-${view}`
159
+ && shell.title === TITLES[view] && shell.hash === `#${view}`;
109
160
  for (const view of VIEWS) {
110
161
  await run(`location.hash = '#${view}'`);
111
162
  await waitFor(() => run(`location.hash === '#${view}'`), `the ${view} hash`);
@@ -116,15 +167,23 @@ async function main() {
116
167
  // shell properties prove the product booted into that view - a complete
117
168
  // readyState alone cannot show that. One atomic evaluation per attempt;
118
169
  // two round-trips can straddle the document swap.
119
- const bootedInto = view => shell => shell && shell.marker === null
120
- && shell.activeNav.length === 1 && shell.activeNav[0] === view
121
- && shell.activeView.length === 1 && shell.activeView[0] === `view-${view}`
122
- && shell.title === TITLES[view] && shell.hash === `#${view}`;
123
170
  await waitFor(async () => bootedInto(view)(await readShell()), `the reloaded ${view} page reaches its booted state`, 20000);
124
171
  assertShell(await readShell(), view, `reload ${view}`);
125
172
  await browser.screenshot(path.join(evidenceDir, `nav-reload-${view}.png`));
126
173
  }
127
174
 
175
+ // The retired work page must fall back to home, both from a live hash
176
+ // change and when the document boots with the stale #work hash, while its
177
+ // service mount stays hidden in the DOM.
178
+ await run("location.hash = '#work'");
179
+ await waitFor(() => run("location.hash === '#home' && document.querySelector('[data-view].active')?.dataset.view === 'home'"), 'the #work hash to fall back to home');
180
+ assertShell(await readShell(), 'home', 'work hash falls back');
181
+ await run("history.replaceState(null, '', '#work'); window.__navMarker = 'nav-work-boot'");
182
+ await browser.send('Page.reload');
183
+ await waitFor(async () => bootedInto('home')(await readShell()), 'a reloaded #work page to boot into home', 20000);
184
+ assertShell(await readShell(), 'home', 'work hash reload falls back');
185
+ await browser.screenshot(path.join(evidenceDir, 'nav-work-fallback.png'));
186
+
128
187
  // NAV-001 expected 3: moving around writes nothing.
129
188
  const writes = capture.find(entry => entry.url.includes('/api/') && !['GET', 'HEAD', 'OPTIONS'].includes(entry.method));
130
189
  assert.deepEqual(writes.map(entry => `${entry.method} ${entry.url}`), [], 'navigation performs no business write');
@@ -141,10 +200,12 @@ async function main() {
141
200
  if (fs.existsSync(projectDirs)) assert.deepEqual(fs.readdirSync(projectDirs), [], 'no project metadata directory is created');
142
201
  assert.equal(browser.exceptions.length, 0, `no uncaught product JavaScript exceptions: ${JSON.stringify(browser.exceptions)}`);
143
202
 
144
- console.log(`product-navigation-test PASS (${VIEWS.length} pages, click + hash reload, one active entry, no business write)`);
203
+ console.log(`product-navigation-test PASS (${VIEWS.length} pages, click + hash reload, #work falls back to home, one active entry, no business write)`);
145
204
  } finally {
146
205
  await browser?.close();
147
206
  await server.cleanup();
207
+ await engineProxy.close();
208
+ await engine.close().catch(() => {});
148
209
  fs.rmSync(fixture, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
149
210
  }
150
211
  }
@@ -1,4 +1,20 @@
1
1
  'use strict';
2
+ // 进度状态:活动页 SSE 连接状态、维护受阻可见性、重复 online 与真实离线重连。
3
+ //
4
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md):
5
+ // - 引擎 dataSchemaVersion 现为 4:测试桩 /api/health 由 3 改为 4,
6
+ // 否则 shell 的 engine-connection 判定 ENGINE_VERSION_MISMATCH,
7
+ // /api/engine/* 代理全部 503,SSE 永远连不上。
8
+ // - 活动页空态文案「没有知识维护记录」→「此分类没有记录。」(活动页
9
+ // 新增 all/recovering/needs/completed/changes 筛选,空态按分类显示)。
10
+ // - 「失败不得伪装为空」:新 UI 在 runs 为空时仍会显示通用空态文案,
11
+ // 维护受阻以独立错误通告呈现(#activityUpdates 顶部的 .empty.error,
12
+ // strong 标题「提交事件消费受阻」)。原「空态文案必须消失」断言映射为
13
+ // 「错误通告必须存在且带受阻标题」;恢复断言映射为「通告消失且空态
14
+ // 文案回归」。
15
+ // - 维护失败明细渲染字段从 message 改为 code · journalId · sequence
16
+ // (textContent 写入);XSS 载荷从 message 移到 code(当前真实渲染的
17
+ // 字段),message 保留载荷作纵深防御。
2
18
  const assert = require('node:assert/strict');
3
19
  const fs = require('node:fs');
4
20
  const os = require('node:os');
@@ -28,7 +44,7 @@ async function main() {
28
44
  if (cleanPath === '/api/snapshot') snapshots++;
29
45
  if (cleanPath.includes('/health')) healthRequests++;
30
46
  res.writeHead(200, { 'Content-Type': 'application/json' });
31
- res.end(JSON.stringify(cleanPath === '/api/snapshot' ? snapshot : cleanPath === '/api/projects' ? { projects: [] } : { ok: true, name: 'knowledge-engine', dataSchemaVersion: 3 }));
47
+ res.end(JSON.stringify(cleanPath === '/api/snapshot' ? snapshot : cleanPath === '/api/projects' ? { projects: [] } : { ok: true, name: 'knowledge-engine', dataSchemaVersion: 4 }));
32
48
  });
33
49
  await new Promise(resolve => upstream.listen(0, '127.0.0.1', resolve));
34
50
  const moduleUrl = `http://127.0.0.1:${upstream.address().port}`;
@@ -48,16 +64,16 @@ async function main() {
48
64
  await waitFor(async () => await status() === '已连接实时更新', 'initial SSE snapshot');
49
65
  assert.equal(connections, 1);
50
66
  await run("document.querySelector('[data-view=activity]').click()");
51
- await waitFor(() => run("document.getElementById('activityUpdates').textContent.includes('没有知识维护记录')"), 'genuine empty history');
67
+ await waitFor(() => run("document.getElementById('activityUpdates').textContent.includes('此分类没有记录')"), 'genuine empty history');
52
68
  const maintenance = journal => { snapshot.maintenance = { executionEnabled: true, consuming: true, journal }; for (const stream of streams) stream.write('event: progress\ndata: {"type":"knowledge.journal"}\n\n'); };
53
- maintenance({ error: '事件消费异常', failures: [{ journalId: 'test-journal', sequence: 7, code: 'INVALID_ARGUMENT', message: '<img src=x onerror=window.__quotaXss=1>' }] });
69
+ maintenance({ error: '事件消费异常', failures: [{ journalId: 'test-journal', sequence: 7, code: '<img src=x onerror=window.__quotaXss=1>', message: '<img src=x onerror=window.__quotaXss=1>' }] });
54
70
  await waitFor(() => run("document.getElementById('activityUpdates').textContent.includes('事件消费受阻')"), 'pre-queue failure must be visible without a run');
55
- assert.equal(await run("document.getElementById('activityUpdates').textContent.includes('没有知识维护记录')"), false, 'blocked consumption cannot masquerade as an empty history');
71
+ assert.equal(await run("document.querySelector('#activityUpdates .empty.error strong')?.textContent"), '提交事件消费受阻', 'blocked consumption surfaces as an error notice instead of a plain empty history');
56
72
  assert.equal(await run("document.querySelectorAll('#activityUpdates img').length"), 0);
57
73
  assert.equal(await run('window.__quotaXss'), undefined);
58
74
  assert.equal(await run("document.getElementById('systemTitle').textContent"), '提交事件消费受阻');
59
75
  maintenance({ error: null, failures: [] });
60
- await waitFor(() => run("document.getElementById('activityUpdates').textContent.includes('没有知识维护记录')"), 'consumption recovery clears the warning');
76
+ await waitFor(() => run("document.getElementById('activityUpdates').textContent.includes('此分类没有记录') && !document.querySelector('#activityUpdates .empty.error')"), 'consumption recovery clears the warning');
61
77
  for (let attempt = 0; attempt < 2; attempt++) {
62
78
  const beforeHealth = healthRequests, beforeSnapshot = snapshots;
63
79
  await run("window.dispatchEvent(new Event('online'))");
@@ -12,7 +12,17 @@
12
12
  // them (each can be switched offline with 503) and the real vendored
13
13
  // knowledge-engine behind a pass-through proxy that can also be switched
14
14
  // offline. The repair is the product's own action, driven from the browser:
15
- // the "修复接线" button in the project detail.
15
+ // the "修复接线" action for the ACTIVE project.
16
+ //
17
+ // 迁移说明(2026-11 五页简化 UI,只换 UI 驱动方式,业务断言不变):
18
+ // - 项目列表:#projectTree → #projectsContent / .project-row。
19
+ // - 打开项目详情:[data-select-project=<id>] → 项目名按钮
20
+ // [data-action="project-detail"][data-id=<id>];#projectDetail →
21
+ // #projectsContent 内的详情(含 [data-action="project-list"] 返回)。
22
+ // - 修复接线入口:旧项目详情里的 [data-action="repair"] → 系统抽屉里的
23
+ // #repairWiring(#openSystem 打开抽屉);修复目标与旧 UI 相同,取顶栏
24
+ // #projectSelect 的当前项目(先断言当前项目即导入项目)。
25
+ // - #wiringFeedback 反馈元素与文案断言(待恢复 + 模块名)不变。
16
26
  //
17
27
  // Boundary: the modules are not the vendored runtime, they are contract
18
28
  // faithful fixtures — the evidence is the registration state each module
@@ -152,16 +162,21 @@ async function main() {
152
162
  // The browser picks the imported project up from the product registry.
153
163
  await click('[data-view="projects"]');
154
164
  await run("document.dispatchEvent(new Event('visibilitychange'))");
155
- await waitFor(() => run("document.getElementById('projectTree').textContent.includes('部分模块项目')"), 'the imported project in the tree', 20000);
156
- await click(`[data-select-project="${projectId}"]`);
157
- await waitFor(() => run("document.getElementById('projectDetail').textContent.includes('部分模块项目')"), 'the project detail', 10000);
158
- assert.ok(await run("document.getElementById('projectDetail').querySelector('[data-action=\"repair\"]') !== null"), 'the project offers the repair action');
165
+ await waitFor(() => run("document.getElementById('projectsContent').textContent.includes('部分模块项目')"), 'the imported project in the list', 20000);
166
+ await click(`[data-action="project-detail"][data-id="${projectId}"]`);
167
+ await waitFor(() => run("document.getElementById('projectsContent').querySelector('[data-action=\"project-list\"]') !== null && document.getElementById('projectsContent').textContent.includes('部分模块项目')"), 'the project detail', 10000);
168
+ // The repair action targets the ACTIVE project and lives in the system
169
+ // drawer in the five-page UI (the old project-detail entry is gone).
170
+ await waitFor(() => run(`document.getElementById('projectSelect').value === ${JSON.stringify(projectId)}`), 'the imported project is the active project', 10000);
171
+ await click('#openSystem');
172
+ await waitFor(() => run("document.getElementById('systemDrawer').hidden === false && document.getElementById('repairWiring') !== null"), 'the system drawer', 10000);
173
+ assert.ok(await run("document.getElementById('repairWiring') !== null"), 'the project offers the repair action');
159
174
 
160
175
  // Only the terminal comes back. The other three keep answering 503.
161
176
  terminal.setOnline(true);
162
177
  const repairCalls = () => capture.find(entry => entry.method === 'POST' && entry.url.includes('/module-register'));
163
178
  const beforeRepair = repairCalls().length;
164
- await click('[data-action="repair"]');
179
+ await click('#repairWiring');
165
180
  await waitFor(() => repairCalls().length > beforeRepair, 'the repair request', 20000);
166
181
  await waitFor(() => run("document.getElementById('wiringFeedback').textContent.includes('待恢复')"), 'the repair feedback', 20000);
167
182
  const firstRepair = await capture.body(repairCalls()[beforeRepair]);
@@ -186,7 +201,7 @@ async function main() {
186
201
  // The index module comes back as well; the terminal is already wired.
187
202
  vectorHub.setOnline(true);
188
203
  const beforeSecondRepair = repairCalls().length;
189
- await click('[data-action="repair"]');
204
+ await click('#repairWiring');
190
205
  await waitFor(() => repairCalls().length > beforeSecondRepair, 'the second repair request', 20000);
191
206
  await waitFor(() => run("document.getElementById('wiringFeedback').textContent.includes('待恢复')"), 'the second repair feedback', 20000);
192
207
  const secondRepair = await capture.body(repairCalls()[beforeSecondRepair]);