@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,189 @@
|
|
|
1
|
+
// Run: node _site/_test/client-capture-restart-e2e-test.js
|
|
2
|
+
//
|
|
3
|
+
// T21 gates: OpenCode + Claude Code + Codex external sessions are captured into the
|
|
4
|
+
// imported project's Development Conversation; Project-Knowledge offline
|
|
5
|
+
// accumulation is recovered by the startup drain in order without
|
|
6
|
+
// duplicates; fake/duplicate notifications never fabricate events.
|
|
7
|
+
|
|
8
|
+
const assert = require('assert');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const os = require('os');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const { execSync } = require('child_process');
|
|
13
|
+
const { StorageLayout } = require('../lib/storage-layout');
|
|
14
|
+
const { ProjectRegistryStore } = require('../lib/project-registry-store');
|
|
15
|
+
const { ProjectStore } = require('../lib/project-store');
|
|
16
|
+
const { ConversationStore } = require('../lib/conversation-store');
|
|
17
|
+
const { BridgeAdapter } = require('../lib/bridge-adapter');
|
|
18
|
+
const { BridgeConsumerService } = require('../lib/bridge-consumer-service');
|
|
19
|
+
const { readDevelopmentEvents } = require('../lib/conversation-exclusions');
|
|
20
|
+
const bridgePackage = require('@sanqianx/ai-coding-event-bridge');
|
|
21
|
+
const opencodeEntry = require('@sanqianx/ai-coding-event-bridge/src/connectors/opencode/hook-entry');
|
|
22
|
+
const claudeEntry = require('@sanqianx/ai-coding-event-bridge/src/connectors/claude-code/hook-entry');
|
|
23
|
+
const codexEntry = require('@sanqianx/ai-coding-event-bridge/src/connectors/codex/hook-entry');
|
|
24
|
+
|
|
25
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), `kb-client-e2e-${process.pid}-`));
|
|
26
|
+
const layout = new StorageLayout({ dataDir: path.join(temp, 'data') });
|
|
27
|
+
const registry = new ProjectRegistryStore({ layout });
|
|
28
|
+
const projects = new ProjectStore({ layout });
|
|
29
|
+
const bridgeHome = path.join(temp, 'bridge-home');
|
|
30
|
+
const adapter = new BridgeAdapter({ dataDir: layout.dataDir, bridgeModule: bridgePackage, bridgeHomeDir: bridgeHome });
|
|
31
|
+
const store = new ConversationStore({ layout, projectStore: projects, logger: null });
|
|
32
|
+
|
|
33
|
+
const ccs = path.join(temp, 'CCS');
|
|
34
|
+
fs.mkdirSync(ccs, { recursive: true });
|
|
35
|
+
execSync('git init -q', { cwd: ccs, stdio: 'ignore' });
|
|
36
|
+
execSync('git config user.email e@example.test && git config user.name E', { cwd: ccs, shell: true, stdio: 'ignore' });
|
|
37
|
+
fs.writeFileSync(path.join(ccs, 'README.md'), '# ccs\n');
|
|
38
|
+
execSync('git add . && git commit -q -m init', { cwd: ccs, shell: true, stdio: 'ignore' });
|
|
39
|
+
|
|
40
|
+
const sessionsRoot = path.join(temp, 'codex-sessions');
|
|
41
|
+
fs.mkdirSync(sessionsRoot, { recursive: true });
|
|
42
|
+
|
|
43
|
+
function codexSessionFile(sessionId, cwd, turns, { day = '20', suffix = '' } = {}) {
|
|
44
|
+
const dir = path.join(sessionsRoot, '2026', '08', day);
|
|
45
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
46
|
+
const lines = [JSON.stringify({ type: 'session_meta', payload: { cwd } })];
|
|
47
|
+
for (const turn of turns) {
|
|
48
|
+
lines.push(JSON.stringify({
|
|
49
|
+
type: 'response_item',
|
|
50
|
+
payload: {
|
|
51
|
+
type: 'message',
|
|
52
|
+
role: turn.role,
|
|
53
|
+
phase: turn.phase,
|
|
54
|
+
internal_chat_message_metadata_passthrough: { turn_id: turn.turnId },
|
|
55
|
+
content: [{ type: turn.role === 'user' ? 'input_text' : 'output_text', text: turn.text }],
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
const file = path.join(dir, `rollout-2026-08-${day}T00-00-00-${sessionId}${suffix ? `_${suffix}` : ''}.jsonl`);
|
|
60
|
+
fs.writeFileSync(file, `${lines.join('\n')}\n`);
|
|
61
|
+
return file;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function main() {
|
|
65
|
+
await registry.initialize();
|
|
66
|
+
const identity = (await bridgePackage.resolveRepoContext(ccs)).repoIdentity;
|
|
67
|
+
const watermark = await adapter.getHighWatermark({});
|
|
68
|
+
await projects.create('project-ccs', {
|
|
69
|
+
storageName: 'project-ccs', displayName: 'project-ccs',
|
|
70
|
+
repoPath: ccs, knowledgePath: path.join(temp, 'knowledge', 'project-ccs'),
|
|
71
|
+
repoIdentity: identity,
|
|
72
|
+
}, { conversationBaselineCursor: watermark.cursor });
|
|
73
|
+
await registry.add('project-ccs', { displayName: 'project-ccs' });
|
|
74
|
+
|
|
75
|
+
// OpenCode external session without client turnIds (GATE CLIENT-OPENCODE-001).
|
|
76
|
+
const ocUser = await opencodeEntry.main({ home: bridgeHome, payload: { type: 'user', sessionId: 'oc-s1', cwd: ccs, text: 'OpenCode prompt in CCS' } });
|
|
77
|
+
const ocAssistant = await opencodeEntry.main({ home: bridgeHome, payload: { type: 'assistant', sessionId: 'oc-s1', cwd: ccs, text: 'OpenCode reply in CCS' } });
|
|
78
|
+
assert.match(ocUser.turnId, /^turn_/, 'Bridge mints the user turnId');
|
|
79
|
+
assert.strictEqual(ocAssistant.turnId, ocUser.turnId, 'assistant binds to the same durable turn');
|
|
80
|
+
|
|
81
|
+
// Claude Code real hook payload names and durable prompt/Stop pairing
|
|
82
|
+
// (GATE CLIENT-CLAUDE-001).
|
|
83
|
+
const claudeUser = await claudeEntry.main({ home: bridgeHome, payload: {
|
|
84
|
+
hook_event_name: 'UserPromptSubmit', session_id: 'claude-s1', cwd: ccs, prompt: 'Claude prompt in CCS',
|
|
85
|
+
} });
|
|
86
|
+
const claudeAssistant = await claudeEntry.main({ home: bridgeHome, payload: {
|
|
87
|
+
hook_event_name: 'Stop', session_id: 'claude-s1', cwd: ccs, last_assistant_message: 'Claude reply in CCS',
|
|
88
|
+
} });
|
|
89
|
+
assert.strictEqual(claudeAssistant.turnId, claudeUser.turnId, 'Claude Stop closes the submitted prompt turn');
|
|
90
|
+
|
|
91
|
+
// Codex external session driven by authoritative session_meta cwd and the
|
|
92
|
+
// real nested turn id. Simulate an installed Bridge 0.1.1 cursor pinned to
|
|
93
|
+
// the first rollout, then discover and recover its continuation (GATE
|
|
94
|
+
// CLIENT-CODEX-001 / CODEX-CURSOR-MIGRATION-001).
|
|
95
|
+
const codexFirst = codexSessionFile('codex-s1', ccs, [
|
|
96
|
+
{ role: 'user', turnId: 'codex-turn-1', text: '<environment_context>generated transport context</environment_context>' },
|
|
97
|
+
{ role: 'user', turnId: 'codex-turn-1', text: 'Codex prompt in CCS' },
|
|
98
|
+
{ role: 'assistant', turnId: 'codex-turn-1', phase: 'commentary', text: 'Codex working in CCS' },
|
|
99
|
+
]);
|
|
100
|
+
const codexFirstResult = await codexEntry.main({ home: bridgeHome, payload: { session_id: 'codex-s1', sessions_root: sessionsRoot } });
|
|
101
|
+
assert.strictEqual(codexFirstResult.status, 'captured');
|
|
102
|
+
assert.strictEqual(codexFirstResult.captured, 3);
|
|
103
|
+
const codexCursorFile = path.join(bridgeHome, 'cursors', 'codex', 'codex-s1.json');
|
|
104
|
+
const codexCursorV2 = JSON.parse(fs.readFileSync(codexCursorFile, 'utf8'));
|
|
105
|
+
const firstFileCursor = Object.values(codexCursorV2.files)[0];
|
|
106
|
+
fs.writeFileSync(codexCursorFile, JSON.stringify({
|
|
107
|
+
sessionId: 'codex-s1',
|
|
108
|
+
filePath: codexFirst,
|
|
109
|
+
byteOffset: firstFileCursor.byteOffset,
|
|
110
|
+
lastRecordKey: firstFileCursor.lastRecordKey,
|
|
111
|
+
activeCwd: firstFileCursor.activeCwd,
|
|
112
|
+
repoIdentity: firstFileCursor.repoIdentity,
|
|
113
|
+
projectPath: firstFileCursor.projectPath,
|
|
114
|
+
branch: firstFileCursor.branch,
|
|
115
|
+
headAtCapture: firstFileCursor.headAtCapture,
|
|
116
|
+
}));
|
|
117
|
+
codexSessionFile('codex-s1', ccs, [
|
|
118
|
+
{ role: 'assistant', turnId: 'codex-turn-1', phase: 'final_answer', text: 'Codex reply in CCS' },
|
|
119
|
+
], { day: '21', suffix: 'continuation' });
|
|
120
|
+
const codexResult = await codexEntry.main({ home: bridgeHome, payload: { session_id: 'codex-s1', sessions_root: sessionsRoot } });
|
|
121
|
+
assert.strictEqual(codexResult.captured, 1, 'continuation captured without replaying the first rollout');
|
|
122
|
+
assert.strictEqual(codexResult.files, 2);
|
|
123
|
+
const migratedCursor = JSON.parse(fs.readFileSync(codexCursorFile, 'utf8'));
|
|
124
|
+
assert.strictEqual(migratedCursor.schema, 'codex-cursor/v2');
|
|
125
|
+
assert.strictEqual(Object.keys(migratedCursor.files).length, 2);
|
|
126
|
+
|
|
127
|
+
// OFFLINE-001: the consumer process was "stopped" while the events above
|
|
128
|
+
// accumulated; a fresh service instance (restart) recovers everything from
|
|
129
|
+
// the durable journal — in order, once, with no notification dependency.
|
|
130
|
+
const restarted = new BridgeConsumerService({
|
|
131
|
+
bridgeAdapter: adapter, conversationStore: store, registryStore: registry, projectStore: projects, logger: null,
|
|
132
|
+
});
|
|
133
|
+
await restarted.start();
|
|
134
|
+
const rawEvents = store.readEvents('project-ccs');
|
|
135
|
+
assert.strictEqual(rawEvents.length, 8, 'startup drain recovered every durable external record');
|
|
136
|
+
const events = readDevelopmentEvents(store, 'project-ccs');
|
|
137
|
+
assert.strictEqual(events.length, 7, 'generated Codex context is excluded from Development Conversation');
|
|
138
|
+
assert.deepStrictEqual(
|
|
139
|
+
events.map(event => event.sequence).sort((a, b) => a - b),
|
|
140
|
+
[...events.map(event => event.sequence)].sort((a, b) => a - b),
|
|
141
|
+
);
|
|
142
|
+
const ocEvents = events.filter(event => event.source === 'opencode');
|
|
143
|
+
assert.strictEqual(ocEvents.length, 2);
|
|
144
|
+
assert.strictEqual(ocEvents[0].turnId, ocEvents[1].turnId, 'OpenCode turn grouped durably');
|
|
145
|
+
const claudeEvents = events.filter(event => event.source === 'claude-code');
|
|
146
|
+
assert.strictEqual(claudeEvents.length, 2);
|
|
147
|
+
assert.strictEqual(claudeEvents[0].turnId, claudeEvents[1].turnId, 'Claude Code turn grouped durably');
|
|
148
|
+
const codexEvents = events.filter(event => event.source === 'codex');
|
|
149
|
+
assert.strictEqual(codexEvents.length, 3);
|
|
150
|
+
assert.ok(codexEvents.every(event => event.repoIdentity.workspaceId === identity.workspaceId),
|
|
151
|
+
'Codex events attributed from session_meta.cwd, not the session file location');
|
|
152
|
+
assert.ok(codexEvents.every(event => event.turnId === 'codex-turn-1'), 'all Codex phases share the real turn identity');
|
|
153
|
+
assert.strictEqual(new Set(events.map(event => event.eventId)).size, 7, 'no duplicates after recovery');
|
|
154
|
+
|
|
155
|
+
// NOTIFY-001: fake/duplicate notifications with garbage bodies never
|
|
156
|
+
// fabricate journal events; the consumer only drains the durable journal.
|
|
157
|
+
const beforeNotify = store.readEvents('project-ccs').length;
|
|
158
|
+
await restarted.handleNotification();
|
|
159
|
+
await restarted.handleNotification();
|
|
160
|
+
assert.strictEqual(store.readEvents('project-ccs').length, beforeNotify, 'duplicate wake-ups are idempotent');
|
|
161
|
+
|
|
162
|
+
// Duplicate physical events (re-fired connector payload with same eventKey
|
|
163
|
+
// semantics) do not double-project: re-running the Codex notify with no new
|
|
164
|
+
// bytes captures nothing.
|
|
165
|
+
const codexAgain = await codexEntry.main({ home: bridgeHome, payload: { session_id: 'codex-s1', sessions_root: sessionsRoot } });
|
|
166
|
+
assert.strictEqual(codexAgain.captured, 0, 'cursor-based idempotency');
|
|
167
|
+
await restarted.drain('notify');
|
|
168
|
+
assert.strictEqual(store.readEvents('project-ccs').length, beforeNotify, 'no event loss or duplication from replayed notifies');
|
|
169
|
+
|
|
170
|
+
// Capture-disable: an internal-marked session never reaches the store.
|
|
171
|
+
const previousCapture = process.env.AI_CODING_EVENT_BRIDGE_CAPTURE;
|
|
172
|
+
process.env.AI_CODING_EVENT_BRIDGE_CAPTURE = '0';
|
|
173
|
+
try {
|
|
174
|
+
const disabled = await opencodeEntry.main({ home: bridgeHome, payload: { type: 'user', sessionId: 'oc-internal', cwd: ccs, text: 'internal session' } });
|
|
175
|
+
assert.deepStrictEqual(disabled, { status: 'ignored', reason: 'capture-disabled' });
|
|
176
|
+
} finally {
|
|
177
|
+
if (previousCapture === undefined) delete process.env.AI_CODING_EVENT_BRIDGE_CAPTURE;
|
|
178
|
+
else process.env.AI_CODING_EVENT_BRIDGE_CAPTURE = previousCapture;
|
|
179
|
+
}
|
|
180
|
+
await restarted.drain('notify');
|
|
181
|
+
assert.strictEqual(store.readEvents('project-ccs').length, beforeNotify, 'internal sessions add zero Development Conversation events');
|
|
182
|
+
|
|
183
|
+
console.log('client-capture-restart-e2e-test PASS');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
main().catch(error => {
|
|
187
|
+
console.error(error.stack || error.message);
|
|
188
|
+
process.exitCode = 1;
|
|
189
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Run: node _site/_test/codex-conversation-projection-test.js
|
|
2
|
+
//
|
|
3
|
+
// Codex Bridge 0.1.1 compatibility: generated rollout context is excluded,
|
|
4
|
+
// orphan assistant records are projected onto the latest real user turn, and
|
|
5
|
+
// raw append-only events are never rewritten.
|
|
6
|
+
|
|
7
|
+
const assert = require('assert');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const {
|
|
11
|
+
computeConversationExclusions,
|
|
12
|
+
projectCodexTurns,
|
|
13
|
+
} = require('../lib/conversation-exclusions');
|
|
14
|
+
|
|
15
|
+
const projectId = 'project-codex-projection';
|
|
16
|
+
const sessionId = 'codex-session';
|
|
17
|
+
const base = {
|
|
18
|
+
source: 'codex',
|
|
19
|
+
sessionId,
|
|
20
|
+
rawEventType: 'response_item',
|
|
21
|
+
capturedAt: '2026-08-24T16:06:00.000Z',
|
|
22
|
+
};
|
|
23
|
+
const event = input => ({ ...base, ...input });
|
|
24
|
+
const context = event({
|
|
25
|
+
eventId: 'context', sequence: 1, role: 'user', turnId: 'generated-context',
|
|
26
|
+
content: '<recommended_plugins>generated</recommended_plugins>\n<environment_context>generated</environment_context>',
|
|
27
|
+
});
|
|
28
|
+
const user = event({ eventId: 'user', sequence: 2, role: 'user', turnId: 'turn-user', content: 'hello' });
|
|
29
|
+
const commentary = event({ eventId: 'assistant-1', sequence: 3, role: 'assistant', turnId: null, content: 'Working.' });
|
|
30
|
+
const finalReply = event({ eventId: 'assistant-2', sequence: 4, role: 'assistant', turnId: null, content: 'Done.' });
|
|
31
|
+
const nextUser = event({ eventId: 'next-user', sequence: 5, role: 'user', turnId: 'turn-next', content: 'Next request.' });
|
|
32
|
+
const aborted = event({
|
|
33
|
+
eventId: 'aborted', sequence: 6, role: 'user', turnId: 'generated-abort',
|
|
34
|
+
content: '<turn_aborted>\nThe user interrupted the previous turn.\n</turn_aborted>',
|
|
35
|
+
});
|
|
36
|
+
const orphan = event({ eventId: 'orphan', sequence: 7, role: 'assistant', turnId: null, sessionId: 'other-session', content: 'No known user.' });
|
|
37
|
+
const raw = [orphan, aborted, finalReply, nextUser, context, commentary, user];
|
|
38
|
+
const before = JSON.stringify(raw);
|
|
39
|
+
|
|
40
|
+
const manifest = computeConversationExclusions(projectId, raw);
|
|
41
|
+
assert.deepStrictEqual(manifest.excludedEventIds, ['aborted', 'context']);
|
|
42
|
+
|
|
43
|
+
const projected = projectCodexTurns(raw, manifest.excludedEventIds);
|
|
44
|
+
assert.deepStrictEqual(projected.map(item => item.eventId), ['user', 'assistant-1', 'assistant-2', 'next-user', 'orphan']);
|
|
45
|
+
assert.deepStrictEqual(
|
|
46
|
+
projected.filter(item => item.eventId.startsWith('assistant-')).map(item => item.turnId),
|
|
47
|
+
['turn-user', 'turn-user'],
|
|
48
|
+
'all Codex assistant messages in the turn must pair with its real user prompt',
|
|
49
|
+
);
|
|
50
|
+
assert.strictEqual(projected.find(item => item.eventId === 'user').developmentTurnClosedAtSequence, 5);
|
|
51
|
+
assert.strictEqual(projected.find(item => item.eventId === 'next-user').developmentTurnClosedAtSequence, 6);
|
|
52
|
+
assert.strictEqual(projected.find(item => item.eventId === 'orphan').turnId, null, 'never pair across Codex sessions');
|
|
53
|
+
assert.strictEqual(JSON.stringify(raw), before, 'projection must not rewrite durable source events');
|
|
54
|
+
|
|
55
|
+
const uiSource = fs.readFileSync(path.resolve(__dirname, '..', '..', 'ui', 'app.js'), 'utf8');
|
|
56
|
+
assert(!uiSource.includes('(无用户文本)'), 'UI must not invent a user message for an assistant-only record');
|
|
57
|
+
assert(!uiSource.includes('(尚无回复)'), 'UI must not invent an assistant reply for an incomplete turn');
|
|
58
|
+
|
|
59
|
+
console.log('codex-conversation-projection-test PASS');
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Run: node _site/_test/codex-notify-fanout-test.js
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { spawnSync } = require('child_process');
|
|
7
|
+
|
|
8
|
+
const ROOT = path.resolve(__dirname, '..', '..');
|
|
9
|
+
const TEMP = fs.mkdtempSync(path.join(os.tmpdir(), `pk-codex-fanout-${process.pid}-`));
|
|
10
|
+
const receiver = path.join(TEMP, 'receiver.cjs');
|
|
11
|
+
const nextOutput = path.join(TEMP, 'next.json');
|
|
12
|
+
const bridgeOutput = path.join(TEMP, 'bridge.json');
|
|
13
|
+
|
|
14
|
+
fs.writeFileSync(receiver, "let data=''; process.stdin.on('data', chunk => data += chunk); process.stdin.on('end', () => require('fs').writeFileSync(process.argv[2], data));", 'utf8');
|
|
15
|
+
|
|
16
|
+
function encoded(output) {
|
|
17
|
+
return Buffer.from(JSON.stringify([process.execPath, receiver, output])).toString('base64');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function waitFor(file) {
|
|
21
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
22
|
+
if (fs.existsSync(file)) return;
|
|
23
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`timed out waiting for ${path.basename(file)}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
(async () => {
|
|
29
|
+
const payload = JSON.stringify({ session_id: 'codex-session-test', type: 'turn-ended' });
|
|
30
|
+
const result = spawnSync(process.execPath, [
|
|
31
|
+
path.join(ROOT, '_site', 'scripts', 'codex-notify-fanout.cjs'),
|
|
32
|
+
'--next-base64', encoded(nextOutput),
|
|
33
|
+
'--bridge-base64', encoded(bridgeOutput),
|
|
34
|
+
], { input: payload, encoding: 'utf8', windowsHide: true });
|
|
35
|
+
assert.strictEqual(result.status, 0, result.stderr || 'fan-out process should succeed');
|
|
36
|
+
await Promise.all([waitFor(nextOutput), waitFor(bridgeOutput)]);
|
|
37
|
+
assert.strictEqual(fs.readFileSync(nextOutput, 'utf8'), payload, 'existing notifier must receive the original Codex payload');
|
|
38
|
+
assert.strictEqual(fs.readFileSync(bridgeOutput, 'utf8'), payload, 'Bridge must receive the same Codex payload');
|
|
39
|
+
console.log('codex-notify-fanout-test PASS');
|
|
40
|
+
})().catch(error => {
|
|
41
|
+
console.error(error.stack || error.message);
|
|
42
|
+
process.exitCode = 1;
|
|
43
|
+
}).finally(() => {
|
|
44
|
+
fs.rmSync(TEMP, { recursive: true, force: true });
|
|
45
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// Run: node _site/_test/commit-boundary-freeze-test.js
|
|
2
|
+
//
|
|
3
|
+
// T13 gates: frozen snapshots never contain events beyond the commit
|
|
4
|
+
// boundary (I-13), same-workspace-only binding, legacy confidence
|
|
5
|
+
// translation, and idempotent freeze.
|
|
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 { CommitConversationBinder } = require('../lib/commit-conversation-binder');
|
|
17
|
+
const bridgeModule = require('@sanqianx/ai-coding-event-bridge');
|
|
18
|
+
|
|
19
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), `kb-boundary-freeze-${process.pid}-`));
|
|
20
|
+
const layout = new StorageLayout({ dataDir: path.join(temp, 'data') });
|
|
21
|
+
const registry = new ProjectRegistryStore({ layout });
|
|
22
|
+
const projects = new ProjectStore({ layout });
|
|
23
|
+
const store = new ConversationStore({ layout, projectStore: projects, logger: null });
|
|
24
|
+
|
|
25
|
+
function gitRepo(name) {
|
|
26
|
+
const dir = path.join(temp, name);
|
|
27
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
28
|
+
execSync('git init -q', { cwd: dir, stdio: 'ignore' });
|
|
29
|
+
return dir;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function bridgeRecord(sequence, eventType, role, content, repoIdentity, turnId, confidence) {
|
|
33
|
+
return {
|
|
34
|
+
schema: 'ai-coding-event/v1',
|
|
35
|
+
eventId: `evt-${sequence}`,
|
|
36
|
+
sequence,
|
|
37
|
+
source: 'claude-code',
|
|
38
|
+
eventType,
|
|
39
|
+
role,
|
|
40
|
+
content,
|
|
41
|
+
sessionId: 's-boundary',
|
|
42
|
+
turnId,
|
|
43
|
+
repoIdentity,
|
|
44
|
+
identityConfidence: confidence || 'exact',
|
|
45
|
+
captureStatus: 'complete',
|
|
46
|
+
capturedAt: new Date().toISOString(),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
(async () => {
|
|
51
|
+
await registry.initialize();
|
|
52
|
+
const ccsPath = gitRepo('ccs');
|
|
53
|
+
const ccbPath = gitRepo('ccb');
|
|
54
|
+
const ccs = (await bridgeModule.resolveRepoContext(ccsPath)).repoIdentity;
|
|
55
|
+
const ccb = (await bridgeModule.resolveRepoContext(ccbPath)).repoIdentity;
|
|
56
|
+
const projectId = 'project-freeze';
|
|
57
|
+
await projects.create(projectId, {
|
|
58
|
+
storageName: projectId,
|
|
59
|
+
displayName: projectId,
|
|
60
|
+
repoPath: ccsPath,
|
|
61
|
+
knowledgePath: path.join(temp, 'knowledge', projectId),
|
|
62
|
+
repoIdentity: ccs,
|
|
63
|
+
}, { conversationBaselineCursor: 99 });
|
|
64
|
+
await registry.add(projectId, { displayName: projectId });
|
|
65
|
+
|
|
66
|
+
const binder = new CommitConversationBinder({ layout, projectStore: projects, conversationStore: store, logger: null });
|
|
67
|
+
|
|
68
|
+
const boundary = (commitSha, cursor, openTurnIds) => store.writeBoundary(projectId, {
|
|
69
|
+
repoIdentity: ccs,
|
|
70
|
+
commitSha,
|
|
71
|
+
parentShas: [],
|
|
72
|
+
branch: 'main',
|
|
73
|
+
committedAt: new Date().toISOString(),
|
|
74
|
+
bridgeCursorAtCommit: cursor,
|
|
75
|
+
openTurnIdsAtCommit: openTurnIds || [],
|
|
76
|
+
operationId: `op-${cursor}`,
|
|
77
|
+
journalSequence: cursor,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// BOUNDARY-001: user(100), boundary(101), assistant(102) created later.
|
|
81
|
+
await store.appendBridgeEvent(projectId, bridgeRecord(100, 'user_prompt', 'user', 'prompt before boundary', ccs, 'turn-1'));
|
|
82
|
+
await store.appendBridgeEvent(projectId, bridgeRecord(102, 'assistant_response', 'assistant', 'reply after boundary', ccs, 'turn-1'));
|
|
83
|
+
boundary('a'.repeat(40), 101, []);
|
|
84
|
+
const snapshotA = await binder.bind({ projectId, commitSha: 'a'.repeat(40) });
|
|
85
|
+
assert.strictEqual(snapshotA.status, 'available');
|
|
86
|
+
assert.strictEqual(snapshotA.turns.length, 1);
|
|
87
|
+
assert.strictEqual(snapshotA.turns[0].turnId, 'turn-1');
|
|
88
|
+
assert.ok(snapshotA.turns[0].userEvents.some(event => event.sequence === 100), 'user event inside window is bound');
|
|
89
|
+
assert.strictEqual(snapshotA.turns[0].assistantEvents.length, 0, 'assistant beyond boundaryEndCursor must never enter the frozen snapshot');
|
|
90
|
+
|
|
91
|
+
// BOUNDARY-002: user(200), assistant(201) before boundary(202).
|
|
92
|
+
await store.appendBridgeEvent(projectId, bridgeRecord(200, 'user_prompt', 'user', 'second prompt', ccs, 'turn-2'));
|
|
93
|
+
await store.appendBridgeEvent(projectId, bridgeRecord(201, 'assistant_response', 'assistant', 'reply before boundary', ccs, 'turn-2'));
|
|
94
|
+
boundary('b'.repeat(40), 202, []);
|
|
95
|
+
const snapshotB = await binder.bind({ projectId, commitSha: 'b'.repeat(40) });
|
|
96
|
+
assert.ok(snapshotB.turns.some(turn => turn.turnId === 'turn-2'
|
|
97
|
+
&& turn.assistantEvents.some(event => event.sequence === 201)), 'assistant before boundary may enter');
|
|
98
|
+
assert.ok(!snapshotB.turns.some(turn => turn.turnId === 'turn-1'), 'already-bound turn is not re-selected in the next window');
|
|
99
|
+
|
|
100
|
+
// Cross-repo: CCB event right before a CCS commit is never substituted.
|
|
101
|
+
// The consumer would never project a CCB event into the CCS store at all
|
|
102
|
+
// (appendBridgeEvent rejects it); raw appendEvent simulates legacy stored
|
|
103
|
+
// data so the binder's workspace filter is exercised directly.
|
|
104
|
+
{
|
|
105
|
+
const rejected = await store.appendBridgeEvent(projectId, bridgeRecord(299, 'user_prompt', 'user', 'blocked at the door', ccb, 'turn-ccb-blocked')).catch(error => error);
|
|
106
|
+
assert.ok(rejected instanceof Error && rejected.code === 'DATA_CORRUPT', 'appendBridgeEvent rejects foreign-workspace events');
|
|
107
|
+
}
|
|
108
|
+
await store.appendEvent(projectId, {
|
|
109
|
+
eventId: 'evt-300',
|
|
110
|
+
sequence: 300,
|
|
111
|
+
source: 'claude-code',
|
|
112
|
+
eventType: 'user_prompt',
|
|
113
|
+
role: 'user',
|
|
114
|
+
content: 'Modify CCB parser',
|
|
115
|
+
sessionId: 's-boundary',
|
|
116
|
+
turnId: 'turn-ccb',
|
|
117
|
+
repoIdentity: ccb,
|
|
118
|
+
identityConfidence: 'exact',
|
|
119
|
+
captureStatus: 'complete',
|
|
120
|
+
capturedAt: new Date().toISOString(),
|
|
121
|
+
});
|
|
122
|
+
boundary('c'.repeat(40), 301, []);
|
|
123
|
+
const snapshotC = await binder.bind({ projectId, commitSha: 'c'.repeat(40) });
|
|
124
|
+
assert.strictEqual(snapshotC.status, 'no-new-user-prompt', 'no CCS conversation yields a deterministic empty status');
|
|
125
|
+
assert.ok(!JSON.stringify(snapshotC).includes('Modify CCB parser'), 'CCB conversation must not leak into a CCS snapshot');
|
|
126
|
+
|
|
127
|
+
// Legacy confidence translation: stored 'high' behaves as exact.
|
|
128
|
+
await store.appendBridgeEvent(projectId, bridgeRecord(400, 'user_prompt', 'user', 'legacy confidence prompt', ccs, 'turn-3', 'high'));
|
|
129
|
+
boundary('d'.repeat(40), 401, []);
|
|
130
|
+
const snapshotD = await binder.bind({ projectId, commitSha: 'd'.repeat(40) });
|
|
131
|
+
assert.ok(snapshotD.turns.some(turn => turn.turnId === 'turn-3'), 'legacy high/trusted translates to exact for old stored data');
|
|
132
|
+
|
|
133
|
+
// Partial confidence never binds as direct evidence.
|
|
134
|
+
await store.appendBridgeEvent(projectId, bridgeRecord(500, 'user_prompt', 'user', 'partial identity prompt', ccs, 'turn-4', 'partial'));
|
|
135
|
+
boundary('e'.repeat(40), 501, []);
|
|
136
|
+
const snapshotE = await binder.bind({ projectId, commitSha: 'e'.repeat(40) });
|
|
137
|
+
assert.ok(!snapshotE.turns.some(turn => turn.turnId === 'turn-4'), 'partial identity is ambiguous, never direct evidence');
|
|
138
|
+
|
|
139
|
+
// Immutable freeze: rebinding returns the identical hash.
|
|
140
|
+
const rebound = await binder.bind({ projectId, commitSha: 'a'.repeat(40) });
|
|
141
|
+
assert.strictEqual(rebound.snapshotHash, snapshotA.snapshotHash, 'frozen snapshots are never rewritten');
|
|
142
|
+
|
|
143
|
+
console.log('commit-boundary-freeze-test PASS');
|
|
144
|
+
})().catch(error => {
|
|
145
|
+
console.error(error.stack || error.message);
|
|
146
|
+
process.exitCode = 1;
|
|
147
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { StorageLayout } = require('../lib/storage-layout');
|
|
6
|
+
const { ProjectStore } = require('../lib/project-store');
|
|
7
|
+
const { ConversationStore } = require('../lib/conversation-store');
|
|
8
|
+
const { CommitConversationBinder } = require('../lib/commit-conversation-binder');
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-conversation-binding-'));
|
|
12
|
+
const layout = new StorageLayout({ dataDir: path.join(root, 'data') });
|
|
13
|
+
const projectStore = new ProjectStore({ layout });
|
|
14
|
+
const projectId = 'project-binding';
|
|
15
|
+
const repoIdentity = { commonDir: path.join(root, 'repo', '.git') };
|
|
16
|
+
await projectStore.create(projectId, {
|
|
17
|
+
displayName: 'Binding',
|
|
18
|
+
storageName: 'binding',
|
|
19
|
+
repoPath: path.join(root, 'repo'),
|
|
20
|
+
knowledgePath: path.join(root, 'knowledge'),
|
|
21
|
+
repoIdentity,
|
|
22
|
+
}, { conversationBaselineCursor: 0, conversation: { lastConsumedCursor: 0, captureStatus: 'captured' } });
|
|
23
|
+
const store = new ConversationStore({ layout, projectStore });
|
|
24
|
+
const binder = new CommitConversationBinder({ layout, projectStore, conversationStore: store });
|
|
25
|
+
const c1 = '1'.repeat(40);
|
|
26
|
+
const c2 = '2'.repeat(40);
|
|
27
|
+
const c3 = '3'.repeat(40);
|
|
28
|
+
const cMerge = '4'.repeat(40);
|
|
29
|
+
const cAmbiguous = '5'.repeat(40);
|
|
30
|
+
|
|
31
|
+
const append = input => store.appendEvent(projectId, {
|
|
32
|
+
source: 'codex',
|
|
33
|
+
sessionId: 'session-1',
|
|
34
|
+
projectPath: path.join(root, 'repo'),
|
|
35
|
+
repoIdentity,
|
|
36
|
+
branch: 'main',
|
|
37
|
+
headAtCapture: '0'.repeat(40),
|
|
38
|
+
capturedAt: `2026-08-18T02:${String(input.sequence || 0).padStart(2, '0')}:00.000Z`,
|
|
39
|
+
rawEventType: input.eventType,
|
|
40
|
+
identityConfidence: 'high',
|
|
41
|
+
captureStatus: 'captured',
|
|
42
|
+
...input,
|
|
43
|
+
});
|
|
44
|
+
await append({ eventId: 'r1', sequence: 1, eventType: 'user_prompt', role: 'user', content: 'Requirement before C1.', turnId: 'turn-1' });
|
|
45
|
+
const boundaryC1 = { commitSha: c1, repoIdentity, parentShas: [], branch: 'main', committedAt: '2026-08-18T02:02:00.000Z', bridgeCursorAtCommit: 2, journalSequence: 2, openTurnIdsAtCommit: ['turn-1'], operationId: 'op-c1' };
|
|
46
|
+
store.writeBoundary(projectId, boundaryC1);
|
|
47
|
+
assert.strictEqual(store.writeBoundary(projectId, boundaryC1).commitSha, c1, 'identical bridge/hook boundary is idempotent');
|
|
48
|
+
assert.throws(() => store.writeBoundary(projectId, { ...boundaryC1, branch: 'other' }), error => error.code === 'DATA_CORRUPT');
|
|
49
|
+
await append({ eventId: 'a1', sequence: 3, eventType: 'assistant_response', role: 'assistant', content: 'Late assistant before claim.', turnId: 'turn-1' });
|
|
50
|
+
await append({ eventId: 'r2', sequence: 4, eventType: 'user_prompt', role: 'user', content: 'Requirement after C1.', turnId: 'turn-2', headAtCapture: c1 });
|
|
51
|
+
|
|
52
|
+
const frozenC1 = await binder.bind({ projectId, commitSha: c1 });
|
|
53
|
+
assert.strictEqual(frozenC1.status, 'available');
|
|
54
|
+
assert.deepStrictEqual(frozenC1.turns.map(turn => turn.turnId), ['turn-1'], 'future R2 must never bind back to C1');
|
|
55
|
+
assert.deepStrictEqual(frozenC1.turns[0].assistantEvents.map(event => event.eventId), [], 'assistant beyond boundaryEndCursor must never enter the frozen snapshot (I-13)');
|
|
56
|
+
assert.strictEqual(frozenC1.excludedFuturePromptCount, 1);
|
|
57
|
+
const frozenHash = frozenC1.snapshotHash;
|
|
58
|
+
await append({ eventId: 'a1-after-claim', sequence: 6, eventType: 'assistant_response', role: 'assistant', content: 'Assistant arrived after Claim.', turnId: 'turn-1' });
|
|
59
|
+
const retriedC1 = await binder.bind({ projectId, commitSha: c1 });
|
|
60
|
+
assert.strictEqual(retriedC1.snapshotHash, frozenHash, 'retry must reuse the exact Claim-time conversation freeze');
|
|
61
|
+
assert.deepStrictEqual(retriedC1.turns[0].assistantEvents.map(event => event.eventId), [], 'delayed binder execution must not pull post-commit replies into the old snapshot');
|
|
62
|
+
|
|
63
|
+
store.writeBoundary(projectId, { commitSha: c2, repoIdentity, parentShas: [c1], branch: 'main', committedAt: '2026-08-18T02:05:00.000Z', bridgeCursorAtCommit: 5, journalSequence: 5, openTurnIdsAtCommit: ['turn-1'], operationId: 'op-c2' });
|
|
64
|
+
const frozenC2 = await binder.bind({ projectId, commitSha: c2 });
|
|
65
|
+
assert.deepStrictEqual(frozenC2.turns.map(turn => [turn.turnId, turn.bindingKind]), [['turn-1', 'shared-spanning'], ['turn-2', 'direct']]);
|
|
66
|
+
assert.deepStrictEqual(frozenC2.turns[0].assistantEvents.map(event => event.eventId), ['a1'], 'the assistant reply inside the C2 window belongs to the spanning turn');
|
|
67
|
+
assert.strictEqual(frozenC2.turns[0].turnId, frozenC1.turns[0].turnId, 'spanning turns must retain one stable identity across commits');
|
|
68
|
+
|
|
69
|
+
store.writeBoundary(projectId, { commitSha: c3, repoIdentity, parentShas: [c2], branch: 'main', committedAt: '2026-08-18T02:07:00.000Z', bridgeCursorAtCommit: 7, journalSequence: 7, openTurnIdsAtCommit: ['turn-1'], operationId: 'op-c3' });
|
|
70
|
+
const frozenC3 = await binder.bind({ projectId, commitSha: c3 });
|
|
71
|
+
assert.strictEqual(frozenC3.status, 'no-new-user-prompt');
|
|
72
|
+
assert.deepStrictEqual(frozenC3.turns, [], 'a stale Bridge open-turn id must not copy a closed requirement into a later commit');
|
|
73
|
+
|
|
74
|
+
await append({ eventId: 'r-merge', sequence: 8, eventType: 'user_prompt', role: 'user', content: 'Merge-window requirement.', turnId: 'turn-merge' });
|
|
75
|
+
store.writeBoundary(projectId, { commitSha: cMerge, repoIdentity, parentShas: [c1, c2], branch: 'main', committedAt: '2026-08-18T02:10:00.000Z', bridgeCursorAtCommit: 10, journalSequence: 10, openTurnIdsAtCommit: [], operationId: 'op-merge' });
|
|
76
|
+
const mergeSnapshot = await binder.bind({ projectId, commitSha: cMerge });
|
|
77
|
+
assert.strictEqual(mergeSnapshot.boundaryStartCursor, 7, 'merge window must use previous durable repo boundary, not an arbitrary Git parent');
|
|
78
|
+
assert.deepStrictEqual(mergeSnapshot.turns.map(turn => turn.turnId), ['turn-merge']);
|
|
79
|
+
|
|
80
|
+
await append({ eventId: 'r-ambiguous', sequence: 11, eventType: 'user_prompt', role: 'user', content: 'Identity unavailable.', turnId: null, repoIdentity: null, identityConfidence: 'unknown' });
|
|
81
|
+
store.writeBoundary(projectId, { commitSha: cAmbiguous, repoIdentity, parentShas: [cMerge], branch: 'main', committedAt: '2026-08-18T02:12:00.000Z', bridgeCursorAtCommit: 12, journalSequence: 12, openTurnIdsAtCommit: [], operationId: 'op-ambiguous' });
|
|
82
|
+
const ambiguous = await binder.bind({ projectId, commitSha: cAmbiguous });
|
|
83
|
+
assert.strictEqual(ambiguous.status, 'ambiguous');
|
|
84
|
+
assert.deepStrictEqual(ambiguous.turns, []);
|
|
85
|
+
|
|
86
|
+
const missingBoundary = await binder.bind({ projectId, commitSha: '6'.repeat(40) });
|
|
87
|
+
assert.strictEqual(missingBoundary.status, 'unavailable', 'missing boundary/capture gap must never fall back to timestamp or ancestry guessing');
|
|
88
|
+
|
|
89
|
+
const explicitSha = '7'.repeat(40);
|
|
90
|
+
await append({ eventId: 'explicit-r', sequence: null, eventType: 'user_prompt', role: 'user', content: 'Explicit requirement.', turnId: 'turn-explicit', explicitCommitSha: explicitSha, identityConfidence: 'explicit' });
|
|
91
|
+
const explicit = await binder.bind({ projectId, commitSha: explicitSha });
|
|
92
|
+
assert.strictEqual(explicit.status, 'available');
|
|
93
|
+
assert.strictEqual(explicit.turns[0].bindingKind, 'explicit');
|
|
94
|
+
|
|
95
|
+
console.log('commit-conversation-binding-test PASS');
|
|
96
|
+
})().catch(error => {
|
|
97
|
+
console.error(error.stack || error.message);
|
|
98
|
+
process.exitCode = 1;
|
|
99
|
+
});
|