返回 last30days-skill
test_phrase_preservation.py
根目录 / tests / test_phrase_preservation.py
1 """Quoted proper-noun phrases must survive into the provider query.
2
3 Two compounding defects meant a phrase search never actually happened:
4
5 1. planner._keyword_query emitted the quoted compound *and* a core that
6 already contained the same words: '"Peter Steinberger" peter steinberger
7 steipete'.
8 2. bird_x stripped the quotes before building the X query, degrading an
9 intended phrase match into a bare token conjunction
10 (peter AND steinberger AND steipete).
11
12 On the measured 'Peter Steinberger steipete' baseline the primary X lane
13 returned nothing as a result, and the whole run depended on the supplement
14 lanes.
15 """
16
17 from lib import bird_x, planner
18
19
20 def test_quoted_phrase_words_are_not_repeated_unquoted():
21 q = planner._keyword_query("Peter Steinberger steipete", "peter steinberger steipete")
22 assert q.lower().count("steinberger") == 1, (
23 f"'steinberger' appears more than once in {q!r}; the quoted compound "
24 "is being emitted alongside a core that already contains it"
25 )
26 assert '"Peter Steinberger"' in q, "the proper-noun phrase must stay quoted"
27
28
29 def test_distinct_topic_tokens_survive_alongside_the_phrase():
30 q = planner._keyword_query("Peter Steinberger steipete", "peter steinberger steipete")
31 assert "steipete" in q.lower(), (
32 f"deduplicating the phrase must not drop unrelated topic tokens: {q!r}"
33 )
34
35
36 def test_single_word_topic_is_unchanged():
37 q = planner._keyword_query("bentgo", "bentgo")
38 assert q.strip() == "bentgo"
39
40
41 def test_topic_with_no_title_cased_compound_is_unquoted():
42 q = planner._keyword_query("open source llm tooling", "open source llm tooling")
43 assert '"' not in q
44
45
46 def test_provider_query_preserves_quoted_phrase():
47 """bird_x must not strip quotes out of the phrase before querying X.
48
49 X advanced search supports quoted phrases natively, so passing them
50 through is strictly better retrieval than a token conjunction.
51 """
52 built = bird_x.build_topic_query('"Peter Steinberger" steipete', "2026-07-14")
53 assert '"Peter Steinberger"' in built, (
54 f"quoted phrase was stripped before reaching X: {built!r}"
55 )
56 assert "since:2026-07-14" in built
57
58
59 def test_provider_query_keeps_bare_tokens():
60 built = bird_x.build_topic_query("bentgo lunch", "2026-07-14")
61 assert "bentgo" in built and "lunch" in built
62 assert '"' not in built
63
64
65 def test_provider_query_drops_grouping_syntax_but_not_phrases():
66 """Bird grouping characters are still noise; phrase quotes are not."""
67 built = bird_x.build_topic_query('("Claude Code") review', "2026-07-14")
68 assert '"Claude Code"' in built
69 assert "(" not in built and ")" not in built
70
71
72 def test_unbalanced_quote_falls_back_to_bare_tokens():
73 """An orphan quote must never reach X.
74
75 Upstream trimming (core-subject extraction, the retry ladder shortening a
76 query) can cut a topic mid-phrase, leaving 'berlin "mixed-use'. X reads the
77 orphan as an unterminated phrase and matches nothing, so a query that
78 cannot be balanced is safer unquoted.
79 """
80 built = bird_x.build_topic_query('immobilienmakler berlin "mixed-use', "2026-07-12")
81 assert '"' not in built, f"unbalanced quote survived into the query: {built!r}"
82 assert "immobilienmakler" in built and "mixed-use" in built
83
84
85 def test_balanced_quotes_are_still_preserved():
86 built = bird_x.build_topic_query('"Claude Code" "Peter Steinberger"', "2026-07-14")
87 assert built.count('"') == 4
88
88 lines PYTHON