@sanqianx/project-knowledge 5.0.18 → 5.0.20-rc.1

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 (209) hide show
  1. package/.agents/plugins/marketplace.json +3 -3
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/CHANGELOG.md +14 -0
  4. package/LICENSE +201 -201
  5. package/NOTICE +5 -5
  6. package/README.md +349 -349
  7. package/_modules/knowledge-engine/README.md +4 -0
  8. package/_modules/knowledge-engine/src/analysis-contract.js +4 -3
  9. package/_modules/knowledge-engine/src/analysis-failures.js +39 -0
  10. package/_modules/knowledge-engine/src/analysis-worker.js +6 -2
  11. package/_modules/knowledge-engine/src/coordinator.js +8 -0
  12. package/_modules/knowledge-engine/src/headless-analyzer.js +2 -1
  13. package/_modules/knowledge-engine/src/memories.js +10 -5
  14. package/_modules/knowledge-engine/src/memory-eligibility.js +74 -0
  15. package/_modules/knowledge-engine/src/retrieval-ranking.js +19 -1
  16. package/_modules/knowledge-engine/src/runtime/commit-conversation-binder.js +1 -0
  17. package/_modules/knowledge-engine/src/runtime/commit-prompt.js +12 -9
  18. package/_modules/knowledge-engine/src/runtime/conversation-store.js +2 -0
  19. package/_modules/knowledge-engine/src/server.js +1 -1
  20. package/_site/_test/agent-capture-mcp-ui-test.js +67 -67
  21. package/_site/_test/ai-profile-test.js +75 -75
  22. package/_site/_test/ai-vendor-presets-test.js +91 -91
  23. package/_site/_test/automatic-context-test.js +70 -70
  24. package/_site/_test/bin-cli-test.js +230 -230
  25. package/_site/_test/bridge-adapter-test.js +95 -95
  26. package/_site/_test/bridge-consumer-service-test.js +310 -310
  27. package/_site/_test/candidate-bin-content-test.js +35 -0
  28. package/_site/_test/candidate-product-assets-test.js +13 -0
  29. package/_site/_test/candidate-release-contract-test.js +14 -14
  30. package/_site/_test/capture-hook-dedup-test.js +158 -158
  31. package/_site/_test/claude-executable-discovery-test.js +28 -28
  32. package/_site/_test/claude-session-lifecycle-sweep-test.js +252 -252
  33. package/_site/_test/cli-instance-management-test.js +62 -62
  34. package/_site/_test/client-capture-restart-e2e-test.js +189 -189
  35. package/_site/_test/codex-conversation-projection-test.js +60 -60
  36. package/_site/_test/codex-marketplace-scoped-path-test.js +186 -186
  37. package/_site/_test/codex-notify-capture-e2e-test.js +101 -101
  38. package/_site/_test/codex-notify-fanout-test.js +134 -134
  39. package/_site/_test/codex-notify-upgrade-test.js +253 -253
  40. package/_site/_test/commit-boundary-freeze-test.js +147 -147
  41. package/_site/_test/commit-conversation-binding-test.js +4 -4
  42. package/_site/_test/configuration-generation-test.js +22 -22
  43. package/_site/_test/context-pack-test.js +200 -200
  44. package/_site/_test/conversation-api-test.js +10 -10
  45. package/_site/_test/conversation-origin-test.js +15 -0
  46. package/_site/_test/cross-repo-isolation-e2e-test.js +187 -187
  47. package/_site/_test/embedding-config-test.js +32 -32
  48. package/_site/_test/fixtures/fake-browser-exit.js +10 -10
  49. package/_site/_test/fixtures/fake-browser-hang.js +10 -10
  50. package/_site/_test/fixtures/integration-busy-worker.cjs +6 -6
  51. package/_site/_test/fixtures/make-git-repos.js +92 -92
  52. package/_site/_test/fixtures/retrieval-gold-queries.json +32 -0
  53. package/_site/_test/fresh-hook-reimport-test.js +53 -53
  54. package/_site/_test/fresh-product-data-test.js +56 -56
  55. package/_site/_test/git-path-compatibility-test.js +80 -80
  56. package/_site/_test/git-validation-test.js +81 -81
  57. package/_site/_test/hook-worktree-test.js +42 -42
  58. package/_site/_test/index-builder-test.js +41 -41
  59. package/_site/_test/index-error-display-contract-test.js +10 -10
  60. package/_site/_test/integration-adapters-test.js +67 -67
  61. package/_site/_test/integration-capture-setup-test.js +118 -118
  62. package/_site/_test/integration-runtime-binding-a2-test.js +566 -566
  63. package/_site/_test/integration-runtime-binding-a3-test.js +227 -227
  64. package/_site/_test/integration-runtime-binding-test.js +473 -473
  65. package/_site/_test/integration-status-scan-test.js +29 -29
  66. package/_site/_test/kb-framework-test.js +57 -57
  67. package/_site/_test/kbpath-follow-test.js +63 -63
  68. package/_site/_test/knowledge-db-test.js +144 -144
  69. package/_site/_test/knowledge-engine-client-test.js +109 -109
  70. package/_site/_test/knowledge-maintenance-test.js +40 -40
  71. package/_site/_test/knowledge-panel-ui-contract-test.js +112 -0
  72. package/_site/_test/knowledge-scopes-test.js +37 -37
  73. package/_site/_test/knowledge-storage-location-test.js +28 -28
  74. package/_site/_test/launcher-readiness-test.js +80 -80
  75. package/_site/_test/legacy-claude-session-alias-test.js +106 -106
  76. package/_site/_test/legacy-routes-removed-test.js +47 -47
  77. package/_site/_test/legacy-workbench-exclusion-test.js +92 -92
  78. package/_site/_test/live-gateway-test.js +48 -48
  79. package/_site/_test/local-marketplace-test.js +16 -16
  80. package/_site/_test/log-redaction-test.js +58 -58
  81. package/_site/_test/markdown-maintenance-test.js +11 -11
  82. package/_site/_test/model-context-windows-test.js +89 -89
  83. package/_site/_test/module-agent-start-proxy-test.js +65 -65
  84. package/_site/_test/module-artifact-integrity-test.js +27 -27
  85. package/_site/_test/module-boundary-test.js +30 -30
  86. package/_site/_test/module-bridge-eventbridge-test.js +202 -202
  87. package/_site/_test/module-dynamic-port-test.js +118 -118
  88. package/_site/_test/module-index-proxy-test.js +33 -0
  89. package/_site/_test/module-model-configuration-test.js +44 -44
  90. package/_site/_test/module-process-lifecycle-test.js +35 -35
  91. package/_site/_test/module-stream-proxy-test.js +34 -34
  92. package/_site/_test/module-terminal-restart-test.js +63 -0
  93. package/_site/_test/module-wiring-unbind-race-test.js +59 -59
  94. package/_site/_test/native-context-integrations-test.js +86 -86
  95. package/_site/_test/orphaned-claim-recovery-test.js +80 -80
  96. package/_site/_test/package-boundary-test.js +43 -42
  97. package/_site/_test/package-startup-test.js +56 -56
  98. package/_site/_test/packaged-ui-smoke-test.js +88 -88
  99. package/_site/_test/pr-consumer-contract-test.js +55 -55
  100. package/_site/_test/product-brand-contract-test.js +25 -25
  101. package/_site/_test/product-diagnostics-ui-test.js +93 -93
  102. package/_site/_test/product-import-ui-test.js +104 -104
  103. package/_site/_test/product-progress-status-test.js +12 -1
  104. package/_site/_test/project-remove-running-guard-test.js +79 -79
  105. package/_site/_test/project-store-test.js +90 -90
  106. package/_site/_test/registry-events-test.js +38 -0
  107. package/_site/_test/release-version-sync-test.js +115 -115
  108. package/_site/_test/requirement-binding-test.js +113 -113
  109. package/_site/_test/runtime-endpoint-test.js +64 -64
  110. package/_site/_test/scanner-test.js +83 -83
  111. package/_site/_test/server-security-test.js +96 -96
  112. package/_site/_test/sessions-stream-test.js +93 -93
  113. package/_site/_test/shared-scope-root-binding-test.js +67 -67
  114. package/_site/_test/simple-import-test.js +98 -98
  115. package/_site/_test/startup-analysis-disabled-test.js +6 -6
  116. package/_site/_test/team-knowledge-store-sparse-checkout-test.js +196 -196
  117. package/_site/_test/team-knowledge-store-test.js +132 -132
  118. package/_site/_test/test-server-cleanup-test.js +35 -35
  119. package/_site/_test/test-server-module-isolation-test.js +37 -37
  120. package/_site/_test/tracking-start-test.js +35 -35
  121. package/_site/_test/workbench-context-receipts-test.js +22 -0
  122. package/_site/_test/workspace-ui-contract-test.js +31 -31
  123. package/_site/_test/zcode-capture-integration-test.js +108 -108
  124. package/_site/lib/ai-vendor-presets.js +83 -83
  125. package/_site/lib/ai-workspace.js +3 -3
  126. package/_site/lib/atomic-file.js +204 -204
  127. package/_site/lib/bridge-adapter.js +260 -260
  128. package/_site/lib/capture-hook-config.js +108 -108
  129. package/_site/lib/claude-cli-runner.js +89 -89
  130. package/_site/lib/cli-instances.js +43 -43
  131. package/_site/lib/codex-context-status.js +17 -17
  132. package/_site/lib/codex-notify-config.js +193 -193
  133. package/_site/lib/commit-conversation-binder.js +13 -12
  134. package/_site/lib/commit-reconciler.js +38 -38
  135. package/_site/lib/context-pack-builder.js +299 -299
  136. package/_site/lib/conversation-exclusions.js +204 -204
  137. package/_site/lib/conversation-query-service.js +17 -17
  138. package/_site/lib/conversation-store.js +2 -0
  139. package/_site/lib/data-dir.js +13 -13
  140. package/_site/lib/embedding-service.js +85 -85
  141. package/_site/lib/engine-connection.js +93 -90
  142. package/_site/lib/engine-knowledge-client.js +72 -72
  143. package/_site/lib/folder-picker-output.js +3 -3
  144. package/_site/lib/git-path.js +14 -14
  145. package/_site/lib/github-team-store.js +3 -3
  146. package/_site/lib/index-builder.js +157 -157
  147. package/_site/lib/integration-status-scan.js +99 -99
  148. package/_site/lib/integration-status-worker.js +14 -14
  149. package/_site/lib/kb-framework.js +15 -15
  150. package/_site/lib/knowledge-db.js +363 -363
  151. package/_site/lib/knowledge-schema.js +121 -121
  152. package/_site/lib/live-gateway.js +78 -76
  153. package/_site/lib/llm-client.js +12 -12
  154. package/_site/lib/model-context-windows.js +82 -82
  155. package/_site/lib/module-bridge.js +874 -865
  156. package/_site/lib/module-port-resolver.js +57 -57
  157. package/_site/lib/post-commit-automation.js +54 -54
  158. package/_site/lib/product-data.js +35 -35
  159. package/_site/lib/project-lifecycle-service.js +14 -14
  160. package/_site/lib/project-registry-store.js +129 -129
  161. package/_site/lib/prompt-registry.js +148 -148
  162. package/_site/lib/registry-events.js +16 -0
  163. package/_site/lib/requirement-adapters.js +10 -10
  164. package/_site/lib/requirement-binder.js +112 -112
  165. package/_site/lib/runtime-control.js +89 -89
  166. package/_site/lib/runtime-endpoint.js +5 -5
  167. package/_site/lib/server-app.js +10 -1
  168. package/_site/lib/zcode-context-integration.js +60 -60
  169. package/_site/scripts/codex-notify-fanout.cjs +95 -95
  170. package/_site/scripts/install-module-candidates.js +69 -69
  171. package/_site/scripts/pack-module-candidates.js +89 -72
  172. package/_site/scripts/sync-product-content.js +28 -28
  173. package/_site/scripts/sync-release-version.js +164 -164
  174. package/_site/scripts/vendor-modules.js +49 -49
  175. package/_site/scripts/verify-module-runtime.js +50 -50
  176. package/_site/scripts/verify-product-runtime.js +36 -36
  177. package/_site/scripts/verify-retrieval-gold.js +83 -0
  178. package/_site/server.js +15 -15
  179. package/_site/start.bat +26 -26
  180. package/_site/stop.bat +11 -11
  181. package/bin/project-knowledge-integrations.js +254 -254
  182. package/bin/project-knowledge-kb.js +67 -67
  183. package/bin/project-knowledge-mcp.js +8 -8
  184. package/bin/project-knowledge.js +170 -170
  185. package/claude-prompts.json +21 -21
  186. package/docs/README.zh-CN.md +205 -205
  187. package/docs/assets/architecture.svg +181 -181
  188. package/docs/assets/logo.svg +49 -49
  189. package/docs/fresh-v5-start.md +42 -42
  190. package/docs/leader-glm-workbench-playbook.md +122 -119
  191. package/docs/project-registry-schema.md +11 -11
  192. package/docs/release-5.0.16-acceptance.md +176 -176
  193. package/docs/release-5.0.17-acceptance.md +117 -117
  194. package/docs/release-5.0.19-acceptance.md +39 -0
  195. package/docs/team-knowledge-mode-a-plan.md +73 -73
  196. package/module-runtime-manifest.json +126 -104
  197. package/package.json +110 -108
  198. package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
  199. package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
  200. package/plugins/project-knowledge/.mcp.json +1 -1
  201. package/plugins/project-knowledge/opencode/project-knowledge.md +3 -3
  202. package/plugins/project-knowledge/skills/project-knowledge/SKILL.md +28 -28
  203. package/templates/change.md +30 -30
  204. package/templates/project-readme.md +18 -18
  205. package/ui/index.html +1 -1
  206. package/ui/knowledge-panel.html +118 -0
  207. package/ui/product.css +8 -0
  208. package/ui/product.js +175 -8
  209. package/vendor-manifest.json +55 -53
@@ -1,98 +1,98 @@
1
- const assert = require('assert');
2
- const fs = require('fs');
3
- const os = require('os');
4
- const path = require('path');
5
- const { spawnSync } = require('child_process');
6
- const { spawnServer } = require('./helpers/spawn-server');
7
- const freePort = require('./helpers/free-port');
8
-
9
- const ROOT = path.resolve(__dirname, '..', '..');
10
- let PORT, BASE;
11
- const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pkb-import-v2-'));
12
- const repoPath = fs.mkdtempSync(path.join(os.tmpdir(), 'pkb-import-repo-'));
13
- const knowledgeRoot = path.join(dataDir, 'knowledge');
14
-
15
- function git(args) {
16
- const result = spawnSync('git', args, { cwd: repoPath, encoding: 'utf8' });
17
- assert.strictEqual(result.status, 0, result.stderr);
18
- return String(result.stdout || '').trim();
19
- }
20
-
21
- async function request(method, pathname, body) {
22
- const response = await fetch(`${BASE}${pathname}`, {
23
- method,
24
- headers: body === undefined ? undefined : { 'content-type': 'application/json' },
25
- body: body === undefined ? undefined : JSON.stringify(body),
26
- });
27
- return { status: response.status, data: await response.json() };
28
- }
29
-
30
- async function waitForServer() {
31
- for (let attempt = 0; attempt < 100; attempt += 1) {
32
- try { if ((await fetch(`${BASE}/api/health`)).ok) return; } catch {}
33
- await new Promise(resolve => setTimeout(resolve, 100));
34
- }
35
- throw new Error('server did not start');
36
- }
37
-
38
- (async () => {
39
- PORT = await freePort(); BASE = `http://127.0.0.1:${PORT}`;
40
- git(['init', '--initial-branch=main']);
41
- git(['config', 'user.email', 'import@example.test']);
42
- git(['config', 'user.name', 'Import Test']);
43
- fs.writeFileSync(path.join(repoPath, 'README.md'), '# source\n', 'utf8');
44
- git(['add', 'README.md']);
45
- git(['commit', '-m', 'baseline']);
46
- const baseline = git(['rev-parse', 'HEAD']);
47
-
48
- const spawned = spawnServer({ root: ROOT, port: PORT, dataDir, tag: 'simple-import-v2', extraEnv: { KB_SKIP_MIGRATION: '1' } });
49
- let output = '';
50
- spawned.child.stdout.on('data', chunk => { output += chunk; });
51
- spawned.child.stderr.on('data', chunk => { output += chunk; });
52
- try {
53
- await waitForServer();
54
- let result = await request('PATCH', '/api/settings', { knowledge: { rootPath: knowledgeRoot } });
55
- assert.strictEqual(result.status, 200, JSON.stringify(result.data));
56
-
57
- result = await request('POST', '/api/projects/import', { localPath: repoPath, displayName: 'Imported v2' });
58
- assert.strictEqual(result.status, 201, JSON.stringify(result.data));
59
- assert.match(result.data.projectId, /^project-/);
60
- assert.strictEqual(result.data.project.config.projectId, result.data.projectId);
61
- assert.strictEqual(result.data.project.state.trackingStartCommit, baseline);
62
- assert.strictEqual(result.data.project.state.lastAnalyzedCommit, null);
63
- assert.strictEqual(result.data.project.state.analysis.status, 'idle');
64
- assert.strictEqual(result.data.hook.ok, true);
65
- assert.strictEqual(result.data.project.state.hook.managedVersion, 2);
66
- assert.deepStrictEqual(fs.readdirSync(result.data.project.config.knowledgePath), [], 'import must not create speculative knowledge');
67
- assert(!fs.existsSync(path.join(dataDir, 'projects', result.data.projectId, 'requirements.jsonl')));
68
-
69
- const projectId = result.data.projectId;
70
- result = await request('PATCH', `/api/projects/${projectId}`, { displayName: 'Renamed safely', knowledgeLanguage: 'en-US' });
71
- assert.strictEqual(result.status, 200, JSON.stringify(result.data));
72
- assert.strictEqual(result.data.config.displayName, 'Renamed safely');
73
- result = await request('PATCH', `/api/projects/${projectId}`, { repoPath: path.join(repoPath, 'unverified') });
74
- assert.strictEqual(result.status, 400, 'generic PATCH must not bypass Hook-verified repo relocation');
75
- assert.strictEqual(result.data.error.code, 'INVALID_ARGUMENT');
76
- result = await request('PATCH', `/api/projects/${projectId}`, { teamBinding: { provider: 'github' } });
77
- assert.strictEqual(result.status, 400, 'generic PATCH must not change a fixed team binding');
78
-
79
- const hookPath = path.join(repoPath, '.git', 'hooks', 'post-commit');
80
- assert(fs.existsSync(hookPath), 'managed Hook was not installed');
81
- const hook = fs.readFileSync(hookPath, 'utf8');
82
- assert(hook.includes('PROJECT-KNOWLEDGE-HOOK'));
83
- assert(hook.includes(projectId));
84
-
85
- result = await request('GET', '/api/projects');
86
- assert.strictEqual(result.status, 200);
87
- assert.strictEqual(result.data.projects.length, 1);
88
- assert.strictEqual(result.data.projects[0].projectId, result.data.projects[0].config.projectId);
89
- assert(!fs.existsSync(path.join(dataDir, 'runtime', 'staging')), 'import must not dispatch analysis');
90
- console.log('simple-import-test PASS');
91
- } catch (error) {
92
- console.error(output);
93
- throw error;
94
- } finally {
95
- await spawned.cleanup();
96
- fs.rmSync(repoPath, { recursive: true, force: true });
97
- }
98
- })().catch(error => { console.error(error); process.exitCode = 1; });
1
+ const assert = require('assert');
2
+ const fs = require('fs');
3
+ const os = require('os');
4
+ const path = require('path');
5
+ const { spawnSync } = require('child_process');
6
+ const { spawnServer } = require('./helpers/spawn-server');
7
+ const freePort = require('./helpers/free-port');
8
+
9
+ const ROOT = path.resolve(__dirname, '..', '..');
10
+ let PORT, BASE;
11
+ const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pkb-import-v2-'));
12
+ const repoPath = fs.mkdtempSync(path.join(os.tmpdir(), 'pkb-import-repo-'));
13
+ const knowledgeRoot = path.join(dataDir, 'knowledge');
14
+
15
+ function git(args) {
16
+ const result = spawnSync('git', args, { cwd: repoPath, encoding: 'utf8' });
17
+ assert.strictEqual(result.status, 0, result.stderr);
18
+ return String(result.stdout || '').trim();
19
+ }
20
+
21
+ async function request(method, pathname, body) {
22
+ const response = await fetch(`${BASE}${pathname}`, {
23
+ method,
24
+ headers: body === undefined ? undefined : { 'content-type': 'application/json' },
25
+ body: body === undefined ? undefined : JSON.stringify(body),
26
+ });
27
+ return { status: response.status, data: await response.json() };
28
+ }
29
+
30
+ async function waitForServer() {
31
+ for (let attempt = 0; attempt < 100; attempt += 1) {
32
+ try { if ((await fetch(`${BASE}/api/health`)).ok) return; } catch {}
33
+ await new Promise(resolve => setTimeout(resolve, 100));
34
+ }
35
+ throw new Error('server did not start');
36
+ }
37
+
38
+ (async () => {
39
+ PORT = await freePort(); BASE = `http://127.0.0.1:${PORT}`;
40
+ git(['init', '--initial-branch=main']);
41
+ git(['config', 'user.email', 'import@example.test']);
42
+ git(['config', 'user.name', 'Import Test']);
43
+ fs.writeFileSync(path.join(repoPath, 'README.md'), '# source\n', 'utf8');
44
+ git(['add', 'README.md']);
45
+ git(['commit', '-m', 'baseline']);
46
+ const baseline = git(['rev-parse', 'HEAD']);
47
+
48
+ const spawned = spawnServer({ root: ROOT, port: PORT, dataDir, tag: 'simple-import-v2', extraEnv: { KB_SKIP_MIGRATION: '1' } });
49
+ let output = '';
50
+ spawned.child.stdout.on('data', chunk => { output += chunk; });
51
+ spawned.child.stderr.on('data', chunk => { output += chunk; });
52
+ try {
53
+ await waitForServer();
54
+ let result = await request('PATCH', '/api/settings', { knowledge: { rootPath: knowledgeRoot } });
55
+ assert.strictEqual(result.status, 200, JSON.stringify(result.data));
56
+
57
+ result = await request('POST', '/api/projects/import', { localPath: repoPath, displayName: 'Imported v2' });
58
+ assert.strictEqual(result.status, 201, JSON.stringify(result.data));
59
+ assert.match(result.data.projectId, /^project-/);
60
+ assert.strictEqual(result.data.project.config.projectId, result.data.projectId);
61
+ assert.strictEqual(result.data.project.state.trackingStartCommit, baseline);
62
+ assert.strictEqual(result.data.project.state.lastAnalyzedCommit, null);
63
+ assert.strictEqual(result.data.project.state.analysis.status, 'idle');
64
+ assert.strictEqual(result.data.hook.ok, true);
65
+ assert.strictEqual(result.data.project.state.hook.managedVersion, 2);
66
+ assert.deepStrictEqual(fs.readdirSync(result.data.project.config.knowledgePath), [], 'import must not create speculative knowledge');
67
+ assert(!fs.existsSync(path.join(dataDir, 'projects', result.data.projectId, 'requirements.jsonl')));
68
+
69
+ const projectId = result.data.projectId;
70
+ result = await request('PATCH', `/api/projects/${projectId}`, { displayName: 'Renamed safely', knowledgeLanguage: 'en-US' });
71
+ assert.strictEqual(result.status, 200, JSON.stringify(result.data));
72
+ assert.strictEqual(result.data.config.displayName, 'Renamed safely');
73
+ result = await request('PATCH', `/api/projects/${projectId}`, { repoPath: path.join(repoPath, 'unverified') });
74
+ assert.strictEqual(result.status, 400, 'generic PATCH must not bypass Hook-verified repo relocation');
75
+ assert.strictEqual(result.data.error.code, 'INVALID_ARGUMENT');
76
+ result = await request('PATCH', `/api/projects/${projectId}`, { teamBinding: { provider: 'github' } });
77
+ assert.strictEqual(result.status, 400, 'generic PATCH must not change a fixed team binding');
78
+
79
+ const hookPath = path.join(repoPath, '.git', 'hooks', 'post-commit');
80
+ assert(fs.existsSync(hookPath), 'managed Hook was not installed');
81
+ const hook = fs.readFileSync(hookPath, 'utf8');
82
+ assert(hook.includes('PROJECT-KNOWLEDGE-HOOK'));
83
+ assert(hook.includes(projectId));
84
+
85
+ result = await request('GET', '/api/projects');
86
+ assert.strictEqual(result.status, 200);
87
+ assert.strictEqual(result.data.projects.length, 1);
88
+ assert.strictEqual(result.data.projects[0].projectId, result.data.projects[0].config.projectId);
89
+ assert(!fs.existsSync(path.join(dataDir, 'runtime', 'staging')), 'import must not dispatch analysis');
90
+ console.log('simple-import-test PASS');
91
+ } catch (error) {
92
+ console.error(output);
93
+ throw error;
94
+ } finally {
95
+ await spawned.cleanup();
96
+ fs.rmSync(repoPath, { recursive: true, force: true });
97
+ }
98
+ })().catch(error => { console.error(error); process.exitCode = 1; });
@@ -8,9 +8,9 @@ const contracts = require('../lib/contracts');
8
8
  const automation = require('../lib/post-commit-automation');
9
9
 
10
10
  assert.deepEqual(contracts.TRIGGERS, ['git-hook']);
11
- assert.equal(/reconcileProjectCommits\(projectId, 'startup'/.test(server), false);
12
- assert.equal(server.includes('reconcile.startup_failed'), false);
13
- assert.equal(Object.hasOwn(automation, 'dispatchPendingAutomations'), false);
14
- assert.equal(typeof automation.recoverOrphanedClaims, 'function');
15
- assert.equal(/recoverOrphanedClaims\(runtime\)/.test(server), true);
16
- console.log('startup-analysis-disabled-test PASS');
11
+ assert.equal(/reconcileProjectCommits\(projectId, 'startup'/.test(server), false);
12
+ assert.equal(server.includes('reconcile.startup_failed'), false);
13
+ assert.equal(Object.hasOwn(automation, 'dispatchPendingAutomations'), false);
14
+ assert.equal(typeof automation.recoverOrphanedClaims, 'function');
15
+ assert.equal(/recoverOrphanedClaims\(runtime\)/.test(server), true);
16
+ console.log('startup-analysis-disabled-test PASS');
@@ -1,196 +1,196 @@
1
- // Tests for sparse-checkout automation in github-team-store.js.
2
- // Style mirrors team-knowledge-store-test.js (IIFE + assert()).
3
- //
4
- // Three scenarios:
5
- // 1. New sparse clone — checkoutStore({ subdir, partialClone }) clones with
6
- // --filter=blob:none --sparse --no-checkout, applies cone, and materializes
7
- // only the requested subdirectory.
8
- // 2. Re-clone / switch — calling checkoutStore twice on the same local path
9
- // re-applies sparse-checkout cone (idempotent).
10
- // 3. Git version fallback — _setGitVersionForTests forces a low version; the
11
- // partial-clone branch must fall back to a full clone and return warning.
12
-
13
- const fs = require('fs');
14
- const os = require('os');
15
- const path = require('path');
16
- const { execFileSync } = require('child_process');
17
-
18
- const githubTeamStore = require('../lib/github-team-store');
19
- const gitRunner = require('../lib/git-runner');
20
-
21
- function assert(cond, msg) {
22
- if (!cond) throw new Error(msg);
23
- }
24
-
25
- function git(cwd, args) {
26
- return execFileSync('git', args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] }).toString('utf-8').trim();
27
- }
28
-
29
- function initBareRemote(cwd) {
30
- fs.mkdirSync(cwd, { recursive: true });
31
- git(cwd, ['init', '--bare']);
32
- }
33
-
34
- function seedRemoteWith(cwd, files) {
35
- const work = fs.mkdtempSync(path.join(os.tmpdir(), `kb-sparse-seed-${process.pid}-`));
36
- git(work, ['init']);
37
- git(work, ['config', 'user.name', 'Test User']);
38
- git(work, ['config', 'user.email', 'test@example.com']);
39
- for (const [relPath, content] of Object.entries(files)) {
40
- const abs = path.join(work, relPath);
41
- fs.mkdirSync(path.dirname(abs), { recursive: true });
42
- fs.writeFileSync(abs, content);
43
- }
44
- git(work, ['add', '-A']);
45
- git(work, ['commit', '-m', 'seed']);
46
- git(work, ['branch', '-M', 'main']);
47
- const head = git(work, ['rev-parse', 'HEAD']);
48
- git(cwd, ['symbolic-ref', 'HEAD', 'refs/heads/main']);
49
- const pushTarget = `file://${path.resolve(cwd)}`;
50
- git(work, ['remote', 'add', 'origin', pushTarget]);
51
- git(work, ['push', 'origin', 'main']);
52
- return { work, head };
53
- }
54
-
55
- async function run() {
56
- const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), `kb-team-sparse-${process.pid}-`));
57
- const TEAM_REMOTE_SPARSE = path.join(tmpRoot, 'remote-sparse.git');
58
- const LOCAL_CLONE = path.join(tmpRoot, 'local-clone');
59
- const remoteUrl = `file://${TEAM_REMOTE_SPARSE.replace(/\\/g, '/')}`;
60
-
61
- let scenariosPassed = 0;
62
- let scenariosTotal = 0;
63
-
64
- // ------------------------------------------------------------------
65
- // Scenario 1: New sparse clone
66
- // ------------------------------------------------------------------
67
- {
68
- scenariosTotal++;
69
- fs.rmSync(TEAM_REMOTE_SPARSE, { recursive: true, force: true });
70
- fs.rmSync(LOCAL_CLONE, { recursive: true, force: true });
71
- initBareRemote(TEAM_REMOTE_SPARSE);
72
- seedRemoteWith(TEAM_REMOTE_SPARSE, {
73
- 'acc/README.md': '# acc\n',
74
- 'other/README.md': '# other\n',
75
- 'docs/notes.md': 'docs\n',
76
- });
77
-
78
- const result = await githubTeamStore.checkoutStore({
79
- cloneUrl: remoteUrl,
80
- branch: 'main',
81
- localPath: LOCAL_CLONE,
82
- subdir: 'acc',
83
- partialClone: true,
84
- });
85
-
86
- assert(result.ok, `[scenario 1] checkoutStore should succeed: ${result.error || ''}`);
87
- assert(result.action === 'cloned-partial', `[scenario 1] expected action='cloned-partial' but got '${result.action}'`);
88
- assert(result.sparseCheckedOut === true, '[scenario 1] sparseCheckedOut should be true');
89
- assert(fs.existsSync(path.join(LOCAL_CLONE, 'acc', 'README.md')), '[scenario 1] acc/README.md should exist');
90
- assert(!fs.existsSync(path.join(LOCAL_CLONE, 'other', 'README.md')), '[scenario 1] other/README.md should NOT exist (cone excluded)');
91
- assert(!fs.existsSync(path.join(LOCAL_CLONE, 'docs', 'notes.md')), '[scenario 1] docs/notes.md should NOT exist (cone excluded)');
92
- const sparseFile = path.join(LOCAL_CLONE, '.git', 'info', 'sparse-checkout');
93
- assert(fs.existsSync(sparseFile), '[scenario 1] .git/info/sparse-checkout should be present');
94
- scenariosPassed++;
95
- console.log('[scenario 1: NEW sparse clone] OK');
96
- }
97
-
98
- // ------------------------------------------------------------------
99
- // Scenario 2: Re-clone / add cone
100
- // ------------------------------------------------------------------
101
- {
102
- scenariosTotal++;
103
- fs.rmSync(TEAM_REMOTE_SPARSE, { recursive: true, force: true });
104
- fs.rmSync(LOCAL_CLONE, { recursive: true, force: true });
105
- initBareRemote(TEAM_REMOTE_SPARSE);
106
- seedRemoteWith(TEAM_REMOTE_SPARSE, {
107
- 'acc/README.md': '# acc\n',
108
- 'other/README.md': '# other\n',
109
- });
110
- // First clone with subdir='acc'
111
- const first = await githubTeamStore.checkoutStore({
112
- cloneUrl: remoteUrl,
113
- branch: 'main',
114
- localPath: LOCAL_CLONE,
115
- subdir: 'acc',
116
- partialClone: true,
117
- });
118
- assert(first.ok && first.action === 'cloned-partial', `[scenario 2] first clone should be partial`);
119
- assert(fs.existsSync(path.join(LOCAL_CLONE, 'acc', 'README.md')), '[scenario 2] acc/README.md should exist after first clone');
120
-
121
- // Add a new subdir to remote
122
- const work = fs.mkdtempSync(path.join(os.tmpdir(), `kb-sparse-switch-${process.pid}-`));
123
- fs.rmSync(work, { recursive: true, force: true });
124
- fs.mkdirSync(work, { recursive: true });
125
- git(work, ['clone', `file://${TEAM_REMOTE_SPARSE}`, '.']);
126
- git(work, ['config', 'user.name', 'Test User']);
127
- git(work, ['config', 'user.email', 'test@example.com']);
128
- fs.mkdirSync(path.join(work, 'acc2'), { recursive: true });
129
- fs.writeFileSync(path.join(work, 'acc2', 'README.md'), '# acc2\n');
130
- git(work, ['add', '-A']);
131
- git(work, ['commit', '-m', 'add acc2']);
132
- git(work, ['push']);
133
-
134
- // Re-sync with subdir='acc2' should expand the cone, not remove acc.
135
- const second = await githubTeamStore.checkoutStore({
136
- cloneUrl: remoteUrl,
137
- branch: 'main',
138
- localPath: LOCAL_CLONE,
139
- subdir: 'acc2',
140
- partialClone: true,
141
- });
142
- assert(second.ok, `[scenario 2] second checkout should succeed: ${second.error || ''}`);
143
- assert(second.action === 'pulled-partial', `[scenario 2] expected action='pulled-partial' but got '${second.action}'`);
144
- assert(fs.existsSync(path.join(LOCAL_CLONE, 'acc2', 'README.md')), '[scenario 2] acc2/README.md should exist after adding cone');
145
- assert(fs.existsSync(path.join(LOCAL_CLONE, 'acc', 'README.md')), '[scenario 2] acc/README.md should still exist after adding acc2');
146
- scenariosPassed++;
147
- console.log('[scenario 2: cone expand] OK');
148
- }
149
-
150
- // ------------------------------------------------------------------
151
- // Scenario 3: Git version fallback
152
- // ------------------------------------------------------------------
153
- {
154
- scenariosTotal++;
155
- fs.rmSync(TEAM_REMOTE_SPARSE, { recursive: true, force: true });
156
- fs.rmSync(LOCAL_CLONE, { recursive: true, force: true });
157
- initBareRemote(TEAM_REMOTE_SPARSE);
158
- seedRemoteWith(TEAM_REMOTE_SPARSE, {
159
- 'acc/README.md': '# acc\n',
160
- 'other/README.md': '# other\n',
161
- });
162
-
163
- // Force the cached version to be < 2.25
164
- gitRunner._setGitVersionForTests({ ok: true, major: 2, minor: 24, raw: 'git version 2.24.0' });
165
- try {
166
- const result = await githubTeamStore.checkoutStore({
167
- cloneUrl: remoteUrl,
168
- branch: 'main',
169
- localPath: LOCAL_CLONE,
170
- subdir: 'acc',
171
- partialClone: true,
172
- });
173
- assert(result.ok, `[scenario 3] checkoutStore should fall back to full clone: ${result.error || ''}`);
174
- assert(result.action === 'cloned-fallback', `[scenario 3] expected action='cloned-fallback' but got '${result.action}'`);
175
- assert(typeof result.warning === 'string' && /2\.25/.test(result.warning), `[scenario 3] warning should mention 2.25: ${result.warning || ''}`);
176
- // Full clone means both subdirs ARE present.
177
- assert(fs.existsSync(path.join(LOCAL_CLONE, 'acc', 'README.md')), '[scenario 3] acc/README.md should exist (full clone)');
178
- assert(fs.existsSync(path.join(LOCAL_CLONE, 'other', 'README.md')), '[scenario 3] other/README.md should exist (full clone)');
179
- scenariosPassed++;
180
- console.log('[scenario 3: Git < 2.25 fallback] OK');
181
- } finally {
182
- gitRunner._setGitVersionForTests(null);
183
- }
184
- }
185
-
186
- console.log(`\nsummary: ${scenariosPassed}/${scenariosTotal} scenarios passed`);
187
- if (scenariosPassed !== scenariosTotal) {
188
- process.exitCode = 1;
189
- }
190
- }
191
-
192
- run().catch(err => {
193
- console.error('test failed:', err.message);
194
- console.error(err.stack);
195
- process.exitCode = 1;
196
- });
1
+ // Tests for sparse-checkout automation in github-team-store.js.
2
+ // Style mirrors team-knowledge-store-test.js (IIFE + assert()).
3
+ //
4
+ // Three scenarios:
5
+ // 1. New sparse clone — checkoutStore({ subdir, partialClone }) clones with
6
+ // --filter=blob:none --sparse --no-checkout, applies cone, and materializes
7
+ // only the requested subdirectory.
8
+ // 2. Re-clone / switch — calling checkoutStore twice on the same local path
9
+ // re-applies sparse-checkout cone (idempotent).
10
+ // 3. Git version fallback — _setGitVersionForTests forces a low version; the
11
+ // partial-clone branch must fall back to a full clone and return warning.
12
+
13
+ const fs = require('fs');
14
+ const os = require('os');
15
+ const path = require('path');
16
+ const { execFileSync } = require('child_process');
17
+
18
+ const githubTeamStore = require('../lib/github-team-store');
19
+ const gitRunner = require('../lib/git-runner');
20
+
21
+ function assert(cond, msg) {
22
+ if (!cond) throw new Error(msg);
23
+ }
24
+
25
+ function git(cwd, args) {
26
+ return execFileSync('git', args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] }).toString('utf-8').trim();
27
+ }
28
+
29
+ function initBareRemote(cwd) {
30
+ fs.mkdirSync(cwd, { recursive: true });
31
+ git(cwd, ['init', '--bare']);
32
+ }
33
+
34
+ function seedRemoteWith(cwd, files) {
35
+ const work = fs.mkdtempSync(path.join(os.tmpdir(), `kb-sparse-seed-${process.pid}-`));
36
+ git(work, ['init']);
37
+ git(work, ['config', 'user.name', 'Test User']);
38
+ git(work, ['config', 'user.email', 'test@example.com']);
39
+ for (const [relPath, content] of Object.entries(files)) {
40
+ const abs = path.join(work, relPath);
41
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
42
+ fs.writeFileSync(abs, content);
43
+ }
44
+ git(work, ['add', '-A']);
45
+ git(work, ['commit', '-m', 'seed']);
46
+ git(work, ['branch', '-M', 'main']);
47
+ const head = git(work, ['rev-parse', 'HEAD']);
48
+ git(cwd, ['symbolic-ref', 'HEAD', 'refs/heads/main']);
49
+ const pushTarget = `file://${path.resolve(cwd)}`;
50
+ git(work, ['remote', 'add', 'origin', pushTarget]);
51
+ git(work, ['push', 'origin', 'main']);
52
+ return { work, head };
53
+ }
54
+
55
+ async function run() {
56
+ const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), `kb-team-sparse-${process.pid}-`));
57
+ const TEAM_REMOTE_SPARSE = path.join(tmpRoot, 'remote-sparse.git');
58
+ const LOCAL_CLONE = path.join(tmpRoot, 'local-clone');
59
+ const remoteUrl = `file://${TEAM_REMOTE_SPARSE.replace(/\\/g, '/')}`;
60
+
61
+ let scenariosPassed = 0;
62
+ let scenariosTotal = 0;
63
+
64
+ // ------------------------------------------------------------------
65
+ // Scenario 1: New sparse clone
66
+ // ------------------------------------------------------------------
67
+ {
68
+ scenariosTotal++;
69
+ fs.rmSync(TEAM_REMOTE_SPARSE, { recursive: true, force: true });
70
+ fs.rmSync(LOCAL_CLONE, { recursive: true, force: true });
71
+ initBareRemote(TEAM_REMOTE_SPARSE);
72
+ seedRemoteWith(TEAM_REMOTE_SPARSE, {
73
+ 'acc/README.md': '# acc\n',
74
+ 'other/README.md': '# other\n',
75
+ 'docs/notes.md': 'docs\n',
76
+ });
77
+
78
+ const result = await githubTeamStore.checkoutStore({
79
+ cloneUrl: remoteUrl,
80
+ branch: 'main',
81
+ localPath: LOCAL_CLONE,
82
+ subdir: 'acc',
83
+ partialClone: true,
84
+ });
85
+
86
+ assert(result.ok, `[scenario 1] checkoutStore should succeed: ${result.error || ''}`);
87
+ assert(result.action === 'cloned-partial', `[scenario 1] expected action='cloned-partial' but got '${result.action}'`);
88
+ assert(result.sparseCheckedOut === true, '[scenario 1] sparseCheckedOut should be true');
89
+ assert(fs.existsSync(path.join(LOCAL_CLONE, 'acc', 'README.md')), '[scenario 1] acc/README.md should exist');
90
+ assert(!fs.existsSync(path.join(LOCAL_CLONE, 'other', 'README.md')), '[scenario 1] other/README.md should NOT exist (cone excluded)');
91
+ assert(!fs.existsSync(path.join(LOCAL_CLONE, 'docs', 'notes.md')), '[scenario 1] docs/notes.md should NOT exist (cone excluded)');
92
+ const sparseFile = path.join(LOCAL_CLONE, '.git', 'info', 'sparse-checkout');
93
+ assert(fs.existsSync(sparseFile), '[scenario 1] .git/info/sparse-checkout should be present');
94
+ scenariosPassed++;
95
+ console.log('[scenario 1: NEW sparse clone] OK');
96
+ }
97
+
98
+ // ------------------------------------------------------------------
99
+ // Scenario 2: Re-clone / add cone
100
+ // ------------------------------------------------------------------
101
+ {
102
+ scenariosTotal++;
103
+ fs.rmSync(TEAM_REMOTE_SPARSE, { recursive: true, force: true });
104
+ fs.rmSync(LOCAL_CLONE, { recursive: true, force: true });
105
+ initBareRemote(TEAM_REMOTE_SPARSE);
106
+ seedRemoteWith(TEAM_REMOTE_SPARSE, {
107
+ 'acc/README.md': '# acc\n',
108
+ 'other/README.md': '# other\n',
109
+ });
110
+ // First clone with subdir='acc'
111
+ const first = await githubTeamStore.checkoutStore({
112
+ cloneUrl: remoteUrl,
113
+ branch: 'main',
114
+ localPath: LOCAL_CLONE,
115
+ subdir: 'acc',
116
+ partialClone: true,
117
+ });
118
+ assert(first.ok && first.action === 'cloned-partial', `[scenario 2] first clone should be partial`);
119
+ assert(fs.existsSync(path.join(LOCAL_CLONE, 'acc', 'README.md')), '[scenario 2] acc/README.md should exist after first clone');
120
+
121
+ // Add a new subdir to remote
122
+ const work = fs.mkdtempSync(path.join(os.tmpdir(), `kb-sparse-switch-${process.pid}-`));
123
+ fs.rmSync(work, { recursive: true, force: true });
124
+ fs.mkdirSync(work, { recursive: true });
125
+ git(work, ['clone', `file://${TEAM_REMOTE_SPARSE}`, '.']);
126
+ git(work, ['config', 'user.name', 'Test User']);
127
+ git(work, ['config', 'user.email', 'test@example.com']);
128
+ fs.mkdirSync(path.join(work, 'acc2'), { recursive: true });
129
+ fs.writeFileSync(path.join(work, 'acc2', 'README.md'), '# acc2\n');
130
+ git(work, ['add', '-A']);
131
+ git(work, ['commit', '-m', 'add acc2']);
132
+ git(work, ['push']);
133
+
134
+ // Re-sync with subdir='acc2' should expand the cone, not remove acc.
135
+ const second = await githubTeamStore.checkoutStore({
136
+ cloneUrl: remoteUrl,
137
+ branch: 'main',
138
+ localPath: LOCAL_CLONE,
139
+ subdir: 'acc2',
140
+ partialClone: true,
141
+ });
142
+ assert(second.ok, `[scenario 2] second checkout should succeed: ${second.error || ''}`);
143
+ assert(second.action === 'pulled-partial', `[scenario 2] expected action='pulled-partial' but got '${second.action}'`);
144
+ assert(fs.existsSync(path.join(LOCAL_CLONE, 'acc2', 'README.md')), '[scenario 2] acc2/README.md should exist after adding cone');
145
+ assert(fs.existsSync(path.join(LOCAL_CLONE, 'acc', 'README.md')), '[scenario 2] acc/README.md should still exist after adding acc2');
146
+ scenariosPassed++;
147
+ console.log('[scenario 2: cone expand] OK');
148
+ }
149
+
150
+ // ------------------------------------------------------------------
151
+ // Scenario 3: Git version fallback
152
+ // ------------------------------------------------------------------
153
+ {
154
+ scenariosTotal++;
155
+ fs.rmSync(TEAM_REMOTE_SPARSE, { recursive: true, force: true });
156
+ fs.rmSync(LOCAL_CLONE, { recursive: true, force: true });
157
+ initBareRemote(TEAM_REMOTE_SPARSE);
158
+ seedRemoteWith(TEAM_REMOTE_SPARSE, {
159
+ 'acc/README.md': '# acc\n',
160
+ 'other/README.md': '# other\n',
161
+ });
162
+
163
+ // Force the cached version to be < 2.25
164
+ gitRunner._setGitVersionForTests({ ok: true, major: 2, minor: 24, raw: 'git version 2.24.0' });
165
+ try {
166
+ const result = await githubTeamStore.checkoutStore({
167
+ cloneUrl: remoteUrl,
168
+ branch: 'main',
169
+ localPath: LOCAL_CLONE,
170
+ subdir: 'acc',
171
+ partialClone: true,
172
+ });
173
+ assert(result.ok, `[scenario 3] checkoutStore should fall back to full clone: ${result.error || ''}`);
174
+ assert(result.action === 'cloned-fallback', `[scenario 3] expected action='cloned-fallback' but got '${result.action}'`);
175
+ assert(typeof result.warning === 'string' && /2\.25/.test(result.warning), `[scenario 3] warning should mention 2.25: ${result.warning || ''}`);
176
+ // Full clone means both subdirs ARE present.
177
+ assert(fs.existsSync(path.join(LOCAL_CLONE, 'acc', 'README.md')), '[scenario 3] acc/README.md should exist (full clone)');
178
+ assert(fs.existsSync(path.join(LOCAL_CLONE, 'other', 'README.md')), '[scenario 3] other/README.md should exist (full clone)');
179
+ scenariosPassed++;
180
+ console.log('[scenario 3: Git < 2.25 fallback] OK');
181
+ } finally {
182
+ gitRunner._setGitVersionForTests(null);
183
+ }
184
+ }
185
+
186
+ console.log(`\nsummary: ${scenariosPassed}/${scenariosTotal} scenarios passed`);
187
+ if (scenariosPassed !== scenariosTotal) {
188
+ process.exitCode = 1;
189
+ }
190
+ }
191
+
192
+ run().catch(err => {
193
+ console.error('test failed:', err.message);
194
+ console.error(err.stack);
195
+ process.exitCode = 1;
196
+ });