@sanqianx/project-knowledge 5.2.0 → 5.3.0

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 (33) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +4 -0
  3. package/README.md +6 -0
  4. package/_site/_test/automatic-context-test.js +6 -0
  5. package/_site/_test/context-session-index-test.js +19 -9
  6. package/_site/_test/helpers/parallel-memory-shell.js +15 -7
  7. package/_site/_test/helpers/parallel-qa-engine-endpoint-isolate.js +3 -1
  8. package/_site/_test/memory-groups-ui-test.js +27 -3
  9. package/_site/_test/parallel-capture-safety-r5-mem005-health-test.js +2 -2
  10. package/_site/_test/parallel-engine-final-eng012-test.js +4 -4
  11. package/_site/_test/parallel-memory-candidate-test.js +7 -5
  12. package/_site/_test/parallel-memory-capture-r3-mem005-persistence-test.js +1 -1
  13. package/_site/_test/parallel-memory-capture-r4-mem005-health-test.js +2 -2
  14. package/_site/_test/parallel-memory-home-review-test.js +1 -1
  15. package/_site/_test/parallel-memory-manual-test.js +14 -25
  16. package/_site/_test/parallel-memory-scope-test.js +66 -264
  17. package/_site/_test/parallel-memory-source-test.js +5 -7
  18. package/_site/_test/parallel-memory-sync-test.js +8 -8
  19. package/_site/_test/parallel-qa-engine-endpoint-guard-test.js +4 -2
  20. package/_site/_test/project-team-ui-test.js +54 -46
  21. package/_site/_test/shared-scope-root-binding-test.js +7 -6
  22. package/_site/_test/t07f-mem-008-coverage-test.js +0 -1
  23. package/_site/lib/engine-connection.js +2 -2
  24. package/_site/lib/engine-knowledge-client.js +1 -1
  25. package/_site/scripts/verify-retrieval-gold.js +10 -13
  26. package/module-runtime-manifest.json +26 -25
  27. package/package.json +3 -3
  28. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  29. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  30. package/plugins/project-knowledge/.mcp.json +1 -1
  31. package/plugins/project-knowledge/scripts/context-hook.cjs +3 -3
  32. package/plugins/project-knowledge/skills/project-knowledge/SKILL.md +5 -6
  33. package/ui/product.js +147 -65
@@ -1,293 +1,95 @@
1
1
  'use strict';
2
- // _site/_test/parallel-memory-scope-test.js
3
- //
4
- // MEM-004 确认目标(适用范围).
5
- //
6
- // Real isolated product instance, real browser, real HTTP and real disk. Three
7
- // real projects are imported into one real brain: two of them belong to a real
8
- // domain, the third belongs to none. Three real memories are added through the
9
- // real UI: one global, one bound to the domain, one bound to a single project.
10
- //
11
- // MEM-004 expected:
12
- // * scopeId与scopeType匹配。 -> the stored memory carries the scope id that
13
- // belongs to its scope type, the UI only offers
14
- // targets of that type, and the engine refuses
15
- // a scope id that does not belong to the
16
- // declared scope type;
17
- // * 只影响指定范围。 -> a global memory reaches every project, a
18
- // domain memory only reaches the projects of
19
- // that domain, a project memory only reaches
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
- // 全局记忆/领域记忆/项目记忆 与目标名称)。
45
2
 
3
+ // MEM-004。组合选择、生效矩阵和磁盘投影。 / Verify combination selection, visibility and Markdown projection.
46
4
  const fs = require('node:fs');
47
5
  const path = require('node:path');
48
6
  const assert = require('node:assert/strict');
49
-
50
7
  const { startHarness, makeRepo } = require('./helpers/parallel-memory-shell');
51
8
 
52
- const EVIDENCE = process.env.PK_TEST_EVIDENCE_DIR ? path.resolve(process.env.PK_TEST_EVIDENCE_DIR) : null;
53
- const GLOBAL_TEXT = '全局约定:所有对外错误信息使用中文表述。';
54
- const DOMAIN_TEXT = '平台领域约定:发布流程必须先跑完整回归。';
55
- const PROJECT_TEXT = '项目约定:数据库迁移脚本一律放在 db/migrations。';
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
- */
61
- async function openMemoryView(harness) {
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;
75
- }
76
-
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
- */
82
- async function addMemoryViaUi(harness, { text, scopeType, scopeId }) {
9
+ async function addMemoryViaUi(harness, text, groupId) {
83
10
  await harness.nativeClick('#memoryContent [data-action="new-memory"]');
84
- await harness.waitFor(
85
- () => harness.run("document.getElementById('appDialog').open === true && document.getElementById('memoryForm') !== null"),
86
- 'the add dialog with the memory form is open',
87
- 10000,
88
- );
89
- // The new contract requires a title; the memory text doubles as its title.
11
+ await harness.waitFor(() => harness.run("Boolean(document.getElementById('memoryForm') && document.getElementById('appDialog').open)"), 'the editor opens');
12
+ assert.equal(await harness.run("Boolean(document.querySelector('#memoryForm [name=scopeType], #memoryForm [name=scopeTarget]'))"), false);
90
13
  await harness.nativeClick('#memoryForm input[name="title"]');
91
14
  await harness.browser.send('Input.insertText', { text });
92
15
  await harness.nativeClick('#memoryForm textarea[name="text"]');
93
16
  await harness.browser.send('Input.insertText', { text });
94
- await harness.selectOption('#memoryForm select[name="scopeType"]', scopeType);
95
- if (scopeType !== 'global') {
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)");
102
- assert.ok(options.includes(scopeId), `the ${scopeType} scope offers ${scopeId}: ${JSON.stringify(options)}`);
103
- await harness.selectOption('#memoryForm [data-role="scope-target"] select[name="scopeTarget"]', scopeId);
104
- }
105
- const postsBefore = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).length;
17
+ const choices = await harness.run("[...document.querySelector('#memoryForm select[name=groupId]').options].map(o => o.value)");
18
+ assert.ok(choices.includes(groupId), 'group selector options: ' + JSON.stringify(choices));
19
+ await harness.selectOption('#memoryForm select[name="groupId"]', groupId);
106
20
  await harness.nativeClick('#appDialogActions button.primary');
107
- await harness.waitFor(
108
- () => harness.run("document.getElementById('appDialog').open === false"),
109
- 'the dialog closes after the save',
110
- 15000,
111
- );
112
- const post = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories'))[postsBefore];
113
- assert.ok(post, 'the shell really posted the memory');
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');
117
- const body = await harness.network.body(post);
118
- assert.ok(body && body.memory, `the real POST answers with the memory: ${JSON.stringify(body)}`);
119
- assert.equal(body.memory.text, text, 'the saved text is the text that was typed');
120
- assert.equal(body.memory.scopeType, scopeType, 'the saved scope type is the chosen one');
121
- assert.equal(body.memory.scopeId, scopeId || body.memory.brainId, 'the saved scope id belongs to the scope type');
122
- assert.equal(body.memory.status, 'confirmed', 'the memory is saved as confirmed');
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, '') };
21
+ await harness.waitFor(() => harness.run("!document.getElementById('appDialog').open"), 'the memory saves');
22
+
23
+ const post = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).at(-1);
24
+ assert.equal(post.status, 200);
25
+ assert.deepEqual(post.body, { title: text, text, brainId: 'brain-default', groupId });
26
+ const { memory } = await harness.network.body(post);
27
+ assert.equal(memory.status, 'confirmed');
28
+ assert.deepEqual(memory.groups.map(item => item.id), [groupId]);
29
+ return memory;
130
30
  }
131
31
 
132
32
  async function main() {
133
- const harness = await startHarness({ tag: 'memscope', evidenceDir: EVIDENCE || undefined });
134
- const evidence = [];
33
+ const evidenceDir = process.env.PK_TEST_EVIDENCE_DIR && path.resolve(process.env.PK_TEST_EVIDENCE_DIR);
34
+ const harness = await startHarness({ tag: 'memscope', evidenceDir: evidenceDir || undefined });
135
35
  try {
136
36
  const domain = await harness.addDomain('平台领域');
137
- assert.ok(domain.id, 'the real domain has an id');
138
-
139
- const repoA = makeRepo(harness.fixture, 'memscope-a', { 'README.md': '# 甲\n' });
140
- const repoB = makeRepo(harness.fixture, 'memscope-b', { 'README.md': '# 乙\n' });
141
- const repoC = makeRepo(harness.fixture, 'memscope-c', { 'README.md': '# 丙\n' });
142
- const a = await harness.importProject(repoA, '范围甲', { domainId: domain.id });
143
- const b = await harness.importProject(repoB, '范围乙', { domainId: domain.id });
144
- const c = await harness.importProject(repoC, '范围丙');
145
-
37
+ const projects = [];
38
+ for (const label of ['甲', '乙', '丙']) {
39
+ const repo = makeRepo(harness.fixture, 'memscope-' + projects.length);
40
+ const { projectId } = await harness.importProject(repo, '范围' + label, label === '丙' ? {} : { domainId: domain.id });
41
+ projects.push(projectId);
42
+ }
43
+ const groups = [
44
+ await harness.addGroup('错误文案', projects),
45
+ await harness.addGroup('发布回归', [projects[0], projects[2]]),
46
+ await harness.addGroup('数据库迁移', [projects[1]]),
47
+ ];
146
48
  await harness.requestRegistryRefresh();
147
- // The new home page no longer lists projects; the registry projection is
148
- // surfaced by the topbar project selector instead.
149
- await harness.waitFor(
150
- () => harness.run("document.getElementById('projectSelect').textContent.includes('范围丙')"),
151
- 'the imported projects are listed',
152
- 20000,
153
- );
154
-
155
- // The engine really knows the domain binding of every project.
156
- const engineProjects = (await harness.engineApi('GET', '/api/projects')).body.projects;
157
- assert.equal(engineProjects.find(p => p.projectId === a.projectId).domainId, domain.id, 'the engine knows the domain of 甲');
158
- assert.equal(engineProjects.find(p => p.projectId === b.projectId).domainId, domain.id, 'the engine knows the domain of 乙');
159
- assert.equal(engineProjects.find(p => p.projectId === c.projectId).domainId || null, null, 'the engine knows 丙 has no domain');
160
-
161
- // The UI works on project 甲, the one inside the domain.
162
- await harness.selectOption('#projectSelect', a.projectId);
163
- await harness.waitFor(
164
- () => harness.run("document.getElementById('projectSelect').value === " + JSON.stringify(a.projectId)),
165
- 'the active project is 甲',
166
- 10000,
167
- );
168
- await openMemoryView(harness);
169
- await harness.waitFor(
170
- () => harness.run("document.querySelector('#memoryContent [data-action=\"new-memory\"]') !== null"),
171
- 'the engine is reachable and the add action is live',
172
- 20000,
173
- );
174
-
175
- // ---------------------------------------------------------------- MEM-004
176
- const globalMemory = await addMemoryViaUi(harness, { text: GLOBAL_TEXT, scopeType: 'global' });
177
- const domainMemory = await addMemoryViaUi(harness, { text: DOMAIN_TEXT, scopeType: 'domain', scopeId: domain.id });
178
- const projectMemory = await addMemoryViaUi(harness, { text: PROJECT_TEXT, scopeType: 'project', scopeId: a.projectId });
179
-
180
- assert.equal(globalMemory.memory.scopeId, globalMemory.memory.brainId, 'a global memory targets the brain itself');
181
- assert.equal(domainMemory.memory.scopeId, domain.id, 'a domain memory targets the domain');
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');
49
+ await harness.nativeClick('nav [data-view="memory"]');
50
+ await harness.waitFor(() => harness.run("Boolean(document.querySelector('#memoryContent [data-action=new-memory]'))"), 'the memory library is ready');
186
51
 
187
- // The scope id has to belong to the scope type: the engine refuses the
188
- // mismatched combinations instead of silently storing them.
189
- const mismatches = [
190
- { scopeType: 'domain', scopeId: a.projectId, why: 'a project id is not a domain' },
191
- { scopeType: 'project', scopeId: domain.id, why: 'a domain id is not a project' },
192
- { scopeType: 'global', scopeId: a.projectId, why: 'a global memory always targets the brain' },
52
+ const memories = [
53
+ await addMemoryViaUi(harness, '所有对外错误信息使用中文。', groups[0].id),
54
+ await addMemoryViaUi(harness, '发布前必须运行完整回归。', groups[1].id),
55
+ await addMemoryViaUi(harness, '数据库迁移脚本放在指定目录。', groups[2].id),
193
56
  ];
194
- for (const mismatch of mismatches) {
195
- const refused = await harness.productApi('POST', '/api/engine/memories', { text: `范围不匹配的记忆:${mismatch.why}`, scopeType: mismatch.scopeType, scopeId: mismatch.scopeId });
196
- assert.equal(refused.status, 400, `the engine refuses ${mismatch.why}: ${JSON.stringify(refused.body)}`);
197
- assert.equal(refused.body.error, 'INVALID_ARGUMENT', 'the engine reports an invalid argument');
198
- assert.match(String(refused.body.message), /所选记忆目标不存在或不属于当前智脑。/, 'the engine names the missing target');
57
+ const rejected = [];
58
+ for (const [scopeType, scopeId] of [['global', 'brain-default'], ['domain', domain.id], ['project', projects[0]]]) {
59
+ const response = await harness.productApi('POST', '/api/engine/memories', { text: '旧作用域写入', scopeType, scopeId });
60
+ assert.equal(response.status, 400);
61
+ assert.equal(response.body.error, 'INVALID_ARGUMENT');
62
+ rejected.push(scopeType);
199
63
  }
200
- const noMismatch = await harness.productMemories();
201
- assert.ok(!noMismatch.some(memory => memory.text.startsWith('范围不匹配的记忆')), 'no mismatched memory was stored');
202
64
 
203
- // 只影响指定范围: the injection matrix.
204
- const injectedA = await harness.injectedMemories(a.projectId);
205
- const injectedB = await harness.injectedMemories(b.projectId);
206
- const injectedC = await harness.injectedMemories(c.projectId);
207
- const ids = injected => injected.map(entry => entry.memoryId);
208
- assert.ok(ids(injectedA).includes(globalMemory.memory.id), 'the global memory reaches 甲');
209
- assert.ok(ids(injectedB).includes(globalMemory.memory.id), 'the global memory reaches 乙');
210
- assert.ok(ids(injectedC).includes(globalMemory.memory.id), 'the global memory reaches 丙');
211
- assert.ok(ids(injectedA).includes(domainMemory.memory.id), 'the domain memory reaches 甲');
212
- assert.ok(ids(injectedB).includes(domainMemory.memory.id), 'the domain memory reaches 乙');
213
- assert.ok(!ids(injectedC).includes(domainMemory.memory.id), `the domain memory does not reach 丙: ${JSON.stringify(injectedC)}`);
214
- assert.ok(ids(injectedA).includes(projectMemory.memory.id), 'the project memory reaches 甲');
215
- assert.ok(!ids(injectedB).includes(projectMemory.memory.id), `the project memory does not reach 乙: ${JSON.stringify(injectedB)}`);
216
- assert.ok(!ids(injectedC).includes(projectMemory.memory.id), `the project memory does not reach 丙: ${JSON.stringify(injectedC)}`);
65
+ const expected = [[memories[0].id, memories[1].id], [memories[0].id, memories[2].id], [memories[0].id, memories[1].id]];
66
+ const injected = [];
67
+ for (const [index, id] of projects.entries()) {
68
+ const memoryIds = (await harness.injectedMemories(id)).map(memory => memory.memoryId).sort();
69
+ assert.deepEqual(memoryIds, [...expected[index]].sort());
70
+ injected.push(memoryIds);
71
+ }
72
+ const root = path.join(harness.brainScopePath(), 'memories');
73
+ for (const relative of ['confirmed.md', 'domains', 'projects']) assert.equal(fs.existsSync(path.join(root, relative)), false);
74
+ for (const [index, group] of groups.entries()) {
75
+ const content = fs.readFileSync(path.join(root, 'groups', group.id + '.md'), 'utf8');
76
+ assert.ok(content.includes(memories[index].id));
77
+ assert.ok(memories.every((item, offset) => offset === index || !content.includes(item.id)));
78
+ }
217
79
 
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).
220
80
  await harness.reload();
221
- await openMemoryView(harness);
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"]');
228
- await harness.waitFor(
229
- () => harness.run(`document.getElementById('memoryContent').textContent.includes(${JSON.stringify(GLOBAL_TEXT)})`),
230
- 'the confirmed memories are listed',
231
- 15000,
232
- );
233
- const scopeLabels = await harness.run("Array.from(document.querySelectorAll('#memoryContent .memory-item')).map(el => el.textContent)");
234
- const globalCard = scopeLabels.find(text => text.includes(GLOBAL_TEXT));
235
- const domainCard = scopeLabels.find(text => text.includes(DOMAIN_TEXT));
236
- const projectCard = scopeLabels.find(text => text.includes(PROJECT_TEXT));
237
- assert.ok(globalCard && domainCard && projectCard, `all three memories have cards: ${JSON.stringify(scopeLabels)}`);
238
- assert.match(globalCard, /全局/, 'the UI names the global scope');
239
- assert.match(domainCard, /领域/, 'the UI names the domain scope');
240
- assert.match(domainCard, new RegExp(domain.name), 'the UI names the domain');
241
- assert.match(projectCard, /项目/, 'the UI names the project scope');
242
- assert.match(projectCard, new RegExp('范围甲'), 'the UI names the project');
243
- if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem004-scopes.png'));
244
-
245
- // The memory files really live in the scope they claim. The engine
246
- // materializes every scope's memory file in the brain's shared directory:
247
- // the domain scope directory itself holds no memory file.
248
- const brainScope = harness.brainScopePath();
249
- const domainScope = harness.domainScopePath(domain.id);
250
- assert.ok(fs.existsSync(path.join(brainScope, 'memories', 'confirmed.md')), 'the global memory file exists');
251
- assert.ok(fs.existsSync(path.join(brainScope, 'memories', 'domains', `${domain.id}.md`)), 'the domain memory file exists');
252
- assert.ok(fs.existsSync(path.join(brainScope, 'memories', 'projects', `${a.projectId}.md`)), 'the project memory file exists');
253
- assert.ok(!fs.existsSync(path.join(domainScope, 'memories')), 'the domain scope directory holds no memory file of its own');
254
- const globalFile = fs.readFileSync(path.join(brainScope, 'memories', 'confirmed.md'), 'utf8');
255
- assert.ok(globalFile.includes(globalMemory.memory.id), 'the global file holds the global memory');
256
- assert.ok(!globalFile.includes(domainMemory.memory.id), 'the global file does not hold the domain memory');
257
- const domainFile = fs.readFileSync(path.join(brainScope, 'memories', 'domains', `${domain.id}.md`), 'utf8');
258
- assert.ok(domainFile.includes(domainMemory.memory.id), 'the domain file holds the domain memory');
259
- const projectFile = fs.readFileSync(path.join(brainScope, 'memories', 'projects', `${a.projectId}.md`), 'utf8');
260
- assert.ok(projectFile.includes(projectMemory.memory.id), 'the project file holds the project memory');
261
- assert.ok(!projectFile.includes(globalMemory.memory.id), 'the project file does not hold the global memory');
262
-
263
- evidence.push({
264
- case: 'MEM-004',
265
- domain: { id: domain.id, name: domain.name },
266
- projects: { a: a.projectId, b: b.projectId, c: c.projectId },
267
- memories: {
268
- global: { id: globalMemory.memory.id, scopeType: globalMemory.memory.scopeType, scopeId: globalMemory.memory.scopeId },
269
- domain: { id: domainMemory.memory.id, scopeType: domainMemory.memory.scopeType, scopeId: domainMemory.memory.scopeId },
270
- project: { id: projectMemory.memory.id, scopeType: projectMemory.memory.scopeType, scopeId: projectMemory.memory.scopeId },
271
- },
272
- mismatchedScopes: mismatches.map(mismatch => mismatch.scopeType),
273
- injected: { a: ids(injectedA), b: ids(injectedB), c: ids(injectedC) },
274
- files: {
275
- brainScope,
276
- domainScope,
277
- global: path.join(brainScope, 'memories', 'confirmed.md'),
278
- domain: path.join(brainScope, 'memories', 'domains', `${domain.id}.md`),
279
- project: path.join(brainScope, 'memories', 'projects', `${a.projectId}.md`),
280
- },
281
- });
282
-
283
- assert.equal(harness.browser.exceptions.length, 0, `no uncaught product JavaScript exceptions: ${JSON.stringify(harness.browser.exceptions)}`);
284
-
285
- if (harness.evidence) {
286
- fs.mkdirSync(harness.evidence, { recursive: true });
287
- fs.writeFileSync(path.join(harness.evidence, 'mem004-scope.json'), `${JSON.stringify(evidence, null, 2)}\n`, 'utf8');
81
+ await harness.nativeClick('nav [data-view="memory"]');
82
+ await harness.waitFor(() => harness.run("document.querySelectorAll('#memoryContent .memory-item').length === 3"), 'the saved records reload');
83
+ const cards = await harness.run("[...document.querySelectorAll('#memoryContent .memory-item')].map(el => el.textContent)");
84
+ for (const [index, memory] of memories.entries()) {
85
+ const card = cards.find(text => text.includes(memory.title));
86
+ assert.ok(card?.includes(groups[index].name));
87
+ assert.doesNotMatch(card, /全局记忆|领域记忆|项目记忆/);
288
88
  }
289
-
290
- console.log('parallel-memory-scope-test PASS (MEM-004 scope id matches scope type; global, domain and project scopes only reach their own range)');
89
+ assert.deepEqual(harness.browser.exceptions, []);
90
+ await harness.browser.screenshot(path.join(harness.evidence, 'mem004-combinations.png'));
91
+ fs.writeFileSync(path.join(harness.evidence, 'mem004-scope.json'), JSON.stringify([{ case: 'MEM-004', projects, groups, injected, rejected }], null, 2));
92
+ console.log('parallel-memory-scope-test PASS (MEM-004 combination boundaries)');
291
93
  } finally {
292
94
  await harness.cleanup();
293
95
  }
@@ -11,7 +11,7 @@
11
11
  // 问题,断言仍是「视图真正激活」)。
12
12
  // * 候选箱 tab:[data-memory-tab="candidate"] 选择器不变;tab 栏由
13
13
  // #memoryContent 动态渲染且仅引擎可达时出现,先等 tab 渲染再点击。
14
- // * 候选箱空态文案仍含「候选箱为空。」断言不变。
14
+ // * 候选箱空态文案为「这个范围内没有待确认的记忆。」。
15
15
  // * 首页边界文案:「没有待确认记忆。」→「没有待确认的记忆。」(新 UI
16
16
  // 措辞微调),语义(智脑不会自动把项目行为当作偏好)不变。
17
17
  // * 冻结来源:本例四个候选全部被引擎来源门拒绝,没有可审核对象,UI 侧
@@ -89,7 +89,7 @@ async function main() {
89
89
  document: `# 冻结证据\n\n${DELEGATED_TEXT}\n`,
90
90
  inputOrigin: 'agent-delegation',
91
91
  eventContent: `委派任务:${DELEGATED_TEXT}`,
92
- candidate: event => harness.memoryCandidate({ text: DELEGATED_TEXT, event, scopeType: 'global' }),
92
+ candidate: event => harness.memoryCandidate({ text: DELEGATED_TEXT, event }),
93
93
  });
94
94
  assert.equal(delegated.capture.accepted, 0, 'a delegated task order is not admitted');
95
95
  assert.deepEqual(delegated.capture.rejected.map(entry => entry.code), ['SOURCE_NOT_HUMAN'], 'the gate names the non-human source');
@@ -101,7 +101,7 @@ async function main() {
101
101
  document: `# 冻结证据\n\n${UNKNOWN_TEXT}\n`,
102
102
  inputOrigin: 'unknown',
103
103
  eventContent: `无法确认来源的输入:${UNKNOWN_TEXT}`,
104
- candidate: event => harness.memoryCandidate({ text: UNKNOWN_TEXT, event, scopeType: 'global' }),
104
+ candidate: event => harness.memoryCandidate({ text: UNKNOWN_TEXT, event }),
105
105
  });
106
106
  assert.equal(unknown.capture.accepted, 0, 'an unverifiable source is not admitted');
107
107
  assert.deepEqual(unknown.capture.rejected.map(entry => entry.code), ['SOURCE_NOT_HUMAN'], 'the gate names the non-human source');
@@ -115,7 +115,6 @@ async function main() {
115
115
  candidate: () => ({
116
116
  text: UNSOURCED_TEXT,
117
117
  quote: UNSOURCED_TEXT,
118
- scopeType: 'global',
119
118
  eligibility: { durable: true, crossProject: true, reason: '人工明确表达的长期偏好', scopeReason: '适用于所有领域与项目' },
120
119
  }),
121
120
  });
@@ -131,7 +130,6 @@ async function main() {
131
130
  candidate: () => ({
132
131
  text: MISSING_EVENT_TEXT,
133
132
  quote: MISSING_EVENT_TEXT,
134
- scopeType: 'global',
135
133
  sourceEventId: 'event-does-not-exist',
136
134
  sourceHash: 'sha256:0000000000000000000000000000000000000000000000000000000000000000',
137
135
  eligibility: { durable: true, crossProject: true, reason: '人工明确表达的长期偏好', scopeReason: '适用于所有领域与项目' },
@@ -193,7 +191,7 @@ async function main() {
193
191
  await harness.nativeClick('#memoryContent [data-memory-tab="candidate"]');
194
192
  try {
195
193
  await harness.waitFor(
196
- () => harness.run("document.getElementById('memoryContent').textContent.includes('候选箱为空。')"),
194
+ () => harness.run("document.getElementById('memoryContent').textContent.includes('这个范围内没有待确认的记忆。')"),
197
195
  'the candidate box is really empty once the engine answered again',
198
196
  20000,
199
197
  );
@@ -202,7 +200,7 @@ async function main() {
202
200
  throw error;
203
201
  }
204
202
  const candidateBox = await harness.run("document.getElementById('memoryContent').textContent");
205
- assert.match(candidateBox, /候选箱为空。/, `the candidate box is really empty: ${candidateBox}`);
203
+ assert.match(candidateBox, /这个范围内没有待确认的记忆。/, `the candidate box is really empty: ${candidateBox}`);
206
204
  assert.ok(!candidateBox.includes(DELEGATED_TEXT), 'the delegated order is not listed');
207
205
  assert.ok(!candidateBox.includes(UNSOURCED_TEXT), 'the unsourced preference is not listed');
208
206
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem008-candidate-empty.png'));
@@ -29,7 +29,7 @@
29
29
  // * 添加表单:#memoryDialog/#memoryText/#memoryScope/#confirmMemory →
30
30
  // #appDialog 内 #memoryForm:标题 input[name="title"](新契约必填)与
31
31
  // 正文 textarea[name="text"] 都用 CDP Input.insertText(真实粘贴路径),
32
- // 适用范围 select[name="scopeType"]=global,提交 =
32
+ // 加入组合 select[name="groupId"],提交 =
33
33
  // #appDialogActions button.primary(type=submit 关联 #memoryForm)。
34
34
  // * 记忆卡片:[data-memory-card=<id>] → .memory-item(以
35
35
  // [data-action="memory-detail"][data-id=<id>] 定位)。旧卡片的
@@ -40,12 +40,12 @@
40
40
  // 「未同步内容不注入」语义仍由引擎注入门(/api/context)断言证明。
41
41
  // * 恢复后的「已确认」卡片文案在新 UI 不存在;等价断言 = 恢复的记忆重新
42
42
  // 出现在「记忆库」tab([data-memory-tab="library"],旧 confirmed tab,
43
- // 仅列出 status=confirmed 的记忆)、卡片带「全局记忆」作用域行且无
43
+ // 仅列出 status=confirmed 的记忆)、卡片带组合名称且无
44
44
  // pending 徽标。
45
45
  // * 导入项目已列出的等待:旧首页项目面板(homeContent 含项目名)已删除,
46
46
  // 等价为顶栏 #projectSelect 选项里出现项目名(同一 registry projection)。
47
47
  // * 引擎/数据断言(POST 200、created.status=confirmed、syncStatus=pending、
48
- // syncError、注入门、confirmed.md 物化与恢复)保持不变;本测试使用真实
48
+ // syncError、注入门、the group Markdown 物化与恢复)保持不变;本测试使用真实
49
49
  // 引擎(dataSchemaVersion 由引擎自身报告,当前为 4),无需同步任何桩。
50
50
 
51
51
  const fs = require('node:fs');
@@ -94,6 +94,7 @@ async function main() {
94
94
  try {
95
95
  const repo = makeRepo(harness.fixture, 'memsync-repo', { 'README.md': '# 同步甲\n' });
96
96
  const { projectId } = await harness.importProject(repo, '同步甲');
97
+ const group = await harness.addGroup('同步组合', [projectId]);
97
98
  await harness.requestRegistryRefresh();
98
99
  // The new home page no longer lists projects (领域/项目面板已删除);the
99
100
  // registry projection is surfaced by the topbar project selector instead.
@@ -113,12 +114,11 @@ async function main() {
113
114
  // Break the real write path: the confirmed memory file path becomes a
114
115
  // directory, so the engine cannot write the memory file.
115
116
  const brainScope = harness.brainScopePath();
116
- const memoryFile = path.join(brainScope, 'memories', 'confirmed.md');
117
- fs.rmSync(memoryFile, { recursive: true, force: true });
117
+ const memoryFile = path.join(brainScope, 'memories', 'groups', group.id + '.md');
118
118
  fs.mkdirSync(memoryFile, { recursive: true });
119
119
  assert.ok(fs.lstatSync(memoryFile).isDirectory(), 'the confirmed memory file path really is occupied by a directory');
120
120
 
121
- // Add the memory through the real UI as a global memory: the new-memory
121
+ // Add the memory through the real UI with the project-bound combination: the new-memory
122
122
  // dialog (#appDialog > #memoryForm) with title + multiline body, scope
123
123
  // global, submitted by the primary (type=submit) action button.
124
124
  await harness.nativeClick('#memoryContent [data-action="new-memory"]');
@@ -131,7 +131,7 @@ async function main() {
131
131
  await harness.browser.send('Input.insertText', { text: MEMORY_TITLE });
132
132
  await harness.nativeClick('#memoryForm textarea[name="text"]');
133
133
  await harness.browser.send('Input.insertText', { text: MEMORY_TEXT });
134
- await harness.selectOption('#memoryForm select[name="scopeType"]', 'global');
134
+ await harness.selectOption('#memoryForm select[name="groupId"]', group.id);
135
135
  const postsBefore = harness.network.find(entry => entry.method === 'POST' && entry.url.includes('/api/engine/memories')).length;
136
136
  await harness.nativeClick('#appDialogActions button.primary');
137
137
  await harness.waitFor(
@@ -239,7 +239,7 @@ async function main() {
239
239
  const recoveredCard = await memoryCardText(harness, created.id);
240
240
  assert.ok(recoveredCard, 'the recovered memory has a card');
241
241
  assert.ok(!recoveredCard.includes('写入待恢复'), `the card no longer shows the pending write: ${recoveredCard}`);
242
- assert.match(recoveredCard, /全局记忆/, 'the card is a live library card with its global scope (the 记忆库 tab only lists confirmed memories)');
242
+ assert.match(recoveredCard, /同步组合/, 'the recovered card shows its combination');
243
243
  if (harness.evidence) await harness.browser.screenshot(path.join(harness.evidence, 'mem006-recovered.png'));
244
244
 
245
245
  evidence.push({
@@ -92,7 +92,8 @@ const {
92
92
  assert.equal(negScope.index.error.details.upstreamCode, EGRESS_BLOCK_CODE);
93
93
 
94
94
  // S1/S2 chain: manual memory confirm → materialize → onMaterialized → import.
95
- const negMemory = await negativeEngine.coordinator.memories.create({ text: '负向回归:确认流必须在 LIVE 8787 之前被拦截', brainId: 'brain-r5' });
95
+ const negGroup = await negativeEngine.coordinator.memoryGroups.create({ name: '负向测试组合', brainId: 'brain-r5' });
96
+ const negMemory = await negativeEngine.coordinator.memories.create({ text: '负向回归:确认流必须在 LIVE 8787 之前被拦截', brainId: 'brain-r5', groupId: negGroup.id });
96
97
  assert.equal(negMemory.status, 'confirmed');
97
98
  await waitFor(() => guard.blocked.filter(entry => entry.href === 'http://127.0.0.1:8787/api/import').length >= 2, 'confirm chain attempting LIVE import while blocked');
98
99
  // index() chain: run maintenance index → /api/sync at LIVE 8787.
@@ -143,7 +144,8 @@ const {
143
144
  // content then takes the GET /api/projects health path and skips import.
144
145
  const importsAfterConfigure = importCount();
145
146
  const healthGets = () => standin.records.filter(record => record.method === 'GET' && record.path === '/api/projects').length;
146
- const posMemory = await positiveEngine.coordinator.memories.create({ text: '正向证明:确认流导入必须落到自有替身', brainId: 'brain-pos' });
147
+ const posGroup = await positiveEngine.coordinator.memoryGroups.create({ name: '正向测试组合', brainId: 'brain-pos' });
148
+ const posMemory = await positiveEngine.coordinator.memories.create({ text: '正向证明:确认流导入必须落到自有替身', brainId: 'brain-pos', groupId: posGroup.id });
147
149
  assert.equal(posMemory.status, 'confirmed');
148
150
  await waitFor(() => importCount() >= importsAfterConfigure + 1, 'confirm chain importing at the OWN stand-in');
149
151
  assert.equal(importCount(), importsAfterConfigure + 1, 'materialized memory must trigger exactly one real import at the stand-in');