Files
mantra-kmp/composeApp
Kgothatso NgakoandClaude Opus 5 5623df530c test: execute the nostr filter query against real sqlite
NostrEventFilterQueryTest pins the SQL string the builder produces. It never
runs that string, and the gap between "the SQL reads correctly" and "sqlite
returns the right rows" is where this query's expensive mistakes live. Four
classes of bug survive a string assertion intact, and all four are covered
here.

SQL that is well-formed but not accepted. The clause emitted for a
present-but-empty list is the bare literal `0`. Whether sqlite takes that as a
false boolean expression rather than rejecting it is not something the builder
test can answer; ids, authors, kinds and tags are each asserted to match
nothing when handed an empty list.

Binding indices. The limit is bound after every tag pattern, so its placeholder
is the last in the statement. A drift in that order produces a byte-identical
SQL string and different rows, so it is covered by a filter that carries
authors, kinds, since, until, search, a tag and a limit at once.

LIKE semantics against the column as actually written. The tag pattern is a
fragment of the encoded tag -- `["p","<hex>"` -- and only real stored JSON can
show that it anchors on the tag name (a pubkey in an `e` tag is not a `p`
match, which is exactly the regression the substring scan `tags LIKE
'%<pubkey>%'` caused), that it tolerates the relay hint and marker that follow
a real tag value, and that escapeLike keeps a `%` in a tag value literal
instead of widening the match.

Timestamp units. This is a cross-file invariant nothing enforces:
NostrEventFilterQuery binds since/until as epochSeconds, and
MantraConverters.instantToTimestamp writes the createdAt column as
epochSeconds. They agree today. Move either to milliseconds and both files
still read correctly on their own while the filter silently selects nothing or
everything, so the agreement is now asserted directly.

Also covered: the NIP-01 inclusive bounds on both ends, using events stamped
exactly on since and on until -- the case that tells an inclusive bound from
the strict `createdAt > :since` this replaced; tags ORing values within a name
and ANDing across names, against tagsAll which ANDs within a name too;
newest-first ordering with the `id DESC` tiebreak, and a limit keeping the
newest rather than the oldest window the per-shape queries used to return.

Three of these were checked by mutation rather than assumed. Reverting the tag
pattern to the naive `%value%` substring fails `a tag value is matched in its
own position`; relaxing `createdAt >= ?` back to `>` fails both the inclusive
bounds test and the units test. The mutations were reverted; no production
source is touched by this commit.

14 tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 02:50:14 +02:00
..