test(ask): cover stopwords, multi-keyword, ties, order, and archived#11
Merged
jstuart0 merged 1 commit intojstuart0:mainfrom Apr 24, 2026
Merged
Conversation
Adds the five test cases requested in jstuart0#10 and fixes one small implementation bug that the order-preservation test surfaced. Tests (all five against the shared __test_db.ts helper): 1. Stopword filtering - "is the api session healthy?" scores against "api" (and "healthy"); "is", "the", "session" are dropped via STOPWORDS and never reach scoreSession. 2. Multi-keyword match - a session whose cwd contains both "sourcebridge" and "oauth" outranks one that only matches one. 3. Stable ordering on ties - two identically-scored sessions order by lastActivityAt desc. Sets both timestamps explicitly to avoid racing on the datetime('now') tick. 4. fetchSessionsById preserves order - passing ["b", "a"] returns in that order, not the SQLite IN-clause's insertion/rowid order. 5. Archived sessions excluded - a session with status "archived" (and isWorking=false) does not leak into the resolver pool. Implementation fix in resolver.ts fetchSessionsById: SQLite's IN clause doesn't preserve input order. Re-index the returned rows by sessionId and walk the caller's ids list to produce the output in the requested order. This makes "@mention"-style references in the UI stable regardless of insert order. Closes jstuart0#10
jstuart0
added a commit
that referenced
this pull request
Apr 24, 2026
PR #11 changed fetchSessionsById to return rows in the caller's input order instead of SQLite's rowid/insertion order. Internal usage doesn't depend on ordering, but document it anyway so any external consumer (e.g. a future @mention UI flow) can rely on it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the five test cases requested in #10 (stopword filtering, multi-keyword ranking, tie-break ordering, explicit-id order preservation, archived-session exclusion) plus one small implementation fix that the
fetchSessionsById preserves input ordertest surfaced.Closes #10.
Tests
All five tests use the shared
src/server/services/ai/__test_db.tshelper, not a private sqlite instance (acceptance criterion 3).Stopword filtering - "is the api session healthy?" ends up scoring against
apiandhealthy;is,the, andsessionare inSTOPWORDSatresolver.ts:36-72. A session namedapi-gatewaymatches viaapi; a session namedunrelated-namematches nothing.Multi-keyword match - "the sourcebridge oauth session" ranks a cwd
/repos/sourcebridge/oauth-providerabove/repos/sourcebridge/uibecausescoreSessionadds +2 per token-in-haystack hit (both tokens in the first, only one in the second).Stable ordering on ties - two sessions that score identically on
targetsort bylastActivityAtdescending. Uses explicit timestamps (2020 vs 2030) to avoid racing on the defaultdatetime('now')tick.fetchSessionsById preserves input order - passing
["b", "a"]returns["b", "a"], not the SQLite IN-clause default. See implementation fix below.Archived sessions excluded - a session with
status: "archived"(andisWorking: false) does not leak into the resolver pool. Inserts viadb.insert(...)directly so the test exercises the resolver's WHERE clause without being restricted by theinsertSessionhelper's narrower type union.Test count before: 4. After: 9.
bun test src/server/services/ask/resolver.test.tsruns all 9 green.Implementation fix
fetchSessionsByIdatsrc/server/services/ask/resolver.ts:170previously mapped the raw SQLite result:SQLite's
INclause doesn't preserve input order, so callers got back results in insertion / rowid order. The fix indexes the rows bysessionIdand walksidsin the order the caller passed them:This keeps "@mention"-style references in the UI stable regardless of how the sessions were inserted.
Testing
AI disclosure
This contribution was developed with AI assistance (Claude Code).