feat(core): add first-class Pi session indexing (#23)
Pi cannot be read as another linear JSONL stream. Its history is a tree with a durable leaf, orphan roots, branch summaries, and two compaction forms, so the active context is something the format states rather than something line order implies. The adapter keeps those semantics inside itself and projects the result into the existing canonical tables. Sessions are keyed by (normalized header cwd, header id) rather than by path, because Pi's --session-id lookup is project-local: two projects may reuse an id, while a move or an identical copy is still one session. Discovery covers both layouts Pi writes and fingerprints each file by mtime, ctime, size and inode, so a rewrite that preserves mtime is not read as unchanged. Abandoned branches are preserved rather than dropped. Visibility becomes three-state -- visible, inactive, hidden -- and helpers return only visible rows until includeInactive asks for the superseded path, labeling every row so a caller knows which it holds. Usage counts all three, because an abandoned call still spent tokens; message_count reports only the visible transcript. A committed MIT-licensed oracle transcribed from Pi 0.83.0 pins the context algorithms, and a fixed-seed differential runs 512 generated sessions against it on every test run. Schema changes are additive.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Regression tests for the write-transaction runner (docs/adr/0006):
|
||||
// - a transient BUSY (auto-rolled-back txn) is retried and recovers;
|
||||
// - a persistent BUSY exhausts retries, and that file is SKIPPED, not fatal;
|
||||
// - a persistent BUSY exhausts retries without publishing a partial force rebuild;
|
||||
// - the guarded rollback never masks the real error ("cannot rollback ...").
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
@@ -180,7 +180,7 @@ test('a transient BUSY during a file transaction is retried and recovers', () =>
|
||||
assert.equal(result.skipped, 0);
|
||||
});
|
||||
|
||||
test('a persistent BUSY exhausts retries and skips just that file, not the build', () => {
|
||||
test('a persistent BUSY rolls back the complete force rebuild', () => {
|
||||
const { home, dbPath, projectsDir } = twoFileHome('POISON alpha', 'hello beta');
|
||||
// Always poison writes that carry alpha's marker text; beta is untouched.
|
||||
const Db = makeDbClass((args) => args.some(a => typeof a === 'string' && a.includes('POISON')));
|
||||
@@ -191,7 +191,8 @@ test('a persistent BUSY exhausts retries and skips just that file, not the build
|
||||
const check = new DatabaseSync(dbPath);
|
||||
const sessions = check.prepare('SELECT id FROM sessions ORDER BY id').all().map(r => r.id);
|
||||
check.close();
|
||||
assert.deepEqual(sessions, ['beta'], 'the persistently-failing file is skipped; the other indexes');
|
||||
assert.deepEqual(sessions, [], 'no partial force snapshot is published');
|
||||
assert.equal(result.complete, false);
|
||||
assert.equal(result.skipped, 1, 'the skipped file is reported in the build result');
|
||||
assert.equal(result.skippedFiles[0].diagnostics?.phase, 'work', 'diagnostics record the failing phase');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user