From 4e4ac3efd832ebfe167f4d6c2da84c4e73c03ab2 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Tue, 17 Nov 2026 18:37:47 +1100 Subject: [PATCH] fix(mobile): fold accents when matching mention names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `@jos` listed José María, `@jose` listed nobody and `@josé` listed them again: mobile only lowercased names. Name matching now follows section 3 of the shared mention rules, as buzz-app does (recommendation 6). Each code point is NFKD-normalized, its combining accents (the Combining Diacritical Marks blocks) are removed, it is lowercased and a final `ς` becomes `σ`, so `jose` matches `José`, `fiona` matches `fio` and `jose` matches `jose`, while `ø`, `ł`, `æ`, `ß`, `ı` and the marks of other scripts stay distinct. Words are runs of letters, marks and digits, so a hyphen or apostrophe separates them: `jane` finds `Mary-Jane` and `brien` finds `O'Brien`. The folding lives in `name_match.dart` and drives the chooser, Space selection, multi-word admission, the verified-name matches and the recipient pickers, so `@jose maria` lists José María with no accents typed. The vendored fixture moves from version 1 (95 cases) to version 4 of buzz-app's `mention-rules.fixtures.json` (125 cases), copied unchanged, and the conformance test runs every section, with a new `matching` group. No case is skipped. The rules the newer versions added are implemented too: an exact public key (64 hex in either case, or a complete lowercase or uppercase npub with an optional `nostr:` prefix) matches only its owner, even one with no name, and Space selects that owner; the viewer's own agent whose name continues the query with a new word leads (`Sol 6` for `sol`), and an exact person leads over it; agents from the viewer's other communities follow everyone here; an outside choice's longer name no longer blocks a member's exact name on Space, and a choice's own longer alias is not its own namesake. The search cache's exact-key exemption uses the same `typedPublicKey`. Refutation itself stays lowercase-only on purpose: it reasons about the relay's prefix search, which is out of scope here, so an accented query is a new search rather than a continuation. A refuted query still matches members on the device by folding: after `z` finds nobody, `@zoe` lists the member Zoë without a search. Tests: the compose bar search journey types `@jose maria` and sees José María, and `@zoe` after the `z` refutation sees Zoë; both and seven fixture cases fail when accent stripping is removed. `dart format`, `flutter analyze` and the full mobile `flutter test` suite pass. Co-Authored-By: Claude Fable 5.1 Signed-off-by: Matt Toohey --- .../mentions/mention_candidates_provider.dart | 12 +- mobile/lib/shared/mentions/mention_rules.dart | 146 +++- mobile/lib/shared/mentions/name_match.dart | 129 +++ mobile/lib/shared/utils/string_utils.dart | 28 + .../mention_search_tests.dart | 21 +- .../mentions/mention-rules.fixtures.json | 783 +++++++++++++++++- .../shared/mentions/mention_rules_test.dart | 29 +- 7 files changed, 1087 insertions(+), 61 deletions(-) create mode 100644 mobile/lib/shared/mentions/name_match.dart diff --git a/mobile/lib/features/channels/mentions/mention_candidates_provider.dart b/mobile/lib/features/channels/mentions/mention_candidates_provider.dart index 83a7688af4..f266925d25 100644 --- a/mobile/lib/features/channels/mentions/mention_candidates_provider.dart +++ b/mobile/lib/features/channels/mentions/mention_candidates_provider.dart @@ -7,6 +7,7 @@ import '../../../shared/identity_names/identity_names.dart'; import '../../../shared/identity_names/identity_names_provider.dart'; import '../../../shared/mentions/agent_identity_provider.dart'; import '../../../shared/relay/relay.dart'; +import '../../../shared/utils/string_utils.dart'; import '../../../shared/profile/user_cache_provider.dart'; import '../../../shared/profile/user_profile.dart'; import '../../../shared/verified_profiles/verified_profile.dart'; @@ -103,13 +104,16 @@ class MentionSearchCache { /// The last finished search that found nobody, or null. String? _refuted; + /// Lowercase only, not the section 3 folding: the directory is the relay's + /// search, whose prefix rule is what a refutation reasons about, so an + /// accented query is a different search, not a continuation of the plain + /// one. The device still matches members and found people by folding. static String _key(String query) => query.trim().toLowerCase(); - /// Only a query with a letter or digit searches names; a public key is an - /// author lookup that no name prefix can refute. + /// Only a query with a letter or digit searches names; an exact public key + /// is an author lookup that no name prefix can refute. static final _wordCharacter = RegExp(r'[\p{L}\p{N}]', unicode: true); - static final _npub = RegExp(r'^(?:nostr:)?npub1[02-9ac-hj-np-z]{58}$'); - static bool _exactKey(String key) => isMentionKey(key) || _npub.hasMatch(key); + static bool _exactKey(String key) => typedPublicKey(key) != null; /// Whether the last finished search found nobody for a shorter query that /// [query] continues, so a search for [query] would find nobody either. diff --git a/mobile/lib/shared/mentions/mention_rules.dart b/mobile/lib/shared/mentions/mention_rules.dart index 8eb7a8835f..eeeb07a6b2 100644 --- a/mobile/lib/shared/mentions/mention_rules.dart +++ b/mobile/lib/shared/mentions/mention_rules.dart @@ -1,7 +1,10 @@ import 'package:flutter/foundation.dart'; +import '../utils/string_utils.dart'; +import 'name_match.dart'; + /// One key the user can mention. The fields are the inputs of the portable -/// mention rules (buzz-app `src/bundled/mentions/README.md`, version 1). +/// mention rules (buzz-app `src/bundled/mentions/README.md`, version 4). @immutable class MentionChoice { /// Lowercase 64-hex public key. @@ -22,6 +25,10 @@ class MentionChoice { final bool owned; final bool managed; + /// The other community this agent of the viewer's comes from, or null for + /// a choice of this community (section 4, rule 2). + final String? elsewhere; + const MentionChoice({ required this.pubkey, required this.name, @@ -31,24 +38,14 @@ class MentionChoice { this.agent = false, this.owned = false, this.managed = false, + this.elsewhere, }); + + /// Every name of this choice: its aliases and its label. + List get _names => [...aliases, label]; } -String _normalized(String text) => text.trim().toLowerCase(); - -final _whitespace = RegExp(r'\s+', unicode: true); - -/// Tier 0 to 3 from section 3, or null for no match. -int? _nameMatch(String text, String needle) { - if (needle.isEmpty) return 0; - final name = _normalized(text); - if (name == needle) return 0; - if (name.startsWith(needle)) return 1; - final words = name.split(_whitespace); - if (words.contains(needle)) return 2; - if (words.any((word) => word.startsWith(needle))) return 3; - return null; -} +List _runes(String needle) => needle.runes.toList(); int? _min(Iterable values) { int? best; @@ -58,27 +55,52 @@ int? _min(Iterable values) { return best; } -int? _baseMatch(MentionChoice choice, String needle) => - _min(choice.aliases.map((name) => _nameMatch(name, needle))); +int? _baseMatch(MentionChoice choice, List needle) => + _min(choice.aliases.map((name) => foldedNameMatchTier(name, needle))); -/// A choice's match (section 3): the label tier, else 4 plus the best alias -/// tier. Null means the choice does not match. Keys are never searchable. -@visibleForTesting -int? mentionMatch(MentionChoice choice, String query) { - final needle = _normalized(query); - if (needle.isEmpty) return 0; +/// [mentionMatch] for a normalized, non-empty [needle] and the query's +/// exact public [key], if it is one. +int? _labelMatch(MentionChoice choice, List needle, String? key) { + // An exact public key is not a name: it matches only its owner. + if (key != null) return choice.pubkey == key ? 0 : null; // No known name: the label is only a key fallback. if (choice.aliases.isEmpty) return null; - final visible = _nameMatch(choice.label, needle); + final visible = foldedNameMatchTier(choice.label, needle); if (visible != null) return visible; final base = _baseMatch(choice, needle); return base == null ? null : 4 + base; } +/// A choice's match (section 3): the label tier, else 4 plus the best alias +/// tier. Null means the choice does not match. Keys are never searchable, +/// except an exact public key, which matches only the choice it names. +@visibleForTesting +int? mentionMatch(MentionChoice choice, String query) { + final needle = normalizeName(query); + if (needle.isEmpty) return 0; + return _labelMatch(choice, _runes(needle), typedPublicKey(query)); +} + +/// Section 4 rule 3: a choice whose shown label matches the query leads when +/// one of its names (aliases, never generated label parts) is the query, or, +/// for the viewer's own agent, continues it with a new word (`Sol 6` for +/// `sol`, not `Solana`). [needle] is normalized and non-empty. +bool _leads(MentionChoice choice, String needle, List needleRunes) { + if (choice.agent && !choice.owned) return false; + if (foldedNameMatchTier(choice.label, needleRunes) == null) return false; + return choice.aliases.any( + (name) => + normalizeName(name) == needle || + (choice.agent && nameContinues(name, needle)), + ); +} + int _compare(String a, String b) => a.compareTo(b); /// Section 4 order. Every rule is a key of one choice, so the result is the -/// same for any input order. Agents that share a name form one block at its +/// same for any input order. Another community's agents follow everyone +/// here; an exact person and the viewer's own agents that start with the +/// query's words lead. Agents that share a name form one block at its /// lowest label; recency, managed and presence order only that block. List rankMentions( Iterable choices, @@ -86,10 +108,12 @@ List rankMentions( Map history = const {}, String Function(String pubkey)? presence, }) { - final needle = _normalized(query); + final needle = normalizeName(query); + final needleRunes = _runes(needle); + final key = typedPublicKey(query); final keyed = <_Keyed>[]; for (final choice in choices) { - final match = mentionMatch(choice, query); + final match = needle.isEmpty ? 0 : _labelMatch(choice, needleRunes, key); if (match == null) continue; final status = presence?.call(choice.pubkey); keyed.add( @@ -97,13 +121,15 @@ List rankMentions( choice: choice, tier: [ choice.member ? 0 : 1, + choice.elsewhere == null ? 0 : 1, + needle.isNotEmpty && _leads(choice, needle, needleRunes) ? 0 : 1, match, // No aliases: after every named choice, even for the empty query. - _baseMatch(choice, needle) ?? 1 << 30, + _baseMatch(choice, needleRunes) ?? 1 << 30, choice.agent && choice.owned ? 0 : 1, ], - label: _normalized(choice.label), - blockName: choice.agent ? _normalized(choice.name) : null, + label: normalizeName(choice.label), + blockName: choice.agent ? normalizeName(choice.name) : null, recent: history[choice.pubkey] ?? 0, online: switch (status) { 'online' => 0, @@ -171,17 +197,48 @@ class _Keyed { : '1${tier.join(',')}\u0000$blockName'; } +bool _hasExactName(MentionChoice choice, String needle) => + choice._names.any((name) => normalizeName(name) == needle); + +/// Section 5: whether a known longer name keeps the query's exact name from +/// selecting. Once a member has the exact name, only another member's longer +/// name does: a choice outside the channel never makes a member's name +/// ambiguous. A choice's own longer name does not count when that same +/// choice also has the exact name (`Example Agent` beside `Example`), nor +/// does a generated `(agent)` suffix on its label. +bool _continued(Iterable choices, String needle) { + final member = choices.any( + (c) => c.member && c.aliases.isNotEmpty && _hasExactName(c, needle), + ); + for (final choice in choices) { + if (member && !choice.member) continue; + if (_hasExactName(choice, needle)) continue; + final longer = + choice.agent && + choice.aliases.any( + (name) => '${name.trim()} (agent)' == choice.label, + ) + ? choice.aliases + : choice._names; + if (longer.any((name) => nameContinues(name, needle))) return true; + } + return false; +} + /// Section 5: the key Space selects, or null. Checked against the full, -/// uncapped choice set. +/// uncapped choice set. An exact public key names only its owner, even one +/// with no known name, and no name continues it. String? exactMention(Iterable choices, String query) { - final needle = _normalized(query); - if (needle.isEmpty) return null; + final key = typedPublicKey(query); + if (key != null) { + return choices.where((choice) => choice.pubkey == key).firstOrNull?.pubkey; + } + final needle = normalizeName(query); + if (needle.isEmpty || _continued(choices, needle)) return null; String? found; var count = 0; for (final choice in choices) { - final names = [...choice.aliases, choice.label].map(_normalized); - if (names.any((name) => name.startsWith('$needle '))) return null; - if (choice.aliases.isNotEmpty && names.contains(needle)) { + if (choice.aliases.isNotEmpty && _hasExactName(choice, needle)) { count++; found = choice.pubkey; } @@ -210,14 +267,13 @@ MentionQuery? findMentionQuery(String text, int caret) { } /// Section 2 multi-word rule: a query with a space stays open only while it -/// is still the start of a known name. A complete name plus a trailing space -/// is prose. +/// is still the start of a known name, compared after section 3 folding of +/// the names. The query itself is not trimmed: a complete name plus a +/// trailing space is prose. bool matchesMentionQuery(String query, Iterable names) { if (!query.contains(' ')) return true; - final lower = query.toLowerCase(); - if (lower.endsWith(' ') && - names.any((name) => name.toLowerCase() == lower.trimRight())) { - return false; - } - return names.any((name) => name.toLowerCase().startsWith(lower)); + final folded = foldName(query); + final known = names.map(normalizeName).toList(); + if (folded.endsWith(' ') && known.contains(folded.trimRight())) return false; + return known.any((name) => name.startsWith(folded)); } diff --git a/mobile/lib/shared/mentions/name_match.dart b/mobile/lib/shared/mentions/name_match.dart new file mode 100644 index 0000000000..678413ea5f --- /dev/null +++ b/mobile/lib/shared/mentions/name_match.dart @@ -0,0 +1,129 @@ +/// The one rule for matching a typed name to a person or agent name: the +/// portable mention rules, section 3 (buzz-app +/// `src/bundled/mentions/README.md`). Mentions, Space selection, query +/// admission and the recipient pickers all use it, so the same text finds +/// the same people, and `jose` finds `José`. +/// +/// Normalization per code point: Unicode NFKD, the combining accents of the +/// "Combining Diacritical Marks" blocks removed, lowercase, and `ς` as `σ`. +/// Other marks stay, since in many scripts a mark makes a different letter +/// (`राम` is not `रम`, `ジョン` is not `ション`), and letters without a +/// decomposition do not fold (`ø`, `ł`, `æ`, `ß` and `ı` stay themselves). +/// This is deliberately narrower than platform diacritic-insensitive or full +/// case-folding comparisons, which the contract forbids. +library; + +import 'package:unorm_dart/unorm_dart.dart' as unorm; + +bool _isAccent(int rune) => + (rune >= 0x0300 && rune <= 0x036F) || + (rune >= 0x1AB0 && rune <= 0x1AFF) || + (rune >= 0x1DC0 && rune <= 0x1DFF) || + (rune >= 0x20D0 && rune <= 0x20FF) || + (rune >= 0xFE20 && rune <= 0xFE2F); + +/// Folds one non-ASCII code point. +String _foldPoint(String char) { + final buffer = StringBuffer(); + for (final rune in unorm.nfkd(char).runes) { + if (!_isAccent(rune)) buffer.writeCharCode(rune); + } + return buffer.toString().toLowerCase().replaceAll('ς', 'σ'); +} + +/// Folding is the cost of matching, and the same names meet a new query on +/// every keystroke, so folded names stay folded. Long names are not kept. +final _folded = {}; +const _foldedLimit = 4096; +const _foldedLength = 128; + +/// [text] without accents and case, as section 3 says. Keeps the spaces at +/// its ends, which query admission needs. +String foldName(String text) { + final cached = _folded[text]; + if (cached != null) return cached; + final buffer = StringBuffer(); + for (final rune in text.runes) { + if (rune < 0x80) { + // ASCII has no accents, decompositions or final sigma. + buffer.writeCharCode(rune >= 0x41 && rune <= 0x5A ? rune + 0x20 : rune); + } else { + buffer.write(_foldPoint(String.fromCharCode(rune))); + } + } + final folded = buffer.toString(); + if (text.length <= _foldedLength) { + if (_folded.length >= _foldedLimit) _folded.clear(); + _folded[text] = folded; + } + return folded; +} + +/// The form for comparing and ordering names: [foldName], trimmed. +String normalizeName(String text) => foldName(text).trim(); + +final _wordCharacter = RegExp(r'^[\p{L}\p{M}\p{N}]$', unicode: true); +final _whitespace = RegExp(r'\s', unicode: true); + +/// A word is a run of letters, marks and digits; every other code point +/// separates words, so `jane` finds `Mary-Jane` and `brien` finds `O'Brien`. +bool isNameWordCharacter(int rune) { + if (rune < 0x80) { + return (rune >= 0x30 && rune <= 0x39) || + (rune >= 0x41 && rune <= 0x5A) || + (rune >= 0x61 && rune <= 0x7A); + } + return _wordCharacter.hasMatch(String.fromCharCode(rune)); +} + +bool _startsAt(List chars, List needle, int from) { + if (from + needle.length > chars.length) return false; + for (var i = 0; i < needle.length; i++) { + if (chars[from + i] != needle[i]) return false; + } + return true; +} + +/// Section 3 tier of [name] for a query whose [normalizeName] runes are +/// [needle], or null for no match. An empty query matches at tier 0. +int? foldedNameMatchTier(String name, List needle) { + if (needle.isEmpty) return 0; + final chars = normalizeName(name).runes.toList(); + if (chars.length == needle.length && _startsAt(chars, needle, 0)) return 0; + if (chars.length > needle.length && _startsAt(chars, needle, 0)) return 1; + // A later word: the match starts where a word starts, and is that whole + // word (tier 2) when it also ends where the word ends. A query with a + // space matches only from the start of the name. + if (needle.any((rune) => _whitespace.hasMatch(String.fromCharCode(rune)))) { + return null; + } + var prefix = false; + for (var from = 1; from < chars.length; from++) { + if (!isNameWordCharacter(chars[from]) || + isNameWordCharacter(chars[from - 1]) || + !_startsAt(chars, needle, from)) { + continue; + } + final stop = from + needle.length; + if (stop >= chars.length || !isNameWordCharacter(chars[stop])) return 2; + prefix = true; + } + return prefix ? 3 : null; +} + +/// Section 3 tier of [name] for [query], or null for no match. +int? nameMatchTier(String name, String query) => + foldedNameMatchTier(name, normalizeName(query).runes.toList()); + +/// Whether [name] is longer than the normalized query [needle] and continues +/// it with a new word, as `Jose Luis` and `Jose-Luis` continue `jose` but +/// `Josefa` does not. Such a name keeps Space from selecting a shorter exact +/// name (section 5). +bool nameContinues(String name, String needle) { + if (needle.isEmpty) return false; + final whole = normalizeName(name).runes.toList(); + final query = needle.runes.toList(); + return whole.length > query.length && + _startsAt(whole, query, 0) && + !isNameWordCharacter(whole[query.length]); +} diff --git a/mobile/lib/shared/utils/string_utils.dart b/mobile/lib/shared/utils/string_utils.dart index 177a4ec6aa..f61924c049 100644 --- a/mobile/lib/shared/utils/string_utils.dart +++ b/mobile/lib/shared/utils/string_utils.dart @@ -50,6 +50,34 @@ String? fullNpub(String identity) { } } +/// The hex public key that typed text names exactly (portable mention rules, +/// Terms): 64 hex characters in either case, or a complete all-lowercase or +/// all-uppercase npub, with or without a `nostr:` prefix in any case. Null +/// for anything else, including a key still being typed, a mixed-case npub, +/// or one with a bad checksum or a payload of another length. +String? typedPublicKey(String text) { + final value = text.trim(); + if (isHexPubkey(value)) return value.toLowerCase(); + const scheme = 'nostr:'; + final npub = + value.length > scheme.length && + value.substring(0, scheme.length).toLowerCase() == scheme + ? value.substring(scheme.length) + : value; + if (!npub.toLowerCase().startsWith('npub1')) return null; + try { + // bech32 rejects mixed case itself. + final decoded = nostr.Nip19.decode(payload: npub); + if (decoded.prefix != nostr.Nip19Prefix.npub || + !isHexPubkey(decoded.data)) { + return null; + } + return decoded.data.toLowerCase(); + } catch (_) { + return null; + } +} + /// Encoded npubs by lowercase hex key. Identity views label every roster /// member without a profile name by npub on each rebuild, and bech32 encoding /// dominated those rebuilds on large channels. Bounded: once full it keeps diff --git a/mobile/test/features/channels/compose_bar_test/mention_search_tests.dart b/mobile/test/features/channels/compose_bar_test/mention_search_tests.dart index e55bd0dfcc..c5e1b9a057 100644 --- a/mobile/test/features/channels/compose_bar_test/mention_search_tests.dart +++ b/mobile/test/features/channels/compose_bar_test/mention_search_tests.dart @@ -7,8 +7,9 @@ part of '../compose_bar_test.dart'; void mentionSearchTests() { final bob = 'b' * 64; final alice = 'a' * 64; + final zoe = '9' * 64; final members = [ - for (final (key, name) in [(bob, 'Bob'), (alice, 'Alice')]) + for (final (key, name) in [(bob, 'Bob'), (alice, 'Alice'), (zoe, 'Zoë')]) ChannelMember( pubkey: key, displayName: name, @@ -107,13 +108,15 @@ void mentionSearchTests() { // Multi-word names are searched word by word: a second word that // continues no local name still goes to the directory, and one that - // continues a found name keeps that person listed. + // continues a found name keeps that person listed. Names fold accents + // (section 3, recommendation 6): `jose maria` lists José María. searched.clear(); await tester.enterText(field, ''); await tester.pump(); - await type(tester, '', '@jos mar'); + await type(tester, '', '@jose maria'); expect(searched, contains('jos')); - expect(searched.last, 'jos mar'); + expect(searched.last, 'jose maria'); + expect(row('José María'), findsOneWidget); searched.clear(); await tester.enterText(field, ''); await tester.pump(); @@ -122,11 +125,19 @@ void mentionSearchTests() { expect(row('Alice Smith'), findsOneWidget); // Once a search finds nobody, longer queries are refuted: no search, - // and the chooser closes. The same query searches again when it is + // and the chooser closes. A refuted query still matches members on the + // device, folding accents: `@zoe` lists the member Zoë after `z` found + // nobody in the directory. The same query searches again when it is // typed afresh. searched.clear(); await tester.enterText(field, ''); await tester.pump(); + await type(tester, '', '@zoe'); + expect(searched.where((q) => q.isNotEmpty), ['z']); + expect(row('Zoë'), findsOneWidget); + searched.clear(); + await tester.enterText(field, ''); + await tester.pump(); await type(tester, '', '@z'); expect(searched.where((q) => q.isNotEmpty), ['z']); searched.clear(); diff --git a/mobile/test/shared/mentions/mention-rules.fixtures.json b/mobile/test/shared/mentions/mention-rules.fixtures.json index 271481a87e..ae10c5c567 100644 --- a/mobile/test/shared/mentions/mention-rules.fixtures.json +++ b/mobile/test/shared/mentions/mention-rules.fixtures.json @@ -1,6 +1,146 @@ { - "$comment": "Mention rules v1: semantic inputs, no signed events. Spec: README.md. Keys are lowercase 64-hex. Choice defaults: label = name, aliases = [name], agent/owned/managed = false. history maps key to recency (higher is more recent); presence maps key to online/away (missing is unknown). ranking.expected is the full ordered key list; space.expected is a key or null. Expected outputs are literal, not generated by the code under test.", - "version": 1, + "$comment": "Mention rules v4: semantic inputs, no signed events. Spec: README.md. Keys are lowercase 64-hex. Choice defaults: label = name, aliases = [name], agent/owned/managed = false. history maps key to recency (higher is more recent); presence maps key to online/away (missing is unknown). matching.expected is the tier (0 to 3) or null; ranking.expected is the full ordered key list; space.expected is a key or null. Expected outputs are literal, not generated by the code under test. A query may also be an exact public key (README Terms).", + "version": 4, + "matching": [ + { + "name": "decomposed_name", + "label": "Jose\u0301", + "query": "josé", + "expected": 0 + }, + { + "name": "decomposed_query", + "label": "José", + "query": "jose\u0301", + "expected": 0 + }, + { + "name": "ligature", + "label": "fiona", + "query": "fio", + "expected": 1 + }, + { + "name": "full_width", + "label": "jose", + "query": "jose", + "expected": 0 + }, + { + "name": "dotted_capital_i", + "label": "İpek", + "query": "ipek", + "expected": 0 + }, + { + "name": "dotless_i_stays_distinct", + "label": "Kılıç", + "query": "kilic", + "expected": null + }, + { + "name": "greek_final_sigma", + "label": "ΟΔΥΣΣΕΥΣ", + "query": "οδυσσευς", + "expected": 0 + }, + { + "name": "accented_whole_word", + "label": "Mary José", + "query": "jose", + "expected": 2 + }, + { + "name": "accented_word_prefix", + "label": "Ana Josefa", + "query": "jose", + "expected": 3 + }, + { + "name": "hyphen_separates_words", + "label": "Mary-Jane", + "query": "jane", + "expected": 2 + }, + { + "name": "apostrophe_separates_words", + "label": "Pat O'Brien", + "query": "brien", + "expected": 2 + }, + { + "name": "next_line_separates_words", + "label": "Anne\u0085Marie", + "query": "marie", + "expected": 2 + }, + { + "name": "no_break_space_separates_words", + "label": "Anne\u00a0Marie", + "query": "marie", + "expected": 2 + }, + { + "name": "stroke_letter_does_not_fold", + "label": "Łukasz", + "query": "lukasz", + "expected": null + }, + { + "name": "slashed_o_does_not_fold", + "label": "Øyvind", + "query": "oyvind", + "expected": null + }, + { + "name": "ligature_letter_does_not_fold", + "label": "Æsir", + "query": "aesir", + "expected": null + }, + { + "name": "sharp_s_does_not_fold", + "label": "Straße", + "query": "strasse", + "expected": null + }, + { + "name": "devanagari_vowel_sign_kept", + "label": "र\u093eम", + "query": "रम", + "expected": null + }, + { + "name": "japanese_voicing_mark_kept", + "label": "ジョン", + "query": "ション", + "expected": null + }, + { + "name": "japanese_same_name", + "label": "ジョン", + "query": "ジョン", + "expected": 0 + }, + { + "name": "text_inside_a_word", + "label": "Honey", + "query": "oney", + "expected": null + }, + { + "name": "query_with_space_matches_only_at_start", + "label": "Visible Legacy Bee", + "query": "legacy bee", + "expected": null + }, + { + "name": "trimmed_both_sides", + "label": " Honey ", + "query": " HONEY ", + "expected": 0 + } + ], "ranking": [ { "name": "match_tiers_within_members", @@ -119,6 +259,71 @@ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ] }, + { + "name": "accents_and_case_fold", + "query": "jose", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Mary José", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "JOSÉ", + "member": true + }, + { + "pubkey": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "name": "Joséphine", + "member": true + }, + { + "pubkey": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", + "name": "Jo Se", + "member": true + } + ], + "expected": [ + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "accented_query_matches_plain_name", + "query": "Zöe", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Zoe", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Zoey", + "member": true + } + ], + "expected": [ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + ] + }, + { + "name": "final_sigma_folds", + "query": "παρος", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "ΠΑΡΟΣ", + "member": true + } + ], + "expected": [ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, { "name": "public_keys_are_not_searchable", "query": "abcdef12", @@ -387,7 +592,7 @@ ] }, { - "name": "ownership_does_not_override_match_quality", + "name": "owned_agent_starting_with_the_query_words_beats_another_agents_exact_name", "query": "Rizz", "choices": [ { @@ -404,11 +609,217 @@ "owned": true } ], + "expected": [ + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "ownership_does_not_override_match_quality_inside_a_word", + "query": "Rizz", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Rizz", + "member": true, + "agent": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Rizzo", + "member": true, + "agent": true, + "owned": true + } + ], "expected": [ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ] }, + { + "name": "exact_person_before_owned_agent_starting_with_the_query", + "query": "sol", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Sol 6", + "member": true, + "agent": true, + "owned": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Sol", + "member": true + }, + { + "pubkey": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "name": "Sol", + "label": "Sol · cccc", + "member": true + }, + { + "pubkey": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", + "name": "Sol", + "label": "Wes’s Sol", + "member": true, + "agent": true + } + ], + "expected": [ + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" + ] + }, + { + "name": "another_persons_agent_continuing_the_query_does_not_lead", + "query": "sol", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Sol 6", + "member": true, + "agent": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Sol", + "member": true, + "agent": true + } + ], + "expected": [ + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "owned_agent_leads_for_a_multi_word_query_and_a_hyphen", + "query": "sol 6", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Sol 6", + "member": true, + "agent": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Sol 6.1 High", + "member": true, + "agent": true, + "owned": true + } + ], + "expected": [ + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "owned_agent_with_a_hyphenated_name_leads", + "query": "sol", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Sol", + "member": true, + "agent": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Sol-6", + "member": true, + "agent": true, + "owned": true + } + ], + "expected": [ + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "hidden_alias_does_not_lead", + "query": "sol", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Helper", + "aliases": ["Helper", "Sol 6"], + "member": true, + "agent": true, + "owned": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Sol", + "label": "Wes’s Sol", + "member": true, + "agent": true + }, + { + "pubkey": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "name": "Solveig", + "member": true + } + ], + "expected": [ + "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "generated_owner_prefix_does_not_lead", + "query": "tho", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Rizz", + "label": "tho’s Rizz", + "member": true, + "agent": true, + "owned": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Tho", + "member": true, + "agent": true + } + ], + "expected": [ + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "lead_does_not_override_membership", + "query": "sol", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Sol 6", + "member": false, + "agent": true, + "owned": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Sol", + "member": true, + "agent": true + } + ], + "expected": [ + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, { "name": "visible_prefix_beats_owned_word_prefix", "query": "riz", @@ -670,6 +1081,139 @@ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ] + }, + { + "name": "other_community_agents_follow_everyone_here", + "query": "honey", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Honey", + "member": false, + "agent": true, + "elsewhere": "oss.example.com" + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Honey Bee", + "member": false, + "agent": true + }, + { + "pubkey": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "name": "Honey Bear", + "member": true + } + ], + "expected": [ + "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "exact_public_key_matches_only_its_owner", + "query": "npub1424242424242424242424242424242424242424242424242424qamrcaj", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Honey", + "member": true + }, + { + "pubkey": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "name": "Honey", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "npub1424242424242424242424242424242424242424242424242424qamrcaj", + "member": true + } + ], + "expected": [ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "uppercase_nostr_npub_matches_its_owner", + "query": "NOSTR:NPUB1424242424242424242424242424242424242424242424242424QAMRCAJ", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Honey", + "member": true + }, + { + "pubkey": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "name": "Honey", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "npub1424242424242424242424242424242424242424242424242424qamrcaj", + "member": true + } + ], + "expected": [ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "uppercase_hex_key_matches_its_owner", + "query": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Honey", + "member": true + }, + { + "pubkey": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "name": "Honey", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "member": true + } + ], + "expected": [ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "exact_public_key_matches_an_unnamed_owner", + "query": "npub1424242424242424242424242424242424242424242424242424qamrcaj", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "npub…rcaj", + "aliases": [], + "member": true + }, + { + "pubkey": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "name": "Honey", + "member": true + } + ], + "expected": [ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ] + }, + { + "name": "partial_npub_is_not_searchable", + "query": "npub1424242", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Honey", + "member": true + } + ], + "expected": [] } ], "space": [ @@ -863,6 +1407,221 @@ } ], "expected": null + }, + { + "name": "outside_longer_name_does_not_block_a_member", + "query": "Jose", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Jose", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Jose-Luis", + "member": false + } + ], + "expected": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + { + "name": "outside_longer_name_blocks_an_outside_name", + "query": "Jose", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Jose", + "member": false + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Jose-Luis", + "member": false + } + ], + "expected": null + }, + { + "name": "exact_after_folding", + "query": "jose", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "José", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Josefa", + "member": true + } + ], + "expected": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + { + "name": "names_equal_after_folding_are_not_unique", + "query": "jose", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "José", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Jose", + "member": true + } + ], + "expected": null + }, + { + "name": "folded_longer_name_blocks_space", + "query": "jose", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Jose", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "José Luis", + "member": true + } + ], + "expected": null + }, + { + "name": "longer_name_after_tab_blocks", + "query": "Jose", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Jose", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Jose\tLuis", + "member": true + } + ], + "expected": null + }, + { + "name": "longer_name_after_hyphen_blocks", + "query": "Jose", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Jose", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Jose-Luis", + "member": true + } + ], + "expected": null + }, + { + "name": "accented_longer_name_blocks", + "query": "jose", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "José", + "member": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "José Luis", + "member": true + } + ], + "expected": null + }, + { + "name": "alias_of_same_identity_does_not_block", + "query": "example", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Example", + "aliases": ["Example Agent", "Example"], + "member": false, + "agent": true, + "owned": true + }, + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "Member", + "member": true + } + ], + "expected": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + { + "name": "exact_public_key_selects_its_owner_among_namesakes", + "query": "npub1424242424242424242424242424242424242424242424242424qamrcaj", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Honey", + "member": true + }, + { + "pubkey": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "name": "Honey", + "member": true + } + ], + "expected": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + { + "name": "name_equal_to_a_key_does_not_select", + "query": "npub1424242424242424242424242424242424242424242424242424qamrcaj", + "choices": [ + { + "pubkey": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "name": "npub1424242424242424242424242424242424242424242424242424qamrcaj", + "member": true + }, + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Honey", + "member": true + } + ], + "expected": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + { + "name": "exact_public_key_selects_an_unnamed_owner", + "query": "npub1424242424242424242424242424242424242424242424242424qamrcaj", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "npub…rcaj", + "aliases": [], + "member": true + } + ], + "expected": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + { + "name": "partial_npub_does_not_select", + "query": "npub1424242", + "choices": [ + { + "pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name": "Honey", + "member": true + } + ], + "expected": null } ], "query": [ @@ -999,6 +1758,24 @@ "query": "Honey ", "names": ["Honey Bee"], "expected": true + }, + { + "name": "multi_word_prefix_after_folding", + "query": "jose l", + "names": ["José Luis"], + "expected": true + }, + { + "name": "completed_folded_name_with_space_closes", + "query": "jose ", + "names": ["José"], + "expected": false + }, + { + "name": "padded_known_name_with_space_closes", + "query": "jose ", + "names": ["José "], + "expected": false } ], "tags": { diff --git a/mobile/test/shared/mentions/mention_rules_test.dart b/mobile/test/shared/mentions/mention_rules_test.dart index 6fe8276591..3d8c6f93b4 100644 --- a/mobile/test/shared/mentions/mention_rules_test.dart +++ b/mobile/test/shared/mentions/mention_rules_test.dart @@ -3,10 +3,12 @@ import 'dart:io'; import 'package:buzz/shared/mentions/mention_rules.dart'; import 'package:buzz/shared/mentions/mention_tags.dart'; +import 'package:buzz/shared/mentions/name_match.dart'; import 'package:flutter_test/flutter_test.dart'; // Portable fixtures, copied unchanged from buzz-app -// src/bundled/mentions/mention-rules.fixtures.json (mention rules v1). +// src/bundled/mentions/mention-rules.fixtures.json (mention rules v4). +// Every case runs; none is skipped. final Map _fixtures = jsonDecode( File( @@ -37,6 +39,7 @@ MentionChoice _choice(Map json) { agent: json['agent'] as bool? ?? false, owned: json['owned'] as bool? ?? false, managed: json['managed'] as bool? ?? false, + elsewhere: json['elsewhere'] as String?, ); } @@ -46,13 +49,31 @@ List _choices(Map fixture) => [ ]; void main() { - test('reads mention fixtures version 1', () { - expect(_fixtures['version'], 1); - for (final section in ['ranking', 'space', 'query', 'admission']) { + test('reads mention fixtures version 4', () { + expect(_fixtures['version'], 4); + final sections = ['matching', 'ranking', 'space', 'query', 'admission']; + for (final section in sections) { expect(_cases(section), isNotEmpty, reason: section); } expect(_tagCases('write'), isNotEmpty); expect(_tagCases('read'), isNotEmpty); + // Every fixture section above has a group below that runs each case. + expect(_fixtures.keys.where((key) => !key.startsWith(r'$')).toSet(), { + ...sections, + 'version', + 'tags', + }); + }); + + group('matching fixtures', () { + for (final fixture in _cases('matching')) { + test(fixture['name'], () { + expect( + nameMatchTier(fixture['label'] as String, fixture['query'] as String), + fixture['expected'], + ); + }); + } }); group('tag writer fixtures', () {