@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.
- package/.agents/plugins/marketplace.json +3 -3
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +14 -0
- package/LICENSE +201 -201
- package/NOTICE +5 -5
- package/README.md +349 -349
- package/_modules/knowledge-engine/README.md +4 -0
- package/_modules/knowledge-engine/src/analysis-contract.js +4 -3
- package/_modules/knowledge-engine/src/analysis-failures.js +39 -0
- package/_modules/knowledge-engine/src/analysis-worker.js +6 -2
- package/_modules/knowledge-engine/src/coordinator.js +8 -0
- package/_modules/knowledge-engine/src/headless-analyzer.js +2 -1
- package/_modules/knowledge-engine/src/memories.js +10 -5
- package/_modules/knowledge-engine/src/memory-eligibility.js +74 -0
- package/_modules/knowledge-engine/src/retrieval-ranking.js +19 -1
- package/_modules/knowledge-engine/src/runtime/commit-conversation-binder.js +1 -0
- package/_modules/knowledge-engine/src/runtime/commit-prompt.js +12 -9
- package/_modules/knowledge-engine/src/runtime/conversation-store.js +2 -0
- package/_modules/knowledge-engine/src/server.js +1 -1
- package/_site/_test/agent-capture-mcp-ui-test.js +67 -67
- package/_site/_test/ai-profile-test.js +75 -75
- package/_site/_test/ai-vendor-presets-test.js +91 -91
- package/_site/_test/automatic-context-test.js +70 -70
- package/_site/_test/bin-cli-test.js +230 -230
- package/_site/_test/bridge-adapter-test.js +95 -95
- package/_site/_test/bridge-consumer-service-test.js +310 -310
- package/_site/_test/candidate-bin-content-test.js +35 -0
- package/_site/_test/candidate-product-assets-test.js +13 -0
- package/_site/_test/candidate-release-contract-test.js +14 -14
- package/_site/_test/capture-hook-dedup-test.js +158 -158
- package/_site/_test/claude-executable-discovery-test.js +28 -28
- package/_site/_test/claude-session-lifecycle-sweep-test.js +252 -252
- package/_site/_test/cli-instance-management-test.js +62 -62
- package/_site/_test/client-capture-restart-e2e-test.js +189 -189
- package/_site/_test/codex-conversation-projection-test.js +60 -60
- package/_site/_test/codex-marketplace-scoped-path-test.js +186 -186
- package/_site/_test/codex-notify-capture-e2e-test.js +101 -101
- package/_site/_test/codex-notify-fanout-test.js +134 -134
- package/_site/_test/codex-notify-upgrade-test.js +253 -253
- package/_site/_test/commit-boundary-freeze-test.js +147 -147
- package/_site/_test/commit-conversation-binding-test.js +4 -4
- package/_site/_test/configuration-generation-test.js +22 -22
- package/_site/_test/context-pack-test.js +200 -200
- package/_site/_test/conversation-api-test.js +10 -10
- package/_site/_test/conversation-origin-test.js +15 -0
- package/_site/_test/cross-repo-isolation-e2e-test.js +187 -187
- package/_site/_test/embedding-config-test.js +32 -32
- package/_site/_test/fixtures/fake-browser-exit.js +10 -10
- package/_site/_test/fixtures/fake-browser-hang.js +10 -10
- package/_site/_test/fixtures/integration-busy-worker.cjs +6 -6
- package/_site/_test/fixtures/make-git-repos.js +92 -92
- package/_site/_test/fixtures/retrieval-gold-queries.json +32 -0
- package/_site/_test/fresh-hook-reimport-test.js +53 -53
- package/_site/_test/fresh-product-data-test.js +56 -56
- package/_site/_test/git-path-compatibility-test.js +80 -80
- package/_site/_test/git-validation-test.js +81 -81
- package/_site/_test/hook-worktree-test.js +42 -42
- package/_site/_test/index-builder-test.js +41 -41
- package/_site/_test/index-error-display-contract-test.js +10 -10
- package/_site/_test/integration-adapters-test.js +67 -67
- package/_site/_test/integration-capture-setup-test.js +118 -118
- package/_site/_test/integration-runtime-binding-a2-test.js +566 -566
- package/_site/_test/integration-runtime-binding-a3-test.js +227 -227
- package/_site/_test/integration-runtime-binding-test.js +473 -473
- package/_site/_test/integration-status-scan-test.js +29 -29
- package/_site/_test/kb-framework-test.js +57 -57
- package/_site/_test/kbpath-follow-test.js +63 -63
- package/_site/_test/knowledge-db-test.js +144 -144
- package/_site/_test/knowledge-engine-client-test.js +109 -109
- package/_site/_test/knowledge-maintenance-test.js +40 -40
- package/_site/_test/knowledge-panel-ui-contract-test.js +112 -0
- package/_site/_test/knowledge-scopes-test.js +37 -37
- package/_site/_test/knowledge-storage-location-test.js +28 -28
- package/_site/_test/launcher-readiness-test.js +80 -80
- package/_site/_test/legacy-claude-session-alias-test.js +106 -106
- package/_site/_test/legacy-routes-removed-test.js +47 -47
- package/_site/_test/legacy-workbench-exclusion-test.js +92 -92
- package/_site/_test/live-gateway-test.js +48 -48
- package/_site/_test/local-marketplace-test.js +16 -16
- package/_site/_test/log-redaction-test.js +58 -58
- package/_site/_test/markdown-maintenance-test.js +11 -11
- package/_site/_test/model-context-windows-test.js +89 -89
- package/_site/_test/module-agent-start-proxy-test.js +65 -65
- package/_site/_test/module-artifact-integrity-test.js +27 -27
- package/_site/_test/module-boundary-test.js +30 -30
- package/_site/_test/module-bridge-eventbridge-test.js +202 -202
- package/_site/_test/module-dynamic-port-test.js +118 -118
- package/_site/_test/module-index-proxy-test.js +33 -0
- package/_site/_test/module-model-configuration-test.js +44 -44
- package/_site/_test/module-process-lifecycle-test.js +35 -35
- package/_site/_test/module-stream-proxy-test.js +34 -34
- package/_site/_test/module-terminal-restart-test.js +63 -0
- package/_site/_test/module-wiring-unbind-race-test.js +59 -59
- package/_site/_test/native-context-integrations-test.js +86 -86
- package/_site/_test/orphaned-claim-recovery-test.js +80 -80
- package/_site/_test/package-boundary-test.js +43 -42
- package/_site/_test/package-startup-test.js +56 -56
- package/_site/_test/packaged-ui-smoke-test.js +88 -88
- package/_site/_test/pr-consumer-contract-test.js +55 -55
- package/_site/_test/product-brand-contract-test.js +25 -25
- package/_site/_test/product-diagnostics-ui-test.js +93 -93
- package/_site/_test/product-import-ui-test.js +104 -104
- package/_site/_test/product-progress-status-test.js +12 -1
- package/_site/_test/project-remove-running-guard-test.js +79 -79
- package/_site/_test/project-store-test.js +90 -90
- package/_site/_test/registry-events-test.js +38 -0
- package/_site/_test/release-version-sync-test.js +115 -115
- package/_site/_test/requirement-binding-test.js +113 -113
- package/_site/_test/runtime-endpoint-test.js +64 -64
- package/_site/_test/scanner-test.js +83 -83
- package/_site/_test/server-security-test.js +96 -96
- package/_site/_test/sessions-stream-test.js +93 -93
- package/_site/_test/shared-scope-root-binding-test.js +67 -67
- package/_site/_test/simple-import-test.js +98 -98
- package/_site/_test/startup-analysis-disabled-test.js +6 -6
- package/_site/_test/team-knowledge-store-sparse-checkout-test.js +196 -196
- package/_site/_test/team-knowledge-store-test.js +132 -132
- package/_site/_test/test-server-cleanup-test.js +35 -35
- package/_site/_test/test-server-module-isolation-test.js +37 -37
- package/_site/_test/tracking-start-test.js +35 -35
- package/_site/_test/workbench-context-receipts-test.js +22 -0
- package/_site/_test/workspace-ui-contract-test.js +31 -31
- package/_site/_test/zcode-capture-integration-test.js +108 -108
- package/_site/lib/ai-vendor-presets.js +83 -83
- package/_site/lib/ai-workspace.js +3 -3
- package/_site/lib/atomic-file.js +204 -204
- package/_site/lib/bridge-adapter.js +260 -260
- package/_site/lib/capture-hook-config.js +108 -108
- package/_site/lib/claude-cli-runner.js +89 -89
- package/_site/lib/cli-instances.js +43 -43
- package/_site/lib/codex-context-status.js +17 -17
- package/_site/lib/codex-notify-config.js +193 -193
- package/_site/lib/commit-conversation-binder.js +13 -12
- package/_site/lib/commit-reconciler.js +38 -38
- package/_site/lib/context-pack-builder.js +299 -299
- package/_site/lib/conversation-exclusions.js +204 -204
- package/_site/lib/conversation-query-service.js +17 -17
- package/_site/lib/conversation-store.js +2 -0
- package/_site/lib/data-dir.js +13 -13
- package/_site/lib/embedding-service.js +85 -85
- package/_site/lib/engine-connection.js +93 -90
- package/_site/lib/engine-knowledge-client.js +72 -72
- package/_site/lib/folder-picker-output.js +3 -3
- package/_site/lib/git-path.js +14 -14
- package/_site/lib/github-team-store.js +3 -3
- package/_site/lib/index-builder.js +157 -157
- package/_site/lib/integration-status-scan.js +99 -99
- package/_site/lib/integration-status-worker.js +14 -14
- package/_site/lib/kb-framework.js +15 -15
- package/_site/lib/knowledge-db.js +363 -363
- package/_site/lib/knowledge-schema.js +121 -121
- package/_site/lib/live-gateway.js +78 -76
- package/_site/lib/llm-client.js +12 -12
- package/_site/lib/model-context-windows.js +82 -82
- package/_site/lib/module-bridge.js +874 -865
- package/_site/lib/module-port-resolver.js +57 -57
- package/_site/lib/post-commit-automation.js +54 -54
- package/_site/lib/product-data.js +35 -35
- package/_site/lib/project-lifecycle-service.js +14 -14
- package/_site/lib/project-registry-store.js +129 -129
- package/_site/lib/prompt-registry.js +148 -148
- package/_site/lib/registry-events.js +16 -0
- package/_site/lib/requirement-adapters.js +10 -10
- package/_site/lib/requirement-binder.js +112 -112
- package/_site/lib/runtime-control.js +89 -89
- package/_site/lib/runtime-endpoint.js +5 -5
- package/_site/lib/server-app.js +10 -1
- package/_site/lib/zcode-context-integration.js +60 -60
- package/_site/scripts/codex-notify-fanout.cjs +95 -95
- package/_site/scripts/install-module-candidates.js +69 -69
- package/_site/scripts/pack-module-candidates.js +89 -72
- package/_site/scripts/sync-product-content.js +28 -28
- package/_site/scripts/sync-release-version.js +164 -164
- package/_site/scripts/vendor-modules.js +49 -49
- package/_site/scripts/verify-module-runtime.js +50 -50
- package/_site/scripts/verify-product-runtime.js +36 -36
- package/_site/scripts/verify-retrieval-gold.js +83 -0
- package/_site/server.js +15 -15
- package/_site/start.bat +26 -26
- package/_site/stop.bat +11 -11
- package/bin/project-knowledge-integrations.js +254 -254
- package/bin/project-knowledge-kb.js +67 -67
- package/bin/project-knowledge-mcp.js +8 -8
- package/bin/project-knowledge.js +170 -170
- package/claude-prompts.json +21 -21
- package/docs/README.zh-CN.md +205 -205
- package/docs/assets/architecture.svg +181 -181
- package/docs/assets/logo.svg +49 -49
- package/docs/fresh-v5-start.md +42 -42
- package/docs/leader-glm-workbench-playbook.md +122 -119
- package/docs/project-registry-schema.md +11 -11
- package/docs/release-5.0.16-acceptance.md +176 -176
- package/docs/release-5.0.17-acceptance.md +117 -117
- package/docs/release-5.0.19-acceptance.md +39 -0
- package/docs/team-knowledge-mode-a-plan.md +73 -73
- package/module-runtime-manifest.json +126 -104
- package/package.json +110 -108
- package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.mcp.json +1 -1
- package/plugins/project-knowledge/opencode/project-knowledge.md +3 -3
- package/plugins/project-knowledge/skills/project-knowledge/SKILL.md +28 -28
- package/templates/change.md +30 -30
- package/templates/project-readme.md +18 -18
- package/ui/index.html +1 -1
- package/ui/knowledge-panel.html +118 -0
- package/ui/product.css +8 -0
- package/ui/product.js +175 -8
- package/vendor-manifest.json +55 -53
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { spawnServer } = require('./helpers/spawn-server');
|
|
6
|
-
|
|
7
|
-
const ROOT = path.resolve(__dirname, '..', '..');
|
|
8
|
-
const PORT = 7795;
|
|
9
|
-
const BASE = `http://127.0.0.1:${PORT}`;
|
|
10
|
-
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pkb-ai-v2-'));
|
|
11
|
-
|
|
12
|
-
async function request(method, pathname, body) {
|
|
13
|
-
const response = await fetch(`${BASE}${pathname}`, {
|
|
14
|
-
method,
|
|
15
|
-
headers: body === undefined ? undefined : { 'content-type': 'application/json' },
|
|
16
|
-
body: body === undefined ? undefined : JSON.stringify(body),
|
|
17
|
-
});
|
|
18
|
-
return { status: response.status, text: await response.text() };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function json(method, pathname, body) {
|
|
22
|
-
const result = await request(method, pathname, body);
|
|
23
|
-
return { ...result, data: JSON.parse(result.text || '{}') };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function waitForServer() {
|
|
27
|
-
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
28
|
-
try { if ((await fetch(`${BASE}/api/health`)).ok) return; } catch {}
|
|
29
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
30
|
-
}
|
|
31
|
-
throw new Error('server did not start');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
(async () => {
|
|
35
|
-
const spawned = spawnServer({ root: ROOT, port: PORT, dataDir, tag: 'ai-profile-v2', extraEnv: { KB_SKIP_MIGRATION: '1' } });
|
|
36
|
-
try {
|
|
37
|
-
await waitForServer();
|
|
38
|
-
let result = await json('PUT', '/api/ai-profiles', {
|
|
39
|
-
schema: 'ai-profiles/v1', defaultProfileId: 'secure', profiles: [{
|
|
40
|
-
id: 'secure', name: 'Secure', enabled: true, implementation: 'claude-code-agent', apiKeyUpdate: { mode: 'replace', value: 'sk-secret-1234' },
|
|
41
|
-
}],
|
|
42
|
-
});
|
|
43
|
-
assert.strictEqual(result.status, 200, result.text);
|
|
44
|
-
assert.strictEqual(result.data.config.profiles[0].hasApiKey, true);
|
|
45
|
-
assert.strictEqual(result.data.config.profiles[0].apiKeyMasked, '****1234');
|
|
46
|
-
assert(!result.text.includes('sk-secret-1234'));
|
|
47
|
-
|
|
48
|
-
result = await json('GET', '/api/ai-profiles');
|
|
49
|
-
assert.strictEqual(result.status, 200);
|
|
50
|
-
assert(!result.text.includes('sk-secret-1234'));
|
|
51
|
-
assert(!/"apiKey"\s*:/.test(result.text));
|
|
52
|
-
|
|
53
|
-
result = await json('PUT', '/api/ai-profiles', {
|
|
54
|
-
schema: 'ai-profiles/v1', defaultProfileId: 'secure', profiles: [{ id: 'secure', name: 'Renamed', enabled: true, implementation: 'claude-code-agent', apiKeyUpdate: { mode: 'preserve' } }],
|
|
55
|
-
});
|
|
56
|
-
assert.strictEqual(result.status, 200);
|
|
57
|
-
let settings = JSON.parse(fs.readFileSync(path.join(dataDir, 'settings.json'), 'utf8'));
|
|
58
|
-
assert.strictEqual(settings.ai.profiles[0].apiKey, 'sk-secret-1234');
|
|
59
|
-
|
|
60
|
-
result = await json('PUT', '/api/ai-profiles', {
|
|
61
|
-
schema: 'ai-profiles/v1', defaultProfileId: 'secure', profiles: [{ id: 'secure', name: 'Renamed', enabled: true, implementation: 'claude-code-agent', apiKeyUpdate: { mode: 'clear' } }],
|
|
62
|
-
});
|
|
63
|
-
assert.strictEqual(result.status, 200);
|
|
64
|
-
settings = JSON.parse(fs.readFileSync(path.join(dataDir, 'settings.json'), 'utf8'));
|
|
65
|
-
assert(!Object.prototype.hasOwnProperty.call(settings.ai.profiles[0], 'apiKey'));
|
|
66
|
-
|
|
67
|
-
result = await json('PUT', '/api/ai-profiles', { profiles: [{ id: '../bad', apiKeyUpdate: { mode: 'clear' } }] });
|
|
68
|
-
assert.strictEqual(result.status, 400);
|
|
69
|
-
assert.strictEqual(result.data.error.code, 'INVALID_ARGUMENT');
|
|
70
|
-
assert(!Object.prototype.hasOwnProperty.call(result.data.error, 'stack'));
|
|
71
|
-
console.log('ai-profile-test PASS');
|
|
72
|
-
} finally {
|
|
73
|
-
await spawned.cleanup();
|
|
74
|
-
}
|
|
75
|
-
})().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 { spawnServer } = require('./helpers/spawn-server');
|
|
6
|
+
|
|
7
|
+
const ROOT = path.resolve(__dirname, '..', '..');
|
|
8
|
+
const PORT = 7795;
|
|
9
|
+
const BASE = `http://127.0.0.1:${PORT}`;
|
|
10
|
+
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pkb-ai-v2-'));
|
|
11
|
+
|
|
12
|
+
async function request(method, pathname, body) {
|
|
13
|
+
const response = await fetch(`${BASE}${pathname}`, {
|
|
14
|
+
method,
|
|
15
|
+
headers: body === undefined ? undefined : { 'content-type': 'application/json' },
|
|
16
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
17
|
+
});
|
|
18
|
+
return { status: response.status, text: await response.text() };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function json(method, pathname, body) {
|
|
22
|
+
const result = await request(method, pathname, body);
|
|
23
|
+
return { ...result, data: JSON.parse(result.text || '{}') };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function waitForServer() {
|
|
27
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
28
|
+
try { if ((await fetch(`${BASE}/api/health`)).ok) return; } catch {}
|
|
29
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
30
|
+
}
|
|
31
|
+
throw new Error('server did not start');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
(async () => {
|
|
35
|
+
const spawned = spawnServer({ root: ROOT, port: PORT, dataDir, tag: 'ai-profile-v2', extraEnv: { KB_SKIP_MIGRATION: '1' } });
|
|
36
|
+
try {
|
|
37
|
+
await waitForServer();
|
|
38
|
+
let result = await json('PUT', '/api/ai-profiles', {
|
|
39
|
+
schema: 'ai-profiles/v1', defaultProfileId: 'secure', profiles: [{
|
|
40
|
+
id: 'secure', name: 'Secure', enabled: true, implementation: 'claude-code-agent', apiKeyUpdate: { mode: 'replace', value: 'sk-secret-1234' },
|
|
41
|
+
}],
|
|
42
|
+
});
|
|
43
|
+
assert.strictEqual(result.status, 200, result.text);
|
|
44
|
+
assert.strictEqual(result.data.config.profiles[0].hasApiKey, true);
|
|
45
|
+
assert.strictEqual(result.data.config.profiles[0].apiKeyMasked, '****1234');
|
|
46
|
+
assert(!result.text.includes('sk-secret-1234'));
|
|
47
|
+
|
|
48
|
+
result = await json('GET', '/api/ai-profiles');
|
|
49
|
+
assert.strictEqual(result.status, 200);
|
|
50
|
+
assert(!result.text.includes('sk-secret-1234'));
|
|
51
|
+
assert(!/"apiKey"\s*:/.test(result.text));
|
|
52
|
+
|
|
53
|
+
result = await json('PUT', '/api/ai-profiles', {
|
|
54
|
+
schema: 'ai-profiles/v1', defaultProfileId: 'secure', profiles: [{ id: 'secure', name: 'Renamed', enabled: true, implementation: 'claude-code-agent', apiKeyUpdate: { mode: 'preserve' } }],
|
|
55
|
+
});
|
|
56
|
+
assert.strictEqual(result.status, 200);
|
|
57
|
+
let settings = JSON.parse(fs.readFileSync(path.join(dataDir, 'settings.json'), 'utf8'));
|
|
58
|
+
assert.strictEqual(settings.ai.profiles[0].apiKey, 'sk-secret-1234');
|
|
59
|
+
|
|
60
|
+
result = await json('PUT', '/api/ai-profiles', {
|
|
61
|
+
schema: 'ai-profiles/v1', defaultProfileId: 'secure', profiles: [{ id: 'secure', name: 'Renamed', enabled: true, implementation: 'claude-code-agent', apiKeyUpdate: { mode: 'clear' } }],
|
|
62
|
+
});
|
|
63
|
+
assert.strictEqual(result.status, 200);
|
|
64
|
+
settings = JSON.parse(fs.readFileSync(path.join(dataDir, 'settings.json'), 'utf8'));
|
|
65
|
+
assert(!Object.prototype.hasOwnProperty.call(settings.ai.profiles[0], 'apiKey'));
|
|
66
|
+
|
|
67
|
+
result = await json('PUT', '/api/ai-profiles', { profiles: [{ id: '../bad', apiKeyUpdate: { mode: 'clear' } }] });
|
|
68
|
+
assert.strictEqual(result.status, 400);
|
|
69
|
+
assert.strictEqual(result.data.error.code, 'INVALID_ARGUMENT');
|
|
70
|
+
assert(!Object.prototype.hasOwnProperty.call(result.data.error, 'stack'));
|
|
71
|
+
console.log('ai-profile-test PASS');
|
|
72
|
+
} finally {
|
|
73
|
+
await spawned.cleanup();
|
|
74
|
+
}
|
|
75
|
+
})().catch(error => { console.error(error); process.exitCode = 1; });
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
// Tests for ai-vendor-presets: 4 vendors with full fields, name/id lookup.
|
|
2
|
-
|
|
3
|
-
const { AI_VENDOR_PRESETS, listVendorPresetNames, findVendorPresetByName } = require('../lib/ai-vendor-presets');
|
|
4
|
-
|
|
5
|
-
function assert(cond, msg) { if (!cond) throw new Error(msg); }
|
|
6
|
-
|
|
7
|
-
(() => {
|
|
8
|
-
try {
|
|
9
|
-
// 1. Exactly 4 vendors
|
|
10
|
-
assert(Array.isArray(AI_VENDOR_PRESETS), 'AI_VENDOR_PRESETS should be an array');
|
|
11
|
-
assert(AI_VENDOR_PRESETS.length === 4, `expected 4 vendors, got ${AI_VENDOR_PRESETS.length}`);
|
|
12
|
-
|
|
13
|
-
// 2. IDs unique and match the expected set
|
|
14
|
-
const ids = AI_VENDOR_PRESETS.map(v => v.id).sort();
|
|
15
|
-
assert(JSON.stringify(ids) === JSON.stringify(['anthropic', 'deepseek', 'minimax', 'zhipu']),
|
|
16
|
-
`vendor ids should be anthropic/deepseek/minimax/zhipu, got ${JSON.stringify(ids)}`);
|
|
17
|
-
|
|
18
|
-
// 3. Every preset has the required fields
|
|
19
|
-
const required = ['id', 'name', 'baseUrl', 'mainModel', 'thinkingModel',
|
|
20
|
-
'haikuModel', 'sonnetModel', 'opusModel', 'contextWindow', 'website'];
|
|
21
|
-
for (const v of AI_VENDOR_PRESETS) {
|
|
22
|
-
for (const f of required) {
|
|
23
|
-
assert(v[f] !== undefined && v[f] !== null && v[f] !== '',
|
|
24
|
-
`vendor ${v.id} missing or empty field: ${f}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// 4. baseUrl: https://, no trailing slash
|
|
29
|
-
for (const v of AI_VENDOR_PRESETS) {
|
|
30
|
-
assert(/^https?:\/\//.test(v.baseUrl), `${v.id} baseUrl must start with http(s)://`);
|
|
31
|
-
assert(!/\/$/.test(v.baseUrl), `${v.id} baseUrl must NOT have trailing slash`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// 5. contextWindow is a positive integer
|
|
35
|
-
for (const v of AI_VENDOR_PRESETS) {
|
|
36
|
-
assert(Number.isInteger(v.contextWindow) && v.contextWindow > 0,
|
|
37
|
-
`${v.id} contextWindow must be a positive integer, got ${v.contextWindow}`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 6. Specific known values
|
|
41
|
-
const minimax = findVendorPresetByName('MiniMax');
|
|
42
|
-
assert(minimax && minimax.baseUrl === 'https://api.minimaxi.com/anthropic',
|
|
43
|
-
`minimax baseUrl wrong: ${minimax && minimax.baseUrl}`);
|
|
44
|
-
assert(minimax && minimax.mainModel === 'MiniMax-M3',
|
|
45
|
-
`minimax mainModel wrong: ${minimax && minimax.mainModel}`);
|
|
46
|
-
assert(minimax && minimax.contextWindow === 1048576,
|
|
47
|
-
`minimax contextWindow should be 1M`);
|
|
48
|
-
|
|
49
|
-
const anthropic = findVendorPresetByName('Anthropic Claude');
|
|
50
|
-
assert(anthropic && anthropic.baseUrl === 'https://api.anthropic.com',
|
|
51
|
-
`anthropic baseUrl wrong`);
|
|
52
|
-
assert(anthropic && anthropic.contextWindow === 200000,
|
|
53
|
-
`anthropic contextWindow should be 200K`);
|
|
54
|
-
|
|
55
|
-
const zhipu = findVendorPresetByName('智谱 GLM');
|
|
56
|
-
assert(zhipu && zhipu.baseUrl === 'https://open.bigmodel.cn/api/anthropic',
|
|
57
|
-
`zhipu baseUrl wrong: ${zhipu && zhipu.baseUrl}`);
|
|
58
|
-
|
|
59
|
-
const deepseek = findVendorPresetByName('DeepSeek');
|
|
60
|
-
assert(deepseek && deepseek.baseUrl === 'https://api.deepseek.com/anthropic',
|
|
61
|
-
`deepseek baseUrl wrong: ${deepseek && deepseek.baseUrl}`);
|
|
62
|
-
assert(deepseek && deepseek.mainModel === 'deepseek-chat',
|
|
63
|
-
`deepseek mainModel wrong`);
|
|
64
|
-
assert(deepseek && deepseek.thinkingModel === 'deepseek-reasoner',
|
|
65
|
-
`deepseek thinkingModel wrong`);
|
|
66
|
-
|
|
67
|
-
// 7. Case-insensitive lookup by name
|
|
68
|
-
assert(findVendorPresetByName('minimax').id === 'minimax', 'lowercase name lookup');
|
|
69
|
-
assert(findVendorPresetByName('MINIMAX').id === 'minimax', 'uppercase name lookup');
|
|
70
|
-
|
|
71
|
-
// 8. Lookup by id also works
|
|
72
|
-
assert(findVendorPresetByName('minimax').id === 'minimax', 'id lookup');
|
|
73
|
-
|
|
74
|
-
// 9. Unknown / empty / null returns null (no false positive)
|
|
75
|
-
assert(findVendorPresetByName('Totally Unknown Vendor') === null, 'unknown vendor → null');
|
|
76
|
-
assert(findVendorPresetByName('') === null, 'empty name → null');
|
|
77
|
-
assert(findVendorPresetByName(null) === null, 'null name → null');
|
|
78
|
-
assert(findVendorPresetByName(undefined) === null, 'undefined name → null');
|
|
79
|
-
|
|
80
|
-
// 10. listVendorPresetNames returns all 4 names in stable order
|
|
81
|
-
const names = listVendorPresetNames();
|
|
82
|
-
assert(names.length === 4, `expected 4 names, got ${names.length}`);
|
|
83
|
-
assert(names.every(n => typeof n === 'string' && n.length > 0),
|
|
84
|
-
'all names should be non-empty strings');
|
|
85
|
-
|
|
86
|
-
console.log('ai-vendor-presets test passed');
|
|
87
|
-
} catch (e) {
|
|
88
|
-
console.error('ai-vendor-presets test failed:', e.message);
|
|
89
|
-
process.exitCode = 1;
|
|
90
|
-
}
|
|
91
|
-
})();
|
|
1
|
+
// Tests for ai-vendor-presets: 4 vendors with full fields, name/id lookup.
|
|
2
|
+
|
|
3
|
+
const { AI_VENDOR_PRESETS, listVendorPresetNames, findVendorPresetByName } = require('../lib/ai-vendor-presets');
|
|
4
|
+
|
|
5
|
+
function assert(cond, msg) { if (!cond) throw new Error(msg); }
|
|
6
|
+
|
|
7
|
+
(() => {
|
|
8
|
+
try {
|
|
9
|
+
// 1. Exactly 4 vendors
|
|
10
|
+
assert(Array.isArray(AI_VENDOR_PRESETS), 'AI_VENDOR_PRESETS should be an array');
|
|
11
|
+
assert(AI_VENDOR_PRESETS.length === 4, `expected 4 vendors, got ${AI_VENDOR_PRESETS.length}`);
|
|
12
|
+
|
|
13
|
+
// 2. IDs unique and match the expected set
|
|
14
|
+
const ids = AI_VENDOR_PRESETS.map(v => v.id).sort();
|
|
15
|
+
assert(JSON.stringify(ids) === JSON.stringify(['anthropic', 'deepseek', 'minimax', 'zhipu']),
|
|
16
|
+
`vendor ids should be anthropic/deepseek/minimax/zhipu, got ${JSON.stringify(ids)}`);
|
|
17
|
+
|
|
18
|
+
// 3. Every preset has the required fields
|
|
19
|
+
const required = ['id', 'name', 'baseUrl', 'mainModel', 'thinkingModel',
|
|
20
|
+
'haikuModel', 'sonnetModel', 'opusModel', 'contextWindow', 'website'];
|
|
21
|
+
for (const v of AI_VENDOR_PRESETS) {
|
|
22
|
+
for (const f of required) {
|
|
23
|
+
assert(v[f] !== undefined && v[f] !== null && v[f] !== '',
|
|
24
|
+
`vendor ${v.id} missing or empty field: ${f}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 4. baseUrl: https://, no trailing slash
|
|
29
|
+
for (const v of AI_VENDOR_PRESETS) {
|
|
30
|
+
assert(/^https?:\/\//.test(v.baseUrl), `${v.id} baseUrl must start with http(s)://`);
|
|
31
|
+
assert(!/\/$/.test(v.baseUrl), `${v.id} baseUrl must NOT have trailing slash`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 5. contextWindow is a positive integer
|
|
35
|
+
for (const v of AI_VENDOR_PRESETS) {
|
|
36
|
+
assert(Number.isInteger(v.contextWindow) && v.contextWindow > 0,
|
|
37
|
+
`${v.id} contextWindow must be a positive integer, got ${v.contextWindow}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 6. Specific known values
|
|
41
|
+
const minimax = findVendorPresetByName('MiniMax');
|
|
42
|
+
assert(minimax && minimax.baseUrl === 'https://api.minimaxi.com/anthropic',
|
|
43
|
+
`minimax baseUrl wrong: ${minimax && minimax.baseUrl}`);
|
|
44
|
+
assert(minimax && minimax.mainModel === 'MiniMax-M3',
|
|
45
|
+
`minimax mainModel wrong: ${minimax && minimax.mainModel}`);
|
|
46
|
+
assert(minimax && minimax.contextWindow === 1048576,
|
|
47
|
+
`minimax contextWindow should be 1M`);
|
|
48
|
+
|
|
49
|
+
const anthropic = findVendorPresetByName('Anthropic Claude');
|
|
50
|
+
assert(anthropic && anthropic.baseUrl === 'https://api.anthropic.com',
|
|
51
|
+
`anthropic baseUrl wrong`);
|
|
52
|
+
assert(anthropic && anthropic.contextWindow === 200000,
|
|
53
|
+
`anthropic contextWindow should be 200K`);
|
|
54
|
+
|
|
55
|
+
const zhipu = findVendorPresetByName('智谱 GLM');
|
|
56
|
+
assert(zhipu && zhipu.baseUrl === 'https://open.bigmodel.cn/api/anthropic',
|
|
57
|
+
`zhipu baseUrl wrong: ${zhipu && zhipu.baseUrl}`);
|
|
58
|
+
|
|
59
|
+
const deepseek = findVendorPresetByName('DeepSeek');
|
|
60
|
+
assert(deepseek && deepseek.baseUrl === 'https://api.deepseek.com/anthropic',
|
|
61
|
+
`deepseek baseUrl wrong: ${deepseek && deepseek.baseUrl}`);
|
|
62
|
+
assert(deepseek && deepseek.mainModel === 'deepseek-chat',
|
|
63
|
+
`deepseek mainModel wrong`);
|
|
64
|
+
assert(deepseek && deepseek.thinkingModel === 'deepseek-reasoner',
|
|
65
|
+
`deepseek thinkingModel wrong`);
|
|
66
|
+
|
|
67
|
+
// 7. Case-insensitive lookup by name
|
|
68
|
+
assert(findVendorPresetByName('minimax').id === 'minimax', 'lowercase name lookup');
|
|
69
|
+
assert(findVendorPresetByName('MINIMAX').id === 'minimax', 'uppercase name lookup');
|
|
70
|
+
|
|
71
|
+
// 8. Lookup by id also works
|
|
72
|
+
assert(findVendorPresetByName('minimax').id === 'minimax', 'id lookup');
|
|
73
|
+
|
|
74
|
+
// 9. Unknown / empty / null returns null (no false positive)
|
|
75
|
+
assert(findVendorPresetByName('Totally Unknown Vendor') === null, 'unknown vendor → null');
|
|
76
|
+
assert(findVendorPresetByName('') === null, 'empty name → null');
|
|
77
|
+
assert(findVendorPresetByName(null) === null, 'null name → null');
|
|
78
|
+
assert(findVendorPresetByName(undefined) === null, 'undefined name → null');
|
|
79
|
+
|
|
80
|
+
// 10. listVendorPresetNames returns all 4 names in stable order
|
|
81
|
+
const names = listVendorPresetNames();
|
|
82
|
+
assert(names.length === 4, `expected 4 names, got ${names.length}`);
|
|
83
|
+
assert(names.every(n => typeof n === 'string' && n.length > 0),
|
|
84
|
+
'all names should be non-empty strings');
|
|
85
|
+
|
|
86
|
+
console.log('ai-vendor-presets test passed');
|
|
87
|
+
} catch (e) {
|
|
88
|
+
console.error('ai-vendor-presets test failed:', e.message);
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
}
|
|
91
|
+
})();
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const os = require('node:os');
|
|
5
|
-
const path = require('node:path');
|
|
6
|
-
const { IntegrationManager } = require('../lib/integration-installer');
|
|
7
|
-
const { run, writeOutput } = require('../../plugins/project-knowledge/scripts/context-hook.cjs');
|
|
8
|
-
|
|
9
|
-
async function main() {
|
|
10
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'automatic-context-'));
|
|
11
|
-
try {
|
|
12
|
-
const endpoint = { schema: 'project-knowledge/runtime-endpoint/v1', host: '127.0.0.1', pid: process.pid, port: 23456, startedAt: 'now' };
|
|
13
|
-
fs.writeFileSync(path.join(root, 'runtime-endpoint.json'), JSON.stringify(endpoint));
|
|
14
|
-
const payload = { cwd: root, session_id: 'session-a', hook_event_name: 'UserPromptSubmit', prompt: 'Develop export normally' };
|
|
15
|
-
const env = { KB_DATA_DIR: root }, calls = [];
|
|
16
|
-
const identity = { ...endpoint, schema: 'project-knowledge/runtime-control/v1', name: 'project-knowledge', dataDir: root };
|
|
17
|
-
const fetchImpl = async (url, options) => {
|
|
18
|
-
calls.push({ url: String(url), options });
|
|
19
|
-
if (String(url).endsWith('/identity')) return Response.json(identity);
|
|
20
|
-
const input = JSON.parse(options.body);
|
|
21
|
-
return Response.json({ ok: true, requestId: input.requestId, projectId: 'project-a', status: 'ready', memoryStatus: 'ready', prompt: '<knowledge_context>export revision 37</knowledge_context>', facts: [{}], memories: [{}], references: [{}] });
|
|
22
|
-
};
|
|
23
|
-
const output = await run(payload, { env, fetchImpl });
|
|
24
|
-
assert.match(output.hookSpecificOutput.additionalContext, /revision 37/); assert.equal(calls.length, 2);
|
|
25
|
-
assert.equal(JSON.parse(calls[1].options.body).query, payload.prompt);
|
|
26
|
-
assert.ok(!JSON.stringify(output).includes('receipt')); assert.ok(!fs.existsSync(path.join(root, 'logs')));
|
|
27
|
-
await writeOutput(output, { write: (text, callback) => { assert.ok(!text.includes('receipt')); callback(); } });
|
|
28
|
-
const logDir = path.join(root, 'logs/projects/project-a'); const logText = fs.readFileSync(path.join(logDir, fs.readdirSync(logDir)[0]), 'utf8');
|
|
29
|
-
assert.ok(!logText.includes(payload.prompt)); assert.ok(!logText.includes('revision 37')); assert.ok(logText.includes('agent.context.output'));
|
|
30
|
-
calls.length = 0;
|
|
31
|
-
assert.deepEqual(await run(payload, { env: { ...env, KB_KNOWLEDGE_CONTEXT: '0' }, fetchImpl }), {}); assert.equal(calls.length, 0);
|
|
32
|
-
assert.deepEqual(await run({ ...payload, hook_event_name: 'Stop' }, { env, fetchImpl }), {});
|
|
33
|
-
const mismatch = await run(payload, { env, fetchImpl: async () => Response.json({ ...identity, dataDir: path.join(root, 'other') }) });
|
|
34
|
-
assert.match(mismatch.systemMessage, /CONTEXT_IDENTITY_MISMATCH/);
|
|
35
|
-
const unknown = await run(payload, { env, fetchImpl: async url => String(url).endsWith('/identity') ? Response.json(identity) : Response.json({ ok: false, error: 'PROJECT_NOT_FOUND' }, { status: 404 }) });
|
|
36
|
-
assert.match(unknown.systemMessage, /未识别到当前代码目录/);
|
|
37
|
-
assert.match(unknown.hookSpecificOutput.additionalContext, /不代表知识库为空/);
|
|
38
|
-
const offline = await run(payload, { env, fetchImpl: async () => { throw new Error('sensitive untrusted upstream text'); } });
|
|
39
|
-
assert.match(offline.systemMessage, /可继续开发/); assert.ok(!JSON.stringify(offline).includes('sensitive'));
|
|
40
|
-
const slow = await run(payload, { env, timeoutMs: 30, fetchImpl: (url, options) => new Promise((resolve, reject) => options.signal.addEventListener('abort', () => reject(new Error('aborted')), { once: true })) });
|
|
41
|
-
assert.match(slow.systemMessage, /CONTEXT_TIMEOUT/);
|
|
42
|
-
let version = '4.2.16'; const commandCalls = [];
|
|
43
|
-
const manager = new IntegrationManager({ homeDir: root, commandResolver: name => name, runner: (command, args) => {
|
|
44
|
-
commandCalls.push(args.join(' '));
|
|
45
|
-
if (args.join(' ') === 'plugin list --json') return { status: 0, stdout: JSON.stringify([{ id: 'project-knowledge@project-knowledge', version, enabled: true }]) };
|
|
46
|
-
if (args.join(' ') === 'plugin marketplace list --json') return { status: 0, stdout: JSON.stringify([{ name: 'project-knowledge' }]) };
|
|
47
|
-
if (args.slice(0, 2).join(' ') === 'plugin update') {
|
|
48
|
-
version = manager.version;
|
|
49
|
-
const source = path.resolve(__dirname, '../../plugins/project-knowledge'), cache = path.join(root, '.claude/plugins/cache/project-knowledge/project-knowledge', version);
|
|
50
|
-
fs.mkdirSync(cache, { recursive: true }); fs.cpSync(source, cache, { recursive: true });
|
|
51
|
-
}
|
|
52
|
-
return { status: 0, stdout: '' };
|
|
53
|
-
} });
|
|
54
|
-
const knownMarketplaces = path.join(root, '.claude/plugins/known_marketplaces.json');
|
|
55
|
-
fs.mkdirSync(path.dirname(knownMarketplaces), { recursive: true });
|
|
56
|
-
fs.writeFileSync(knownMarketplaces, JSON.stringify({ 'project-knowledge': { source: { source: 'directory', path: manager.rootDir } } }));
|
|
57
|
-
assert.equal(manager.statusClaude().state, 'needs-update');
|
|
58
|
-
manager.installClaude();
|
|
59
|
-
assert.ok(commandCalls.includes('plugin marketplace update project-knowledge'));
|
|
60
|
-
assert.ok(commandCalls.includes('plugin update project-knowledge@project-knowledge --scope user'));
|
|
61
|
-
assert.equal(manager.statusClaude().state, 'installed');
|
|
62
|
-
const cacheRoot = path.join(root, '.claude/plugins/cache/project-knowledge/project-knowledge', manager.version);
|
|
63
|
-
for (const file of ['hooks/claude.json', 'scripts/context-hook.cjs']) fs.writeFileSync(path.join(cacheRoot, file), fs.readFileSync(path.join(cacheRoot, file), 'utf8').replace(/\r?\n/g, '\r\n'));
|
|
64
|
-
assert.equal(manager.automaticContextStatus('claude', manager.statusClaude()).configured, true, 'Git CRLF checkout and npm LF are the same client integration');
|
|
65
|
-
const before = commandCalls.filter(c => c.startsWith('plugin update')).length; manager.installClaude();
|
|
66
|
-
assert.equal(commandCalls.filter(c => c.startsWith('plugin update')).length, before);
|
|
67
|
-
console.log('Automatic context protocol, fail-open safety and stale-plugin upgrade passed.');
|
|
68
|
-
} finally { fs.rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); }
|
|
69
|
-
}
|
|
70
|
-
main().catch(error => { console.error(error); process.exitCode = 1; });
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const { IntegrationManager } = require('../lib/integration-installer');
|
|
7
|
+
const { run, writeOutput } = require('../../plugins/project-knowledge/scripts/context-hook.cjs');
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'automatic-context-'));
|
|
11
|
+
try {
|
|
12
|
+
const endpoint = { schema: 'project-knowledge/runtime-endpoint/v1', host: '127.0.0.1', pid: process.pid, port: 23456, startedAt: 'now' };
|
|
13
|
+
fs.writeFileSync(path.join(root, 'runtime-endpoint.json'), JSON.stringify(endpoint));
|
|
14
|
+
const payload = { cwd: root, session_id: 'session-a', hook_event_name: 'UserPromptSubmit', prompt: 'Develop export normally' };
|
|
15
|
+
const env = { KB_DATA_DIR: root }, calls = [];
|
|
16
|
+
const identity = { ...endpoint, schema: 'project-knowledge/runtime-control/v1', name: 'project-knowledge', dataDir: root };
|
|
17
|
+
const fetchImpl = async (url, options) => {
|
|
18
|
+
calls.push({ url: String(url), options });
|
|
19
|
+
if (String(url).endsWith('/identity')) return Response.json(identity);
|
|
20
|
+
const input = JSON.parse(options.body);
|
|
21
|
+
return Response.json({ ok: true, requestId: input.requestId, projectId: 'project-a', status: 'ready', memoryStatus: 'ready', prompt: '<knowledge_context>export revision 37</knowledge_context>', facts: [{}], memories: [{}], references: [{}] });
|
|
22
|
+
};
|
|
23
|
+
const output = await run(payload, { env, fetchImpl });
|
|
24
|
+
assert.match(output.hookSpecificOutput.additionalContext, /revision 37/); assert.equal(calls.length, 2);
|
|
25
|
+
assert.equal(JSON.parse(calls[1].options.body).query, payload.prompt);
|
|
26
|
+
assert.ok(!JSON.stringify(output).includes('receipt')); assert.ok(!fs.existsSync(path.join(root, 'logs')));
|
|
27
|
+
await writeOutput(output, { write: (text, callback) => { assert.ok(!text.includes('receipt')); callback(); } });
|
|
28
|
+
const logDir = path.join(root, 'logs/projects/project-a'); const logText = fs.readFileSync(path.join(logDir, fs.readdirSync(logDir)[0]), 'utf8');
|
|
29
|
+
assert.ok(!logText.includes(payload.prompt)); assert.ok(!logText.includes('revision 37')); assert.ok(logText.includes('agent.context.output'));
|
|
30
|
+
calls.length = 0;
|
|
31
|
+
assert.deepEqual(await run(payload, { env: { ...env, KB_KNOWLEDGE_CONTEXT: '0' }, fetchImpl }), {}); assert.equal(calls.length, 0);
|
|
32
|
+
assert.deepEqual(await run({ ...payload, hook_event_name: 'Stop' }, { env, fetchImpl }), {});
|
|
33
|
+
const mismatch = await run(payload, { env, fetchImpl: async () => Response.json({ ...identity, dataDir: path.join(root, 'other') }) });
|
|
34
|
+
assert.match(mismatch.systemMessage, /CONTEXT_IDENTITY_MISMATCH/);
|
|
35
|
+
const unknown = await run(payload, { env, fetchImpl: async url => String(url).endsWith('/identity') ? Response.json(identity) : Response.json({ ok: false, error: 'PROJECT_NOT_FOUND' }, { status: 404 }) });
|
|
36
|
+
assert.match(unknown.systemMessage, /未识别到当前代码目录/);
|
|
37
|
+
assert.match(unknown.hookSpecificOutput.additionalContext, /不代表知识库为空/);
|
|
38
|
+
const offline = await run(payload, { env, fetchImpl: async () => { throw new Error('sensitive untrusted upstream text'); } });
|
|
39
|
+
assert.match(offline.systemMessage, /可继续开发/); assert.ok(!JSON.stringify(offline).includes('sensitive'));
|
|
40
|
+
const slow = await run(payload, { env, timeoutMs: 30, fetchImpl: (url, options) => new Promise((resolve, reject) => options.signal.addEventListener('abort', () => reject(new Error('aborted')), { once: true })) });
|
|
41
|
+
assert.match(slow.systemMessage, /CONTEXT_TIMEOUT/);
|
|
42
|
+
let version = '4.2.16'; const commandCalls = [];
|
|
43
|
+
const manager = new IntegrationManager({ homeDir: root, commandResolver: name => name, runner: (command, args) => {
|
|
44
|
+
commandCalls.push(args.join(' '));
|
|
45
|
+
if (args.join(' ') === 'plugin list --json') return { status: 0, stdout: JSON.stringify([{ id: 'project-knowledge@project-knowledge', version, enabled: true }]) };
|
|
46
|
+
if (args.join(' ') === 'plugin marketplace list --json') return { status: 0, stdout: JSON.stringify([{ name: 'project-knowledge' }]) };
|
|
47
|
+
if (args.slice(0, 2).join(' ') === 'plugin update') {
|
|
48
|
+
version = manager.version;
|
|
49
|
+
const source = path.resolve(__dirname, '../../plugins/project-knowledge'), cache = path.join(root, '.claude/plugins/cache/project-knowledge/project-knowledge', version);
|
|
50
|
+
fs.mkdirSync(cache, { recursive: true }); fs.cpSync(source, cache, { recursive: true });
|
|
51
|
+
}
|
|
52
|
+
return { status: 0, stdout: '' };
|
|
53
|
+
} });
|
|
54
|
+
const knownMarketplaces = path.join(root, '.claude/plugins/known_marketplaces.json');
|
|
55
|
+
fs.mkdirSync(path.dirname(knownMarketplaces), { recursive: true });
|
|
56
|
+
fs.writeFileSync(knownMarketplaces, JSON.stringify({ 'project-knowledge': { source: { source: 'directory', path: manager.rootDir } } }));
|
|
57
|
+
assert.equal(manager.statusClaude().state, 'needs-update');
|
|
58
|
+
manager.installClaude();
|
|
59
|
+
assert.ok(commandCalls.includes('plugin marketplace update project-knowledge'));
|
|
60
|
+
assert.ok(commandCalls.includes('plugin update project-knowledge@project-knowledge --scope user'));
|
|
61
|
+
assert.equal(manager.statusClaude().state, 'installed');
|
|
62
|
+
const cacheRoot = path.join(root, '.claude/plugins/cache/project-knowledge/project-knowledge', manager.version);
|
|
63
|
+
for (const file of ['hooks/claude.json', 'scripts/context-hook.cjs']) fs.writeFileSync(path.join(cacheRoot, file), fs.readFileSync(path.join(cacheRoot, file), 'utf8').replace(/\r?\n/g, '\r\n'));
|
|
64
|
+
assert.equal(manager.automaticContextStatus('claude', manager.statusClaude()).configured, true, 'Git CRLF checkout and npm LF are the same client integration');
|
|
65
|
+
const before = commandCalls.filter(c => c.startsWith('plugin update')).length; manager.installClaude();
|
|
66
|
+
assert.equal(commandCalls.filter(c => c.startsWith('plugin update')).length, before);
|
|
67
|
+
console.log('Automatic context protocol, fail-open safety and stale-plugin upgrade passed.');
|
|
68
|
+
} finally { fs.rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); }
|
|
69
|
+
}
|
|
70
|
+
main().catch(error => { console.error(error); process.exitCode = 1; });
|