@sanqianx/project-knowledge 5.0.33 → 5.0.35

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 (52) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +14 -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-supervisor-backoff-reset-test.js +64 -0
  12. package/_site/_test/module-terminal-restart-test.js +1 -1
  13. package/_site/_test/packaged-ui-smoke-test.js +40 -2
  14. package/_site/_test/parallel-capture-safety-r5-mem005-health-test.js +94 -33
  15. package/_site/_test/parallel-knowledge-client-error-code-test.js +11 -1
  16. package/_site/_test/parallel-logging-acceptance-log008-test.js +23 -11
  17. package/_site/_test/parallel-memory-candidate-test.js +134 -84
  18. package/_site/_test/parallel-memory-capture-r3-mem005-persistence-test.js +100 -38
  19. package/_site/_test/parallel-memory-capture-r4-mem005-health-test.js +92 -32
  20. package/_site/_test/parallel-memory-home-review-test.js +148 -0
  21. package/_site/_test/parallel-memory-manual-test.js +140 -34
  22. package/_site/_test/parallel-memory-scope-test.js +91 -23
  23. package/_site/_test/parallel-memory-source-test.js +54 -25
  24. package/_site/_test/parallel-memory-sync-test.js +102 -75
  25. package/_site/_test/parallel-nav-failure-test.js +36 -16
  26. package/_site/_test/parallel-nav-home-issues-test.js +159 -0
  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/module-bridge.js +16 -6
  43. package/_site/lib/server-app.js +23 -0
  44. package/_site/scripts/refresh-runtime-manifest.js +108 -0
  45. package/module-runtime-manifest.json +17 -15
  46. package/package.json +2 -2
  47. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  48. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  49. package/plugins/project-knowledge/.mcp.json +1 -1
  50. package/ui/index.html +14 -11
  51. package/ui/product.css +42 -0
  52. package/ui/product.js +861 -212
@@ -31,6 +31,27 @@
31
31
  // frozen source and the real UI's healthy-page projection — never about the
32
32
  // model's judgement. The health gates are read-only observations of the real
33
33
  // page; the driver never sets any availability flag.
34
+ //
35
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md):
36
+ // * 导入项目已列出的等待:旧首页项目面板(homeContent 含项目名)已删除,
37
+ // 等价为顶栏 #projectSelect 选项里出现项目名(同一 registry projection)。
38
+ // 首页「待确认记忆」面板仍在(homeContent),对照候选 B 的首页门不变。
39
+ // * 候选卡片:[data-memory-card=<id>] → 候选箱行内的
40
+ // [data-action="review-candidate"][data-id=<id>]「审核」按钮;健康门的
41
+ // 卡片计数([data-memory-card] ≥ 2)等价为该审核按钮计数 ≥ 2。
42
+ // * 忽略动作:旧行内 [data-memory-action="ignore"] → 审核对话框
43
+ // (#appDialog > #reviewForm)里 #appDialogActions button.danger;
44
+ // 旧 confirm 按钮([data-memory-action="confirm"])在新 UI 不再是行内
45
+ // 按钮,忽略/确认都在审核对话框内,「A 无 ignore/confirm 按钮」合并为
46
+ // 「A 无审核入口(行已消失)」。
47
+ // * 候选计数:旧 #candidateCount(已删除)→ 导航徽标 #memoryCount
48
+ // (overview.totals.candidates),期望值 '1'(只剩对照 B)。
49
+ // * 确认 tab:[data-memory-tab="confirmed"] → [data-memory-tab="library"];
50
+ // 空态「还没有已确认的长期记忆」→「没有匹配的记忆。」;重载后 tab 栏
51
+ // 需等 boot snapshot 应答后再点击。
52
+ // * 离线横幅文案在新 UI 保持原文(renderMemories 的
53
+ // 「知识引擎暂时不可用。…」),banner 门不变;/api/engine/snapshot 200
54
+ // 门、引擎/冻结源/注入断言完全不变;真实引擎自报 dataSchemaVersion=4。
34
55
 
35
56
  const fs = require('node:fs');
36
57
  const path = require('node:path');
@@ -45,18 +66,44 @@ const TEXT_A = 'R4 健康页忽略持久性(忽略项):对外错误信息
45
66
  const TEXT_B = 'R4 对照记忆(保持候选):发布前必须运行隔离回归,不允许跳过。';
46
67
  const REPO_NAME = 'mem005r4-repo';
47
68
 
48
- async function openMemoryView(harness) {
49
- await harness.nativeClick('nav [data-view="memory"]');
69
+ /**
70
+ * Open a nav view with one retry against the known reload commit-gap race
71
+ * (the shell's reload() gate proves the FRESH document, but a CDP click
72
+ * dispatched right at the commit boundary can still be lost — see the
73
+ * parallel-memory-shell.js reload comment). Driver robustness only: the
74
+ * assertion stays "the view is really active".
75
+ */
76
+ async function openView(harness, view) {
77
+ let lastError = null;
78
+ for (let attempt = 0; attempt < 3; attempt += 1) {
79
+ await harness.nativeClick(`nav [data-view="${view}"]`);
80
+ try {
81
+ await harness.waitFor(
82
+ () => harness.run(`document.getElementById('view-${view}').classList.contains('active')`),
83
+ `the ${view} view is open`,
84
+ 5000,
85
+ );
86
+ return;
87
+ } catch (error) { lastError = error; }
88
+ }
89
+ throw lastError;
90
+ }
91
+
92
+ const openMemoryView = harness => openView(harness, 'memory');
93
+
94
+ /** The memory tab bar exists only after the reloaded page read engine data. */
95
+ async function waitForMemoryTabs(harness) {
50
96
  await harness.waitFor(
51
- () => harness.run("document.getElementById('view-memory').classList.contains('active')"),
52
- 'the memory view is open',
53
- 10000,
97
+ () => harness.run("document.querySelector('#memoryContent [data-memory-tab=\"candidate\"]') !== null"),
98
+ 'the memory tab bar is rendered from real engine data',
99
+ 20000,
54
100
  );
55
101
  }
56
102
 
57
103
  async function openCandidateBox(harness) {
58
104
  await openMemoryView(harness);
59
- await harness.nativeClick('[data-memory-tab="candidate"]');
105
+ await waitForMemoryTabs(harness);
106
+ await harness.nativeClick('#memoryContent [data-memory-tab="candidate"]');
60
107
  }
61
108
 
62
109
  /** A memory card's text is rendered by the real page (implies engine data). */
@@ -72,6 +119,11 @@ const bannerInHome = harness => harness.run(
72
119
  `document.getElementById('homeContent').textContent.includes(${JSON.stringify(BANNER)})`,
73
120
  );
74
121
 
122
+ /** A candidate is offered by the real UI iff its 审核 (review) button exists. */
123
+ const candidateOffered = (harness, memoryId) => harness.run(
124
+ `Boolean(document.querySelector('#memoryContent [data-action="review-candidate"][data-id=${JSON.stringify(memoryId)}]'))`,
125
+ );
126
+
75
127
  /**
76
128
  * The healthy-page gate: the contrast candidate B must be visible AND the
77
129
  * offline banner absent. Waiting for B's real text is the essential part —
@@ -99,8 +151,10 @@ async function main() {
99
151
  const repo = makeRepo(harness.fixture, REPO_NAME, { 'README.md': '# R4 健康页忽略持久性夹具\n' });
100
152
  const { projectId, knowledgePath } = await harness.importProject(repo, 'R4健康页忽略持久性');
101
153
  await harness.requestRegistryRefresh();
154
+ // The new home page no longer lists projects; the registry projection is
155
+ // surfaced by the topbar project selector instead.
102
156
  await harness.waitFor(
103
- () => harness.run("document.getElementById('homeContent').textContent.includes('R4健康页忽略持久性')"),
157
+ () => harness.run("document.getElementById('projectSelect').textContent.includes('R4健康页忽略持久性')"),
104
158
  'the imported project is listed',
105
159
  20000,
106
160
  );
@@ -145,15 +199,23 @@ async function main() {
145
199
  await openCandidateBox(harness);
146
200
  const gateBefore = await waitHealthyCandidateBox(harness, 'before ignore');
147
201
  assert.equal(await cardTextVisible(harness, TEXT_A), true, 'A is listed alongside B before the ignore');
148
- const cardsBefore = await harness.run("document.querySelectorAll('#memoryContent [data-memory-card]').length");
202
+ const cardsBefore = await harness.run("document.querySelectorAll('#memoryContent [data-action=\"review-candidate\"]').length");
149
203
  assert.ok(Number(cardsBefore) >= 2, `the healthy candidate box really shows both cards: ${cardsBefore}`);
150
204
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem005-r4-healthy-before-ignore.png'));
151
205
 
152
- // 4. Ignore A through the real UI. The strong half: A must leave while B
153
- // STAYS — an emptied, errored or offline box can never pass this.
154
- await harness.nativeClick(`[data-memory-action="ignore"][data-memory-id="${candidateA.id}"]`);
206
+ // 4. Ignore A through the real UI: the review dialog's danger action sends
207
+ // the same engine PATCH {status:'ignored'}. The strong half: A must
208
+ // leave while B STAYS — an emptied, errored or offline box can never
209
+ // pass this.
210
+ await harness.nativeClick(`#memoryContent [data-action="review-candidate"][data-id="${candidateA.id}"]`);
211
+ await harness.waitFor(
212
+ () => harness.run("document.getElementById('appDialog').open === true && document.getElementById('reviewForm') !== null"),
213
+ 'the candidate review dialog is open',
214
+ 10000,
215
+ );
216
+ await harness.nativeClick('#appDialogActions button.danger');
155
217
  await harness.waitFor(
156
- () => harness.run(`!document.getElementById('memoryContent').textContent.includes(${JSON.stringify(TEXT_A)})`),
218
+ () => harness.run(`document.getElementById('appDialog').open === false && !document.getElementById('memoryContent').textContent.includes(${JSON.stringify(TEXT_A)})`),
157
219
  'the ignored candidate A leaves the candidate box',
158
220
  15000,
159
221
  );
@@ -168,12 +230,7 @@ async function main() {
168
230
  // and the page's own snapshot requests answered 200.
169
231
  await harness.reload();
170
232
  await harness.waitFor(() => harness.run("document.readyState === 'complete'"), 'the reloaded page is complete', 20000);
171
- await harness.nativeClick('nav [data-view="home"]');
172
- await harness.waitFor(
173
- () => harness.run("document.getElementById('view-home').classList.contains('active')"),
174
- 'the home view is open after the reload',
175
- 10000,
176
- );
233
+ await openView(harness, 'home');
177
234
  await harness.waitFor(
178
235
  () => harness.run(`document.getElementById('homeContent').textContent.includes(${JSON.stringify(TEXT_B)})`),
179
236
  'the home view\'s 待确认记忆 panel lists the contrast candidate B after the reload',
@@ -183,38 +240,41 @@ async function main() {
183
240
 
184
241
  await openCandidateBox(harness);
185
242
  const gateAfter = await waitHealthyCandidateBox(harness, 'after reload');
243
+ // The new UI has no per-row ignore/confirm buttons — the row's only action
244
+ // is 审核 (review-candidate), so "no review entry" covers both old checks.
186
245
  const afterReload = {
187
- candidateACardPresent: await harness.run(`Boolean(document.querySelector('[data-memory-card=${JSON.stringify(candidateA.id)}]'))`),
246
+ candidateACardPresent: await candidateOffered(harness, candidateA.id),
188
247
  textAInMemoryView: await cardTextVisible(harness, TEXT_A),
189
- candidateCountBadge: await harness.run("document.getElementById('candidateCount').textContent"),
190
- ignoreButtonPresent: await harness.run(`Boolean(document.querySelector('[data-memory-action="ignore"][data-memory-id=${JSON.stringify(candidateA.id)}]'))`),
191
- confirmButtonPresent: await harness.run(`Boolean(document.querySelector('[data-memory-action="confirm"][data-memory-id=${JSON.stringify(candidateA.id)}]'))`),
192
- contrastCardPresent: await harness.run(`Boolean(document.querySelector('[data-memory-card=${JSON.stringify(candidateB.id)}]'))`),
248
+ candidateCountBadge: await harness.run("document.getElementById('memoryCount').hidden ? '' : document.getElementById('memoryCount').textContent"),
249
+ ignoreButtonPresent: await candidateOffered(harness, candidateA.id),
250
+ confirmButtonPresent: await candidateOffered(harness, candidateA.id),
251
+ contrastCardPresent: await candidateOffered(harness, candidateB.id),
193
252
  };
194
253
  assert.equal(afterReload.candidateACardPresent, false, 'the ignored A has no card after the reload');
195
254
  assert.equal(afterReload.textAInMemoryView, false, 'A\'s text is not in the memory view after the reload');
196
255
  assert.equal(String(afterReload.candidateCountBadge).trim(), '1', `the candidate counter counts only the contrast candidate B after the reload: ${JSON.stringify(afterReload.candidateCountBadge)}`);
197
- assert.equal(afterReload.ignoreButtonPresent, false, 'A offers no ignore button after the reload');
198
- assert.equal(afterReload.confirmButtonPresent, false, 'A offers no confirm button after the reload');
256
+ assert.equal(afterReload.ignoreButtonPresent, false, 'A offers no ignore (review) entry after the reload');
257
+ assert.equal(afterReload.confirmButtonPresent, false, 'A offers no confirm (review) entry after the reload');
199
258
  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');
200
259
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem005-r4-after-reload-healthy-candidates.png'));
201
260
 
202
- // 6. The confirmed tab: rendered from real data (B is not confirmed, so
203
- // the real empty-state text shows), banner absent, A not confirmed.
204
- await harness.nativeClick('[data-memory-tab="confirmed"]');
261
+ // 6. The library tab (old confirmed tab): rendered from real data (B is
262
+ // not confirmed, so the real empty-state text shows), banner absent,
263
+ // A not confirmed.
264
+ await harness.nativeClick('#memoryContent [data-memory-tab="library"]');
205
265
  await harness.waitFor(
206
- () => harness.run(`(!document.getElementById('memoryContent').textContent.includes(${JSON.stringify(BANNER)}) && (document.getElementById('memoryContent').textContent.includes('还没有已确认的长期记忆') || document.querySelectorAll('[data-memory-card]').length > 0))`),
207
- 'the confirmed tab is rendered from real data (not the offline banner)',
266
+ () => harness.run(`(!document.getElementById('memoryContent').textContent.includes(${JSON.stringify(BANNER)}) && (document.getElementById('memoryContent').textContent.includes('没有匹配的记忆。') || document.querySelectorAll('#memoryContent .memory-item').length > 0))`),
267
+ 'the library tab is rendered from real data (not the offline banner)',
208
268
  15000,
209
269
  );
210
270
  const confirmedTab = {
211
- cardAPresent: await harness.run(`Boolean(document.querySelector('[data-memory-card=${JSON.stringify(candidateA.id)}]'))`),
271
+ cardAPresent: await harness.run(`Boolean(document.querySelector('#memoryContent [data-action="memory-detail"][data-id=${JSON.stringify(candidateA.id)}]'))`),
212
272
  textAPresent: await cardTextVisible(harness, TEXT_A),
213
273
  bannerPresent: await bannerInMemoryView(harness),
214
274
  };
215
275
  assert.equal(confirmedTab.cardAPresent, false, 'A is not shown as a confirmed memory');
216
276
  assert.equal(confirmedTab.textAPresent, false, 'A\'s text is not shown in the confirmed tab');
217
- assert.equal(confirmedTab.bannerPresent, false, 'the confirmed tab is not the offline fallback');
277
+ assert.equal(confirmedTab.bannerPresent, false, 'the library tab is not the offline fallback');
218
278
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem005-r4-after-reload-confirmed.png'));
219
279
 
220
280
  // 7. The page's own snapshot requests after the reload answered 200.
@@ -0,0 +1,148 @@
1
+ 'use strict';
2
+ // MEM-HOME — 首页待确认记忆直达审核。
3
+ //
4
+ // 迁移说明(五页简化 UI):
5
+ // - 首页不再罗列项目:导入成功的可见面改为顶栏 #projectSelect 的选项。
6
+ // - 首页候选行的审核入口改为 data-action="review-candidate"(data-id 绑定
7
+ // 具体候选),与「长期记忆」页候选箱共用 reviewCandidate() 的
8
+ // #appDialog 审核对话框;确认动作为表单提交(reviewForm 的提交按钮)。
9
+ // - 冻结依据的展示从「原始总结」字段改为「查看原始依据(冻结原文)」
10
+ // 折叠块;确认后面板空态文案为「没有待确认的记忆」。
11
+ //
12
+ // The home「待确认记忆」panel names a candidate memory, so it must be an
13
+ // entry into review, not a read-only preview: one real pointer click on the
14
+ // candidate row must open the review dialog for THAT exact candidate — text,
15
+ // scope and frozen evidence included — and the confirm action in the dialog
16
+ // must complete the handling without ever visiting the memory view. The old
17
+ // shell offered only a generic「查看候选箱」jump, leaving the user to find
18
+ // the candidate again in the full list.
19
+ //
20
+ // The regression drives the real product UI in a real browser against an
21
+ // isolated instance (own port, own data dir, own knowledge dir, own Bridge
22
+ // journal, own browser profile). The candidate is produced by the REAL
23
+ // pipeline — a real follow-up commit, a real conversation event, a real
24
+ // maintenance run, the real eligibility gate — so the home panel lists what
25
+ // the engine really stored. Every pointer action is a CDP
26
+ // Input.dispatchMouseEvent on the real coordinates of the real control, and
27
+ // the page itself records that the click it received carried
28
+ // isTrusted === true.
29
+ //
30
+ // Screenshots are written to PK_TEST_EVIDENCE_DIR when the batch sets it, so
31
+ // this tracked file stays free of machine-specific paths.
32
+
33
+ const path = require('node:path');
34
+ const assert = require('node:assert/strict');
35
+
36
+ const { startHarness, makeRepo } = require('./helpers/parallel-memory-shell');
37
+
38
+ const EVIDENCE = process.env.PK_TEST_EVIDENCE_DIR ? path.resolve(process.env.PK_TEST_EVIDENCE_DIR) : null;
39
+
40
+ const CANDIDATE_TEXT = '对外错误信息使用中文表述,并优先复用已有模块。';
41
+
42
+ /** Record every click the page really receives on the home review entry. */
43
+ async function installHomeReviewClickRecorder(harness) {
44
+ await harness.run(`(() => {
45
+ window.__homeReviewClicks = [];
46
+ if (!window.__homeReviewHooked) {
47
+ window.__homeReviewHooked = true;
48
+ document.addEventListener('click', event => {
49
+ const button = event.target.closest ? event.target.closest('#homeContent [data-action="review-candidate"]') : null;
50
+ if (button) window.__homeReviewClicks.push({
51
+ trusted: event.isTrusted === true,
52
+ memoryId: button.getAttribute('data-id'),
53
+ label: (button.textContent || '').trim(),
54
+ });
55
+ }, true);
56
+ }
57
+ return true;
58
+ })()`);
59
+ }
60
+
61
+ async function main() {
62
+ const harness = await startHarness({ tag: 'memhome', evidenceDir: EVIDENCE || undefined });
63
+ try {
64
+ // A real project, imported through the real product API. The five-page
65
+ // shell surfaces the registry in the top-bar project selector.
66
+ const repo = makeRepo(harness.fixture, 'memhome-repo', { 'README.md': '# 首页候选\n' });
67
+ const { projectId } = await harness.importProject(repo, '首页候选甲');
68
+ await harness.requestRegistryRefresh();
69
+ await harness.waitFor(
70
+ () => harness.run("document.getElementById('projectSelect').textContent.includes('首页候选甲')"),
71
+ 'the imported project is listed',
72
+ 20000,
73
+ );
74
+
75
+ // A real candidate through the real pipeline (commit + event + run + gate).
76
+ const produced = await harness.produceCandidate({ repo, projectId, text: CANDIDATE_TEXT, scopeType: 'global' });
77
+ assert.equal(produced.capture.accepted, 1, `the real run admitted one candidate: ${JSON.stringify(produced.capture)}`);
78
+ const stored = (await harness.productMemories()).find(m => m.text === CANDIDATE_TEXT);
79
+ assert.ok(stored, 'the candidate really exists in the engine');
80
+ assert.equal(stored.status, 'candidate', 'the stored candidate is still pending review');
81
+
82
+ await installHomeReviewClickRecorder(harness);
83
+
84
+ // MEM-HOME expected 1: the home panel not only names the candidate, it
85
+ // exposes a per-item review entry bound to that exact memory.
86
+ await harness.requestRegistryRefresh();
87
+ await harness.waitFor(
88
+ () => harness.run(`(() => {
89
+ const button = document.querySelector('#homeContent [data-action="review-candidate"]');
90
+ if (!button) return false;
91
+ const panel = button.closest('section.panel');
92
+ const row = button.closest('.row');
93
+ return panel && panel.querySelector('h2').textContent.includes('待确认记忆')
94
+ && row && row.textContent.includes(${JSON.stringify(CANDIDATE_TEXT)})
95
+ && button.getAttribute('data-id') === ${JSON.stringify(stored.id)};
96
+ })()`),
97
+ 'the home 待确认记忆 panel offers a review entry for the exact candidate',
98
+ 20000,
99
+ );
100
+ await harness.browser.screenshot(path.join(harness.evidence, 'memhome-home-review-entry.png'));
101
+
102
+ // MEM-HOME expected 2: one trusted pointer click opens the review dialog
103
+ // for that exact candidate, straight from the home view.
104
+ await harness.nativeClick('#homeContent [data-action="review-candidate"]');
105
+ const clicks = await harness.run('window.__homeReviewClicks || []');
106
+ assert.ok(clicks.length >= 1, 'the page really received the home review click');
107
+ const click = clicks[clicks.length - 1];
108
+ assert.equal(click.trusted, true, `the click the page received is a trusted browser event: ${JSON.stringify(click)}`);
109
+ assert.equal(click.memoryId, stored.id, `the click is bound to the exact candidate: ${JSON.stringify(click)}`);
110
+
111
+ await harness.waitFor(
112
+ () => harness.run(`(() => document.getElementById('appDialog').open === true
113
+ && document.getElementById('appDialogTitle').textContent.includes('审核候选记忆')
114
+ && document.getElementById('appDialogBody').textContent.includes(${JSON.stringify(CANDIDATE_TEXT)}))()`),
115
+ 'the review dialog opens with the exact candidate',
116
+ 10000,
117
+ );
118
+ const dialogText = await harness.run("document.getElementById('appDialog').textContent");
119
+ assert.ok(dialogText.includes('原始依据'), `the dialog carries the frozen source evidence: ${dialogText.slice(0, 120)}`);
120
+ await harness.browser.screenshot(path.join(harness.evidence, 'memhome-review-dialog.png'));
121
+
122
+ // MEM-HOME expected 3: the handling completes in place — confirm inside
123
+ // the dialog, and the home panel itself reflects the resolved candidate.
124
+ await harness.nativeClick('#appDialogActions button[type="submit"]');
125
+ await harness.waitFor(
126
+ () => harness.run("document.getElementById('appDialog').open === false"),
127
+ 'the review dialog closes after confirming',
128
+ 10000,
129
+ );
130
+ await harness.waitFor(
131
+ () => harness.run(`(() => document.getElementById('homeContent').textContent.includes('没有待确认的记忆')
132
+ && !document.querySelectorAll('#homeContent [data-action="review-candidate"]').length)()`),
133
+ 'the home panel no longer offers the confirmed candidate for review',
134
+ 20000,
135
+ );
136
+ const confirmed = (await harness.productMemories()).find(m => m.id === stored.id);
137
+ assert.equal(confirmed.status, 'confirmed', `the engine really holds the confirmed memory: ${JSON.stringify(confirmed.status)}`);
138
+ await harness.browser.screenshot(path.join(harness.evidence, 'memhome-confirmed-home.png'));
139
+
140
+ assert.equal(harness.browser.exceptions.length, 0, `no uncaught product JavaScript exceptions: ${JSON.stringify(harness.browser.exceptions)}`);
141
+
142
+ console.log('parallel-memory-home-review-test PASS (the home 待确认记忆 entry opens the exact candidate for review and confirm completes in place)');
143
+ } finally {
144
+ await harness.cleanup();
145
+ }
146
+ }
147
+
148
+ main().catch(error => { console.error(error.stack || error.message); process.exitCode = 1; });
@@ -7,8 +7,8 @@
7
7
  // data dir, knowledge root, Bridge journal home and browser profile, with the
8
8
  // REAL vendored knowledge engine in-process behind a pass-through proxy. The
9
9
  // memory is added through the real UI in a real Chrome: a real pointer click
10
- // opens the dialog, real key events type the content, a real pointer click
11
- // submits it.
10
+ // opens the dialog, a real paste (CDP Input.insertText, the same path a real
11
+ // paste takes) fills the content, a real pointer click submits it.
12
12
  //
13
13
  // MEM-001 expected:
14
14
  // * POST真实保存为confirmed。 -> the captured POST really answers
@@ -23,6 +23,34 @@
23
23
  // sending a request, and the engine
24
24
  // itself rejects a blank body;
25
25
  // * 不出现空记忆。 -> no memory exists anywhere afterwards.
26
+ //
27
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md):
28
+ // * 添加记忆入口:#addMemory → 记忆库 tab 头部
29
+ // #memoryContent [data-action="new-memory"];「引擎可达」等待从
30
+ // 「#addMemory 未禁用」等价为「[data-action="new-memory"] 已渲染」
31
+ // (engineAvailable 为 false 时 renderMemories 只渲染离线横幅)。
32
+ // * 添加对话框:#memoryDialog/#memoryText/#confirmMemory → #appDialog 内
33
+ // #memoryForm(标题 input[name="title"](新契约必填)+ 正文
34
+ // textarea[name="text"]),提交 = #appDialogActions button.primary
35
+ // (type=submit 关联 #memoryForm)。标题/正文都用 CDP
36
+ // Input.insertText(真实粘贴路径)录入。
37
+ // * MEM-002 空白拒绝:新编辑器靠原生 required——空标题+空正文时点击提交
38
+ // 不触发 submit、不发请求、对话框保持打开(等 1.5s 仍 open + POST 计数
39
+ // 不变);仅空格正文能穿过原生 required(值非空),由 shell 的提交处理
40
+ // 器拦下,等价旧 #memoryFeedback 的 #appDialogFeedback 报
41
+ // 「请填写标题和记忆内容。」,同样不发请求。
42
+ // * 引擎空白拒绝保持(400 INVALID_ARGUMENT / 记忆内容必须为 1–N 个字符);
43
+ // N 随引擎版本由 2000 变为 8000(MEMORY_TEXT_LIMIT),断言语义不变。
44
+ // * 旧 UI 的默认作用域=当前项目;新表单默认=组合记忆。MEM-001 的「项目
45
+ // 作用域存储」语义保持:在表单里显式选择 适用范围=项目 +
46
+ // 适用目标=当前项目(#memoryForm select[name="scopeType"] 与
47
+ // [data-role="scope-target"] select[name="scopeTarget"]),存储的
48
+ // scopeType/scopeId 另用 engineApi GET /api/memories 复核。
49
+ // * 「导入项目已列出」等待:旧首页项目面板(homeContent 含项目名)已删除,
50
+ // 等价为顶栏 #projectSelect 选项里出现项目名(同一 registry projection)。
51
+ // * 其余引擎断言(POST 200、confirmed/manual/evidence null、磁盘记忆文件
52
+ // memories/projects/<projectId>.md 与「来源:手动添加(用户确认)」、
53
+ // 注入门 /api/context、真实 reload 后保留、syncStatus=ready)保持不变。
26
54
 
27
55
  const fs = require('node:fs');
28
56
  const path = require('node:path');
@@ -31,15 +59,27 @@ const assert = require('node:assert/strict');
31
59
  const { startHarness, makeRepo } = require('./helpers/parallel-memory-shell');
32
60
 
33
61
  const EVIDENCE = process.env.PK_TEST_EVIDENCE_DIR ? path.resolve(process.env.PK_TEST_EVIDENCE_DIR) : null;
62
+ const MEMORY_TITLE = '对外表述约定';
34
63
  const MEMORY_TEXT = '对外错误信息使用中文表述,并优先复用已有模块。';
35
64
 
65
+ /**
66
+ * Open the memory view with retries against the known reload commit-gap race
67
+ * (driver robustness only: the assertion stays "the view is really active").
68
+ */
36
69
  async function openMemoryView(harness) {
37
- await harness.nativeClick('nav [data-view="memory"]');
38
- await harness.waitFor(
39
- () => harness.run("document.getElementById('view-memory').classList.contains('active')"),
40
- 'the memory view is open',
41
- 10000,
42
- );
70
+ let lastError = null;
71
+ for (let attempt = 0; attempt < 3; attempt += 1) {
72
+ await harness.nativeClick('nav [data-view="memory"]');
73
+ try {
74
+ await harness.waitFor(
75
+ () => harness.run("document.getElementById('view-memory').classList.contains('active')"),
76
+ 'the memory view is open',
77
+ 5000,
78
+ );
79
+ return;
80
+ } catch (error) { lastError = error; }
81
+ }
82
+ throw lastError;
43
83
  }
44
84
 
45
85
  async function main() {
@@ -51,40 +91,75 @@ async function main() {
51
91
 
52
92
  // The shell has to know the project before it can bind a project scope.
53
93
  await harness.requestRegistryRefresh();
94
+ // The new home page no longer lists projects; the registry projection is
95
+ // surfaced by the topbar project selector instead.
54
96
  await harness.waitFor(
55
- () => harness.run("document.getElementById('homeContent').textContent.includes('记忆甲')"),
97
+ () => harness.run("document.getElementById('projectSelect').textContent.includes('记忆甲')"),
56
98
  'the imported project is listed',
57
99
  20000,
58
100
  );
59
101
 
60
102
  await openMemoryView(harness);
61
103
  await harness.waitFor(
62
- () => harness.run("!document.getElementById('addMemory').disabled"),
63
- 'the engine is reachable and the add button is live',
104
+ () => harness.run("document.querySelector('#memoryContent [data-action=\"new-memory\"]') !== null"),
105
+ 'the engine is reachable and the add action is live',
64
106
  20000,
65
107
  );
66
108
 
67
109
  // ---------------------------------------------------------------- MEM-002
68
- await harness.nativeClick('#addMemory');
110
+ await harness.nativeClick('#memoryContent [data-action="new-memory"]');
69
111
  await harness.waitFor(
70
- () => harness.run("document.getElementById('memoryDialog').open === true"),
71
- 'the add dialog is open',
112
+ () => harness.run("document.getElementById('appDialog').open === true && document.getElementById('memoryForm') !== null"),
113
+ 'the add dialog with the memory form is open',
72
114
  10000,
73
115
  );
74
- // Real key events into the really focused textarea.
75
- await harness.typeText(' ');
76
- const typed = await harness.run("document.getElementById('memoryText').value");
116
+
117
+ // Native required: an empty title AND an empty body never even submit —
118
+ // the browser blocks the form-associated submit button, so no request
119
+ // leaves the page and the dialog stays open.
120
+ const postsBeforeEmpty = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).length;
121
+ await harness.nativeClick('#appDialogActions button.primary');
122
+ await harness.wait(1500);
123
+ assert.equal(
124
+ await harness.run("document.getElementById('appDialog').open === true && document.getElementById('memoryForm') !== null"),
125
+ true,
126
+ 'the native required check keeps the dialog open for an empty form',
127
+ );
128
+ assert.equal(
129
+ await harness.run("document.getElementById('appDialogFeedback').hidden === true"),
130
+ true,
131
+ 'no submit ever ran, so the dialog feedback stays hidden',
132
+ );
133
+ assert.equal(
134
+ harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).length,
135
+ postsBeforeEmpty,
136
+ 'the empty form sends no request at all',
137
+ );
138
+
139
+ // A whitespace-only body passes the native required check (the value is
140
+ // not empty) and is then refused by the shell's own submit handler, which
141
+ // names the missing content exactly like the old #memoryFeedback did.
142
+ await harness.nativeClick('#memoryForm input[name="title"]');
143
+ await harness.browser.send('Input.insertText', { text: MEMORY_TITLE });
144
+ await harness.nativeClick('#memoryForm textarea[name="text"]');
145
+ await harness.browser.send('Input.insertText', { text: ' ' });
146
+ const typed = await harness.run("document.getElementById('memoryForm').elements.text.value");
77
147
  assert.equal(typed, ' ', 'the blank body really reached the textarea');
78
148
 
79
149
  const postsBefore = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).length;
80
- await harness.nativeClick('#confirmMemory');
150
+ await harness.nativeClick('#appDialogActions button.primary');
81
151
  await harness.waitFor(
82
- () => harness.run("document.getElementById('memoryFeedback').hidden === false"),
152
+ () => harness.run("document.getElementById('appDialogFeedback').hidden === false"),
83
153
  'the shell refuses the blank body in the dialog',
84
154
  10000,
85
155
  );
86
- const feedback = await harness.run("document.getElementById('memoryFeedback').textContent");
87
- assert.match(String(feedback), /请填写记忆内容。/, 'the shell names the missing content');
156
+ const feedback = await harness.run("document.getElementById('appDialogFeedback').textContent");
157
+ assert.match(String(feedback), /请填写标题和记忆内容。/, 'the shell names the missing content');
158
+ assert.equal(
159
+ await harness.run("document.getElementById('appDialog').open === true"),
160
+ true,
161
+ 'the refused dialog stays open',
162
+ );
88
163
  const postsAfter = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).length;
89
164
  assert.equal(postsAfter, postsBefore, 'the shell must not send a request for a blank body');
90
165
 
@@ -92,7 +167,9 @@ async function main() {
92
167
  const backendBlank = await harness.productApi('POST', '/api/engine/memories', { text: ' ', scopeType: 'global', scopeId: 'brain-default', brainId: 'brain-default' });
93
168
  assert.equal(backendBlank.status, 400, `the engine refuses a blank body: ${JSON.stringify(backendBlank.body)}`);
94
169
  assert.equal(backendBlank.body.error, 'INVALID_ARGUMENT', 'the engine reports an invalid argument');
95
- assert.match(String(backendBlank.body.message), /记忆内容必须为 1–2000 个字符。/, 'the engine names the length rule');
170
+ assert.match(String(backendBlank.body.message), /记忆内容必须为 1–8000 个字符。/, 'the engine names the length rule (MEMORY_TEXT_LIMIT is 8000 in the current engine)');
171
+ const backendBlankEngine = await harness.engineApi('POST', '/api/memories', { text: ' ', scopeType: 'global', scopeId: 'brain-default', brainId: 'brain-default' });
172
+ assert.equal(backendBlankEngine.status, 400, `the engine behind the proxy refuses it too: ${JSON.stringify(backendBlankEngine.body)}`);
96
173
 
97
174
  const afterBlank = await harness.productMemories();
98
175
  assert.deepEqual(afterBlank, [], 'a refused blank body creates no memory at all');
@@ -100,28 +177,46 @@ async function main() {
100
177
 
101
178
  evidence.push({
102
179
  case: 'MEM-002',
103
- frontEnd: { feedback, requestsSent: postsAfter - postsBefore },
180
+ frontEnd: {
181
+ nativeRequiredBlockedEmptyForm: true,
182
+ feedback,
183
+ requestsSent: postsAfter - postsBefore,
184
+ },
104
185
  backEnd: { status: backendBlank.status, body: backendBlank.body },
105
186
  memoriesAfter: afterBlank.length,
106
187
  });
107
188
 
108
189
  // ---------------------------------------------------------------- MEM-001
109
- // The same dialog now carries a real body. The rejected submit left the
110
- // focus on the confirm button, so the real user clicks back into the field.
111
- await harness.nativeClick('#memoryText');
190
+ // The same dialog now carries a real body. The refused submit left the
191
+ // focus on the submit button, so the real user clicks back into the field.
192
+ await harness.nativeClick('#memoryForm textarea[name="text"]');
112
193
  await harness.pressBackspace(3);
113
- await harness.typeText(MEMORY_TEXT);
114
- const body = await harness.run("document.getElementById('memoryText').value");
194
+ await harness.browser.send('Input.insertText', { text: MEMORY_TEXT });
195
+ const body = await harness.run("document.getElementById('memoryForm').elements.text.value");
115
196
  assert.equal(body, MEMORY_TEXT, 'the real body reached the textarea');
116
197
 
117
- await harness.nativeClick('#confirmMemory');
198
+ // The old UI defaulted a manual add to the active project's scope; the new
199
+ // form defaults to a group memory, so the project-scope semantics are
200
+ // chosen explicitly through the real selects.
201
+ await harness.selectOption('#memoryForm select[name="scopeType"]', 'project');
118
202
  await harness.waitFor(
119
- () => harness.run("document.getElementById('memoryDialog').open === false"),
203
+ () => harness.run("document.querySelector('#memoryForm [data-role=\"scope-target\"]').hidden === false"),
204
+ 'the project scope target select is shown',
205
+ 10000,
206
+ );
207
+ const targetOptions = await harness.run("Array.from(document.querySelector('#memoryForm [data-role=\"scope-target\"] select[name=\"scopeTarget\"]').options).map(o => o.value)");
208
+ assert.ok(targetOptions.includes(projectId), `the project scope offers ${projectId}: ${JSON.stringify(targetOptions)}`);
209
+ await harness.selectOption('#memoryForm [data-role="scope-target"] select[name="scopeTarget"]', projectId);
210
+
211
+ const postsBeforeSave = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).length;
212
+ await harness.nativeClick('#appDialogActions button.primary');
213
+ await harness.waitFor(
214
+ () => harness.run("document.getElementById('appDialog').open === false"),
120
215
  'the dialog closes after a confirmed save',
121
216
  15000,
122
217
  );
123
218
 
124
- const post = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).pop();
219
+ const post = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories'))[postsBeforeSave];
125
220
  assert.ok(post, 'the shell really posted a memory');
126
221
  assert.equal(post.status, 200, `the real POST answers 200: ${JSON.stringify(post.body)}`);
127
222
  const postBody = await harness.network.body(post);
@@ -131,11 +226,20 @@ async function main() {
131
226
  assert.equal(created.sourceType, 'manual', 'a manual memory has no model source');
132
227
  assert.equal(created.evidence, null, 'a manual memory invents no evidence');
133
228
  assert.equal(created.text, MEMORY_TEXT, 'the saved text is the text that was typed');
134
- assert.equal(created.scopeType, 'project', 'the default scope of an active project is the project itself');
229
+ assert.equal(created.title, MEMORY_TITLE, 'the saved title is the title that was typed');
230
+ assert.equal(created.scopeType, 'project', 'the chosen scope of the manual memory is the project');
135
231
  assert.equal(created.scopeId, projectId, 'the scope target is the active project');
136
232
  assert.ok(created.id, 'the memory has an id');
137
233
 
138
- // The memory is listed in the real UI.
234
+ // The engine's own record confirms the stored scope pair.
235
+ const engineRecord = (await harness.engineApi('GET', '/api/memories')).body.memories.find(memory => memory.id === created.id);
236
+ assert.ok(engineRecord, 'the engine really stored the memory');
237
+ assert.equal(engineRecord.scopeType, 'project', 'the engine stores the project scope type');
238
+ assert.equal(engineRecord.scopeId, projectId, 'the engine stores the active project as the scope target');
239
+ assert.equal(engineRecord.status, 'confirmed', 'the engine stores the memory as confirmed');
240
+
241
+ // The memory is listed in the real UI (the 记忆库 tab lists confirmed
242
+ // memories; the card shows the title and the clamped body).
139
243
  await harness.waitFor(
140
244
  () => harness.run(`document.getElementById('memoryContent').textContent.includes(${JSON.stringify(MEMORY_TEXT)})`),
141
245
  'the new memory is listed',
@@ -158,6 +262,7 @@ async function main() {
158
262
 
159
263
  // 刷新后保留: a real reload of the real page.
160
264
  await harness.reload();
265
+ await openMemoryView(harness);
161
266
  await harness.waitFor(
162
267
  () => harness.run(`document.getElementById('memoryContent').textContent.includes(${JSON.stringify(MEMORY_TEXT)})`),
163
268
  'the memory is still listed after a real reload',
@@ -177,6 +282,7 @@ async function main() {
177
282
  case: 'MEM-001',
178
283
  request: { method: post.method, url: post.url.replace(harness.base, ''), status: post.status, request: post.body, response: postBody },
179
284
  memoryFile: { path: memoryFile, sha256: require('node:crypto').createHash('sha256').update(fileText).digest('hex') },
285
+ engineRecord: { id: engineRecord.id, scopeType: engineRecord.scopeType, scopeId: engineRecord.scopeId, status: engineRecord.status },
180
286
  afterReload: kept,
181
287
  injected: injected.map(memory => memory.memoryId),
182
288
  });
@@ -188,7 +294,7 @@ async function main() {
188
294
  fs.writeFileSync(path.join(harness.evidence, 'mem001-manual.json'), `${JSON.stringify(evidence, null, 2)}\n`, 'utf8');
189
295
  }
190
296
 
191
- console.log(`parallel-memory-manual-test PASS (MEM-001 confirmed + survives a real reload; MEM-002 refused by the shell without a request and by the engine with 400)`);
297
+ console.log(`parallel-memory-manual-test PASS (MEM-001 confirmed with an explicit project scope + survives a real reload; MEM-002 refused by native required and by the shell without a request, and by the engine with 400)`);
192
298
  } finally {
193
299
  await harness.cleanup();
194
300
  }