@sanqianx/project-knowledge 5.0.32 → 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 (56) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +15 -0
  3. package/_site/_test/automatic-context-test.js +19 -0
  4. package/_site/_test/chat-claudecodeui-match-test.js +22 -3
  5. package/_site/_test/context-session-index-test.js +244 -0
  6. package/_site/_test/fixtures/retrieval-gold-queries.json +4 -0
  7. package/_site/_test/fresh-product-data-test.js +1 -1
  8. package/_site/_test/glm-ui-refresh-review-test.js +1 -1
  9. package/_site/_test/harness-isolation-test.js +1 -1
  10. package/_site/_test/home-overview-test.js +64 -0
  11. package/_site/_test/index-error-display-contract-test.js +23 -1
  12. package/_site/_test/knowledge-engine-client-test.js +1 -1
  13. package/_site/_test/memory-groups-ui-test.js +149 -0
  14. package/_site/_test/module-terminal-restart-test.js +1 -1
  15. package/_site/_test/packaged-ui-smoke-test.js +40 -2
  16. package/_site/_test/parallel-capture-safety-r5-mem005-health-test.js +94 -33
  17. package/_site/_test/parallel-knowledge-client-error-code-test.js +11 -1
  18. package/_site/_test/parallel-logging-acceptance-log008-test.js +23 -11
  19. package/_site/_test/parallel-memory-candidate-test.js +134 -84
  20. package/_site/_test/parallel-memory-capture-r3-mem005-persistence-test.js +100 -38
  21. package/_site/_test/parallel-memory-capture-r4-mem005-health-test.js +92 -32
  22. package/_site/_test/parallel-memory-manual-test.js +140 -34
  23. package/_site/_test/parallel-memory-scope-test.js +91 -23
  24. package/_site/_test/parallel-memory-source-test.js +54 -25
  25. package/_site/_test/parallel-memory-sync-test.js +102 -75
  26. package/_site/_test/parallel-nav-failure-test.js +36 -16
  27. package/_site/_test/parallel-nav-offline-test.js +37 -9
  28. package/_site/_test/parallel-nav-operability-test.js +12 -1
  29. package/_site/_test/parallel-nav-switch-test.js +65 -19
  30. package/_site/_test/parallel-nav-theme-test.js +52 -7
  31. package/_site/_test/parallel-nav-viewport-test.js +13 -4
  32. package/_site/_test/product-diagnostics-ui-test.js +15 -3
  33. package/_site/_test/product-empty-state-test.js +81 -15
  34. package/_site/_test/product-import-ui-test.js +35 -9
  35. package/_site/_test/product-navigation-test.js +78 -17
  36. package/_site/_test/product-progress-status-test.js +21 -5
  37. package/_site/_test/project-module-partial-recovery-test.js +22 -7
  38. package/_site/_test/project-unbind-late-read-ui-test.js +45 -14
  39. package/_site/_test/workspace-ui-contract-test.js +38 -5
  40. package/_site/lib/engine-connection.js +1 -1
  41. package/_site/lib/engine-knowledge-client.js +1 -1
  42. package/_site/lib/server-app.js +23 -0
  43. package/_site/scripts/ab-rank-v2-v3.js +142 -0
  44. package/_site/scripts/refresh-runtime-manifest.js +108 -0
  45. package/_site/scripts/run-retrieval-gold-isolated.js +221 -0
  46. package/_site/scripts/verify-retrieval-gold.js +57 -10
  47. package/module-runtime-manifest.json +22 -20
  48. package/package.json +2 -2
  49. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  50. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  51. package/plugins/project-knowledge/.mcp.json +1 -1
  52. package/plugins/project-knowledge/scripts/context-hook.cjs +9 -5
  53. package/plugins/project-knowledge/skills/project-knowledge/SKILL.md +39 -28
  54. package/ui/index.html +14 -11
  55. package/ui/product.css +42 -0
  56. package/ui/product.js +830 -212
@@ -0,0 +1,149 @@
1
+ 'use strict';
2
+ // _site/_test/memory-groups-ui-test.js
3
+ //
4
+ // U02 canonical: the full memory-group chain through the real five-page UI,
5
+ // a real product instance and the real knowledge engine.
6
+ //
7
+ // 新建组合 → 新增多段小记忆(加入组合)→ 选入已有记忆到第二个组合
8
+ // → 应用到项目 A/B → 从 A 解绑 → 刷新持久化 → 候选审核入组合。
9
+ //
10
+ // Every write goes through the real dialogs in a real Chrome; every read
11
+ // comes back through the real engine API and the group markdown files on
12
+ // disk. Nothing is mocked at the boundary under test.
13
+
14
+ const fs = require('node:fs');
15
+ const path = require('node:path');
16
+ const assert = require('node:assert/strict');
17
+
18
+ const { startHarness, makeRepo } = require('./helpers/parallel-memory-shell');
19
+
20
+ const EVIDENCE = process.env.PK_TEST_EVIDENCE_DIR ? path.resolve(process.env.PK_TEST_EVIDENCE_DIR) : null;
21
+ const MULTILINE_BODY = '开发与测试使用独立的数据目录和端口。\n\n- 日常知识库保持运行\n- 测试只清理本次创建的进程\n\n中文长段落保持同一条记忆,不按换行拆分。';
22
+
23
+ async function main() {
24
+ const harness = await startHarness({ tag: 'groups-ui', evidenceDir: EVIDENCE || undefined });
25
+ try {
26
+ const repoA = makeRepo(harness.fixture, 'groups-repo-a', { 'README.md': '# 项目甲\n\n保持功能简单。\n' });
27
+ const repoB = makeRepo(harness.fixture, 'groups-repo-b', { 'README.md': '# 项目乙\n\n复用成熟消息流。\n' });
28
+ const { projectId: projectIdA } = await harness.importProject(repoA, '项目甲');
29
+ const { projectId: projectIdB } = await harness.importProject(repoB, '项目乙');
30
+ await harness.requestRegistryRefresh();
31
+
32
+ // ---------- 1. 新建组合 ----------
33
+ await harness.nativeClick('nav [data-view="memory"]');
34
+ await harness.waitFor(() => harness.run("document.getElementById('view-memory').classList.contains('active')"), 'the memory view is open');
35
+ await harness.waitFor(() => harness.run("document.querySelector('[data-action=new-group]') !== null"), 'the group sidebar is rendered');
36
+ await harness.nativeClick('[data-action="new-group"]');
37
+ await harness.waitFor(() => harness.run("document.getElementById('appDialog').open === true"), 'the group dialog opens');
38
+ await harness.nativeClick('#groupForm input[name=name]');
39
+ await harness.typeText('通用约定');
40
+ await harness.nativeClick('#appDialogActions button.primary');
41
+ await harness.waitFor(() => harness.run("document.getElementById('appDialog').open === false"), 'the group dialog closes');
42
+ await harness.waitFor(() => harness.run("[...document.querySelectorAll('.memory-folders button')].some(b => b.textContent.includes('通用约定'))"), 'the new group appears in the folders');
43
+
44
+ // ---------- 2. 新增多段小记忆并加入组合 ----------
45
+ await harness.nativeClick('[data-action="new-memory"]');
46
+ await harness.waitFor(() => harness.run("document.getElementById('memoryForm') !== null"), 'the memory editor opens');
47
+ await harness.nativeClick('#memoryForm input[name=title]');
48
+ // Real-key typing drops newlines in CDP key events; multiline bodies
49
+ // enter through Input.insertText - the same CDP path a real paste uses.
50
+ await harness.nativeClick('#memoryForm input[name=title]');
51
+ await harness.browser.send('Input.insertText', { text: '开发时保护日常服务' });
52
+ await harness.nativeClick('#memoryForm textarea[name=text]');
53
+ await harness.browser.send('Input.insertText', { text: MULTILINE_BODY });
54
+ // 默认 scopeType=group;选择加入「通用约定」
55
+ await harness.run("(() => { const sel = document.getElementById('memoryForm').elements.groupId; sel.value = [...sel.options].find(o => o.text.includes('通用约定'))?.value || ''; return sel.value !== ''; })()");
56
+ await harness.nativeClick('#appDialogActions button.primary');
57
+ await harness.waitFor(() => harness.run("document.getElementById('appDialog').open === false"), 'the memory editor closes');
58
+ await harness.waitFor(() => harness.run("[...document.querySelectorAll('.memory-item')].some(el => el.textContent.includes('开发时保护日常服务'))"), 'the new memory is listed');
59
+
60
+ // 多段正文 = 一条记忆、一个 ID、组合文件包含完整正文
61
+ const groupList = (await harness.engineApi('GET', '/api/memory-groups?limit=10')).body;
62
+ const group = groupList.groups.find(g => g.name === '通用约定');
63
+ assert.ok(group, 'the group exists through the engine API');
64
+ const memories = (await harness.engineApi('GET', `/api/memories?status=confirmed&groupId=${group.id}&limit=10`)).body;
65
+ assert.equal(memories.memories.length, 1, 'exactly one memory record');
66
+ const memory = memories.memories[0];
67
+ assert.equal(memory.title, '开发时保护日常服务');
68
+ assert.ok(memory.text.includes('\n\n'), 'multiline body survives as one record');
69
+ assert.equal(memory.scopeType, 'group');
70
+ const groupFile = path.join(harness.brainScopePath(), 'memories', 'groups', `${group.id}.md`);
71
+ const bytes = fs.readFileSync(groupFile, 'utf8');
72
+ assert.ok(bytes.includes('## ' + memory.id), 'the memory id is the file heading');
73
+ assert.ok(bytes.includes('开发时保护日常服务'));
74
+ assert.ok(bytes.includes('- 日常知识库保持运行'), 'the full multiline body is materialized');
75
+
76
+ // ---------- 3. 第二个组合 + 选入已有记忆 ----------
77
+ await harness.nativeClick('[data-action="new-group"]');
78
+ await harness.waitFor(() => harness.run("document.getElementById('groupForm') !== null"), 'the second group dialog opens');
79
+ await harness.nativeClick('#groupForm input[name=name]');
80
+ await harness.typeText('测试');
81
+ await harness.nativeClick('#appDialogActions button.primary');
82
+ await harness.waitFor(() => harness.run("document.getElementById('appDialog').open === false"), 'the second group dialog closes');
83
+ // 左侧选中「通用约定」文件夹后「选入已有记忆」
84
+ await harness.run("(() => { const btn = [...document.querySelectorAll('.memory-folders button')].find(b => b.textContent.includes('测试')); btn.click(); return true; })()");
85
+ await harness.waitFor(() => harness.run("document.querySelector('[data-action=add-existing]') !== null"), 'the existing-memory picker is available in the group folder');
86
+ await harness.nativeClick('[data-action="add-existing"]');
87
+ await harness.waitFor(() => harness.run("document.getElementById('existingList') !== null"), 'the existing picker opens');
88
+ await harness.waitFor(() => harness.run("document.querySelector('#existingList input[type=checkbox]') !== null"), 'the existing memory is listed for picking');
89
+ await harness.run("(() => { const box = document.querySelector('#existingList input[type=checkbox]'); box.click(); return box.checked; })()");
90
+ await harness.waitFor(() => harness.run("document.getElementById('existingCount').textContent.includes('已选择 1 条')"), 'the selection counter updates');
91
+ await harness.nativeClick('#appDialogActions button.primary');
92
+ await harness.waitFor(() => harness.run("document.getElementById('appDialog').open === false"), 'the existing picker closes');
93
+ const groupList2 = (await harness.engineApi('GET', '/api/memory-groups?limit=10')).body;
94
+ const groupTest = groupList2.groups.find(g => g.name === '测试');
95
+ assert.equal(groupTest.memberCount, 1, 'the shared memory joined the second group without copying');
96
+
97
+ // ---------- 4. 应用到项目 A 和 B ----------
98
+ await harness.nativeClick('nav [data-view="projects"]');
99
+ await harness.waitFor(() => harness.run("[...document.querySelectorAll('.project-row')].length >= 2"), 'the project list is rendered');
100
+ const bindResult = (await harness.engineApi('POST', `/api/projects/${projectIdA}/memory-groups/bind`, { addGroupIds: [group.id, groupTest.id] })).body;
101
+ await harness.engineApi('POST', `/api/projects/${projectIdB}/memory-groups/bind`, { addGroupIds: [group.id] });
102
+ assert.equal(bindResult.added, 2, 'binding is a real engine write');
103
+ await harness.reload();
104
+ await harness.waitFor(() => harness.run("[...document.querySelectorAll('.project-row')].some(r => r.textContent.includes('项目甲') && r.textContent.includes('通用约定') && r.textContent.includes('测试'))"), 'project A shows both group tags');
105
+ // 项目 A 详情:生效记忆去重(同一记忆经两个组合只显示一次)
106
+ await harness.run("(() => { const btn = document.querySelector('[data-action=project-detail]'); btn.click(); return true; })()");
107
+ await harness.waitFor(() => harness.run("document.body.textContent.includes('生效记忆')"), 'the project detail renders');
108
+ const effective = (await harness.engineApi('GET', `/api/projects/${projectIdA}/effective-memories?limit=10`)).body;
109
+ assert.equal(effective.total, 1, 'the dual-group memory counts once');
110
+ assert.equal(effective.memories[0].sources.length, 2, 'both group sources are kept');
111
+
112
+ // ---------- 5. 从 A 解绑「测试」,B 不受影响 ----------
113
+ await harness.engineApi('POST', `/api/projects/${projectIdA}/memory-groups/bind`, { removeGroupIds: [groupTest.id] });
114
+ await harness.reload();
115
+ const effectiveA = (await harness.engineApi('GET', `/api/projects/${projectIdA}/effective-memories?limit=10`)).body;
116
+ assert.equal(effectiveA.total, 1, 'project A keeps the memory through 通用约定');
117
+ assert.equal(effectiveA.memories[0].sources.length, 1, 'only the remaining source applies');
118
+ const effectiveB = (await harness.engineApi('GET', `/api/projects/${projectIdB}/effective-memories?limit=10`)).body;
119
+ assert.equal(effectiveB.total, 1, 'project B is untouched');
120
+
121
+ // ---------- 6. 刷新后一切仍在(持久化) ----------
122
+ await harness.reload();
123
+ await harness.nativeClick('nav [data-view="memory"]');
124
+ await harness.waitFor(() => harness.run("[...document.querySelectorAll('.memory-folders button')].some(b => b.textContent.includes('通用约定')) && [...document.querySelectorAll('.memory-item')].some(el => el.textContent.includes('开发时保护日常服务'))"), 'the group and its memory survive a reload');
125
+
126
+ // ---------- 7. 候选审核:确认并加入组合 ----------
127
+ await harness.produceCandidate({ repo: repoA, projectId: projectIdA, text: '界面变更先给可点击的预览,确认流程后再实施。', scopeType: 'global' });
128
+ await harness.nativeClick('nav [data-view="home"]');
129
+ await harness.waitFor(() => harness.run("document.getElementById('homeContent').textContent.includes('待确认记忆') && document.getElementById('homeCount') !== null"), 'the home overview renders');
130
+ await harness.waitFor(() => harness.run("document.body.textContent.includes('界面变更先给可点击的预览')"), 'the candidate preview shows on home');
131
+ await harness.run("(() => { const btn = [...document.querySelectorAll('#homeContent button')].find(b => b.textContent.includes('审核')); if (btn) btn.click(); return Boolean(btn); })()");
132
+ await harness.waitFor(() => harness.run("document.getElementById('reviewForm') !== null"), 'the review dialog opens with frozen evidence');
133
+ await harness.run("(() => { const sel = document.getElementById('reviewForm').elements.groupId; sel.value = [...sel.options].find(o => o.text.includes('通用约定'))?.value || ''; return sel.value !== ''; })()");
134
+ await harness.nativeClick('#appDialogActions button.primary');
135
+ await harness.waitFor(() => harness.run("document.getElementById('appDialog').open === false"), 'the review dialog closes');
136
+ const confirmed = (await harness.engineApi('GET', `/api/memories?status=confirmed&groupId=${group.id}&limit=10`)).body;
137
+ assert.ok(confirmed.memories.some(m => m.text.includes('可点击的预览')), 'the confirmed candidate joined the group');
138
+
139
+ // ---------- 8. 首页组合入口 ----------
140
+ await harness.nativeClick('nav [data-view="home"]');
141
+ await harness.waitFor(() => harness.run("[...document.querySelectorAll('#homeContent .combo-card')].some(c => c.textContent.includes('通用约定'))"), 'the home shows the group entry');
142
+
143
+ console.log('memory-groups-ui-test: PASS');
144
+ } finally {
145
+ await harness.cleanup();
146
+ }
147
+ }
148
+
149
+ main().catch(error => { console.error(error); process.exitCode = 1; });
@@ -45,7 +45,7 @@ async function main() {
45
45
  registryStore: bridge.registryStore, projectStore: bridge.projectStore,
46
46
  moduleBridge: {
47
47
  engineUrl: 'http://engine.test', runtimeToken: 'fixture',
48
- _fetch: async () => ({ ok: true, status: 200, json: async () => ({ name: 'knowledge-engine', dataSchemaVersion: 3 }) }),
48
+ _fetch: async () => ({ ok: true, status: 200, json: async () => ({ name: 'knowledge-engine', dataSchemaVersion: 4 }) }),
49
49
  _listEngineProjects: async () => [{ projectId: 'project-restart', ...config }],
50
50
  registerProjectLinks: async () => ({ engine: { ok: true }, eventBridge: { ok: true }, terminal: { ok: ++wiringCalls > 1 } }),
51
51
  syncEngineConfiguration: async () => ({}),
@@ -1,13 +1,27 @@
1
+ // 打包 UI 冒烟:npm pack → 安装 tarball → 打包产物启动服务并驱动真实浏览器。
2
+ //
3
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md):
4
+ // - 导航从六页改为五页:nav [data-view] 数量 6 → 5(work 导航按钮已移除,
5
+ // #view-work 仅作为隐藏服务挂载保留在 DOM)。
6
+ // - 新首页空项目态(「从第一个项目开始 / 导入第一个项目」)依赖
7
+ // /api/engine/overview 成功,因此本测试为打包实例接入真实 vendored 知识
8
+ // 引擎(独立空数据目录,经 createUpstreamProxy 改写 runtime token;
9
+ // 引擎进程本身从源码仓库的 dev 依赖解析,与被打包的 shell 进程分离)。
10
+ // - 打包文件清单断言不变:ui/ 仍含 index.html / knowledge-panel.html /
11
+ // product.js / product.css,且不再含 app.js / app.css / i18n.js。
1
12
  const assert = require('assert');
2
13
  const fs = require('fs');
3
14
  const os = require('os');
4
15
  const path = require('path');
16
+ const crypto = require('crypto');
5
17
  const { spawnSync } = require('child_process');
6
18
  const { spawnServer } = require('./helpers/spawn-server');
7
19
  const { findChrome } = require('./helpers/find-chrome');
8
20
  const { launchCdpBrowser, waitFor } = require('./helpers/cdp-browser');
21
+ const { createUpstreamProxy } = require('./helpers/module-fixture');
9
22
 
10
23
  const ROOT = path.resolve(__dirname, '..', '..');
24
+ const ENGINE_ENTRY = path.join(path.dirname(require.resolve('@sanqianx/ai-coding-knowledge-engine/package.json', { paths: [ROOT] })), 'src', 'server.js');
11
25
  const PORT = 8250 + (process.pid % 500);
12
26
  const BASE = `http://127.0.0.1:${PORT}`;
13
27
  const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), `pk-packaged-ui-${process.pid}-`));
@@ -51,12 +65,33 @@ function buildAndInstallPackage() {
51
65
  (async () => {
52
66
  let server;
53
67
  let browser;
68
+ let engine;
69
+ let engineProxy;
54
70
  try {
55
71
  const packagedRoot = buildAndInstallPackage();
56
72
  for (const file of ['index.html', 'knowledge-panel.html', 'product.js', 'product.css']) assert(fs.existsSync(path.join(packagedRoot, 'ui', file)), `packed UI must include ${file}`);
57
73
  for (const file of ['app.js', 'app.css', 'i18n.js']) assert(!fs.existsSync(path.join(packagedRoot, 'ui', file)), `obsolete shell resource must not be shipped: ${file}`);
58
74
 
59
- server = spawnServer({ root: packagedRoot, port: PORT, dataDir: path.join(tempRoot, 'data'), tag: 'packaged-ui', analysisOwner: 'engine', stdio: 'ignore' });
75
+ // The five-page home renders its empty-project state only after the
76
+ // engine overview answered, so the packaged instance gets the real
77
+ // vendored engine (own empty data dir, dead vector/bridge endpoints)
78
+ // behind the shared token-rewriting upstream proxy.
79
+ const { createEngineServer } = require(ENGINE_ENTRY);
80
+ const engineToken = crypto.randomBytes(24).toString('hex');
81
+ engine = createEngineServer({
82
+ dataDir: path.join(tempRoot, 'engine'),
83
+ runtimeToken: engineToken,
84
+ consume: false,
85
+ debug: true,
86
+ vectorUrl: 'http://127.0.0.1:0',
87
+ bridgeUrl: 'http://127.0.0.1:0',
88
+ });
89
+ await engine.ready;
90
+ await new Promise(resolve => engine.server.listen(0, '127.0.0.1', resolve));
91
+ engineProxy = createUpstreamProxy({ target: `http://127.0.0.1:${engine.server.address().port}`, token: engineToken, tag: 'engine' });
92
+ await engineProxy.start();
93
+
94
+ server = spawnServer({ root: packagedRoot, port: PORT, dataDir: path.join(tempRoot, 'data'), tag: 'packaged-ui', analysisOwner: 'engine', stdio: 'ignore', extraEnv: { KB_KNOWLEDGE_ENGINE_URL: engineProxy.url } });
60
95
  await waitFor(async () => {
61
96
  try { return (await fetch(`${BASE}/api/health`)).ok ? { ok: true } : null; }
62
97
  catch { return null; }
@@ -74,12 +109,15 @@ function buildAndInstallPackage() {
74
109
  }, 'packaged UI bootstrap', 20000);
75
110
 
76
111
  assert.strictEqual(await browser.evaluate("document.getElementById('projectSelect').disabled"), true);
77
- assert.strictEqual(await browser.evaluate("document.querySelectorAll('nav [data-view]').length"), 6);
112
+ assert.strictEqual(await browser.evaluate("document.querySelectorAll('nav [data-view]').length"), 5);
113
+ assert.strictEqual(await browser.evaluate("document.querySelector('[data-view=\"work\"]')"), null, 'the packed UI ships no work navigation entry');
78
114
  assert.strictEqual(browser.exceptions.length, 0, `packaged UI runtime exceptions: ${JSON.stringify(browser.exceptions)}`);
79
115
  console.log('packaged-ui-smoke-test PASS');
80
116
  } finally {
81
117
  if (browser) await browser.close();
82
118
  if (server) await server.cleanup();
119
+ if (engineProxy) await engineProxy.close();
120
+ if (engine) await engine.close().catch(() => {});
83
121
  try { fs.rmSync(tempRoot, { recursive: true, force: true }); } catch {}
84
122
  }
85
123
  })().catch(error => {
@@ -37,6 +37,28 @@
37
37
  // frozen source and the real UI's healthy-page projection — never about the
38
38
  // model's judgement. The health gates are read-only observations of the real
39
39
  // page; the driver never sets any availability flag.
40
+ //
41
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md;与 R4 文件的迁移
42
+ // 保持逐条一致,仅外壳 require 不同):
43
+ // * 导入项目已列出的等待:旧首页项目面板(homeContent 含项目名)已删除,
44
+ // 等价为顶栏 #projectSelect 选项里出现项目名(同一 registry projection)。
45
+ // 首页「待确认记忆」面板仍在(homeContent),对照候选 B 的首页门不变。
46
+ // * 候选卡片:[data-memory-card=<id>] → 候选箱行内的
47
+ // [data-action="review-candidate"][data-id=<id>]「审核」按钮;健康门的
48
+ // 卡片计数([data-memory-card] ≥ 2)等价为该审核按钮计数 ≥ 2。
49
+ // * 忽略动作:旧行内 [data-memory-action="ignore"] → 审核对话框
50
+ // (#appDialog > #reviewForm)里 #appDialogActions button.danger;
51
+ // 旧 confirm 按钮([data-memory-action="confirm"])在新 UI 不再是行内
52
+ // 按钮,忽略/确认都在审核对话框内,「A 无 ignore/confirm 按钮」合并为
53
+ // 「A 无审核入口(行已消失)」。
54
+ // * 候选计数:旧 #candidateCount(已删除)→ 导航徽标 #memoryCount
55
+ // (overview.totals.candidates),期望值 '1'(只剩对照 B)。
56
+ // * 确认 tab:[data-memory-tab="confirmed"] → [data-memory-tab="library"];
57
+ // 空态「还没有已确认的长期记忆」→「没有匹配的记忆。」;重载后 tab 栏
58
+ // 需等 boot snapshot 应答后再点击。
59
+ // * 离线横幅文案在新 UI 保持原文(renderMemories 的
60
+ // 「知识引擎暂时不可用。…」),banner 门不变;/api/engine/snapshot 200
61
+ // 门、引擎/冻结源/注入断言完全不变;真实引擎自报 dataSchemaVersion=4。
40
62
 
41
63
  const fs = require('node:fs');
42
64
  const path = require('node:path');
@@ -51,18 +73,44 @@ const TEXT_A = 'R4 健康页忽略持久性(忽略项):对外错误信息
51
73
  const TEXT_B = 'R4 对照记忆(保持候选):发布前必须运行隔离回归,不允许跳过。';
52
74
  const REPO_NAME = 'mem005r4-repo';
53
75
 
54
- async function openMemoryView(harness) {
55
- await harness.nativeClick('nav [data-view="memory"]');
76
+ /**
77
+ * Open a nav view with one retry against the known reload commit-gap race
78
+ * (the shell's reload() gate proves the FRESH document, but a CDP click
79
+ * dispatched right at the commit boundary can still be lost — see the
80
+ * parallel-memory-shell.js reload comment). Driver robustness only: the
81
+ * assertion stays "the view is really active".
82
+ */
83
+ async function openView(harness, view) {
84
+ let lastError = null;
85
+ for (let attempt = 0; attempt < 3; attempt += 1) {
86
+ await harness.nativeClick(`nav [data-view="${view}"]`);
87
+ try {
88
+ await harness.waitFor(
89
+ () => harness.run(`document.getElementById('view-${view}').classList.contains('active')`),
90
+ `the ${view} view is open`,
91
+ 5000,
92
+ );
93
+ return;
94
+ } catch (error) { lastError = error; }
95
+ }
96
+ throw lastError;
97
+ }
98
+
99
+ const openMemoryView = harness => openView(harness, 'memory');
100
+
101
+ /** The memory tab bar exists only after the reloaded page read engine data. */
102
+ async function waitForMemoryTabs(harness) {
56
103
  await harness.waitFor(
57
- () => harness.run("document.getElementById('view-memory').classList.contains('active')"),
58
- 'the memory view is open',
59
- 10000,
104
+ () => harness.run("document.querySelector('#memoryContent [data-memory-tab=\"candidate\"]') !== null"),
105
+ 'the memory tab bar is rendered from real engine data',
106
+ 20000,
60
107
  );
61
108
  }
62
109
 
63
110
  async function openCandidateBox(harness) {
64
111
  await openMemoryView(harness);
65
- await harness.nativeClick('[data-memory-tab="candidate"]');
112
+ await waitForMemoryTabs(harness);
113
+ await harness.nativeClick('#memoryContent [data-memory-tab="candidate"]');
66
114
  }
67
115
 
68
116
  /** A memory card's text is rendered by the real page (implies engine data). */
@@ -78,6 +126,11 @@ const bannerInHome = harness => harness.run(
78
126
  `document.getElementById('homeContent').textContent.includes(${JSON.stringify(BANNER)})`,
79
127
  );
80
128
 
129
+ /** A candidate is offered by the real UI iff its 审核 (review) button exists. */
130
+ const candidateOffered = (harness, memoryId) => harness.run(
131
+ `Boolean(document.querySelector('#memoryContent [data-action="review-candidate"][data-id=${JSON.stringify(memoryId)}]'))`,
132
+ );
133
+
81
134
  /**
82
135
  * The healthy-page gate: the contrast candidate B must be visible AND the
83
136
  * offline banner absent. Waiting for B's real text is the essential part —
@@ -105,8 +158,10 @@ async function main() {
105
158
  const repo = makeRepo(harness.fixture, REPO_NAME, { 'README.md': '# R4 健康页忽略持久性夹具\n' });
106
159
  const { projectId, knowledgePath } = await harness.importProject(repo, 'R4健康页忽略持久性');
107
160
  await harness.requestRegistryRefresh();
161
+ // The new home page no longer lists projects; the registry projection is
162
+ // surfaced by the topbar project selector instead.
108
163
  await harness.waitFor(
109
- () => harness.run("document.getElementById('homeContent').textContent.includes('R4健康页忽略持久性')"),
164
+ () => harness.run("document.getElementById('projectSelect').textContent.includes('R4健康页忽略持久性')"),
110
165
  'the imported project is listed',
111
166
  20000,
112
167
  );
@@ -151,15 +206,23 @@ async function main() {
151
206
  await openCandidateBox(harness);
152
207
  const gateBefore = await waitHealthyCandidateBox(harness, 'before ignore');
153
208
  assert.equal(await cardTextVisible(harness, TEXT_A), true, 'A is listed alongside B before the ignore');
154
- const cardsBefore = await harness.run("document.querySelectorAll('#memoryContent [data-memory-card]').length");
209
+ const cardsBefore = await harness.run("document.querySelectorAll('#memoryContent [data-action=\"review-candidate\"]').length");
155
210
  assert.ok(Number(cardsBefore) >= 2, `the healthy candidate box really shows both cards: ${cardsBefore}`);
156
211
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem005-r4-healthy-before-ignore.png'));
157
212
 
158
- // 4. Ignore A through the real UI. The strong half: A must leave while B
159
- // STAYS — an emptied, errored or offline box can never pass this.
160
- await harness.nativeClick(`[data-memory-action="ignore"][data-memory-id="${candidateA.id}"]`);
213
+ // 4. Ignore A through the real UI: the review dialog's danger action sends
214
+ // the same engine PATCH {status:'ignored'}. The strong half: A must
215
+ // leave while B STAYS — an emptied, errored or offline box can never
216
+ // pass this.
217
+ await harness.nativeClick(`#memoryContent [data-action="review-candidate"][data-id="${candidateA.id}"]`);
218
+ await harness.waitFor(
219
+ () => harness.run("document.getElementById('appDialog').open === true && document.getElementById('reviewForm') !== null"),
220
+ 'the candidate review dialog is open',
221
+ 10000,
222
+ );
223
+ await harness.nativeClick('#appDialogActions button.danger');
161
224
  await harness.waitFor(
162
- () => harness.run(`!document.getElementById('memoryContent').textContent.includes(${JSON.stringify(TEXT_A)})`),
225
+ () => harness.run(`document.getElementById('appDialog').open === false && !document.getElementById('memoryContent').textContent.includes(${JSON.stringify(TEXT_A)})`),
163
226
  'the ignored candidate A leaves the candidate box',
164
227
  15000,
165
228
  );
@@ -174,12 +237,7 @@ async function main() {
174
237
  // and the page's own snapshot requests answered 200.
175
238
  await harness.reload();
176
239
  await harness.waitFor(() => harness.run("document.readyState === 'complete'"), 'the reloaded page is complete', 20000);
177
- await harness.nativeClick('nav [data-view="home"]');
178
- await harness.waitFor(
179
- () => harness.run("document.getElementById('view-home').classList.contains('active')"),
180
- 'the home view is open after the reload',
181
- 10000,
182
- );
240
+ await openView(harness, 'home');
183
241
  await harness.waitFor(
184
242
  () => harness.run(`document.getElementById('homeContent').textContent.includes(${JSON.stringify(TEXT_B)})`),
185
243
  'the home view\'s 待确认记忆 panel lists the contrast candidate B after the reload',
@@ -189,38 +247,41 @@ async function main() {
189
247
 
190
248
  await openCandidateBox(harness);
191
249
  const gateAfter = await waitHealthyCandidateBox(harness, 'after reload');
250
+ // The new UI has no per-row ignore/confirm buttons — the row's only action
251
+ // is 审核 (review-candidate), so "no review entry" covers both old checks.
192
252
  const afterReload = {
193
- candidateACardPresent: await harness.run(`Boolean(document.querySelector('[data-memory-card=${JSON.stringify(candidateA.id)}]'))`),
253
+ candidateACardPresent: await candidateOffered(harness, candidateA.id),
194
254
  textAInMemoryView: await cardTextVisible(harness, TEXT_A),
195
- candidateCountBadge: await harness.run("document.getElementById('candidateCount').textContent"),
196
- ignoreButtonPresent: await harness.run(`Boolean(document.querySelector('[data-memory-action="ignore"][data-memory-id=${JSON.stringify(candidateA.id)}]'))`),
197
- confirmButtonPresent: await harness.run(`Boolean(document.querySelector('[data-memory-action="confirm"][data-memory-id=${JSON.stringify(candidateA.id)}]'))`),
198
- contrastCardPresent: await harness.run(`Boolean(document.querySelector('[data-memory-card=${JSON.stringify(candidateB.id)}]'))`),
255
+ candidateCountBadge: await harness.run("document.getElementById('memoryCount').hidden ? '' : document.getElementById('memoryCount').textContent"),
256
+ ignoreButtonPresent: await candidateOffered(harness, candidateA.id),
257
+ confirmButtonPresent: await candidateOffered(harness, candidateA.id),
258
+ contrastCardPresent: await candidateOffered(harness, candidateB.id),
199
259
  };
200
260
  assert.equal(afterReload.candidateACardPresent, false, 'the ignored A has no card after the reload');
201
261
  assert.equal(afterReload.textAInMemoryView, false, 'A\'s text is not in the memory view after the reload');
202
262
  assert.equal(String(afterReload.candidateCountBadge).trim(), '1', `the candidate counter counts only the contrast candidate B after the reload: ${JSON.stringify(afterReload.candidateCountBadge)}`);
203
- assert.equal(afterReload.ignoreButtonPresent, false, 'A offers no ignore button after the reload');
204
- assert.equal(afterReload.confirmButtonPresent, false, 'A offers no confirm button after the reload');
263
+ assert.equal(afterReload.ignoreButtonPresent, false, 'A offers no ignore (review) entry after the reload');
264
+ assert.equal(afterReload.confirmButtonPresent, false, 'A offers no confirm (review) entry after the reload');
205
265
  assert.equal(afterReload.contrastCardPresent, true, 'B\'s card is right there — the absence of A is a real filtered-out record, not an offline fallback');
206
266
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem005-r4-after-reload-healthy-candidates.png'));
207
267
 
208
- // 6. The confirmed tab: rendered from real data (B is not confirmed, so
209
- // the real empty-state text shows), banner absent, A not confirmed.
210
- await harness.nativeClick('[data-memory-tab="confirmed"]');
268
+ // 6. The library tab (old confirmed tab): rendered from real data (B is
269
+ // not confirmed, so the real empty-state text shows), banner absent,
270
+ // A not confirmed.
271
+ await harness.nativeClick('#memoryContent [data-memory-tab="library"]');
211
272
  await harness.waitFor(
212
- () => harness.run(`(!document.getElementById('memoryContent').textContent.includes(${JSON.stringify(BANNER)}) && (document.getElementById('memoryContent').textContent.includes('还没有已确认的长期记忆') || document.querySelectorAll('[data-memory-card]').length > 0))`),
213
- 'the confirmed tab is rendered from real data (not the offline banner)',
273
+ () => harness.run(`(!document.getElementById('memoryContent').textContent.includes(${JSON.stringify(BANNER)}) && (document.getElementById('memoryContent').textContent.includes('没有匹配的记忆。') || document.querySelectorAll('#memoryContent .memory-item').length > 0))`),
274
+ 'the library tab is rendered from real data (not the offline banner)',
214
275
  15000,
215
276
  );
216
277
  const confirmedTab = {
217
- cardAPresent: await harness.run(`Boolean(document.querySelector('[data-memory-card=${JSON.stringify(candidateA.id)}]'))`),
278
+ cardAPresent: await harness.run(`Boolean(document.querySelector('#memoryContent [data-action="memory-detail"][data-id=${JSON.stringify(candidateA.id)}]'))`),
218
279
  textAPresent: await cardTextVisible(harness, TEXT_A),
219
280
  bannerPresent: await bannerInMemoryView(harness),
220
281
  };
221
282
  assert.equal(confirmedTab.cardAPresent, false, 'A is not shown as a confirmed memory');
222
283
  assert.equal(confirmedTab.textAPresent, false, 'A\'s text is not shown in the confirmed tab');
223
- assert.equal(confirmedTab.bannerPresent, false, 'the confirmed tab is not the offline fallback');
284
+ assert.equal(confirmedTab.bannerPresent, false, 'the library tab is not the offline fallback');
224
285
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem005-r4-after-reload-confirmed.png'));
225
286
 
226
287
  // 7. The page's own snapshot requests after the reload answered 200.
@@ -311,7 +372,7 @@ async function main() {
311
372
  fs.writeFileSync(path.join(harness.evidence, 'mem005-r4-healthy-persistence.json'), `${JSON.stringify(evidence, null, 2)}\n`, 'utf8');
312
373
  }
313
374
 
314
- console.log('parallel-memory-capture-r4-mem005-health-test PASS (on a provably healthy page — contrast candidate visible, offline banner absent, page snapshot 200s — the ignored candidate stays ignored across a real reload and never returns as candidate or confirmed, while the engine, its persisted state and the frozen source are unchanged)');
375
+ console.log('parallel-capture-safety-r5-mem005-health-test PASS (on a provably healthy page — contrast candidate visible, offline banner absent, page snapshot 200s — the ignored candidate stays ignored across a real reload and never returns as candidate or confirmed, while the engine, its persisted state and the frozen source are unchanged)');
315
376
  } finally {
316
377
  await harness.cleanup();
317
378
  }
@@ -1,6 +1,16 @@
1
1
  'use strict';
2
2
  // Parallel knowledge lane — regression for the engine error-code contract.
3
3
  //
4
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md):
5
+ // * 本文件不驱动 UI,唯一的迁移点是引擎 schema:lib/engine-knowledge-client
6
+ // 的身份门现要求 /api/health 返回 dataSchemaVersion === 4,stub 引擎的
7
+ // health 响应从 3 改为 4,否则四个失败场景全部被误判为
8
+ // ENGINE_IDENTITY_MISMATCH(409)而不是各自的错误码。
9
+ // * 业务断言(字符串/对象信封保留错误码、非法码回退
10
+ // ENGINE_REQUEST_FAILED、ok:false+200 → 502、HTTP 状态保留、成功读取
11
+ // 不变)逐字保持,未改任何断言。
12
+ //
13
+ //
4
14
  // The vendored knowledge-engine reports a failed read as { ok:false,
5
15
  // error:'<CODE>' } with the code as a plain string. The product client used to
6
16
  // read the code only from payload.error.code, so every genuine business
@@ -51,7 +61,7 @@ function createEngineStub({ repoPath, knowledgePath, projectId, envelope }) {
51
61
  res.writeHead(status, { 'Content-Type': 'application/json' });
52
62
  res.end(JSON.stringify(body));
53
63
  };
54
- if (req.url === '/api/health') return send(200, { name: 'knowledge-engine', dataSchemaVersion: 3 });
64
+ if (req.url === '/api/health') return send(200, { name: 'knowledge-engine', dataSchemaVersion: 4 });
55
65
  if (req.url === '/api/projects') {
56
66
  return send(200, { ok: true, projects: [{ projectId, enabled: true, repoPath, knowledgePath }] });
57
67
  }
@@ -2,18 +2,30 @@
2
2
  // P-LOG-ACCEPTANCE-01 LOG-008 acceptance driver (real product page in a real
3
3
  // browser against an isolated managed instance).
4
4
  //
5
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md):
6
+ // * 系统抽屉与诊断对话框选择器全部未变:#openSystem / #openLogs /
7
+ // #logsScope / #logsSearch / #loadLogs / #exportLogs / #logsContent /
8
+ // .log-entry / #logsDialog / #toast 均保留,驱动流程不变。
9
+ // * 唯一的产品行为变化:ui/product.js 的 api() 对 GET 的读取超时从 3s
10
+ // 提高到 8s。观察代理对 /api/logs 的延迟从 5s(> 3s)改为 10s(> 8s),
11
+ // 等待窗口相应放宽(toast 8s→20s,延迟响应落地的静置 5.2s→11s)。
12
+ // * 业务断言逐字保持:超时 toast 文案「状态读取超时」、超时不清空已渲染
13
+ // 记录、查询未收窄、导出失败 toast「诊断导出失败。」、零下载文件、
14
+ // 解除阻塞后导出路由恢复并含种子记录。
15
+ //
5
16
  // Case (qa-autopilot/config/test-cases.json LOG-008, P1):
6
17
  // steps: 查询超时和导出失败分别触发。
7
18
  // expected: 1) UI显示失败。
8
19
  // 2) 不能生成空文件冒充成功导出。
9
20
  //
10
- // Real behaviour under test: api() (ui/product.js:31-43) aborts GETs after
11
- // 3s and loadLogs leaves the previous DOM intact on failure; on() toasts the
12
- // error message. The lane observation proxy delays /api/logs by 5s (> the 3s
13
- // timeout) for the query-timeout phase. For export failure, a file placed at
14
- // <dataDir>/cache/exports makes exportToFile's mkdirSync throw → the route
15
- // returns 500 → exportLogs throws 诊断导出失败。 → toast, and no download may
16
- // appear. A control export after unblocking proves the route recovers.
21
+ // Real behaviour under test: api() (ui/product.js, GET timeoutMs 8000)
22
+ // aborts GETs after 8s and loadLogs leaves the previous DOM intact on
23
+ // failure; on() toasts the error message. The lane observation proxy delays
24
+ // /api/logs by 10s (> the 8s timeout) for the query-timeout phase. For
25
+ // export failure, a file placed at <dataDir>/cache/exports makes
26
+ // exportToFile's mkdirSync throw → the route returns 500 → exportLogs
27
+ // throws 诊断导出失败。 → toast, and no download may appear. A control
28
+ // export after unblocking proves the route recovers.
17
29
 
18
30
  const fs = require('node:fs');
19
31
  const path = require('node:path');
@@ -87,14 +99,14 @@ async function main() {
87
99
  }, 'diagnostics dialog rendered the project records', 20000);
88
100
  const domBaseline = JSON.parse(await readDom());
89
101
 
90
- // expected1a (query timeout): delay /api/logs past api()'s 3s timeout.
91
- proxy.setDelay('/api/logs', 5000);
102
+ // expected1a (query timeout): delay /api/logs past api()'s 8s GET timeout.
103
+ proxy.setDelay('/api/logs', 10000);
92
104
  await runExpr(`document.getElementById('logsSearch').value = ${JSON.stringify(MARK)}`);
93
105
  await click('#loadLogs');
94
106
  await waitFor(async () => {
95
107
  const dom = JSON.parse(await readDom());
96
108
  return !dom.toastHidden && dom.toastText.includes('状态读取超时');
97
- }, 'timeout toast appears for the slow query', 8000);
109
+ }, 'timeout toast appears for the slow query', 20000);
98
110
  const domTimeout = JSON.parse(await readDom());
99
111
  evidence.phases.queryTimeout = {
100
112
  baselineEntries: domBaseline.count,
@@ -108,7 +120,7 @@ async function main() {
108
120
  await browser.screenshot(path.join(ARTIFACTS, 'log008-query-timeout-toast.png'));
109
121
  proxy.setDelay('/api/logs', null);
110
122
  // Let the delayed response land and the toast clear before the next phase.
111
- await new Promise(resolve => setTimeout(resolve, 5200));
123
+ await new Promise(resolve => setTimeout(resolve, 11000));
112
124
 
113
125
  // expected1b + expected2 (export failure): block cache/exports with a file.
114
126
  const downloadDir = path.join(ARTIFACTS, 'downloads');