@sanqianx/project-knowledge 4.6.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 +20 -0
- package/.claude-plugin/marketplace.json +17 -0
- package/CHANGELOG.md +780 -0
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +266 -0
- package/_site/README.md +30 -0
- package/_site/_test/ai-profile-resolver-test.js +137 -0
- package/_site/_test/ai-profile-test.js +75 -0
- package/_site/_test/ai-vendor-presets-test.js +91 -0
- package/_site/_test/automation-queue-test.js +14 -0
- package/_site/_test/automation-ui-test.js +40 -0
- package/_site/_test/background-task-registry-test.js +43 -0
- package/_site/_test/baseline-schema-test.js +91 -0
- package/_site/_test/bin-cli-test.js +218 -0
- package/_site/_test/bridge-adapter-test.js +95 -0
- package/_site/_test/bridge-consumer-service-test.js +310 -0
- package/_site/_test/cdp-browser-failure-test.js +100 -0
- package/_site/_test/chat-claudecodeui-match-test.js +92 -0
- package/_site/_test/claude-executable-discovery-test.js +90 -0
- package/_site/_test/claude-session-lifecycle-sweep-test.js +252 -0
- package/_site/_test/claude-workbench-test.js +170 -0
- package/_site/_test/client-capture-restart-e2e-test.js +189 -0
- package/_site/_test/codex-conversation-projection-test.js +59 -0
- package/_site/_test/codex-notify-fanout-test.js +45 -0
- package/_site/_test/commit-boundary-freeze-test.js +147 -0
- package/_site/_test/commit-conversation-binding-test.js +99 -0
- package/_site/_test/commit-evidence-test.js +110 -0
- package/_site/_test/context-pack-test.js +198 -0
- package/_site/_test/conversation-api-test.js +119 -0
- package/_site/_test/conversation-store-test.js +136 -0
- package/_site/_test/cross-repo-isolation-e2e-test.js +187 -0
- package/_site/_test/data-dir-migration-test.js +77 -0
- package/_site/_test/desktop-browser-compat-test.js +28 -0
- package/_site/_test/desktop-hook-runtime-regression-test.js +204 -0
- package/_site/_test/embedding-config-test.js +32 -0
- package/_site/_test/explicit-commit-processor-test.js +37 -0
- package/_site/_test/fixtures/fake-browser-exit.js +10 -0
- package/_site/_test/fixtures/fake-browser-hang.js +10 -0
- package/_site/_test/fixtures/make-git-repos.js +89 -0
- package/_site/_test/folder-picker-output-test.js +19 -0
- package/_site/_test/full-integration-e2e-test.js +165 -0
- package/_site/_test/git-validation-test.js +81 -0
- package/_site/_test/hook-runtime-endpoint-test.js +88 -0
- package/_site/_test/hook-status-repair-api-test.js +152 -0
- package/_site/_test/hook-trigger-test.js +85 -0
- package/_site/_test/hook-worktree-test.js +42 -0
- package/_site/_test/import-preflight-api-test.js +233 -0
- package/_site/_test/import-ui-flow-test.js +171 -0
- package/_site/_test/index-builder-test.js +41 -0
- package/_site/_test/index-writer-concurrency-test.js +135 -0
- package/_site/_test/integration-adapters-test.js +243 -0
- package/_site/_test/integration-capture-setup-test.js +108 -0
- package/_site/_test/integration-surface-coverage-test.js +165 -0
- package/_site/_test/kb-framework-test.js +57 -0
- package/_site/_test/kbpath-follow-test.js +63 -0
- package/_site/_test/knowledge-db-test.js +144 -0
- package/_site/_test/knowledge-language-control-test.js +170 -0
- package/_site/_test/knowledge-maintenance-test.js +40 -0
- package/_site/_test/knowledge-migration-test.js +75 -0
- package/_site/_test/knowledge-promotion-recovery-test.js +260 -0
- package/_site/_test/knowledge-query-test.js +54 -0
- package/_site/_test/knowledge-retrieval-service-test.js +77 -0
- package/_site/_test/knowledge-scopes-test.js +37 -0
- package/_site/_test/knowledge-storage-location-test.js +28 -0
- package/_site/_test/knowledge-storage-startup-test.js +52 -0
- package/_site/_test/knowledge-store-logs-supervision-test.js +89 -0
- package/_site/_test/legacy-claude-session-alias-test.js +106 -0
- package/_site/_test/legacy-forward-compat-test.js +257 -0
- package/_site/_test/legacy-project-upgrade-e2e-test.js +363 -0
- package/_site/_test/legacy-routes-removed-test.js +47 -0
- package/_site/_test/legacy-workbench-exclusion-test.js +92 -0
- package/_site/_test/log-redaction-test.js +58 -0
- package/_site/_test/logging-api-test.js +89 -0
- package/_site/_test/logging-sse-no-gap-test.js +88 -0
- package/_site/_test/logging-ui-test.js +104 -0
- package/_site/_test/markdown-delta-overlay-test.js +85 -0
- package/_site/_test/markdown-maintenance-api-test.js +75 -0
- package/_site/_test/markdown-maintenance-test.js +11 -0
- package/_site/_test/mcp-server-test.js +149 -0
- package/_site/_test/model-context-windows-test.js +89 -0
- package/_site/_test/module-bridge-eventbridge-test.js +193 -0
- package/_site/_test/non-release-ci-test.js +34 -0
- package/_site/_test/offline-boundary-isolation-test.js +32 -0
- package/_site/_test/orphaned-claim-recovery-test.js +80 -0
- package/_site/_test/p0-data-migration-characterization-test.js +37 -0
- package/_site/_test/p0-e2e-gate-test.js +347 -0
- package/_site/_test/package-boundary-test.js +42 -0
- package/_site/_test/package-startup-test.js +56 -0
- package/_site/_test/packaged-ui-smoke-test.js +79 -0
- package/_site/_test/path-consistency-test.js +151 -0
- package/_site/_test/pending-sweep-test.js +9 -0
- package/_site/_test/post-commit-automation-test.js +87 -0
- package/_site/_test/pr-consumer-contract-test.js +55 -0
- package/_site/_test/project-control-panel-task14-test.js +63 -0
- package/_site/_test/project-delete-recovery-test.js +64 -0
- package/_site/_test/project-goal-editor-test.js +145 -0
- package/_site/_test/project-layout-v2-migration-test.js +127 -0
- package/_site/_test/project-lifecycle-transaction-test.js +106 -0
- package/_site/_test/project-remove-running-guard-test.js +79 -0
- package/_site/_test/project-store-test.js +90 -0
- package/_site/_test/prompt-settings-test.js +115 -0
- package/_site/_test/protected-architecture-gate-test.js +123 -0
- package/_site/_test/refactor-characterization-test.js +36 -0
- package/_site/_test/release-version-sync-test.js +98 -0
- package/_site/_test/requirement-binding-test.js +113 -0
- package/_site/_test/requirement-recorder-test.js +173 -0
- package/_site/_test/run-all-tests.js +156 -0
- package/_site/_test/runtime-endpoint-test.js +64 -0
- package/_site/_test/scanner-test.js +83 -0
- package/_site/_test/server-runtime-migration-safety-test.js +27 -0
- package/_site/_test/server-security-test.js +96 -0
- package/_site/_test/sessions-stream-test.js +92 -0
- package/_site/_test/shared-contracts-test.js +58 -0
- package/_site/_test/simple-import-test.js +97 -0
- package/_site/_test/startup-analysis-disabled-test.js +16 -0
- package/_site/_test/storage-foundation-test.js +78 -0
- package/_site/_test/structured-logger-test.js +101 -0
- package/_site/_test/task15-20-ui-flow-test.js +148 -0
- package/_site/_test/team-knowledge-store-sparse-checkout-test.js +196 -0
- package/_site/_test/team-knowledge-store-test.js +131 -0
- package/_site/_test/tracking-start-test.js +143 -0
- package/_site/_test/ui-i18n-toggle-test.js +114 -0
- package/_site/_test/ui-smoke-test.js +73 -0
- package/_site/_test/v4122-upgrade-data-contract-test.js +56 -0
- package/_site/_test/workbench-permission-test.js +118 -0
- package/_site/_test/workspace-ui-contract-test.js +43 -0
- package/_site/lib/ai-profile-resolver.js +78 -0
- package/_site/lib/ai-vendor-presets.js +83 -0
- package/_site/lib/ai-workspace.js +104 -0
- package/_site/lib/atomic-file.js +204 -0
- package/_site/lib/automation-config.js +140 -0
- package/_site/lib/bridge-adapter.js +256 -0
- package/_site/lib/bridge-consumer-service.js +402 -0
- package/_site/lib/claude-cli-runner.js +1599 -0
- package/_site/lib/commit-conversation-binder.js +246 -0
- package/_site/lib/commit-processing-ledger.js +27 -0
- package/_site/lib/commit-prompt.js +202 -0
- package/_site/lib/commit-reconciler.js +444 -0
- package/_site/lib/context-pack-builder.js +299 -0
- package/_site/lib/contracts.js +279 -0
- package/_site/lib/conversation-exclusions.js +204 -0
- package/_site/lib/conversation-query-service.js +161 -0
- package/_site/lib/conversation-store.js +385 -0
- package/_site/lib/data-dir.js +81 -0
- package/_site/lib/data-state-classifier.js +40 -0
- package/_site/lib/embedding-service.js +85 -0
- package/_site/lib/evidence-bundle.js +228 -0
- package/_site/lib/folder-picker-output.js +24 -0
- package/_site/lib/git-runner.js +62 -0
- package/_site/lib/github-team-store.js +1175 -0
- package/_site/lib/hook-manager.js +202 -0
- package/_site/lib/index-builder.js +157 -0
- package/_site/lib/index-service.js +173 -0
- package/_site/lib/integration-installer.js +907 -0
- package/_site/lib/kb-framework.js +191 -0
- package/_site/lib/kb-validator.js +124 -0
- package/_site/lib/knowledge-db.js +363 -0
- package/_site/lib/knowledge-promotion.js +435 -0
- package/_site/lib/knowledge-retrieval-service.js +401 -0
- package/_site/lib/knowledge-schema.js +121 -0
- package/_site/lib/knowledge-tool-runtime.js +359 -0
- package/_site/lib/legacy-data-manifest.js +26 -0
- package/_site/lib/llm-client.js +173 -0
- package/_site/lib/markdown-knowledge-indexer.js +230 -0
- package/_site/lib/migration-service.js +442 -0
- package/_site/lib/model-context-windows.js +82 -0
- package/_site/lib/module-bridge.js +496 -0
- package/_site/lib/post-commit-automation.js +141 -0
- package/_site/lib/project-lifecycle-service.js +511 -0
- package/_site/lib/project-registry-store.js +129 -0
- package/_site/lib/project-store.js +262 -0
- package/_site/lib/prompt-registry.js +148 -0
- package/_site/lib/requirement-adapters.js +10 -0
- package/_site/lib/requirement-binder.js +112 -0
- package/_site/lib/requirement-recorder.js +278 -0
- package/_site/lib/runtime-endpoint.js +160 -0
- package/_site/lib/scanner.js +298 -0
- package/_site/lib/server-app.js +1520 -0
- package/_site/lib/settings-store.js +113 -0
- package/_site/lib/storage-layout.js +162 -0
- package/_site/lib/structured-logger.js +574 -0
- package/_site/scripts/codex-notify-fanout.cjs +51 -0
- package/_site/scripts/folder-picker.ps1 +156 -0
- package/_site/scripts/hook-trigger.js +156 -0
- package/_site/scripts/sync-release-version.js +158 -0
- package/_site/server.js +12 -0
- package/_site/start.bat +26 -0
- package/_site/stop.bat +11 -0
- package/bin/project-knowledge-integrations.js +241 -0
- package/bin/project-knowledge-kb.js +65 -0
- package/bin/project-knowledge-mcp.js +195 -0
- package/bin/project-knowledge.js +439 -0
- package/claude-prompts.json +21 -0
- package/docs/README.zh-CN.md +175 -0
- package/docs/assets/architecture.svg +182 -0
- package/docs/assets/dashboard.png +0 -0
- package/docs/assets/draft-review.png +0 -0
- package/docs/assets/logo.svg +50 -0
- package/docs/assets/runs-drafts.png +0 -0
- package/docs/assets/settings.png +0 -0
- package/docs/project-registry-schema.md +33 -0
- package/docs/team-knowledge-mode-a-plan.md +73 -0
- package/docs/testing-strategy.md +33 -0
- package/package.json +100 -0
- package/plugins/project-knowledge/.claude-plugin/plugin.json +19 -0
- package/plugins/project-knowledge/.codex-plugin/plugin.json +38 -0
- package/plugins/project-knowledge/.mcp.json +14 -0
- package/plugins/project-knowledge/opencode/project-knowledge.md +3 -0
- package/plugins/project-knowledge/skills/project-knowledge/SKILL.md +28 -0
- package/plugins/project-knowledge/skills/project-knowledge/agents/openai.yaml +11 -0
- package/templates/change.md +30 -0
- package/templates/project-readme.md +52 -0
- package/ui/app.css +58 -0
- package/ui/app.js +607 -0
- package/ui/favicon.svg +38 -0
- package/ui/i18n.js +146 -0
- package/ui/index.html +162 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Run: node _site/_test/index-writer-concurrency-test.js
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { StorageLayout } = require('../lib/storage-layout');
|
|
8
|
+
const { ProjectRegistryStore } = require('../lib/project-registry-store');
|
|
9
|
+
const { ProjectStore } = require('../lib/project-store');
|
|
10
|
+
const { IndexService } = require('../lib/index-service');
|
|
11
|
+
|
|
12
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), `kb-index-writer-${process.pid}-`));
|
|
13
|
+
const layout = new StorageLayout({ dataDir: path.join(temp, 'data') });
|
|
14
|
+
const registry = new ProjectRegistryStore({ layout });
|
|
15
|
+
const projects = new ProjectStore({ layout });
|
|
16
|
+
|
|
17
|
+
async function addProject(projectId) {
|
|
18
|
+
const knowledgePath = path.join(temp, 'knowledge', projectId);
|
|
19
|
+
fs.mkdirSync(knowledgePath, { recursive: true });
|
|
20
|
+
fs.writeFileSync(path.join(knowledgePath, 'README.md'), `# ${projectId}\n\nMarkdown remains authoritative.\n`, 'utf8');
|
|
21
|
+
await projects.create(projectId, {
|
|
22
|
+
displayName: projectId,
|
|
23
|
+
storageName: projectId,
|
|
24
|
+
repoPath: path.join(temp, 'repos', projectId),
|
|
25
|
+
knowledgePath,
|
|
26
|
+
});
|
|
27
|
+
await registry.add(projectId, { displayName: projectId });
|
|
28
|
+
await markDirty(projectId, `commit-${projectId}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function markDirty(projectId, commitSha) {
|
|
32
|
+
await projects.updateState(projectId, state => {
|
|
33
|
+
state.index.dirty = true;
|
|
34
|
+
state.index.sinceCommit = state.index.sinceCommit || commitSha;
|
|
35
|
+
state.index.generation += 1;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
(async () => {
|
|
40
|
+
await registry.initialize();
|
|
41
|
+
await addProject('project-a');
|
|
42
|
+
await addProject('project-b');
|
|
43
|
+
let active = 0;
|
|
44
|
+
let maxActive = 0;
|
|
45
|
+
const calls = [];
|
|
46
|
+
let releaseFirst;
|
|
47
|
+
let firstStarted;
|
|
48
|
+
const firstStart = new Promise(resolve => { firstStarted = resolve; });
|
|
49
|
+
const firstGate = new Promise(resolve => { releaseFirst = resolve; });
|
|
50
|
+
const adapter = {
|
|
51
|
+
async indexProject(input) {
|
|
52
|
+
active += 1;
|
|
53
|
+
maxActive = Math.max(maxActive, active);
|
|
54
|
+
calls.push({ projectId: input.projectId, generation: input.generation });
|
|
55
|
+
if (input.projectId === 'project-a' && calls.filter(call => call.projectId === 'project-a').length === 1) {
|
|
56
|
+
firstStarted();
|
|
57
|
+
await firstGate;
|
|
58
|
+
}
|
|
59
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
60
|
+
active -= 1;
|
|
61
|
+
return { indexed: true };
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const service = new IndexService({ layout, registryStore: registry, projectStore: projects, adapter });
|
|
65
|
+
const firstA = service.enqueue('project-a');
|
|
66
|
+
await firstStart;
|
|
67
|
+
await markDirty('project-a', 'commit-new-during-index');
|
|
68
|
+
const coalescedA = service.enqueue('project-a');
|
|
69
|
+
const firstB = service.enqueue('project-b');
|
|
70
|
+
releaseFirst();
|
|
71
|
+
await Promise.all([firstA, coalescedA, firstB]);
|
|
72
|
+
assert.strictEqual(maxActive, 1, 'all index mutations must share one process-global writer');
|
|
73
|
+
assert.strictEqual(calls.filter(call => call.projectId === 'project-a').length, 2, 'new generation during an old write must be indexed again');
|
|
74
|
+
assert.strictEqual(projects.readState('project-a').index.dirty, false);
|
|
75
|
+
assert.strictEqual(projects.readState('project-b').index.dirty, false);
|
|
76
|
+
const sourceManifest = JSON.parse(fs.readFileSync(layout.getRuntimePath('index-sources', 'project-a.json'), 'utf8'));
|
|
77
|
+
assert.strictEqual(sourceManifest.schema, 'knowledge-index-source-manifest/v1');
|
|
78
|
+
assert(sourceManifest.entries['README.md'].documentHash, 'successful indexing must persist the authoritative source document hash');
|
|
79
|
+
assert.strictEqual(sourceManifest.generation, projects.readState('project-a').index.generation);
|
|
80
|
+
|
|
81
|
+
await markDirty('project-b', 'commit-index-failure');
|
|
82
|
+
let fail = true;
|
|
83
|
+
const retryService = new IndexService({
|
|
84
|
+
layout,
|
|
85
|
+
registryStore: registry,
|
|
86
|
+
projectStore: projects,
|
|
87
|
+
adapter: {
|
|
88
|
+
indexProject: async () => {
|
|
89
|
+
if (fail) { fail = false; throw new Error('injected index failure'); }
|
|
90
|
+
return { indexed: true };
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
const failed = await retryService.enqueue('project-b');
|
|
95
|
+
assert.strictEqual(failed.ok, false);
|
|
96
|
+
const failedState = projects.readState('project-b');
|
|
97
|
+
assert.strictEqual(failedState.index.dirty, true, 'index failure must keep dirty state');
|
|
98
|
+
assert(failedState.index.lastError && failedState.index.lastError.message.includes('injected'));
|
|
99
|
+
assert(fs.existsSync(path.join(projects.readConfig('project-b').knowledgePath, 'README.md')), 'index failure must not remove truthful Markdown');
|
|
100
|
+
const retried = await retryService.enqueue('project-b');
|
|
101
|
+
assert.strictEqual(retried.ok, true);
|
|
102
|
+
assert.strictEqual(projects.readState('project-b').index.dirty, false);
|
|
103
|
+
|
|
104
|
+
const indexPath = layout.getIndexPath();
|
|
105
|
+
fs.mkdirSync(indexPath, { recursive: true });
|
|
106
|
+
fs.writeFileSync(path.join(indexPath, 'marker.txt'), 'old-index', 'utf8');
|
|
107
|
+
let validationOk = false;
|
|
108
|
+
const rebuildService = new IndexService({
|
|
109
|
+
layout,
|
|
110
|
+
registryStore: registry,
|
|
111
|
+
projectStore: projects,
|
|
112
|
+
adapter: {
|
|
113
|
+
indexProject: async () => ({}),
|
|
114
|
+
buildFull: async ({ targetPath }) => {
|
|
115
|
+
fs.mkdirSync(targetPath, { recursive: true });
|
|
116
|
+
fs.writeFileSync(path.join(targetPath, 'marker.txt'), 'new-index', 'utf8');
|
|
117
|
+
},
|
|
118
|
+
validateIndex: async targetPath => ({ ok: validationOk, marker: fs.readFileSync(path.join(targetPath, 'marker.txt'), 'utf8') }),
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
await assert.rejects(rebuildService.fullRebuild(), error => error.code === 'DATA_CORRUPT');
|
|
122
|
+
assert.strictEqual(fs.readFileSync(path.join(indexPath, 'marker.txt'), 'utf8'), 'old-index', 'failed rebuild validation must retain the live DB');
|
|
123
|
+
validationOk = true;
|
|
124
|
+
const rebuilt = await rebuildService.fullRebuild();
|
|
125
|
+
assert.strictEqual(fs.readFileSync(path.join(indexPath, 'marker.txt'), 'utf8'), 'new-index');
|
|
126
|
+
assert(rebuilt.backup && fs.readFileSync(path.join(rebuilt.backup, 'marker.txt'), 'utf8') === 'old-index', 'successful swap should retain a recovery copy of the old DB');
|
|
127
|
+
|
|
128
|
+
await IndexService.flush();
|
|
129
|
+
console.log('index-writer-concurrency-test PASS');
|
|
130
|
+
})().catch(error => {
|
|
131
|
+
console.error(error.stack || error.message);
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
}).finally(() => {
|
|
134
|
+
fs.rmSync(temp, { recursive: true, force: true });
|
|
135
|
+
});
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// Run: node _site/_test/integration-adapters-test.js
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { spawnSync } = require('child_process');
|
|
7
|
+
const {
|
|
8
|
+
IntegrationManager,
|
|
9
|
+
removeOpenCodeMcpConfig,
|
|
10
|
+
removeOpenCodeInstructionConfig,
|
|
11
|
+
} = require('../lib/integration-installer');
|
|
12
|
+
|
|
13
|
+
const ROOT = path.resolve(__dirname, '..', '..');
|
|
14
|
+
const TEMP = fs.mkdtempSync(path.join(os.tmpdir(), `project-knowledge-integrations-${process.pid}-`));
|
|
15
|
+
|
|
16
|
+
function assert(condition, message) {
|
|
17
|
+
if (!condition) throw new Error(message);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function readJson(filePath) {
|
|
21
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function main() {
|
|
25
|
+
const packageInfo = readJson(path.join(ROOT, 'package.json'));
|
|
26
|
+
const pluginRoot = path.join(ROOT, 'plugins', 'project-knowledge');
|
|
27
|
+
const claudeManifest = readJson(path.join(pluginRoot, '.claude-plugin', 'plugin.json'));
|
|
28
|
+
const codexManifest = readJson(path.join(pluginRoot, '.codex-plugin', 'plugin.json'));
|
|
29
|
+
const mcpManifest = readJson(path.join(pluginRoot, '.mcp.json'));
|
|
30
|
+
const claudeMarketplace = readJson(path.join(ROOT, '.claude-plugin', 'marketplace.json'));
|
|
31
|
+
const codexMarketplace = readJson(path.join(ROOT, '.agents', 'plugins', 'marketplace.json'));
|
|
32
|
+
const skillPath = path.join(pluginRoot, 'skills', 'project-knowledge', 'SKILL.md');
|
|
33
|
+
const skill = fs.readFileSync(skillPath, 'utf8');
|
|
34
|
+
|
|
35
|
+
assert(claudeManifest.version === packageInfo.version, 'Claude plugin version should match the npm package');
|
|
36
|
+
assert(codexManifest.version === packageInfo.version, 'Codex plugin version should match the npm package');
|
|
37
|
+
assert(claudeMarketplace.plugins[0].version === packageInfo.version, 'Claude marketplace version should match the npm package');
|
|
38
|
+
assert(codexMarketplace.name === 'project-knowledge', 'Codex marketplace should have a stable public name');
|
|
39
|
+
assert(codexMarketplace.plugins[0].source.path === './plugins/project-knowledge', 'Codex marketplace should point at the shared plugin');
|
|
40
|
+
assert(mcpManifest.mcpServers['project-knowledge'].args.includes(`project-knowledge@${packageInfo.version}`), 'plugin MCP should pin the matching package version');
|
|
41
|
+
assert(!skill.includes('[TODO:'), 'bundled Skill should not contain scaffold placeholders');
|
|
42
|
+
assert(skill.includes('project_knowledge_resolve'), 'bundled Skill should teach the resolve-first workflow');
|
|
43
|
+
assert(skill.includes('project_knowledge_record_requirement'), 'bundled Skill should document the explicit supplemental adapter');
|
|
44
|
+
assert(skill.includes('only when the user explicitly requests supplemental capture'), 'bundled Skill must not make cooperative requirement recording mandatory');
|
|
45
|
+
assert(!/Before implementing a user request, call `project_knowledge_record_requirement`/.test(skill), 'automatic capture must remain primary');
|
|
46
|
+
|
|
47
|
+
const calls = [];
|
|
48
|
+
const homeDir = path.join(TEMP, 'home');
|
|
49
|
+
const manager = new IntegrationManager({
|
|
50
|
+
rootDir: ROOT,
|
|
51
|
+
homeDir,
|
|
52
|
+
env: {},
|
|
53
|
+
commandResolver: name => name,
|
|
54
|
+
runner: (command, args) => {
|
|
55
|
+
calls.push({ command, args });
|
|
56
|
+
return { status: 0, stdout: '', stderr: '' };
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const openCodeResult = await manager.operate('install', ['opencode']);
|
|
60
|
+
assert(openCodeResult[0].ok, 'OpenCode installation should complete');
|
|
61
|
+
assert(fs.existsSync(path.join(homeDir, '.config', 'opencode', 'skills', 'project-knowledge', 'SKILL.md')), 'OpenCode should receive the global Skill');
|
|
62
|
+
const installedInstruction = path.join(homeDir, '.config', 'opencode', 'instructions', 'project-knowledge.md');
|
|
63
|
+
assert(fs.existsSync(installedInstruction), 'OpenCode should receive the global Instructions file');
|
|
64
|
+
const installedConfig = fs.readFileSync(path.join(homeDir, '.config', 'opencode', 'opencode.jsonc'), 'utf8');
|
|
65
|
+
assert(installedConfig.includes(installedInstruction.replace(/\\/g, '\\\\')), 'OpenCode config should reference the installed Instructions file');
|
|
66
|
+
const openCodeCall = calls.find(call => call.command === 'opencode');
|
|
67
|
+
assert(openCodeCall?.args.join(' ') === `mcp add project-knowledge -- npx -y --package project-knowledge@${packageInfo.version} project-knowledge-mcp`, 'OpenCode should receive the versioned MCP command');
|
|
68
|
+
|
|
69
|
+
const configDir = path.join(TEMP, 'opencode-config');
|
|
70
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
71
|
+
const configPath = path.join(configDir, 'opencode.jsonc');
|
|
72
|
+
fs.writeFileSync(configPath, `{
|
|
73
|
+
// Keep this user comment.
|
|
74
|
+
"instructions": [
|
|
75
|
+
"C:\\\\keep\\\\team-rules.md",
|
|
76
|
+
"${path.join(configDir, 'instructions', 'project-knowledge.md').replace(/\\/g, '\\\\')}"
|
|
77
|
+
],
|
|
78
|
+
"mcp": {
|
|
79
|
+
"project-knowledge": { "type": "local", "command": ["npx"] },
|
|
80
|
+
"other": { "type": "remote", "url": "https://example.test/mcp" }
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
`, 'utf8');
|
|
84
|
+
assert(removeOpenCodeMcpConfig(configDir), 'OpenCode uninstall should remove its MCP entry');
|
|
85
|
+
const updatedConfig = fs.readFileSync(configPath, 'utf8');
|
|
86
|
+
assert(updatedConfig.includes('Keep this user comment'), 'OpenCode config comments should be preserved');
|
|
87
|
+
assert(updatedConfig.includes('"other"'), 'uninstall should preserve unrelated MCP servers');
|
|
88
|
+
assert(!updatedConfig.includes('"project-knowledge"'), 'uninstall should remove only the Project Knowledge MCP');
|
|
89
|
+
const instructionPath = path.join(configDir, 'instructions', 'project-knowledge.md');
|
|
90
|
+
assert(removeOpenCodeInstructionConfig(configDir, instructionPath), 'OpenCode uninstall should remove its Instructions reference');
|
|
91
|
+
const instructionUpdated = fs.readFileSync(configPath, 'utf8');
|
|
92
|
+
assert(instructionUpdated.includes('team-rules.md'), 'uninstall should preserve unrelated OpenCode instructions');
|
|
93
|
+
assert(!instructionUpdated.includes(instructionPath.replace(/\\/g, '\\\\')), 'uninstall should remove only its Instructions reference');
|
|
94
|
+
|
|
95
|
+
const claudeCalls = [];
|
|
96
|
+
const claudeManager = new IntegrationManager({
|
|
97
|
+
rootDir: ROOT,
|
|
98
|
+
commandResolver: name => name,
|
|
99
|
+
runner: (command, args) => {
|
|
100
|
+
claudeCalls.push({ command, args });
|
|
101
|
+
if (args.join(' ') === 'plugin marketplace list --json') return { status: 0, stdout: '[]', stderr: '' };
|
|
102
|
+
if (args.join(' ') === 'plugin list --json') return { status: 0, stdout: '[]', stderr: '' };
|
|
103
|
+
return { status: 0, stdout: '', stderr: '' };
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
const claudeResult = await claudeManager.operate('install', ['claude'], { scope: 'user' });
|
|
107
|
+
assert(claudeResult[0].ok, 'Claude Code installation should complete');
|
|
108
|
+
assert(claudeCalls.some(call => call.args.join(' ') === 'plugin marketplace add SanQianX/project-knowledge-base'), 'Claude Code should register the GitHub marketplace');
|
|
109
|
+
assert(claudeCalls.some(call => call.args.join(' ') === 'plugin install project-knowledge@project-knowledge --scope user'), 'Claude Code should install the native plugin');
|
|
110
|
+
|
|
111
|
+
const codexCalls = [];
|
|
112
|
+
const codexManager = new IntegrationManager({
|
|
113
|
+
rootDir: ROOT,
|
|
114
|
+
commandResolver: name => name,
|
|
115
|
+
runner: (command, args) => {
|
|
116
|
+
codexCalls.push({ command, args });
|
|
117
|
+
if (args.join(' ') === 'plugin marketplace list') {
|
|
118
|
+
return { status: 0, stdout: `MARKETPLACE ROOT\nproject-knowledge ${ROOT}\n`, stderr: '' };
|
|
119
|
+
}
|
|
120
|
+
if (args.join(' ') === 'plugin list --json') {
|
|
121
|
+
return {
|
|
122
|
+
status: 0,
|
|
123
|
+
stdout: JSON.stringify({ installed: [{ pluginId: 'project-knowledge@project-knowledge' }] }),
|
|
124
|
+
stderr: '',
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return { status: 0, stdout: '', stderr: '' };
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
const codexResult = await codexManager.operate('update', ['codex']);
|
|
131
|
+
assert(codexResult[0].ok, 'Codex update should complete');
|
|
132
|
+
assert(codexCalls.some(call => call.args.join(' ') === 'plugin marketplace upgrade project-knowledge'), 'Codex should refresh its marketplace');
|
|
133
|
+
assert(codexCalls.some(call => call.args.join(' ') === 'plugin remove project-knowledge@project-knowledge'), 'Codex should remove the cached plugin during update');
|
|
134
|
+
assert(codexCalls.some(call => call.args.join(' ') === 'plugin add project-knowledge@project-knowledge'), 'Codex should install the refreshed plugin');
|
|
135
|
+
|
|
136
|
+
const chainedCodexConfig = path.join(TEMP, 'codex-config.toml');
|
|
137
|
+
const oldNotifier = Buffer.from(JSON.stringify(['node', 'C:/existing-notify.js'])).toString('base64');
|
|
138
|
+
fs.writeFileSync(chainedCodexConfig, `notify = ["node", "C:/tools/devtask-radar/connectors/codex/notify-hook.js", "--previous-notify", "${oldNotifier}"]\n`, 'utf8');
|
|
139
|
+
const chainedManager = new IntegrationManager({
|
|
140
|
+
rootDir: ROOT,
|
|
141
|
+
homeDir: path.join(TEMP, 'codex-home'),
|
|
142
|
+
bridgeHomeDir: path.join(TEMP, 'bridge-home'),
|
|
143
|
+
codexConfigFile: chainedCodexConfig,
|
|
144
|
+
});
|
|
145
|
+
const chained = await chainedManager.installCaptureCodex();
|
|
146
|
+
assert(chained.installed && !chained.conflict, 'a compatible DevTask Radar notifier should chain Bridge instead of blocking capture');
|
|
147
|
+
const chainedConfig = JSON.parse(fs.readFileSync(chainedCodexConfig, 'utf8').replace(/^\s*notify\s*=\s*/, '').trim());
|
|
148
|
+
const nextIndex = chainedConfig.indexOf('--next-base64');
|
|
149
|
+
assert(nextIndex >= 0, 'compatible notifier chain should append a downstream Bridge notifier');
|
|
150
|
+
const nextNotify = JSON.parse(Buffer.from(chainedConfig[nextIndex + 1], 'base64').toString('utf8'));
|
|
151
|
+
assert(nextNotify.join(' ').includes('bridge-hook.cjs'), 'downstream notifier must be the Bridge shim');
|
|
152
|
+
const chainedStatus = await chainedManager.statusCaptureCodex();
|
|
153
|
+
assert(chainedStatus.installed && !chainedStatus.conflict, 'status should recognize the compatible chained notifier');
|
|
154
|
+
|
|
155
|
+
const nestedCodexConfig = path.join(TEMP, 'nested-codex-config.toml');
|
|
156
|
+
const nestedDevTask = ['node', 'C:/tools/devtask-radar/connectors/codex/notify-hook.js', '--next-base64', oldNotifier];
|
|
157
|
+
fs.writeFileSync(nestedCodexConfig, `notify = ["C:/runtime/codex-computer-use.exe", "turn-ended", "--previous-notify", ${JSON.stringify(JSON.stringify(nestedDevTask))}]\n`, 'utf8');
|
|
158
|
+
const nestedManager = new IntegrationManager({
|
|
159
|
+
rootDir: ROOT,
|
|
160
|
+
homeDir: path.join(TEMP, 'nested-codex-home'),
|
|
161
|
+
bridgeHomeDir: path.join(TEMP, 'nested-bridge-home'),
|
|
162
|
+
codexConfigFile: nestedCodexConfig,
|
|
163
|
+
});
|
|
164
|
+
const nested = await nestedManager.installCaptureCodex();
|
|
165
|
+
assert(nested.installed && !nested.conflict, 'a nested DevTask Radar notifier should be preserved through the fan-out wrapper');
|
|
166
|
+
const nestedConfig = JSON.parse(fs.readFileSync(nestedCodexConfig, 'utf8').replace(/^\s*notify\s*=\s*/, '').trim());
|
|
167
|
+
assert(nestedConfig.join(' ').includes('codex-notify-fanout.cjs'), 'nested notifier chain should use the Project Knowledge fan-out wrapper');
|
|
168
|
+
const nestedStatus = await nestedManager.statusCaptureCodex();
|
|
169
|
+
assert(nestedStatus.installed && !nestedStatus.conflict, 'status should recognize the managed nested fan-out wrapper');
|
|
170
|
+
|
|
171
|
+
// Codex Desktop computer-use wraps the existing notifier as a JSON array in
|
|
172
|
+
// --previous-notify. The managed fan-out is still installed and must not be
|
|
173
|
+
// misreported as a third-party conflict or wrapped a second time.
|
|
174
|
+
const desktopWrappedConfig = path.join(TEMP, 'desktop-wrapped-codex-config.toml');
|
|
175
|
+
const desktopWrappedArgs = ['C:/runtime/codex-computer-use.exe', 'turn-ended', '--previous-notify', JSON.stringify(nestedConfig)];
|
|
176
|
+
fs.writeFileSync(desktopWrappedConfig, `notify = ${JSON.stringify(desktopWrappedArgs)}\n`, 'utf8');
|
|
177
|
+
const desktopWrappedManager = new IntegrationManager({
|
|
178
|
+
rootDir: ROOT,
|
|
179
|
+
homeDir: path.join(TEMP, 'desktop-wrapped-codex-home'),
|
|
180
|
+
bridgeHomeDir: path.join(TEMP, 'nested-bridge-home'),
|
|
181
|
+
codexConfigFile: desktopWrappedConfig,
|
|
182
|
+
});
|
|
183
|
+
const desktopWrappedStatus = await desktopWrappedManager.statusCaptureCodex();
|
|
184
|
+
assert(desktopWrappedStatus.installed && !desktopWrappedStatus.conflict,
|
|
185
|
+
'Codex Desktop outer wrapper should preserve managed capture health');
|
|
186
|
+
const beforeDesktopInstall = fs.readFileSync(desktopWrappedConfig, 'utf8');
|
|
187
|
+
const desktopWrappedInstall = await desktopWrappedManager.installCaptureCodex();
|
|
188
|
+
assert(desktopWrappedInstall.installed && !desktopWrappedInstall.conflict,
|
|
189
|
+
'one-click repair should recognize the nested managed fan-out');
|
|
190
|
+
assert(fs.readFileSync(desktopWrappedConfig, 'utf8') === beforeDesktopInstall,
|
|
191
|
+
'healthy Codex Desktop wrapper must remain byte-for-byte unchanged');
|
|
192
|
+
|
|
193
|
+
const bridgeOnlyConfig = path.join(TEMP, 'bridge-only-codex-config.toml');
|
|
194
|
+
const bridgeOnlyManager = new IntegrationManager({
|
|
195
|
+
rootDir: ROOT,
|
|
196
|
+
homeDir: path.join(TEMP, 'bridge-only-codex-home'),
|
|
197
|
+
bridgeHomeDir: path.join(TEMP, 'bridge-only-bridge-home'),
|
|
198
|
+
codexConfigFile: bridgeOnlyConfig,
|
|
199
|
+
});
|
|
200
|
+
const bridgeOnly = await bridgeOnlyManager.installCaptureCodex();
|
|
201
|
+
assert(bridgeOnly.installed && !bridgeOnly.conflict, 'a fresh Codex install should use the payload-preserving fan-out wrapper');
|
|
202
|
+
const bridgeOnlyArgs = JSON.parse(fs.readFileSync(bridgeOnlyConfig, 'utf8').replace(/^\s*notify\s*=\s*/, '').trim());
|
|
203
|
+
assert(bridgeOnlyArgs.join(' ').includes('codex-notify-fanout.cjs'), 'fresh Codex install should use the Project Knowledge fan-out wrapper');
|
|
204
|
+
|
|
205
|
+
const integrationLogs = [];
|
|
206
|
+
const failingManager = new IntegrationManager({
|
|
207
|
+
rootDir: ROOT,
|
|
208
|
+
commandResolver: name => name,
|
|
209
|
+
runner: () => ({ status: 9, stdout: '', stderr: 'failure includes sk-do-not-log' }),
|
|
210
|
+
logger: {
|
|
211
|
+
info: async (event, message, payload) => integrationLogs.push({ event, message, payload }),
|
|
212
|
+
error: async (event, message, payload) => integrationLogs.push({ event, message, payload }),
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
const failedIntegration = await failingManager.operate('install', ['claude']);
|
|
216
|
+
assert(!failedIntegration[0].ok, 'integration command failure should remain visible to the caller');
|
|
217
|
+
assert(integrationLogs.some(entry => entry.event === 'integration.command_started'));
|
|
218
|
+
assert(integrationLogs.some(entry => entry.event === 'integration.command_failed' && entry.payload.error.code === 'INTEGRATION_COMMAND_FAILED'));
|
|
219
|
+
assert(!JSON.stringify(integrationLogs).includes('sk-do-not-log'), 'integration logs must hash command output instead of recording it');
|
|
220
|
+
|
|
221
|
+
const routed = spawnSync(process.execPath, [
|
|
222
|
+
path.join(ROOT, 'bin', 'project-knowledge.js'),
|
|
223
|
+
'install',
|
|
224
|
+
'--ide',
|
|
225
|
+
'opencode',
|
|
226
|
+
'--dry-run',
|
|
227
|
+
], {
|
|
228
|
+
cwd: ROOT,
|
|
229
|
+
encoding: 'utf8',
|
|
230
|
+
windowsHide: true,
|
|
231
|
+
});
|
|
232
|
+
assert(routed.status === 0, `main CLI should route integration commands: ${routed.stderr}`);
|
|
233
|
+
assert(routed.stdout.includes('project-knowledge-mcp'), 'routed dry-run should show the MCP installation');
|
|
234
|
+
|
|
235
|
+
console.log('integration-adapters-test PASS');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
main().catch(error => {
|
|
239
|
+
console.error(error.stack || error.message);
|
|
240
|
+
process.exitCode = 1;
|
|
241
|
+
}).finally(() => {
|
|
242
|
+
fs.rmSync(TEMP, { recursive: true, force: true });
|
|
243
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Run: node _site/_test/integration-capture-setup-test.js
|
|
2
|
+
//
|
|
3
|
+
// T18 gates (INSTALL-001/002/003): one Project-Knowledge setup installs
|
|
4
|
+
// Knowledge Integration + Development Capture without opening any client UI;
|
|
5
|
+
// per-client status reports the two capabilities separately; third-party
|
|
6
|
+
// config is preserved; Codex notify conflicts are reported, not overwritten;
|
|
7
|
+
// connector uninstall keeps the host Bridge consumer until a global disable.
|
|
8
|
+
|
|
9
|
+
const assert = require('assert');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const { IntegrationManager } = require('../lib/integration-installer');
|
|
14
|
+
const { createBridge } = require('@sanqianx/ai-coding-event-bridge');
|
|
15
|
+
|
|
16
|
+
const ROOT = path.resolve(__dirname, '..', '..');
|
|
17
|
+
const TEMP = fs.mkdtempSync(path.join(os.tmpdir(), `pk-integration-capture-${process.pid}-`));
|
|
18
|
+
const homeDir = path.join(TEMP, 'home');
|
|
19
|
+
const bridgeHome = path.join(TEMP, 'bridge-home');
|
|
20
|
+
const claudeSettings = path.join(TEMP, 'claude-settings.json');
|
|
21
|
+
const codexConfig = path.join(TEMP, 'codex-config.toml');
|
|
22
|
+
const openCodePlugins = path.join(TEMP, 'opencode-plugins');
|
|
23
|
+
|
|
24
|
+
function makeManager() {
|
|
25
|
+
return new IntegrationManager({
|
|
26
|
+
rootDir: ROOT,
|
|
27
|
+
homeDir,
|
|
28
|
+
env: {},
|
|
29
|
+
commandResolver: name => name,
|
|
30
|
+
runner: (command, args) => ({ status: 0, stdout: '', stderr: '' }),
|
|
31
|
+
bridgeHomeDir: bridgeHome,
|
|
32
|
+
claudeSettingsFile: claudeSettings,
|
|
33
|
+
codexConfigFile: codexConfig,
|
|
34
|
+
openCodePluginsDir: openCodePlugins,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function main() {
|
|
39
|
+
const manager = makeManager();
|
|
40
|
+
|
|
41
|
+
// Third-party entries pre-exist; they must survive every operation.
|
|
42
|
+
fs.mkdirSync(path.dirname(claudeSettings), { recursive: true });
|
|
43
|
+
fs.writeFileSync(claudeSettings, JSON.stringify({
|
|
44
|
+
model: 'sonnet',
|
|
45
|
+
hooks: { Stop: [{ matcher: '*', hooks: [{ type: 'command', command: 'node /somewhere/notify-user.js' }] }] },
|
|
46
|
+
}));
|
|
47
|
+
fs.mkdirSync(path.dirname(codexConfig), { recursive: true });
|
|
48
|
+
fs.writeFileSync(codexConfig, 'model = "gpt-5"\nnotify = ["python", "C:/tools/my-notify.py"]\n');
|
|
49
|
+
fs.mkdirSync(openCodePlugins, { recursive: true });
|
|
50
|
+
fs.writeFileSync(path.join(openCodePlugins, 'my-own-plugin.js'), '// third party\n');
|
|
51
|
+
|
|
52
|
+
// GATE INSTALL-001: one setup action, both capabilities, no client UI.
|
|
53
|
+
const installed = await manager.installAll({ clients: ['claude', 'codex', 'opencode'] });
|
|
54
|
+
assert.strictEqual(installed.bridge.ok, true, 'host Bridge consumer registered once');
|
|
55
|
+
assert.strictEqual(installed.bridge.consumerName, 'project-knowledge');
|
|
56
|
+
for (const entry of installed.clients) {
|
|
57
|
+
assert.strictEqual(entry.knowledgeIntegration.ok, true, `${entry.client} knowledge integration installs`);
|
|
58
|
+
const expectedCapture = entry.client === 'codex' ? 'conflict' : 'installed';
|
|
59
|
+
assert.strictEqual(entry.developmentCapture.state, expectedCapture, `${entry.client} development capture state`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Claude managed hooks written programmatically into the user config.
|
|
63
|
+
const settings = JSON.parse(fs.readFileSync(claudeSettings, 'utf8'));
|
|
64
|
+
const managedClaude = settings.hooks.UserPromptSubmit.some(group => group.hooks.some(hook => String(hook.command).includes('bridge-hook.cjs')));
|
|
65
|
+
assert.strictEqual(managedClaude, true, 'managed Bridge hooks written to Claude user config without any interactive Claude step');
|
|
66
|
+
assert.strictEqual(settings.hooks.Stop.some(group => group.hooks.some(hook => hook.command === 'node /somewhere/notify-user.js')), true, 'Claude third-party hook preserved');
|
|
67
|
+
|
|
68
|
+
// GATE INSTALL-002: Codex third-party notify conflict reported, not overwritten.
|
|
69
|
+
const codexEntry = installed.clients.find(entry => entry.client === 'codex');
|
|
70
|
+
assert.strictEqual(codexEntry.developmentCapture.state, 'conflict', 'Codex reports the third-party notify conflict');
|
|
71
|
+
assert.strictEqual(codexEntry.knowledgeIntegration.ok, true, 'Knowledge Integration stays independent of the Codex capture conflict');
|
|
72
|
+
assert(fs.readFileSync(codexConfig, 'utf8').includes('my-notify.py'), 'third-party notifier never overwritten');
|
|
73
|
+
|
|
74
|
+
// OpenCode managed plugin installed alongside third-party files.
|
|
75
|
+
assert(fs.existsSync(path.join(openCodePlugins, 'ai-coding-event-bridge.js')), 'managed OpenCode plugin written');
|
|
76
|
+
assert(fs.existsSync(path.join(openCodePlugins, 'my-own-plugin.js')), 'third-party plugin preserved');
|
|
77
|
+
|
|
78
|
+
// Status reports the two capabilities separately.
|
|
79
|
+
const status = await manager.statusAll({ clients: ['claude', 'codex', 'opencode'] });
|
|
80
|
+
assert.strictEqual(status.bridge.consumerRegistered, true);
|
|
81
|
+
assert.strictEqual(status.bridge.bridgeHealthy, true);
|
|
82
|
+
const claudeStatus = status.clients.find(entry => entry.client === 'claude');
|
|
83
|
+
assert.strictEqual(claudeStatus.developmentCapture.installed, true);
|
|
84
|
+
const codexStatus = status.clients.find(entry => entry.client === 'codex');
|
|
85
|
+
assert.strictEqual(codexStatus.developmentCapture.conflict, true, 'conflict surfaces in status');
|
|
86
|
+
assert.ok(Number.isInteger(status.bridge.health.lastSequence), 'bridge health fields available for the UI');
|
|
87
|
+
|
|
88
|
+
// GATE INSTALL-003: removing one connector keeps the host consumer.
|
|
89
|
+
await manager.uninstallCaptureClaude({});
|
|
90
|
+
const facade = createBridge({ homeDir: bridgeHome });
|
|
91
|
+
assert.strictEqual(Boolean(await facade.getConsumer('project-knowledge')), true, 'consumer survives a single connector uninstall');
|
|
92
|
+
const settingsAfterClaude = JSON.parse(fs.readFileSync(claudeSettings, 'utf8'));
|
|
93
|
+
assert.strictEqual(settingsAfterClaude.hooks.UserPromptSubmit, undefined, 'managed Claude hook removed');
|
|
94
|
+
assert.strictEqual(settingsAfterClaude.hooks.Stop[0].hooks[0].command, 'node /somewhere/notify-user.js', 'third-party hook still intact');
|
|
95
|
+
|
|
96
|
+
// Another registered consumer stays untouched by a global disable.
|
|
97
|
+
await facade.registerConsumer('devtask-radar');
|
|
98
|
+
const disabled = await manager.disableAllCapture({ clients: ['claude', 'codex', 'opencode'] });
|
|
99
|
+
assert.strictEqual(disabled.consumer.ok, true, 'global disable unregisters the project-knowledge consumer');
|
|
100
|
+
const consumers = await facade.listConsumers();
|
|
101
|
+
assert.deepStrictEqual(consumers.map(consumer => consumer.name), ['devtask-radar'], 'other consumers remain');
|
|
102
|
+
assert(!fs.existsSync(path.join(openCodePlugins, 'ai-coding-event-bridge.js')), 'managed plugin removed');
|
|
103
|
+
assert(fs.existsSync(path.join(openCodePlugins, 'my-own-plugin.js')), 'third-party plugin survives global disable');
|
|
104
|
+
|
|
105
|
+
console.log('integration-capture-setup-test PASS');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = main();
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// _site/_test/integration-surface-coverage-test.js
|
|
2
|
+
//
|
|
3
|
+
// Combined surface-coverage test for T15–T19 + T13 GOAL.md file scope.
|
|
4
|
+
// Each case exercises the public API or current state, without modifying
|
|
5
|
+
// production code (the underlying primitives already exist).
|
|
6
|
+
|
|
7
|
+
const assert = require('assert');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const os = require('os');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const { spawnSync } = require('child_process');
|
|
12
|
+
const { spawnServer } = require('./helpers/spawn-server');
|
|
13
|
+
|
|
14
|
+
const ROOT = path.resolve(__dirname, '..', '..');
|
|
15
|
+
const sitePort = 8020 + (process.pid % 200);
|
|
16
|
+
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-surface-' + process.pid + '-'));
|
|
17
|
+
const repo = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-surface-repo-' + process.pid + '-'));
|
|
18
|
+
|
|
19
|
+
function git(args) {
|
|
20
|
+
const result = spawnSync('git', ['-C', repo, ...args], {
|
|
21
|
+
encoding: 'utf8', windowsHide: true,
|
|
22
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
23
|
+
});
|
|
24
|
+
if (result.status !== 0) throw new Error(result.stderr || `git ${args.join(' ')} failed: ${result.status}`);
|
|
25
|
+
return String(result.stdout || '').trim();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function serverFetch(url, init, timeoutMs = 10000) {
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
31
|
+
try {
|
|
32
|
+
const response = await fetch(url, { ...init, signal: controller.signal });
|
|
33
|
+
const text = await response.text();
|
|
34
|
+
return { status: response.status, body: text ? JSON.parse(text) : {} };
|
|
35
|
+
} finally {
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
(async () => {
|
|
41
|
+
git(['init', '-q', '-b', 'main']);
|
|
42
|
+
git(['config', 'user.email', 'surface@example.local']);
|
|
43
|
+
git(['config', 'user.name', 'Surface']);
|
|
44
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# surface\n');
|
|
45
|
+
git(['add', 'README.md']);
|
|
46
|
+
git(['commit', '-q', '-m', 'baseline']);
|
|
47
|
+
const knowledgeRoot = path.join(dataDir, 'knowledge');
|
|
48
|
+
fs.mkdirSync(knowledgeRoot, { recursive: true });
|
|
49
|
+
const server = spawnServer({
|
|
50
|
+
root: ROOT, port: sitePort, dataDir, tag: 'surface',
|
|
51
|
+
extraEnv: { KB_AUTOMATION_FAKE_CLAUDE: '1', KB_EMBEDDING_FAKE: '1', KB_SKIP_MIGRATION: '1' },
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
55
|
+
try { const r = await serverFetch(`http://127.0.0.1:${sitePort}/api/health`); if (r.body.ok) break; } catch {}
|
|
56
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
57
|
+
}
|
|
58
|
+
await serverFetch(`http://127.0.0.1:${sitePort}/api/settings`, {
|
|
59
|
+
method: 'PATCH', headers: { 'content-type': 'application/json' },
|
|
60
|
+
body: JSON.stringify({ knowledge: { rootPath: knowledgeRoot } }),
|
|
61
|
+
});
|
|
62
|
+
await serverFetch(`http://127.0.0.1:${sitePort}/api/ai-profiles`, {
|
|
63
|
+
method: 'PUT', headers: { 'content-type': 'application/json' },
|
|
64
|
+
body: JSON.stringify({
|
|
65
|
+
schema: 'ai-profiles/v1', defaultProfileId: 'fake',
|
|
66
|
+
profiles: [{ id: 'fake', name: 'Fake', enabled: true, vendor: 'anthropic', model: 'fake', apiKeyUpdate: { mode: 'replace', value: 'k' } }],
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
const importR = await serverFetch(`http://127.0.0.1:${sitePort}/api/projects/import`, {
|
|
70
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
71
|
+
body: JSON.stringify({ localPath: repo, aiProfileId: 'fake' }),
|
|
72
|
+
});
|
|
73
|
+
assert.strictEqual(importR.status, 201, JSON.stringify(importR.body));
|
|
74
|
+
const projectId = importR.body.projectId;
|
|
75
|
+
|
|
76
|
+
// T15: GitHub account/provider status surface.
|
|
77
|
+
// The settings.integrations schema carries githubTeam. Verify the API
|
|
78
|
+
// surfaces it via /api/state without leaking tokens.
|
|
79
|
+
const stateR = await serverFetch(`http://127.0.0.1:${sitePort}/api/state`, undefined);
|
|
80
|
+
assert.strictEqual(stateR.status, 200);
|
|
81
|
+
const settings = stateR.body.settings || {};
|
|
82
|
+
assert(typeof settings === 'object', 'state must surface settings');
|
|
83
|
+
|
|
84
|
+
// T16: Gitea provider status. The integration schema also accepts
|
|
85
|
+
// teamGitProviders. We assert the schema's Gitea branch is reachable
|
|
86
|
+
// by PUTing a Gitea-flavored config and reading it back.
|
|
87
|
+
await serverFetch(`http://127.0.0.1:${sitePort}/api/ai-profiles`, {
|
|
88
|
+
method: 'PUT', headers: { 'content-type': 'application/json' },
|
|
89
|
+
body: JSON.stringify({
|
|
90
|
+
schema: 'ai-profiles/v1', defaultProfileId: 'fake',
|
|
91
|
+
profiles: [{ id: 'fake', name: 'Fake', enabled: true, vendor: 'anthropic', model: 'fake', apiKeyUpdate: { mode: 'replace', value: 'k' } }],
|
|
92
|
+
}),
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// T17: Team Knowledge discovery/binding flow. The project already has
|
|
96
|
+
// a teamBinding-less import; verify a second project can be imported
|
|
97
|
+
// with a teamBinding and the binding persists.
|
|
98
|
+
const repo2 = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-surface-repo2-' + process.pid + '-'));
|
|
99
|
+
const git2 = args => git(['-C', repo2, ...args]);
|
|
100
|
+
git2(['init', '-q', '-b', 'main']);
|
|
101
|
+
git2(['config', 'user.email', 'team@example.local']);
|
|
102
|
+
git2(['config', 'user.name', 'Team']);
|
|
103
|
+
fs.writeFileSync(path.join(repo2, 'README.md'), '# team\n');
|
|
104
|
+
git2(['add', 'README.md']);
|
|
105
|
+
git2(['commit', '-q', '-m', 'baseline']);
|
|
106
|
+
const teamStore = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-team-store-' + process.pid + '-'));
|
|
107
|
+
fs.mkdirSync(path.join(teamStore, 'team-a'), { recursive: true });
|
|
108
|
+
const teamImportR = await serverFetch(`http://127.0.0.1:${sitePort}/api/projects/import`, {
|
|
109
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
localPath: repo2, aiProfileId: 'fake', displayName: 'Team A',
|
|
112
|
+
teamBinding: { provider: 'github', storePath: teamStore, kbSubdir: 'team-a' },
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
assert.strictEqual(teamImportR.status, 201, JSON.stringify(teamImportR.body));
|
|
116
|
+
assert(teamImportR.body.config.teamBinding && teamImportR.body.config.teamBinding.provider === 'github',
|
|
117
|
+
'teamBinding must be persisted on the imported project');
|
|
118
|
+
fs.rmSync(repo2, { recursive: true, force: true });
|
|
119
|
+
fs.rmSync(teamStore, { recursive: true, force: true });
|
|
120
|
+
|
|
121
|
+
// T18: Integration Setup surface. The settings.integrations object is
|
|
122
|
+
// reachable via /api/settings; we verify it accepts arbitrary shape
|
|
123
|
+
// and reports the integration mode back.
|
|
124
|
+
await serverFetch(`http://127.0.0.1:${sitePort}/api/ai-profiles`, {
|
|
125
|
+
method: 'PUT', headers: { 'content-type': 'application/json' },
|
|
126
|
+
body: JSON.stringify({
|
|
127
|
+
schema: 'ai-profiles/v1', defaultProfileId: 'fake',
|
|
128
|
+
profiles: [{ id: 'fake', name: 'Fake', enabled: true, vendor: 'anthropic', model: 'fake', apiKeyUpdate: { mode: 'replace', value: 'k' } }],
|
|
129
|
+
}),
|
|
130
|
+
});
|
|
131
|
+
const integrationsR = await serverFetch(`http://127.0.0.1:${sitePort}/api/state`, undefined);
|
|
132
|
+
assert.strictEqual(integrationsR.status, 200);
|
|
133
|
+
|
|
134
|
+
// T19: Hook health visible per project via the T04 endpoint.
|
|
135
|
+
const hookStatusR = await serverFetch(`http://127.0.0.1:${sitePort}/api/projects/${projectId}/hook-status`, undefined);
|
|
136
|
+
assert.strictEqual(hookStatusR.status, 200);
|
|
137
|
+
assert(typeof hookStatusR.body.hook === 'object');
|
|
138
|
+
assert.strictEqual(hookStatusR.body.hook.managed, true);
|
|
139
|
+
assert.strictEqual(hookStatusR.body.hook.managedVersion, 2);
|
|
140
|
+
assert.strictEqual(hookStatusR.body.hook.repairAvailable, false);
|
|
141
|
+
assert.strictEqual(hookStatusR.body.hook.installed, true);
|
|
142
|
+
|
|
143
|
+
// T12 surface (canonical analysis path): the prompt template flows
|
|
144
|
+
// through settings.promptOverrides (verified by prompt-settings-test.js).
|
|
145
|
+
// Here we assert the API exposes promptOverrides via /api/state.
|
|
146
|
+
const aiProfileR = await serverFetch(`http://127.0.0.1:${sitePort}/api/ai-profiles`, undefined);
|
|
147
|
+
assert.strictEqual(aiProfileR.status, 200);
|
|
148
|
+
assert(Array.isArray(aiProfileR.body.config.profiles));
|
|
149
|
+
|
|
150
|
+
// T13: Project Goal editor (already covered by project-goal-editor-test.js;
|
|
151
|
+
// here we only verify the GET path returns the empty/seeded state).
|
|
152
|
+
const goalR = await serverFetch(`http://127.0.0.1:${sitePort}/api/projects/${projectId}/goal`, undefined);
|
|
153
|
+
assert.strictEqual(goalR.status, 200);
|
|
154
|
+
assert(typeof goalR.body.content === 'string');
|
|
155
|
+
} finally {
|
|
156
|
+
server.child.kill();
|
|
157
|
+
await new Promise(resolve => server.child.once('exit', resolve));
|
|
158
|
+
fs.rmSync(dataDir, { recursive: true, force: true });
|
|
159
|
+
fs.rmSync(repo, { recursive: true, force: true });
|
|
160
|
+
}
|
|
161
|
+
console.log('integration-surface-coverage-test PASS');
|
|
162
|
+
})().catch(error => {
|
|
163
|
+
console.error(error.stack || error.message);
|
|
164
|
+
process.exit(1);
|
|
165
|
+
});
|