fix(ai-vault-search): keep a scope nothing could key from widening the search

This commit is contained in:
Jinwoo-H
2026-09-11 14:24:32 -04:00
parent 1dc747ce83
commit 4eb59e32fa
2 changed files with 13 additions and 3 deletions
@@ -79,6 +79,16 @@ describe('a cwd scope is the sidebar key, or anything below it', () => {
expect(selected(db)).toEqual([1])
})
it('narrows to nothing when no scope the caller gave could be keyed', async () => {
// `cwdKey` returns null for a scope it cannot key, and a scope that matches
// nothing must return nothing; dropping it would answer the whole index.
const db = await openIndex()
addSession(db, 1, '/work/app')
addSession(db, 2, '/elsewhere')
expect(selected(db, { scopePaths: [''] })).toEqual([])
expect(selected(db, { scopePaths: ['', '/work/app'] })).toEqual([1])
})
it('keeps a WSL UNC workspace distinct from the bare Linux spelling', async () => {
// PR 2 decided cwd_key does not qualify a Linux path with its distro: the
// collision is real but every SSH host has it too, and the fix is a column
@@ -53,9 +53,9 @@ export function sessionRowFilter(
const present = filters.scopePaths
.map((scope) => scopeCondition(filter, scope))
.filter((condition) => condition !== null)
if (present.length > 0) {
filter.conditions.push(`(${present.join(' OR ')})`)
}
// Every scope unkeyable still means a scope, so it narrows to nothing;
// pushing no condition would widen the search to every session instead.
filter.conditions.push(present.length > 0 ? `(${present.join(' OR ')})` : '0 = 1')
}
return filter
}