@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,95 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { BridgeAdapter } = require('../lib/bridge-adapter');
|
|
6
|
+
const bridgeModule = require('@sanqianx/ai-coding-event-bridge');
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-bridge-adapter-'));
|
|
10
|
+
const bridgeHome = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-bridge-adapter-home-'));
|
|
11
|
+
|
|
12
|
+
// Real facade: the adapter talks to createBridge() only, with an isolated
|
|
13
|
+
// bridge home — never the user's global spool and never PK's data dir.
|
|
14
|
+
const adapter = new BridgeAdapter({ dataDir, bridgeModule, bridgeHomeDir: bridgeHome });
|
|
15
|
+
assert.strictEqual(adapter.isAvailable(), true);
|
|
16
|
+
|
|
17
|
+
// v1 identity flows through the adapter into the real journal.
|
|
18
|
+
const repoTmp = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-bridge-adapter-repo-'));
|
|
19
|
+
require('child_process').execSync('git init -q', { cwd: repoTmp, stdio: 'ignore' });
|
|
20
|
+
const identityResult = await adapter.resolveRepoIdentity(repoTmp);
|
|
21
|
+
assert.strictEqual(identityResult.status, 'ok');
|
|
22
|
+
assert.strictEqual(identityResult.repoIdentity.schema, 'repo-identity/v1');
|
|
23
|
+
assert.match(identityResult.repoIdentity.workspaceId, /^sha256:[0-9a-f]{64}$/);
|
|
24
|
+
|
|
25
|
+
const baseline = await adapter.getHighWatermark({});
|
|
26
|
+
assert.deepStrictEqual(baseline, { status: 'captured', cursor: 0 });
|
|
27
|
+
|
|
28
|
+
await adapter.registerConsumer('project-knowledge', { notifyUrl: 'http://127.0.0.1:9/bridge' });
|
|
29
|
+
const consumer = await adapter.getHealth?.();
|
|
30
|
+
assert.strictEqual(consumer.status, 'ok');
|
|
31
|
+
assert.ok(consumer.health.consumers.some(entry => entry.name === 'project-knowledge'));
|
|
32
|
+
|
|
33
|
+
const result = await adapter.appendCommitBoundary({
|
|
34
|
+
projectId: 'project-bridge',
|
|
35
|
+
repoIdentity: identityResult.repoIdentity,
|
|
36
|
+
commitSha: 'a'.repeat(40),
|
|
37
|
+
parentShas: ['b'.repeat(40)],
|
|
38
|
+
branch: 'main',
|
|
39
|
+
committedAt: '2026-08-18T02:00:00.000Z',
|
|
40
|
+
operationId: 'op-boundary-test',
|
|
41
|
+
});
|
|
42
|
+
assert.strictEqual(result.status, 'captured');
|
|
43
|
+
assert.strictEqual(result.boundary.bridgeCursorAtCommit, 1);
|
|
44
|
+
assert.deepStrictEqual(result.boundary.repoIdentity.workspaceId, identityResult.repoIdentity.workspaceId);
|
|
45
|
+
|
|
46
|
+
// Consumer APIs through the adapter.
|
|
47
|
+
await adapter.ackConsumerCursor('project-knowledge', 1);
|
|
48
|
+
const acked = await adapter.getHealth();
|
|
49
|
+
assert.strictEqual(acked.health.minConsumerAck, 1);
|
|
50
|
+
const compacted = await adapter.compact({ throughSequence: 1 });
|
|
51
|
+
assert.strictEqual(compacted.status, 'ok');
|
|
52
|
+
|
|
53
|
+
// The old PK-only { commonDir } shape must produce a deterministic gap,
|
|
54
|
+
// never a Bridge write.
|
|
55
|
+
const legacy = await adapter.appendCommitBoundary({
|
|
56
|
+
projectId: 'project-legacy',
|
|
57
|
+
repoIdentity: { commonDir: 'D:\\repo\\.git' },
|
|
58
|
+
commitSha: 'c'.repeat(40),
|
|
59
|
+
operationId: 'op-legacy-test',
|
|
60
|
+
});
|
|
61
|
+
assert.strictEqual(legacy.status, 'unavailable');
|
|
62
|
+
assert.strictEqual(legacy.gap.reason, 'repo-identity-legacy-shape');
|
|
63
|
+
|
|
64
|
+
const missing = await adapter.appendCommitBoundary({
|
|
65
|
+
projectId: 'project-missing',
|
|
66
|
+
repoIdentity: null,
|
|
67
|
+
commitSha: 'd'.repeat(40),
|
|
68
|
+
operationId: 'op-missing-test',
|
|
69
|
+
});
|
|
70
|
+
assert.strictEqual(missing.status, 'unavailable');
|
|
71
|
+
assert.strictEqual(missing.gap.reason, 'repo-identity-missing');
|
|
72
|
+
|
|
73
|
+
// No further journal growth from rejected shapes.
|
|
74
|
+
const after = await adapter.getHighWatermark({});
|
|
75
|
+
assert.strictEqual(after.cursor, 1, 'rejected identities must not append journal records');
|
|
76
|
+
|
|
77
|
+
const unavailable = new BridgeAdapter({ dataDir, bridgeModule: {} });
|
|
78
|
+
const gapResult = await unavailable.appendCommitBoundary({
|
|
79
|
+
projectId: 'project-gap',
|
|
80
|
+
repoIdentity: null,
|
|
81
|
+
commitSha: 'e'.repeat(40),
|
|
82
|
+
operationId: 'op-gap-test',
|
|
83
|
+
});
|
|
84
|
+
assert.strictEqual(gapResult.status, 'unavailable');
|
|
85
|
+
assert.strictEqual(gapResult.gap.reason, 'bridge-unavailable');
|
|
86
|
+
const gapsPath = path.join(dataDir, 'runtime', 'conversation-capture-gaps.jsonl');
|
|
87
|
+
const gaps = fs.readFileSync(gapsPath, 'utf8').trim().split(/\r?\n/).map(JSON.parse);
|
|
88
|
+
assert(gaps.some(gap => gap.commitSha === 'e'.repeat(40) && gap.reason === 'bridge-unavailable'));
|
|
89
|
+
assert(!JSON.stringify(gaps).includes('prompt'), 'capture gap diagnostics must not contain conversation bodies');
|
|
90
|
+
|
|
91
|
+
console.log('bridge-adapter-test PASS');
|
|
92
|
+
})().catch(error => {
|
|
93
|
+
console.error(error.stack || error.message);
|
|
94
|
+
process.exitCode = 1;
|
|
95
|
+
});
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
// Run: node _site/_test/bridge-consumer-service-test.js
|
|
2
|
+
//
|
|
3
|
+
// T11 core gates: exact workspace matching, unimported skip + ACK,
|
|
4
|
+
// duplicate-notify idempotency, contiguous ACK under forced failure,
|
|
5
|
+
// drainThrough joining, ambiguity stop.
|
|
6
|
+
|
|
7
|
+
const assert = require('assert');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const os = require('os');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const { execSync } = require('child_process');
|
|
12
|
+
const { StorageLayout } = require('../lib/storage-layout');
|
|
13
|
+
const { ProjectRegistryStore } = require('../lib/project-registry-store');
|
|
14
|
+
const { ProjectStore } = require('../lib/project-store');
|
|
15
|
+
const { ConversationStore } = require('../lib/conversation-store');
|
|
16
|
+
const { BridgeAdapter } = require('../lib/bridge-adapter');
|
|
17
|
+
const { BridgeConsumerService } = require('../lib/bridge-consumer-service');
|
|
18
|
+
const bridgeModule = require('@sanqianx/ai-coding-event-bridge');
|
|
19
|
+
|
|
20
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), `kb-bridge-consumer-${process.pid}-`));
|
|
21
|
+
const layout = new StorageLayout({ dataDir: path.join(temp, 'data') });
|
|
22
|
+
const registry = new ProjectRegistryStore({ layout });
|
|
23
|
+
const projects = new ProjectStore({ layout });
|
|
24
|
+
const bridgeHome = path.join(temp, 'bridge-home');
|
|
25
|
+
const adapter = new BridgeAdapter({ dataDir: layout.dataDir, bridgeModule, bridgeHomeDir: bridgeHome });
|
|
26
|
+
const store = new ConversationStore({ layout, projectStore: projects, logger: null });
|
|
27
|
+
|
|
28
|
+
function gitRepo(name) {
|
|
29
|
+
const dir = path.join(temp, name);
|
|
30
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
31
|
+
execSync('git init -q', { cwd: dir, stdio: 'ignore' });
|
|
32
|
+
return dir;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function importProject(projectId, repoPath, repoIdentity) {
|
|
36
|
+
await projects.create(projectId, {
|
|
37
|
+
storageName: projectId,
|
|
38
|
+
displayName: projectId,
|
|
39
|
+
repoPath,
|
|
40
|
+
knowledgePath: path.join(temp, 'knowledge', projectId),
|
|
41
|
+
repoIdentity,
|
|
42
|
+
});
|
|
43
|
+
await registry.add(projectId, { displayName: projectId });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function bridgeEvent(eventType, role, content, repoIdentity, sessionId, turnId) {
|
|
47
|
+
return adapter.bridge.appendConversationEvent({
|
|
48
|
+
source: 'claude-code', eventType, role, content,
|
|
49
|
+
sessionId, turnId, repoIdentity,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
(async () => {
|
|
54
|
+
await registry.initialize();
|
|
55
|
+
const ccsPath = gitRepo('ccs');
|
|
56
|
+
const ccbPath = gitRepo('ccb');
|
|
57
|
+
const ccsIdentity = (await bridgeModule.resolveRepoContext(ccsPath)).repoIdentity;
|
|
58
|
+
const ccbIdentity = (await bridgeModule.resolveRepoContext(ccbPath)).repoIdentity;
|
|
59
|
+
|
|
60
|
+
// Only CCS is imported.
|
|
61
|
+
await importProject('project-ccs', ccsPath, ccsIdentity);
|
|
62
|
+
|
|
63
|
+
const service = new BridgeConsumerService({
|
|
64
|
+
bridgeAdapter: adapter,
|
|
65
|
+
conversationStore: store,
|
|
66
|
+
registryStore: registry,
|
|
67
|
+
projectStore: projects,
|
|
68
|
+
logger: null,
|
|
69
|
+
});
|
|
70
|
+
const started = await service.start();
|
|
71
|
+
assert.strictEqual(started.started, true);
|
|
72
|
+
|
|
73
|
+
// The notifyUrl passed to start() must land in the registered consumer
|
|
74
|
+
// meta — connector wake-ups are routed through it. Regression: start(url)
|
|
75
|
+
// used to ignore its argument, leaving meta {} and drains unnotified.
|
|
76
|
+
{
|
|
77
|
+
const registered = await adapter.getConsumer('project-knowledge');
|
|
78
|
+
assert.strictEqual(registered.consumer.meta.notifyUrl, undefined, 'baseline service registered without notifyUrl');
|
|
79
|
+
const svc = new BridgeConsumerService({
|
|
80
|
+
bridgeAdapter: adapter, conversationStore: store, registryStore: registry, projectStore: projects, logger: null,
|
|
81
|
+
});
|
|
82
|
+
await svc.start('http://127.0.0.1:5757/api/bridge/notify');
|
|
83
|
+
const withUrl = await adapter.getConsumer('project-knowledge');
|
|
84
|
+
assert.strictEqual(withUrl.consumer.meta.notifyUrl, 'http://127.0.0.1:5757/api/bridge/notify', 'start(notifyUrl) wires the wake-up URL into consumer meta');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Phase A: develop in unimported CCB.
|
|
88
|
+
const ccbUser = await bridgeEvent('user_prompt', 'user', 'Modify CCB parser', ccbIdentity, 'ccb-s1', 'turn-ccb-1');
|
|
89
|
+
await bridgeEvent('assistant_response', 'assistant', 'CCB parser modified', ccbIdentity, 'ccb-s1', 'turn-ccb-1');
|
|
90
|
+
const drainA = await service.drain('notify');
|
|
91
|
+
assert.strictEqual(drainA.stats.skippedUnregistered, 2, 'unimported workspace events are skipped');
|
|
92
|
+
assert.strictEqual(drainA.stats.persisted, 0);
|
|
93
|
+
assert.deepStrictEqual(store.readEvents('project-ccs'), [], 'CCS store stays empty');
|
|
94
|
+
const ccbStoreDir = layout.getProjectConversationEventsPath('project-ccb');
|
|
95
|
+
assert.ok(!fs.existsSync(path.dirname(ccbStoreDir)), 'no CCB project conversation store is created');
|
|
96
|
+
const consumerA = await adapter.getConsumer('project-knowledge');
|
|
97
|
+
assert.strictEqual(consumerA.consumer.ack, ccbUser.sequence + 1, 'consumer ACK advances through skipped CCB events');
|
|
98
|
+
|
|
99
|
+
// Phase B: develop in imported CCS.
|
|
100
|
+
const ccsUser = await bridgeEvent('user_prompt', 'user', 'Modify CCS autofocus', ccsIdentity, 'ccs-s1', 'turn-ccs-1');
|
|
101
|
+
await bridgeEvent('assistant_response', 'assistant', 'CCS autofocus modified', ccsIdentity, 'ccs-s1', 'turn-ccs-1');
|
|
102
|
+
await service.drain('notify');
|
|
103
|
+
const ccsEvents = store.readEvents('project-ccs');
|
|
104
|
+
assert.strictEqual(ccsEvents.length, 2, 'exactly the CCS turn is projected');
|
|
105
|
+
assert.ok(ccsEvents.every(event => !event.content.includes('CCB')), 'no CCB content leaked into CCS');
|
|
106
|
+
assert.strictEqual(ccsEvents[0].eventId, ccsUser.eventId, 'global bridge eventId preserved');
|
|
107
|
+
assert.strictEqual(ccsEvents[0].sequence, ccsUser.sequence, 'global bridge sequence preserved');
|
|
108
|
+
assert.strictEqual(ccsEvents[0].turnId, 'turn-ccs-1', 'canonical bridge turnId preserved');
|
|
109
|
+
|
|
110
|
+
// Unattributed evidence is never projected into a project.
|
|
111
|
+
await bridgeEvent('user_prompt', 'user', 'no workspace at all', null, 'lost-s1', 'turn-lost-1');
|
|
112
|
+
const drainLost = await service.drain('notify');
|
|
113
|
+
assert.strictEqual(drainLost.stats.skippedNoWorkspace, 1);
|
|
114
|
+
|
|
115
|
+
// Duplicate notifications are idempotent.
|
|
116
|
+
const before = store.readEvents('project-ccs').length;
|
|
117
|
+
await service.handleNotification();
|
|
118
|
+
await service.handleNotification();
|
|
119
|
+
assert.strictEqual(store.readEvents('project-ccs').length, before, 'duplicate wake-ups create no duplicates');
|
|
120
|
+
|
|
121
|
+
// drainThrough joins in-flight drains and covers the boundary sequence.
|
|
122
|
+
const boundaryUser = await bridgeEvent('user_prompt', 'user', 'boundary prompt', ccsIdentity, 'ccs-s2', 'turn-ccs-2');
|
|
123
|
+
const throughResult = await service.drainThrough(boundaryUser.sequence, 'commit-boundary');
|
|
124
|
+
assert.strictEqual(throughResult.ack, boundaryUser.sequence);
|
|
125
|
+
const statusAfter = await service.status();
|
|
126
|
+
assert.strictEqual(statusAfter.ack, boundaryUser.sequence);
|
|
127
|
+
assert.strictEqual(statusAfter.consumerRegistered, true);
|
|
128
|
+
assert.strictEqual(statusAfter.bridgeHealthy, true);
|
|
129
|
+
|
|
130
|
+
// Boundaries are facts too: a startup/notify drain persists them without
|
|
131
|
+
// asking the knowledge analyzer to scan or analyze any commit.
|
|
132
|
+
const boundaryCommit = 'a'.repeat(40);
|
|
133
|
+
const capturedBoundary = await adapter.appendCommitBoundary({
|
|
134
|
+
projectId: 'project-ccs', repoIdentity: ccsIdentity, commitSha: boundaryCommit,
|
|
135
|
+
parentShas: [], branch: 'main', bridgeCursorAtCommit: boundaryUser.sequence,
|
|
136
|
+
openTurnIdsAtCommit: ['turn-ccs-2'], operationId: 'op-boundary-consumer',
|
|
137
|
+
});
|
|
138
|
+
assert.strictEqual(capturedBoundary.status, 'captured');
|
|
139
|
+
const boundaryDrain = await service.drainThrough(capturedBoundary.boundary.journalSequence, 'startup');
|
|
140
|
+
assert.strictEqual(boundaryDrain.stats.boundariesPersisted, 1);
|
|
141
|
+
assert.strictEqual(store.readBoundary('project-ccs', boundaryCommit).commitSha, boundaryCommit);
|
|
142
|
+
await service.drain('duplicate-boundary');
|
|
143
|
+
assert.strictEqual(store.readBoundary('project-ccs', boundaryCommit).commitSha, boundaryCommit, 'duplicate boundary drains are idempotent');
|
|
144
|
+
|
|
145
|
+
// Contiguous ACK under forced persist failure (GATE ACK-001 semantics).
|
|
146
|
+
const failStore = {
|
|
147
|
+
appendBridgeEvent: async (projectId, record) => {
|
|
148
|
+
if (record.content === 'fails once') throw new Error('forced persist failure');
|
|
149
|
+
return { appended: true };
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
const failService = new BridgeConsumerService({
|
|
153
|
+
bridgeAdapter: adapter,
|
|
154
|
+
conversationStore: failStore,
|
|
155
|
+
registryStore: registry,
|
|
156
|
+
projectStore: projects,
|
|
157
|
+
logger: null,
|
|
158
|
+
consumerName: 'project-knowledge',
|
|
159
|
+
});
|
|
160
|
+
await failService.start();
|
|
161
|
+
const okSeq = (await bridgeEvent('user_prompt', 'user', 'succeeds', ccsIdentity, 'ccs-s3', 'turn-f1')).sequence;
|
|
162
|
+
const failSeq = (await bridgeEvent('user_prompt', 'user', 'fails once', ccsIdentity, 'ccs-s3', 'turn-f2')).sequence;
|
|
163
|
+
const afterSeq = (await bridgeEvent('user_prompt', 'user', 'would succeed', ccsIdentity, 'ccs-s3', 'turn-f3')).sequence;
|
|
164
|
+
let drainError = null;
|
|
165
|
+
try {
|
|
166
|
+
await failService.drain('notify');
|
|
167
|
+
} catch (error) {
|
|
168
|
+
drainError = error;
|
|
169
|
+
}
|
|
170
|
+
assert.ok(drainError, 'failing sequence must surface an error');
|
|
171
|
+
const failConsumer = await adapter.getConsumer('project-knowledge');
|
|
172
|
+
assert.strictEqual(failConsumer.consumer.ack, okSeq, 'ACK stopped exactly at the last contiguous success');
|
|
173
|
+
|
|
174
|
+
// After removing the failure, ACK may advance through the rest.
|
|
175
|
+
const healStore = {
|
|
176
|
+
appendBridgeEvent: async () => ({ appended: true }),
|
|
177
|
+
};
|
|
178
|
+
failService.conversationStore = healStore;
|
|
179
|
+
const recovered = await failService.drain('retry');
|
|
180
|
+
assert.strictEqual(recovered.ack, afterSeq, 'recovered drain advances through previously failed sequences');
|
|
181
|
+
await service.stop();
|
|
182
|
+
|
|
183
|
+
// Ambiguous workspace mapping stops ACK and records a gap.
|
|
184
|
+
await importProject('project-ccs-clone', ccsPath, ccsIdentity);
|
|
185
|
+
const ambSeq = (await bridgeEvent('user_prompt', 'user', 'ambiguous', ccsIdentity, 'ccs-s4', 'turn-amb')).sequence;
|
|
186
|
+
let ambiguityError = null;
|
|
187
|
+
try {
|
|
188
|
+
await failService.drain('notify');
|
|
189
|
+
} catch (error) {
|
|
190
|
+
ambiguityError = error;
|
|
191
|
+
}
|
|
192
|
+
assert.ok(ambiguityError && ambiguityError.code === 'PROJECT_AMBIGUOUS', 'ambiguous mapping must stop the drain');
|
|
193
|
+
const ambConsumer = await adapter.getConsumer('project-knowledge');
|
|
194
|
+
assert.strictEqual(ambConsumer.consumer.ack, ambSeq - 1, 'ACK never crosses the ambiguous sequence');
|
|
195
|
+
|
|
196
|
+
// GATE BASELINE-001 (isolated world: fresh stores + fresh bridge journal).
|
|
197
|
+
const temp2 = fs.mkdtempSync(path.join(os.tmpdir(), `kb-bridge-consumer-base-${process.pid}-`));
|
|
198
|
+
const layout2 = new StorageLayout({ dataDir: path.join(temp2, 'data') });
|
|
199
|
+
const registry2 = new ProjectRegistryStore({ layout: layout2 });
|
|
200
|
+
const projects2 = new ProjectStore({ layout: layout2 });
|
|
201
|
+
const adapter2 = new BridgeAdapter({ dataDir: layout2.dataDir, bridgeModule, bridgeHomeDir: path.join(temp2, 'bridge-home') });
|
|
202
|
+
const store2 = new ConversationStore({ layout: layout2, projectStore: projects2, logger: null });
|
|
203
|
+
const emit2 = async (eventType, role, content, repoIdentity, sessionId, turnId) =>
|
|
204
|
+
adapter2.bridge.appendConversationEvent({ source: 'claude-code', eventType, role, content, sessionId, turnId, repoIdentity });
|
|
205
|
+
|
|
206
|
+
await registry2.initialize();
|
|
207
|
+
const basePath = gitRepo('ccs-base');
|
|
208
|
+
const baseIdentity = (await bridgeModule.resolveRepoContext(basePath)).repoIdentity;
|
|
209
|
+
const oldUser = await emit2('user_prompt', 'user', 'old pre-import conversation', baseIdentity, 'base-s1', 'turn-base-old');
|
|
210
|
+
await projects2.create('project-base', {
|
|
211
|
+
storageName: 'project-base', displayName: 'project-base',
|
|
212
|
+
repoPath: basePath, knowledgePath: path.join(temp2, 'knowledge', 'project-base'),
|
|
213
|
+
repoIdentity: baseIdentity,
|
|
214
|
+
}, { conversationBaselineCursor: oldUser.sequence });
|
|
215
|
+
await registry2.add('project-base', { displayName: 'project-base' });
|
|
216
|
+
|
|
217
|
+
const baseService = new BridgeConsumerService({
|
|
218
|
+
bridgeAdapter: adapter2,
|
|
219
|
+
conversationStore: store2,
|
|
220
|
+
registryStore: registry2,
|
|
221
|
+
projectStore: projects2,
|
|
222
|
+
logger: null,
|
|
223
|
+
consumerName: 'project-knowledge',
|
|
224
|
+
});
|
|
225
|
+
const baseStart = await baseService.start();
|
|
226
|
+
const baseDrain = baseStart.drain && baseStart.drain.stats ? baseStart.drain : await baseService.drain('baseline-check');
|
|
227
|
+
assert.strictEqual(baseDrain.stats.skippedBelowBaseline >= 1, true, 'pre-baseline events are skipped, not backfilled');
|
|
228
|
+
assert.deepStrictEqual(store2.readEvents('project-base'), [], 'no pre-import history projected');
|
|
229
|
+
const newUser = await emit2('user_prompt', 'user', 'fresh post-import conversation', baseIdentity, 'base-s2', 'turn-base-new');
|
|
230
|
+
await baseService.drain('notify');
|
|
231
|
+
const baseEvents = store2.readEvents('project-base');
|
|
232
|
+
assert.strictEqual(baseEvents.length, 1);
|
|
233
|
+
assert.strictEqual(baseEvents[0].eventId, newUser.eventId, 'post-import events are projected');
|
|
234
|
+
|
|
235
|
+
// Offline recovery: project imported without a baseline gets one at the
|
|
236
|
+
// current watermark on first attachment — still no backfill.
|
|
237
|
+
const offlinePath = gitRepo('ccs-offline');
|
|
238
|
+
const offlineIdentity = (await bridgeModule.resolveRepoContext(offlinePath)).repoIdentity;
|
|
239
|
+
await emit2('user_prompt', 'user', 'history before offline project attached', offlineIdentity, 'off-s0', 'turn-off-old');
|
|
240
|
+
await projects2.create('project-offline', {
|
|
241
|
+
storageName: 'project-offline', displayName: 'project-offline',
|
|
242
|
+
repoPath: offlinePath, knowledgePath: path.join(temp2, 'knowledge', 'project-offline'),
|
|
243
|
+
repoIdentity: offlineIdentity,
|
|
244
|
+
}, { conversationBaselineCursor: null });
|
|
245
|
+
await registry2.add('project-offline', { displayName: 'project-offline' });
|
|
246
|
+
const attachDrain = await baseService.drain('first-attachment');
|
|
247
|
+
assert.deepStrictEqual(store2.readEvents('project-offline'), [], 'first attachment establishes baseline without backfilling');
|
|
248
|
+
const offlineState = projects2.readState('project-offline');
|
|
249
|
+
assert.ok(Number.isInteger(offlineState.conversationBaselineCursor), 'baseline persisted at attachment-time watermark');
|
|
250
|
+
await emit2('user_prompt', 'user', 'after offline project attached', offlineIdentity, 'off-s1', 'turn-off-new');
|
|
251
|
+
await baseService.drain('notify');
|
|
252
|
+
const offlineEvents = store2.readEvents('project-offline');
|
|
253
|
+
assert.strictEqual(offlineEvents.length, 1, 'only post-attachment events project');
|
|
254
|
+
assert.ok(offlineEvents[0].content.includes('after offline project attached'));
|
|
255
|
+
|
|
256
|
+
// Legacy upgrade (isolated world): a project imported before v4.2.3 has no
|
|
257
|
+
// workspaceId in its config. One drain backfills the canonical identity
|
|
258
|
+
// automatically and the project's conversations start projecting without
|
|
259
|
+
// any manual step.
|
|
260
|
+
{
|
|
261
|
+
const temp3 = fs.mkdtempSync(path.join(os.tmpdir(), `kb-bridge-consumer-legacy-${process.pid}-`));
|
|
262
|
+
const layout3 = new StorageLayout({ dataDir: path.join(temp3, 'data') });
|
|
263
|
+
const registry3 = new ProjectRegistryStore({ layout: layout3 });
|
|
264
|
+
const projects3 = new ProjectStore({ layout: layout3 });
|
|
265
|
+
const adapter3 = new BridgeAdapter({ dataDir: layout3.dataDir, bridgeModule, bridgeHomeDir: path.join(temp3, 'bridge-home') });
|
|
266
|
+
const store3 = new ConversationStore({ layout: layout3, projectStore: projects3, logger: null });
|
|
267
|
+
const emit3 = (eventType, role, content, repoIdentity, sessionId, turnId) =>
|
|
268
|
+
adapter3.bridge.appendConversationEvent({ source: 'claude-code', eventType, role, content, sessionId, turnId, repoIdentity });
|
|
269
|
+
await registry3.initialize();
|
|
270
|
+
|
|
271
|
+
const legacyPath = gitRepo('ccs-legacy');
|
|
272
|
+
const legacyIdentity = (await bridgeModule.resolveRepoContext(legacyPath)).repoIdentity;
|
|
273
|
+
await projects3.create('project-legacy', {
|
|
274
|
+
storageName: 'project-legacy', displayName: 'project-legacy',
|
|
275
|
+
repoPath: legacyPath, knowledgePath: path.join(temp3, 'knowledge', 'project-legacy'),
|
|
276
|
+
repoIdentity: { commonDir: path.join(legacyPath, '.git') }, // pre-v4.2.3 shape
|
|
277
|
+
}, {});
|
|
278
|
+
await registry3.add('project-legacy', { displayName: 'project-legacy' });
|
|
279
|
+
const legacyService = new BridgeConsumerService({
|
|
280
|
+
bridgeAdapter: adapter3, conversationStore: store3, registryStore: registry3, projectStore: projects3, logger: null,
|
|
281
|
+
});
|
|
282
|
+
await legacyService.start();
|
|
283
|
+
await emit3('user_prompt', 'user', 'legacy project conversation', legacyIdentity, 'legacy-s1', 'turn-legacy-1');
|
|
284
|
+
await legacyService.drain('legacy-migration');
|
|
285
|
+
const migratedConfig = projects3.readConfig('project-legacy');
|
|
286
|
+
assert.strictEqual(migratedConfig.repoIdentity.workspaceId, legacyIdentity.workspaceId, 'identity auto-migrated to v1 on first drain');
|
|
287
|
+
assert.ok(Number.isInteger(projects3.readState('project-legacy').conversationBaselineCursor), 'baseline established during the same drain');
|
|
288
|
+
const legacyEvents = store3.readEvents('project-legacy');
|
|
289
|
+
assert.strictEqual(legacyEvents.length, 1, 'post-migration conversation projected automatically');
|
|
290
|
+
assert.strictEqual(legacyEvents[0].content, 'legacy project conversation');
|
|
291
|
+
|
|
292
|
+
// Collision guard: a second legacy project pointing at the same working
|
|
293
|
+
// tree must NOT receive the same workspaceId (that would create the
|
|
294
|
+
// ambiguity the consumer refuses to guess through).
|
|
295
|
+
await projects3.create('project-legacy-clone', {
|
|
296
|
+
storageName: 'project-legacy-clone', displayName: 'project-legacy-clone',
|
|
297
|
+
repoPath: legacyPath, knowledgePath: path.join(temp3, 'knowledge', 'project-legacy-clone'),
|
|
298
|
+
repoIdentity: null,
|
|
299
|
+
}, {});
|
|
300
|
+
await registry3.add('project-legacy-clone', { displayName: 'project-legacy-clone' });
|
|
301
|
+
await legacyService.drain('legacy-collision');
|
|
302
|
+
const cloneConfig = projects3.readConfig('project-legacy-clone');
|
|
303
|
+
assert.ok(!(cloneConfig.repoIdentity && cloneConfig.repoIdentity.workspaceId), 'colliding workspace is never written to a second project');
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
console.log('bridge-consumer-service-test PASS');
|
|
307
|
+
})().catch(error => {
|
|
308
|
+
console.error(error.stack || error.message);
|
|
309
|
+
process.exitCode = 1;
|
|
310
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Regression test for CDP browser launch failures (T00):
|
|
2
|
+
// - browser that exits immediately must fail fast with exit/stderr diagnostics
|
|
3
|
+
// - browser that stays alive but never exposes CDP must hit the launch timeout,
|
|
4
|
+
// then be killed and cleaned up
|
|
5
|
+
// - in both cases: no child process remains alive, profile dir is removed.
|
|
6
|
+
const assert = require('assert');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const os = require('os');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { isWindowsChromeLauncher, platformLaunchArgs, launchCdpBrowser } = require('./helpers/cdp-browser');
|
|
11
|
+
|
|
12
|
+
const FIXTURE_EXIT = path.join(__dirname, 'fixtures', 'fake-browser-exit.js');
|
|
13
|
+
const FIXTURE_HANG = path.join(__dirname, 'fixtures', 'fake-browser-hang.js');
|
|
14
|
+
const FAST_FAIL_BUDGET_MS = 5000;
|
|
15
|
+
|
|
16
|
+
function isPidAlive(pid) {
|
|
17
|
+
try { process.kill(pid, 0); return true; }
|
|
18
|
+
catch (error) { return error.code === 'EPERM'; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function waitForPidExit(pid, timeoutMs = 8000) {
|
|
22
|
+
const deadline = Date.now() + timeoutMs;
|
|
23
|
+
while (Date.now() < deadline) {
|
|
24
|
+
if (!isPidAlive(pid)) return false;
|
|
25
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
26
|
+
}
|
|
27
|
+
return isPidAlive(pid);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function expectLaunchFailure(scenario) {
|
|
31
|
+
const pidFile = path.join(os.tmpdir(), `pk-cdp-failure-${scenario}-pid-${process.pid}.txt`);
|
|
32
|
+
const profileDir = path.join(os.tmpdir(), `pk-cdp-failure-${scenario}-profile-${process.pid}`);
|
|
33
|
+
process.env.KB_FAKE_BROWSER_PIDFILE = pidFile;
|
|
34
|
+
try {
|
|
35
|
+
const start = Date.now();
|
|
36
|
+
let error = null;
|
|
37
|
+
try {
|
|
38
|
+
await launchCdpBrowser(scenario.options(profileDir));
|
|
39
|
+
} catch (caught) {
|
|
40
|
+
error = caught;
|
|
41
|
+
}
|
|
42
|
+
const durationMs = Date.now() - start;
|
|
43
|
+
assert(error, `${scenario.name}: launchCdpBrowser must reject`);
|
|
44
|
+
assert(durationMs < FAST_FAIL_BUDGET_MS, `${scenario.name}: must fail fast, took ${durationMs}ms`);
|
|
45
|
+
const message = error.message;
|
|
46
|
+
assert(message.includes(process.execPath), `${scenario.name}: error must include executable path, got: ${message}`);
|
|
47
|
+
assert(message.includes(profileDir), `${scenario.name}: error must include user-data-dir, got: ${message}`);
|
|
48
|
+
scenario.assertions(message, durationMs);
|
|
49
|
+
assert(!fs.existsSync(profileDir), `${scenario.name}: profile dir must be cleaned after failed launch`);
|
|
50
|
+
assert(fs.existsSync(pidFile), `${scenario.name}: fixture pid file missing; cannot verify cleanup`);
|
|
51
|
+
const pid = Number.parseInt(fs.readFileSync(pidFile, 'utf8').trim(), 10);
|
|
52
|
+
const stillAlive = await waitForPidExit(pid);
|
|
53
|
+
assert(!stillAlive, `${scenario.name}: spawned child pid ${pid} still alive after failure cleanup`);
|
|
54
|
+
return durationMs;
|
|
55
|
+
} finally {
|
|
56
|
+
delete process.env.KB_FAKE_BROWSER_PIDFILE;
|
|
57
|
+
try { fs.rmSync(pidFile, { force: true }); } catch {}
|
|
58
|
+
try { fs.rmSync(profileDir, { recursive: true, force: true }); } catch {}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
(async () => {
|
|
63
|
+
assert.strictEqual(isWindowsChromeLauncher('C:/Program Files/Google/Chrome/Application/chrome.exe'), process.platform === 'win32');
|
|
64
|
+
assert.strictEqual(isWindowsChromeLauncher(process.execPath), false);
|
|
65
|
+
assert.deepStrictEqual(platformLaunchArgs('linux'), ['--disable-dev-shm-usage', '--no-sandbox']);
|
|
66
|
+
assert.deepStrictEqual(platformLaunchArgs('win32'), []);
|
|
67
|
+
const exitDuration = await expectLaunchFailure({
|
|
68
|
+
name: 'immediate-exit',
|
|
69
|
+
options: profileDir => ({
|
|
70
|
+
chrome: process.execPath,
|
|
71
|
+
prependArgs: [FIXTURE_EXIT],
|
|
72
|
+
profileDir,
|
|
73
|
+
url: 'http://127.0.0.1:1/',
|
|
74
|
+
}),
|
|
75
|
+
assertions(message) {
|
|
76
|
+
assert(message.includes('exit code: 3'), `immediate-exit: error must contain exit code, got: ${message}`);
|
|
77
|
+
assert(message.includes('fake-browser-exit stderr: simulated browser crash before CDP'), `immediate-exit: error must contain stderr tail, got: ${message}`);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
console.log(`cdp-browser immediate-exit failure test PASS (${exitDuration}ms)`);
|
|
81
|
+
|
|
82
|
+
const hangDuration = await expectLaunchFailure({
|
|
83
|
+
name: 'hang-timeout',
|
|
84
|
+
options: profileDir => ({
|
|
85
|
+
chrome: process.execPath,
|
|
86
|
+
prependArgs: [FIXTURE_HANG],
|
|
87
|
+
profileDir,
|
|
88
|
+
url: 'http://127.0.0.1:1/',
|
|
89
|
+
launchTimeoutMs: 1500,
|
|
90
|
+
}),
|
|
91
|
+
assertions(message, durationMs) {
|
|
92
|
+
assert(message.includes('DevToolsActivePort'), `hang-timeout: error must mention DevToolsActivePort wait, got: ${message}`);
|
|
93
|
+
assert(durationMs < FAST_FAIL_BUDGET_MS, `hang-timeout: bounded duration, took ${durationMs}ms`);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
console.log(`cdp-browser hang-timeout failure test PASS (${hangDuration}ms)`);
|
|
97
|
+
})().catch(error => {
|
|
98
|
+
console.error(error.stack || error.message);
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const ROOT = path.resolve(__dirname, '..', '..');
|
|
7
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-claude-runner-v2-'));
|
|
8
|
+
process.env.KB_DATA_DIR = path.join(temp, 'data');
|
|
9
|
+
require('../lib/data-dir')._resetCache();
|
|
10
|
+
const runner = require('../lib/claude-cli-runner');
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
const projectPath = path.join(temp, 'repo');
|
|
14
|
+
const kbPath = path.join(temp, 'knowledge');
|
|
15
|
+
fs.mkdirSync(projectPath, { recursive: true });
|
|
16
|
+
fs.mkdirSync(kbPath, { recursive: true });
|
|
17
|
+
const slug = 'chat-runner-v2';
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const started = runner.startSession({
|
|
21
|
+
slug,
|
|
22
|
+
projectPath,
|
|
23
|
+
kbPath,
|
|
24
|
+
promptKey: 'initial-analysis',
|
|
25
|
+
aiProfile: { id: 'test-profile', implementation: 'claude-code-agent', mainModel: 'test-model' },
|
|
26
|
+
vars: { SLUG: slug, PROJECT_PATH: projectPath, KNOWLEDGE_LANGUAGE: 'zh-CN' },
|
|
27
|
+
});
|
|
28
|
+
assert(started.sessionId);
|
|
29
|
+
|
|
30
|
+
const source = fs.readFileSync(path.join(ROOT, '_site', 'lib', 'claude-cli-runner.js'), 'utf8');
|
|
31
|
+
assert(/normalizePermissionMode\(opts\.permissionMode \|\| session\.permissionMode \|\| 'default'\)/.test(source));
|
|
32
|
+
assert(/type === 'claude\/usage' && ev\.usage/.test(source));
|
|
33
|
+
assert(/input_tokens/.test(source) && /output_tokens/.test(source) && /cache_creation_input_tokens/.test(source));
|
|
34
|
+
assert(/spawnClaude is no longer supported/.test(source));
|
|
35
|
+
assert(/type:\s*'claude\/retry'/.test(source) && /maxSdkRetries\(\)/.test(source));
|
|
36
|
+
|
|
37
|
+
const fresh = runner.getSessionTokenUsage(started.sessionId);
|
|
38
|
+
assert.strictEqual(fresh.used, 0);
|
|
39
|
+
assert.strictEqual(fresh.hasUsage, false);
|
|
40
|
+
assert(fresh.total > 0);
|
|
41
|
+
|
|
42
|
+
const liveSession = runner.getSession(started.sessionId);
|
|
43
|
+
liveSession.contextWindow = 1048576;
|
|
44
|
+
assert.strictEqual(runner.getSessionTokenUsage(started.sessionId).total, 1048576);
|
|
45
|
+
liveSession.contextWindow = null;
|
|
46
|
+
assert.strictEqual(runner.getSessionTokenUsage(started.sessionId).total, 200000);
|
|
47
|
+
|
|
48
|
+
const overrides = runner.buildSdkOverridesFromProfile({});
|
|
49
|
+
assert(overrides.systemPrompt && overrides.systemPrompt.preset === 'claude_code');
|
|
50
|
+
const env = runner.buildClaudeEnvFromProfile({
|
|
51
|
+
apiKey: 'sk-plaintext',
|
|
52
|
+
baseUrl: 'https://example.test/anthropic',
|
|
53
|
+
mainModel: 'main',
|
|
54
|
+
thinkingModel: 'think',
|
|
55
|
+
haikuModel: 'hk',
|
|
56
|
+
sonnetModel: 'sn',
|
|
57
|
+
opusModel: 'op',
|
|
58
|
+
timeoutMs: 1234,
|
|
59
|
+
});
|
|
60
|
+
assert.strictEqual(env.ANTHROPIC_AUTH_TOKEN, 'sk-plaintext');
|
|
61
|
+
assert.strictEqual(env.ANTHROPIC_MODEL, 'main');
|
|
62
|
+
assert.strictEqual(env.ANTHROPIC_DEFAULT_HAIKU_MODEL, 'hk');
|
|
63
|
+
assert.strictEqual(env.ANTHROPIC_DEFAULT_SONNET_MODEL, 'sn');
|
|
64
|
+
assert.strictEqual(env.ANTHROPIC_DEFAULT_OPUS_MODEL, 'op');
|
|
65
|
+
assert.strictEqual(env.ANTHROPIC_DEFAULT_THINKING_MODEL, 'think');
|
|
66
|
+
assert.strictEqual(env.API_TIMEOUT_MS, '1234');
|
|
67
|
+
assert.strictEqual(env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC, '1');
|
|
68
|
+
assert(runner.isTransientClaudeError(new Error('429 too many requests')));
|
|
69
|
+
assert(!runner.isTransientClaudeError(new Error('model does not exist')));
|
|
70
|
+
|
|
71
|
+
const server = fs.readFileSync(path.join(ROOT, '_site', 'lib', 'server-app.js'), 'utf8');
|
|
72
|
+
assert(server.includes('body.permissionMode'));
|
|
73
|
+
|
|
74
|
+
const html = fs.readFileSync(path.join(ROOT, 'ui', 'index.html'), 'utf8');
|
|
75
|
+
const app = fs.readFileSync(path.join(ROOT, 'ui', 'app.js'), 'utf8');
|
|
76
|
+
// T2: 内嵌终端取代旧 workbench 聊天面板 —— 壳经 kb:* 协议与会话/事件交互
|
|
77
|
+
assert(html.includes('id="view-terminal"') && html.includes('id="fr-5760"'));
|
|
78
|
+
assert(html.includes('id="view-search"') && html.includes('id="fr-8787"'));
|
|
79
|
+
assert(app.includes("'kb:select-project'") && app.includes("'kb:list-sessions'") && app.includes("'kb:open-session'"));
|
|
80
|
+
assert(app.includes("'kb:sidebar'"), 'embed protocol wiring must cover fold');
|
|
81
|
+
// 会话生命周期(archive/restore)只属于 terminal 模块,壳保持只读投影
|
|
82
|
+
assert(!app.includes("'kb:archive-session'") && !app.includes("'kb:restore-session'"), 'session lifecycle wiring must stay terminal-module-only');
|
|
83
|
+
|
|
84
|
+
runner.deleteSession(started.sessionId);
|
|
85
|
+
console.log('chat runner contract test PASS');
|
|
86
|
+
} finally {
|
|
87
|
+
try { fs.rmSync(temp, { recursive: true, force: true }); } catch {}
|
|
88
|
+
}
|
|
89
|
+
})().catch(error => {
|
|
90
|
+
console.error(error.stack || error.message);
|
|
91
|
+
process.exitCode = 1;
|
|
92
|
+
});
|