mirror of
https://github.com/stablyai/orca.git
synced 2026-10-20 00:03:45 +00:00
fix(runtime): isolate catalog snapshot memo
This commit is contained in:
@@ -63,6 +63,18 @@ describe('resolveWorktreeCatalogSnapshot', () => {
|
||||
expect(resolveWorktreeCatalogSnapshot(result(1), null).snapshotId).toBe(warm)
|
||||
})
|
||||
|
||||
it('isolates the memo from mutation of a previously resolved catalog', () => {
|
||||
const mutable = result(1)
|
||||
const first = resolveWorktreeCatalogSnapshot(mutable, null)
|
||||
|
||||
mutable.totalCount = 2
|
||||
const changed = resolveWorktreeCatalogSnapshot(mutable, first.snapshotId)
|
||||
|
||||
expect(changed).toMatchObject({ totalCount: 2 })
|
||||
expect(changed).not.toHaveProperty('unchanged')
|
||||
expect(changed.snapshotId).not.toBe(first.snapshotId)
|
||||
})
|
||||
|
||||
it('produces ids within the request schema bound', () => {
|
||||
const { snapshotId } = resolveWorktreeCatalogSnapshot(result(1), null)
|
||||
expect(snapshotId.length).toBeGreaterThan(0)
|
||||
|
||||
@@ -24,11 +24,13 @@ function worktreeCatalogSnapshotId(result: RuntimeWorktreePsResult): string {
|
||||
if (memoizedId && isDeepStrictEqual(memoizedId.result, result)) {
|
||||
return memoizedId.snapshotId
|
||||
}
|
||||
const serialized = JSON.stringify(result)
|
||||
const snapshotId = createHash('sha256')
|
||||
.update(JSON.stringify(result))
|
||||
.update(serialized)
|
||||
.digest('base64url')
|
||||
.slice(0, SNAPSHOT_ID_LENGTH)
|
||||
memoizedId = { result, snapshotId }
|
||||
// Why: caller-owned mutation must not let an old id label new catalog content.
|
||||
memoizedId = { result: JSON.parse(serialized) as RuntimeWorktreePsResult, snapshotId }
|
||||
return snapshotId
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user