返回 last30days-skill
test_github_qualifier_only.py
根目录 / tests / test_github_qualifier_only.py
1 """Empty and qualifier-only GitHub topics must not be classified as ERROR (#953).
2
3 Pre-#949, search_github('') built a site-wide created:> window query.
4 The qualifier strip then returned an error envelope with no network call,
5 and pipeline._result_outcome_artifact mapped that error to a failed attempt.
6 """
7
8 from unittest.mock import patch
9
10 from lib import github, pipeline, schema
11
12
13 def _search(topic):
14 with patch.object(github, "_resolve_token", return_value="test-token"):
15 with patch.object(github, "_fetch_json") as mock_fetch:
16 result = github.search_github(topic, "2026-07-01", "2026-07-31")
17 return result, mock_fetch
18
19
20 def _bundle_from_envelope(envelope):
21 artifact = pipeline._result_outcome_artifact("github", envelope)
22 bundle = schema.RetrievalBundle()
23 bundle.mark_attempted("github")
24 outcome = artifact.get("_source_outcome") if isinstance(artifact, dict) else None
25 if isinstance(outcome, dict):
26 bundle.record_failure(
27 "github",
28 outcome["state"],
29 outcome["detail"],
30 attempted=outcome.get("attempted", True),
31 )
32 items = github.parse_github_response(envelope)
33 bundle.add_items("primary", "github", items)
34 return artifact, bundle
35
36
37 def test_empty_topic_is_clean_no_results_not_error():
38 result, mock_fetch = _search("")
39 mock_fetch.assert_not_called()
40 assert result["items"] == []
41 assert "error" not in result
42 artifact, bundle = _bundle_from_envelope(result)
43 assert artifact == {}
44 assert "github" not in bundle.errors_by_source
45 outcome = bundle.source_status["github"]
46 assert outcome.state == schema.NO_RESULTS
47 assert outcome.attempted is True
48
49
50 def test_qualifier_only_topic_is_clean_no_results_not_error():
51 result, mock_fetch = _search("created:>2025-03-20")
52 mock_fetch.assert_not_called()
53 assert result["items"] == []
54 assert "error" not in result
55 artifact, bundle = _bundle_from_envelope(result)
56 assert artifact == {}
57 assert "github" not in bundle.errors_by_source
58 assert bundle.source_status["github"].state == schema.NO_RESULTS
59
60
61 def test_noise_plus_qualifier_topic_is_clean_no_results_not_error():
62 # extract_core_subject('the best stars:>1000') -> 'stars:>1000' -> plain ''
63 result, mock_fetch = _search("the best stars:>1000")
64 mock_fetch.assert_not_called()
65 assert result["items"] == []
66 assert "error" not in result
67 artifact, bundle = _bundle_from_envelope(result)
68 assert artifact == {}
69 assert "github" not in bundle.errors_by_source
70 assert bundle.source_status["github"].state == schema.NO_RESULTS
71
72
73 def test_quote_wrapped_qualifier_only_topic_is_clean_no_results_not_error():
74 # Wrapper shapes from #952 still strip to nothing; #953 is the envelope.
75 result, mock_fetch = _search('"created:>2025-03-20"')
76 mock_fetch.assert_not_called()
77 assert result["items"] == []
78 assert "error" not in result
79 artifact, bundle = _bundle_from_envelope(result)
80 assert artifact == {}
81 assert "github" not in bundle.errors_by_source
82 assert bundle.source_status["github"].state == schema.NO_RESULTS
83
83 lines PYTHON