@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
@@ -18,6 +18,30 @@
18
18
  // domain memory only reaches the projects of
19
19
  // that domain, a project memory only reaches
20
20
  // that project.
21
+ //
22
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md):
23
+ // * 添加记忆:#addMemory/#memoryDialog → #memoryContent
24
+ // [data-action="new-memory"] → #appDialog 内 #memoryForm。新契约要求标题
25
+ // (input[name="title"],本测试以记忆正文为标题)与正文
26
+ // (textarea[name="text"]),均用 CDP Input.insertText(真实粘贴路径)
27
+ // 录入;提交 = #appDialogActions button.primary。
28
+ // * 适用范围:#memoryScope → #memoryForm select[name="scopeType"](新表单
29
+ // 默认 group,global/domain/project 需显式选择,选择后 change 触发
30
+ // fillTargets);适用目标:#memoryTarget →
31
+ // #memoryForm [data-role="scope-target"] select[name="scopeTarget"]
32
+ // (仅 domain/project 显示;「UI 只提供该类型的目标」断言保持为读取
33
+ // 该 select 的 options)。
34
+ // * scope 存储语义断言保持:POST 响应 scopeType/scopeId + 新增 engineApi
35
+ // GET /api/memories 复核引擎存储的 scopeType/scopeId。
36
+ // * 引擎侧断言全部不变:错配 scope 的 400 INVALID_ARGUMENT
37
+ // (所选记忆目标不存在或不属于当前智脑。)、注入矩阵
38
+ // (/api/context)、磁盘文件布局(brain 共享目录下 memories/
39
+ // confirmed.md、domains/<domainId>.md、projects/<projectId>.md,领域目录
40
+ // 自身无记忆文件)。
41
+ // * 「导入项目已列出」等待:旧首页项目面板已删除 → 顶栏 #projectSelect。
42
+ // * 作用域标签断言:旧 confirmed tab 的 [data-memory-card] → library tab
43
+ // ([data-memory-tab="library"])的 .memory-item(卡片第三行仍标注
44
+ // 全局记忆/领域记忆/项目记忆 与目标名称)。
21
45
 
22
46
  const fs = require('node:fs');
23
47
  const path = require('node:path');
@@ -30,47 +54,79 @@ const GLOBAL_TEXT = '全局约定:所有对外错误信息使用中文表述
30
54
  const DOMAIN_TEXT = '平台领域约定:发布流程必须先跑完整回归。';
31
55
  const PROJECT_TEXT = '项目约定:数据库迁移脚本一律放在 db/migrations。';
32
56
 
57
+ /**
58
+ * Open the memory view with retries against the known reload commit-gap race
59
+ * (driver robustness only: the assertion stays "the view is really active").
60
+ */
33
61
  async function openMemoryView(harness) {
34
- await harness.nativeClick('nav [data-view="memory"]');
35
- await harness.waitFor(
36
- () => harness.run("document.getElementById('view-memory').classList.contains('active')"),
37
- 'the memory view is open',
38
- 10000,
39
- );
62
+ let lastError = null;
63
+ for (let attempt = 0; attempt < 3; attempt += 1) {
64
+ await harness.nativeClick('nav [data-view="memory"]');
65
+ try {
66
+ await harness.waitFor(
67
+ () => harness.run("document.getElementById('view-memory').classList.contains('active')"),
68
+ 'the memory view is open',
69
+ 5000,
70
+ );
71
+ return;
72
+ } catch (error) { lastError = error; }
73
+ }
74
+ throw lastError;
40
75
  }
41
76
 
42
- /** Add one memory through the real UI and return what the engine answered. */
77
+ /**
78
+ * Add one memory through the real UI (new-memory dialog: title + body +
79
+ * explicit scope) and return what the engine answered, cross-checked against
80
+ * the engine's own stored record.
81
+ */
43
82
  async function addMemoryViaUi(harness, { text, scopeType, scopeId }) {
44
- await harness.nativeClick('#addMemory');
83
+ await harness.nativeClick('#memoryContent [data-action="new-memory"]');
45
84
  await harness.waitFor(
46
- () => harness.run("document.getElementById('memoryDialog').open === true"),
47
- 'the add dialog is open',
85
+ () => harness.run("document.getElementById('appDialog').open === true && document.getElementById('memoryForm') !== null"),
86
+ 'the add dialog with the memory form is open',
48
87
  10000,
49
88
  );
50
- await harness.typeText(text);
51
- await harness.selectOption('#memoryScope', scopeType);
89
+ // The new contract requires a title; the memory text doubles as its title.
90
+ await harness.nativeClick('#memoryForm input[name="title"]');
91
+ await harness.browser.send('Input.insertText', { text });
92
+ await harness.nativeClick('#memoryForm textarea[name="text"]');
93
+ await harness.browser.send('Input.insertText', { text });
94
+ await harness.selectOption('#memoryForm select[name="scopeType"]', scopeType);
52
95
  if (scopeType !== 'global') {
53
- const options = await harness.run("Array.from(document.getElementById('memoryTarget').options).map(o => o.value)");
96
+ await harness.waitFor(
97
+ () => harness.run("document.querySelector('#memoryForm [data-role=\"scope-target\"]').hidden === false"),
98
+ `the ${scopeType} scope target select is shown`,
99
+ 10000,
100
+ );
101
+ const options = await harness.run("Array.from(document.querySelector('#memoryForm [data-role=\"scope-target\"] select[name=\"scopeTarget\"]').options).map(o => o.value)");
54
102
  assert.ok(options.includes(scopeId), `the ${scopeType} scope offers ${scopeId}: ${JSON.stringify(options)}`);
55
- await harness.selectOption('#memoryTarget', scopeId);
103
+ await harness.selectOption('#memoryForm [data-role="scope-target"] select[name="scopeTarget"]', scopeId);
56
104
  }
57
105
  const postsBefore = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).length;
58
- await harness.nativeClick('#confirmMemory');
106
+ await harness.nativeClick('#appDialogActions button.primary');
59
107
  await harness.waitFor(
60
- () => harness.run("document.getElementById('memoryDialog').open === false"),
108
+ () => harness.run("document.getElementById('appDialog').open === false"),
61
109
  'the dialog closes after the save',
62
110
  15000,
63
111
  );
64
112
  const post = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories'))[postsBefore];
65
113
  assert.ok(post, 'the shell really posted the memory');
66
114
  assert.equal(post.status, 200, `the real POST answers 200: ${JSON.stringify(post.body)}`);
115
+ assert.equal(post.body && post.body.scopeType, scopeType, 'the chosen scope type really travelled with the request');
116
+ if (scopeId) assert.equal(post.body.scopeId, scopeId, 'the chosen scope target really travelled with the request');
67
117
  const body = await harness.network.body(post);
68
118
  assert.ok(body && body.memory, `the real POST answers with the memory: ${JSON.stringify(body)}`);
69
119
  assert.equal(body.memory.text, text, 'the saved text is the text that was typed');
70
120
  assert.equal(body.memory.scopeType, scopeType, 'the saved scope type is the chosen one');
71
121
  assert.equal(body.memory.scopeId, scopeId || body.memory.brainId, 'the saved scope id belongs to the scope type');
72
122
  assert.equal(body.memory.status, 'confirmed', 'the memory is saved as confirmed');
73
- return { memory: body.memory, request: post.body, url: post.url.replace(harness.base, '') };
123
+ // The engine's own stored record confirms the scope pair.
124
+ const engineRecord = (await harness.engineApi('GET', '/api/memories')).body.memories.find(memory => memory.id === body.memory.id);
125
+ assert.ok(engineRecord, 'the engine really stored the memory');
126
+ assert.equal(engineRecord.scopeType, scopeType, `the engine stores the ${scopeType} scope type`);
127
+ assert.equal(engineRecord.scopeId, scopeId || engineRecord.brainId, `the engine stores the ${scopeType} scope id`);
128
+ assert.equal(engineRecord.status, 'confirmed', 'the engine stores the memory as confirmed');
129
+ return { memory: body.memory, engineRecord, request: post.body, url: post.url.replace(harness.base, '') };
74
130
  }
75
131
 
76
132
  async function main() {
@@ -88,8 +144,10 @@ async function main() {
88
144
  const c = await harness.importProject(repoC, '范围丙');
89
145
 
90
146
  await harness.requestRegistryRefresh();
147
+ // The new home page no longer lists projects; the registry projection is
148
+ // surfaced by the topbar project selector instead.
91
149
  await harness.waitFor(
92
- () => harness.run("document.getElementById('homeContent').textContent.includes('范围丙')"),
150
+ () => harness.run("document.getElementById('projectSelect').textContent.includes('范围丙')"),
93
151
  'the imported projects are listed',
94
152
  20000,
95
153
  );
@@ -109,8 +167,8 @@ async function main() {
109
167
  );
110
168
  await openMemoryView(harness);
111
169
  await harness.waitFor(
112
- () => harness.run("!document.getElementById('addMemory').disabled"),
113
- 'the engine is reachable and the add button is live',
170
+ () => harness.run("document.querySelector('#memoryContent [data-action=\"new-memory\"]') !== null"),
171
+ 'the engine is reachable and the add action is live',
114
172
  20000,
115
173
  );
116
174
 
@@ -122,6 +180,9 @@ async function main() {
122
180
  assert.equal(globalMemory.memory.scopeId, globalMemory.memory.brainId, 'a global memory targets the brain itself');
123
181
  assert.equal(domainMemory.memory.scopeId, domain.id, 'a domain memory targets the domain');
124
182
  assert.equal(projectMemory.memory.scopeId, a.projectId, 'a project memory targets the project');
183
+ assert.equal(globalMemory.engineRecord.scopeId, globalMemory.engineRecord.brainId, 'the engine stores the global scope against the brain');
184
+ assert.equal(domainMemory.engineRecord.scopeId, domain.id, 'the engine stores the domain scope');
185
+ assert.equal(projectMemory.engineRecord.scopeId, a.projectId, 'the engine stores the project scope');
125
186
 
126
187
  // The scope id has to belong to the scope type: the engine refuses the
127
188
  // mismatched combinations instead of silently storing them.
@@ -154,19 +215,26 @@ async function main() {
154
215
  assert.ok(!ids(injectedB).includes(projectMemory.memory.id), `the project memory does not reach 乙: ${JSON.stringify(injectedB)}`);
155
216
  assert.ok(!ids(injectedC).includes(projectMemory.memory.id), `the project memory does not reach 丙: ${JSON.stringify(injectedC)}`);
156
217
 
157
- // The real UI names the scope of every memory.
218
+ // The real UI names the scope of every memory (the library tab lists the
219
+ // confirmed memories; each .memory-item card names the scope and target).
158
220
  await harness.reload();
159
221
  await openMemoryView(harness);
160
- await harness.nativeClick('[data-memory-tab="confirmed"]');
222
+ await harness.waitFor(
223
+ () => harness.run("document.querySelector('#memoryContent [data-memory-tab=\"library\"]') !== null"),
224
+ 'the memory tab bar is rendered from real data',
225
+ 20000,
226
+ );
227
+ await harness.nativeClick('#memoryContent [data-memory-tab="library"]');
161
228
  await harness.waitFor(
162
229
  () => harness.run(`document.getElementById('memoryContent').textContent.includes(${JSON.stringify(GLOBAL_TEXT)})`),
163
230
  'the confirmed memories are listed',
164
231
  15000,
165
232
  );
166
- const scopeLabels = await harness.run("Array.from(document.querySelectorAll('[data-memory-card]')).map(el => el.textContent)");
233
+ const scopeLabels = await harness.run("Array.from(document.querySelectorAll('#memoryContent .memory-item')).map(el => el.textContent)");
167
234
  const globalCard = scopeLabels.find(text => text.includes(GLOBAL_TEXT));
168
235
  const domainCard = scopeLabels.find(text => text.includes(DOMAIN_TEXT));
169
236
  const projectCard = scopeLabels.find(text => text.includes(PROJECT_TEXT));
237
+ assert.ok(globalCard && domainCard && projectCard, `all three memories have cards: ${JSON.stringify(scopeLabels)}`);
170
238
  assert.match(globalCard, /全局/, 'the UI names the global scope');
171
239
  assert.match(domainCard, /领域/, 'the UI names the domain scope');
172
240
  assert.match(domainCard, new RegExp(domain.name), 'the UI names the domain');
@@ -3,6 +3,22 @@
3
3
  //
4
4
  // MEM-008 来源边界(维护 / 委派不自动成为人类偏好).
5
5
  //
6
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md):
7
+ // * 「导入项目已列出」等待:旧首页项目面板已删除 → 顶栏 #projectSelect
8
+ // 选项含项目名(同一 registry projection)。
9
+ // * 导航/视图切换:nav [data-view] 与 #view-* 的 active 断言不变;按前批
10
+ // 经验对 reload 后的导航点击加 3 次重试(commit-gap 竞态是驱动鲁棒性
11
+ // 问题,断言仍是「视图真正激活」)。
12
+ // * 候选箱 tab:[data-memory-tab="candidate"] 选择器不变;tab 栏由
13
+ // #memoryContent 动态渲染且仅引擎可达时出现,先等 tab 渲染再点击。
14
+ // * 候选箱空态文案仍含「候选箱为空。」断言不变。
15
+ // * 首页边界文案:「没有待确认记忆。」→「没有待确认的记忆。」(新 UI
16
+ // 措辞微调),语义(智脑不会自动把项目行为当作偏好)不变。
17
+ // * 冻结来源:本例四个候选全部被引擎来源门拒绝,没有可审核对象,UI 侧
18
+ // 不涉及审核流(新 UI 冻结来源/quote 的展示位是 #appDialog 内
19
+ // #reviewForm / #appDialogBody,供候选存活的用例使用);引擎侧
20
+ // accepted/rejected 错误码、零存储、零注入断言逐字保持。
21
+ //
6
22
  // Real isolated product instance, real browser, real HTTP and real disk.
7
23
  //
8
24
  // Every case runs the REAL pipeline: a real follow-up commit, a real frozen
@@ -46,8 +62,9 @@ async function main() {
46
62
  const repo = makeRepo(harness.fixture, 'memsource-repo', { 'README.md': '# 来源甲\n' });
47
63
  const { projectId } = await harness.importProject(repo, '来源甲');
48
64
  await harness.requestRegistryRefresh();
65
+ // 迁移:首页不再列出项目;登记状态由顶栏 #projectSelect 呈现。
49
66
  await harness.waitFor(
50
- () => harness.run("document.getElementById('homeContent').textContent.includes('来源甲')"),
67
+ () => harness.run("document.getElementById('projectSelect').textContent.includes('来源甲')"),
51
68
  'the imported project is listed',
52
69
  20000,
53
70
  );
@@ -147,18 +164,33 @@ async function main() {
147
164
  } catch {}
148
165
  };
149
166
  await harness.reload();
150
- await harness.nativeClick('nav [data-view="memory"]');
151
- try {
152
- await harness.waitFor(
153
- () => harness.run("document.getElementById('view-memory').classList.contains('active')"),
154
- 'the memory view is open',
155
- 10000,
156
- );
157
- } catch (error) {
158
- await debugNavigationFailure('memory-view-open');
159
- throw error;
160
- }
161
- await harness.nativeClick('[data-memory-tab="candidate"]');
167
+ // 迁移:reload 后导航点击有已知 commit-gap 竞态,按前批经验加 3 次重试;
168
+ // 断言本身仍是「视图真正激活」。
169
+ const openViewWithRetry = async (view, stage) => {
170
+ let lastError = null;
171
+ for (let attempt = 0; attempt < 3; attempt += 1) {
172
+ await harness.nativeClick(`nav [data-view="${view}"]`);
173
+ try {
174
+ await harness.waitFor(
175
+ () => harness.run(`document.getElementById('view-${view}').classList.contains('active')`),
176
+ `the ${view} view is open`,
177
+ 5000,
178
+ );
179
+ return;
180
+ } catch (error) { lastError = error; }
181
+ }
182
+ await debugNavigationFailure(stage);
183
+ throw lastError;
184
+ };
185
+ await openViewWithRetry('memory', 'memory-view-open');
186
+ // The tab bar lives in #memoryContent and is rendered only once the
187
+ // engine is reachable, so wait for the real tab before clicking it.
188
+ await harness.waitFor(
189
+ () => harness.run("document.querySelector('#memoryContent [data-memory-tab=\"candidate\"]') !== null"),
190
+ 'the memory tab bar is rendered from real data',
191
+ 20000,
192
+ );
193
+ await harness.nativeClick('#memoryContent [data-memory-tab="candidate"]');
162
194
  try {
163
195
  await harness.waitFor(
164
196
  () => harness.run("document.getElementById('memoryContent').textContent.includes('候选箱为空。')"),
@@ -175,19 +207,16 @@ async function main() {
175
207
  assert.ok(!candidateBox.includes(UNSOURCED_TEXT), 'the unsourced preference is not listed');
176
208
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem008-candidate-empty.png'));
177
209
 
178
- await harness.nativeClick('nav [data-view="home"]');
179
- try {
180
- await harness.waitFor(
181
- () => harness.run("document.getElementById('view-home').classList.contains('active')"),
182
- 'the home view is open',
183
- 10000,
184
- );
185
- } catch (error) {
186
- await debugNavigationFailure('home-view-open');
187
- throw error;
188
- }
210
+ await openViewWithRetry('home', 'home-view-open');
211
+ // The home overview loads asynchronously after the view activates; gate on
212
+ // the boundary sentence before reading the whole panel.
213
+ await harness.waitFor(
214
+ () => harness.run("document.getElementById('homeContent').textContent.includes('没有待确认的记忆。')"),
215
+ 'the home view states the boundary',
216
+ 20000,
217
+ );
189
218
  const home = await harness.run("document.getElementById('homeContent').textContent");
190
- assert.match(home, /没有待确认记忆。智脑不会自动把项目行为当作你的偏好。/, `the home view states the boundary: ${home}`);
219
+ assert.match(home, /没有待确认的记忆。智脑不会自动把项目行为当作你的偏好。/, `the home view states the boundary: ${home}`);
191
220
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem008-home.png'));
192
221
 
193
222
  evidence.push({
@@ -14,12 +14,39 @@
14
14
  // MEM-006 expected:
15
15
  // * sync pending真实显示。 -> the engine really answers syncStatus
16
16
  // 'pending' with the write error, the real UI
17
- // shows 写入待恢复 / 待同步 and the real toast
18
- // warns that the unsynced memory is not
19
- // injected;
17
+ // shows the pending write badge on the memory
18
+ // card (写入待恢复) and the real injection gate
19
+ // refuses the unsynced memory;
20
20
  // * 未同步内容不注入。 -> the engine injects nothing for the unsynced
21
21
  // memory, and it does inject it again once
22
22
  // the file can really be written.
23
+ //
24
+ // 迁移说明(五页简化 UI,见 patches/ui-test-mapping-spec.md):
25
+ // * 添加记忆入口:#addMemory → 记忆库 tab 头部 [data-action="new-memory"];
26
+ // 「引擎可达」等待从「#addMemory 未禁用」等价为「[data-action="new-memory"]
27
+ // 已渲染」(engineAvailable 为 false 时 renderMemories 只渲染离线横幅,
28
+ // 不渲染该按钮)。
29
+ // * 添加表单:#memoryDialog/#memoryText/#memoryScope/#confirmMemory →
30
+ // #appDialog 内 #memoryForm:标题 input[name="title"](新契约必填)与
31
+ // 正文 textarea[name="text"] 都用 CDP Input.insertText(真实粘贴路径),
32
+ // 适用范围 select[name="scopeType"]=global,提交 =
33
+ // #appDialogActions button.primary(type=submit 关联 #memoryForm)。
34
+ // * 记忆卡片:[data-memory-card=<id>] → .memory-item(以
35
+ // [data-action="memory-detail"][data-id=<id>] 定位)。旧卡片的
36
+ // 「写入待恢复 / 待同步」两个标签在新 UI 合并为单个「写入待恢复」徽标
37
+ // (ui/product.js memoryCard),断言等价为:pending 时徽标在、恢复后消失。
38
+ // * 旧 toast「记忆文件待恢复 / 未同步内容不会注入任务。」在新产品里不再
39
+ // 弹出(同步失败改为呈现在卡片徽标上),被动 toast 观察器随之移除;
40
+ // 「未同步内容不注入」语义仍由引擎注入门(/api/context)断言证明。
41
+ // * 恢复后的「已确认」卡片文案在新 UI 不存在;等价断言 = 恢复的记忆重新
42
+ // 出现在「记忆库」tab([data-memory-tab="library"],旧 confirmed tab,
43
+ // 仅列出 status=confirmed 的记忆)、卡片带「全局记忆」作用域行且无
44
+ // pending 徽标。
45
+ // * 导入项目已列出的等待:旧首页项目面板(homeContent 含项目名)已删除,
46
+ // 等价为顶栏 #projectSelect 选项里出现项目名(同一 registry projection)。
47
+ // * 引擎/数据断言(POST 200、created.status=confirmed、syncStatus=pending、
48
+ // syncError、注入门、confirmed.md 物化与恢复)保持不变;本测试使用真实
49
+ // 引擎(dataSchemaVersion 由引擎自身报告,当前为 4),无需同步任何桩。
23
50
 
24
51
  const fs = require('node:fs');
25
52
  const path = require('node:path');
@@ -28,17 +55,39 @@ const assert = require('node:assert/strict');
28
55
  const { startHarness, makeRepo } = require('./helpers/parallel-memory-shell');
29
56
 
30
57
  const EVIDENCE = process.env.PK_TEST_EVIDENCE_DIR ? path.resolve(process.env.PK_TEST_EVIDENCE_DIR) : null;
58
+ const MEMORY_TITLE = '同步失败回归';
31
59
  const MEMORY_TEXT = '同步失败回归:对外错误信息使用中文表述。';
32
60
 
61
+ /**
62
+ * Open the memory view with retries against the known reload commit-gap race
63
+ * (the shell's reload() gate proves the FRESH document, but a CDP click
64
+ * dispatched right at the commit boundary can still be lost — see the
65
+ * parallel-memory-shell.js reload comment). Driver robustness only: the
66
+ * assertion stays "the view is really active".
67
+ */
33
68
  async function openMemoryView(harness) {
34
- await harness.nativeClick('nav [data-view="memory"]');
35
- await harness.waitFor(
36
- () => harness.run("document.getElementById('view-memory').classList.contains('active')"),
37
- 'the memory view is open',
38
- 10000,
39
- );
69
+ let lastError = null;
70
+ for (let attempt = 0; attempt < 3; attempt += 1) {
71
+ await harness.nativeClick('nav [data-view="memory"]');
72
+ try {
73
+ await harness.waitFor(
74
+ () => harness.run("document.getElementById('view-memory').classList.contains('active')"),
75
+ 'the memory view is open',
76
+ 5000,
77
+ );
78
+ return;
79
+ } catch (error) { lastError = error; }
80
+ }
81
+ throw lastError;
40
82
  }
41
83
 
84
+ /** The library card (.memory-item) of one memory, located by its detail button. */
85
+ const memoryCardText = (harness, memoryId) => harness.run(`(() => {
86
+ const button = document.querySelector('#memoryContent [data-action="memory-detail"][data-id=${JSON.stringify(memoryId)}]');
87
+ const card = button ? button.closest('.memory-item') : null;
88
+ return card ? card.textContent : null;
89
+ })()`);
90
+
42
91
  async function main() {
43
92
  const harness = await startHarness({ tag: 'memsync', evidenceDir: EVIDENCE || undefined });
44
93
  const evidence = [];
@@ -46,15 +95,17 @@ async function main() {
46
95
  const repo = makeRepo(harness.fixture, 'memsync-repo', { 'README.md': '# 同步甲\n' });
47
96
  const { projectId } = await harness.importProject(repo, '同步甲');
48
97
  await harness.requestRegistryRefresh();
98
+ // The new home page no longer lists projects (领域/项目面板已删除);the
99
+ // registry projection is surfaced by the topbar project selector instead.
49
100
  await harness.waitFor(
50
- () => harness.run("document.getElementById('homeContent').textContent.includes('同步甲')"),
101
+ () => harness.run("document.getElementById('projectSelect').textContent.includes('同步甲')"),
51
102
  'the imported project is listed',
52
103
  20000,
53
104
  );
54
105
 
55
106
  await openMemoryView(harness);
56
107
  await harness.waitFor(
57
- () => harness.run("!document.getElementById('addMemory').disabled"),
108
+ () => harness.run("document.querySelector('#memoryContent [data-action=\"new-memory\"]') !== null"),
58
109
  'the engine is reachable and the add button is live',
59
110
  20000,
60
111
  );
@@ -67,35 +118,24 @@ async function main() {
67
118
  fs.mkdirSync(memoryFile, { recursive: true });
68
119
  assert.ok(fs.lstatSync(memoryFile).isDirectory(), 'the confirmed memory file path really is occupied by a directory');
69
120
 
70
- // Add the memory through the real UI as a global memory.
71
- await harness.nativeClick('#addMemory');
121
+ // Add the memory through the real UI as a global memory: the new-memory
122
+ // dialog (#appDialog > #memoryForm) with title + multiline body, scope
123
+ // global, submitted by the primary (type=submit) action button.
124
+ await harness.nativeClick('#memoryContent [data-action="new-memory"]');
72
125
  await harness.waitFor(
73
- () => harness.run("document.getElementById('memoryDialog').open === true"),
74
- 'the add dialog is open',
126
+ () => harness.run("document.getElementById('appDialog').open === true && document.getElementById('memoryForm') !== null"),
127
+ 'the add dialog with the memory form is open',
75
128
  10000,
76
129
  );
77
- await harness.typeText(MEMORY_TEXT);
78
- await harness.selectOption('#memoryScope', 'global');
130
+ await harness.nativeClick('#memoryForm input[name="title"]');
131
+ await harness.browser.send('Input.insertText', { text: MEMORY_TITLE });
132
+ await harness.nativeClick('#memoryForm textarea[name="text"]');
133
+ await harness.browser.send('Input.insertText', { text: MEMORY_TEXT });
134
+ await harness.selectOption('#memoryForm select[name="scopeType"]', 'global');
79
135
  const postsBefore = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).length;
80
- // Passive DOM observation installed BEFORE the real click. The product's
81
- // confirm handler closes the dialog BEFORE its post-save refreshSnapshot()
82
- // and shows the toast only after that refresh resolves (ui/product.js:
83
- // 'close(); await refreshSnapshot(); toast(...)'), so a one-shot read
84
- // gated on 'dialog closed' can land inside the refresh gap and see an
85
- // empty toast (CI 40080404131, line 98: empty text). The observer records
86
- // every REAL toast mutation the REAL click produces — text, visibility
87
- // and time — nothing is fabricated or forced.
88
- await harness.run(`(() => {
89
- const el = document.getElementById('toast');
90
- window.__pkToastLog = [{ text: el.textContent, hidden: el.hidden, at: Date.now() }];
91
- new MutationObserver(() => {
92
- window.__pkToastLog.push({ text: el.textContent, hidden: el.hidden, at: Date.now() });
93
- }).observe(el, { childList: true, characterData: true, subtree: true, attributes: true, attributeFilter: ['hidden'] });
94
- return true;
95
- })()`);
96
- await harness.nativeClick('#confirmMemory');
136
+ await harness.nativeClick('#appDialogActions button.primary');
97
137
  await harness.waitFor(
98
- () => harness.run("document.getElementById('memoryDialog').open === false"),
138
+ () => harness.run("document.getElementById('appDialog').open === false"),
99
139
  'the dialog closes after the save',
100
140
  15000,
101
141
  );
@@ -109,50 +149,32 @@ async function main() {
109
149
  assert.equal(created.syncStatus, 'pending', `the engine really answers syncStatus pending: ${JSON.stringify(created)}`);
110
150
  assert.ok(created.syncError, `the engine reports the real write error: ${JSON.stringify(created.syncError)}`);
111
151
 
112
- // The real UI shows the pending state. The wait is on the OBSERVED toast
113
- // record (installed before the click), so the assertion holds no matter
114
- // when the shell's post-save refreshSnapshot() finishes — the observed
115
- // toast is the real one the real click produced. The toast's text also
116
- // persists after its 4s auto-hide (product toast() flips only `hidden`),
117
- // so a late match is still the real text; requiring hidden === false in
118
- // the same record proves it was actually VISIBLE when shown.
152
+ // The real UI shows the pending state: the memory's card in the library
153
+ // (记忆库) tab carries the 写入待恢复 badge (ui/product.js memoryCard —
154
+ // the new UI's single pending indicator, replacing the old card's
155
+ // 写入待恢复 + 待同步 pair and the old pending toast).
119
156
  const debugUiFailure = async stage => {
120
157
  try {
121
158
  const dump = await harness.run(`(() => ({
122
- toasts: window.__pkToastLog || null,
123
- feedback: document.getElementById('memoryFeedback').textContent,
124
- feedbackHidden: document.getElementById('memoryFeedback').hidden,
125
- dialogOpen: document.getElementById('memoryDialog').open,
159
+ feedback: document.getElementById('appDialogFeedback').textContent,
160
+ feedbackHidden: document.getElementById('appDialogFeedback').hidden,
161
+ dialogOpen: document.getElementById('appDialog').open,
126
162
  activeView: (document.querySelector('.view.active') || {}).id || null,
163
+ memoryContent: document.getElementById('memoryContent').textContent.slice(0, 400),
127
164
  }))()`);
128
165
  console.error(`MEM-006 UI failure at ${stage}: ${JSON.stringify(dump)}`);
129
166
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, `mem006-failure-${stage}.png`));
130
167
  } catch {}
131
168
  };
132
- let toastRecord;
133
- try {
134
- toastRecord = await harness.waitFor(
135
- () => harness.run(`(window.__pkToastLog || []).find(t => !t.hidden && t.text.includes('记忆文件待恢复')) || null`),
136
- 'the toast warns about the pending file',
137
- 10000,
138
- );
139
- } catch (error) { await debugUiFailure('toast-pending'); throw error; }
140
- assert.equal(toastRecord.hidden, false, `the pending toast was really visible when shown: ${JSON.stringify(toastRecord)}`);
141
- const toast = toastRecord.text;
142
- assert.match(String(toast), /记忆文件待恢复/, `the toast warns about the pending file: ${toast}`);
143
- assert.match(String(toast), /未同步内容不会注入任务。/, 'the toast warns that the unsynced memory is not injected');
144
-
145
169
  let card;
146
170
  try {
147
- card = await harness.run(`(() => {
148
- const el = document.querySelector('[data-memory-card=${JSON.stringify(created.id)}]');
149
- return el ? el.textContent : null;
150
- })()`);
151
- } catch (error) { await debugUiFailure('card-read'); throw error; }
152
- if (!card) await debugUiFailure('card-listed');
153
- assert.ok(card, 'the confirmed memory is really listed');
171
+ card = await harness.waitFor(
172
+ () => memoryCardText(harness, created.id),
173
+ 'the confirmed memory is really listed with its pending badge',
174
+ 15000,
175
+ );
176
+ } catch (error) { await debugUiFailure('card-listed'); throw error; }
154
177
  assert.match(card, /写入待恢复/, `the card shows the pending write: ${card}`);
155
- assert.match(card, /待同步/, 'the card shows the pending sync state');
156
178
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem006-sync-pending.png'));
157
179
 
158
180
  // 未同步内容不注入: the real injection gate refuses the unsynced memory.
@@ -169,7 +191,7 @@ async function main() {
169
191
  case: 'MEM-006',
170
192
  request: { method: post.method, url: post.url.replace(harness.base, ''), status: post.status, response: postBody },
171
193
  memory: { id: created.id, status: created.status, syncStatus: created.syncStatus, syncError: created.syncError, scopeType: created.scopeType, scopeId: created.scopeId },
172
- ui: { toast, toastObserved: { visibleWhenShown: toastRecord.hidden === false, at: toastRecord.at }, card },
194
+ ui: { card, pendingBadge: '写入待恢复', note: 'the new five-page UI surfaces sync-pending on the card badge; the old pending toast no longer exists' },
173
195
  injectedWhilePending: injected.map(entry => entry.memoryId),
174
196
  blockedPath: memoryFile,
175
197
  });
@@ -200,19 +222,24 @@ async function main() {
200
222
 
201
223
  await harness.reload();
202
224
  await openMemoryView(harness);
203
- await harness.nativeClick('[data-memory-tab="confirmed"]');
225
+ // The reloaded page first renders the offline banner until its boot
226
+ // snapshot answers; the tab bar (and the library tab) exist only after
227
+ // the real engine data is in.
228
+ await harness.waitFor(
229
+ () => harness.run("document.querySelector('#memoryContent [data-memory-tab=\"library\"]') !== null"),
230
+ 'the memory tab bar is rendered from real data',
231
+ 20000,
232
+ );
233
+ await harness.nativeClick('#memoryContent [data-memory-tab="library"]');
204
234
  await harness.waitFor(
205
235
  () => harness.run(`document.getElementById('memoryContent').textContent.includes(${JSON.stringify(MEMORY_TEXT)})`),
206
236
  'the recovered memory is listed again',
207
237
  15000,
208
238
  );
209
- const recoveredCard = await harness.run(`(() => {
210
- const el = document.querySelector('[data-memory-card=${JSON.stringify(created.id)}]');
211
- return el ? el.textContent : null;
212
- })()`);
239
+ const recoveredCard = await memoryCardText(harness, created.id);
213
240
  assert.ok(recoveredCard, 'the recovered memory has a card');
214
241
  assert.ok(!recoveredCard.includes('写入待恢复'), `the card no longer shows the pending write: ${recoveredCard}`);
215
- assert.match(recoveredCard, /已确认/, 'the card shows the confirmed state again');
242
+ assert.match(recoveredCard, /全局记忆/, 'the card is a live library card with its global scope (the 记忆库 tab only lists confirmed memories)');
216
243
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem006-recovered.png'));
217
244
 
218
245
  evidence.push({
@@ -229,7 +256,7 @@ async function main() {
229
256
  fs.writeFileSync(path.join(harness.evidence, 'mem006-sync.json'), `${JSON.stringify(evidence, null, 2)}\n`, 'utf8');
230
257
  }
231
258
 
232
- console.log('parallel-memory-sync-test PASS (MEM-006 the real write failure shows sync pending, the unsynced memory is not injected, and the recovered memory is injected again)');
259
+ console.log('parallel-memory-sync-test PASS (MEM-006 the real write failure shows the pending badge on the memory card, the unsynced memory is not injected, and the recovered memory is injected again)');
233
260
  } finally {
234
261
  await harness.cleanup();
235
262
  }