mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-06 23:44:36 +00:00
fix(agent): validate fork entries against named branch ancestry
Reject off-branch and unknown fork points, handle null tips and before-root placement, and make SQLite validate from the named branch tip.
This commit is contained in:
parent
435b0c69f5
commit
f2eae920c6
5 changed files with 100 additions and 66 deletions
|
|
@ -114,8 +114,9 @@ function readForkSourceEntries(
|
|||
(stored) => stored.address.namespace === sourceAddress.namespace && stored.address.key === sourceAddress.key,
|
||||
) as StoredValue<string | null> | undefined;
|
||||
if (sourceTip === undefined) throw new Error(`Unknown source branch: ${options.branch}`);
|
||||
const requested = options.entryId ?? sourceTip.value;
|
||||
return requested === null ? [] : scanBranchEntries(db, sessionId, { start: requested, order: "oldestFirst" });
|
||||
return sourceTip.value === null
|
||||
? []
|
||||
: scanBranchEntries(db, sessionId, { start: sourceTip.value, order: "oldestFirst" });
|
||||
}
|
||||
|
||||
function createSqliteForkSnapshot(
|
||||
|
|
|
|||
|
|
@ -155,10 +155,9 @@ export class SqliteStorage implements Storage {
|
|||
(stored) => stored.address.namespace === sourceAddress.namespace && stored.address.key === sourceAddress.key,
|
||||
) as StoredValue<string | null> | undefined;
|
||||
if (sourceTip === undefined) throw new Error(`Unknown source branch: ${options.branch}`);
|
||||
const requested = options.entryId ?? sourceTip.value;
|
||||
return requested === null
|
||||
return sourceTip.value === null
|
||||
? []
|
||||
: scanBranchEntries(this.db, this.sessionId, { start: requested, order: "oldestFirst" });
|
||||
: scanBranchEntries(this.db, this.sessionId, { start: sourceTip.value, order: "oldestFirst" });
|
||||
}
|
||||
|
||||
private applyCommit(writes: Write[]): CommitResult {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue