eb2d7a0f37
CI was running only test_plugin_contract.py and test_version_consistency.py (2 of 84 test files), masking 13 rotted tests across 4 clusters. The suite is fully offline-safe (1402 tests in ~7s without network), so the narrow scope wasn't gating integration flakiness; it was just stale. validate.yml now runs `uv run pytest` against the full suite. Engine fix: store.findings_from_report is rerank-first. ranked_candidates is the primary persistence path; hackernews/polymarket are unconditionally supplemented from items_by_source because they rank poorly but matter for watchlists. When ranked_candidates was empty (rerank failed or skipped), reddit, x, and every other source were silently dropped. The supplement loop now falls back to all sources only when ranked_candidates is empty; the normal path is unchanged. Test repairs: - test_store.py (6) + test_watchlist_commands.py (2): cascade from the engine fix - test_get_new_findings_filters_by_date (latent): local-time vs SQLite UTC flake — switched to datetime.now(timezone.utc) - TestPollDeviceAuth (3): mock_time.time side_effect lists too short after impl added a last_reminder call — padded timeout test, pinned others to return_value=0 (loops terminate via urlopen, not the clock) - test_bare_run_emits_web_promo: engine reads ~/.config/last30days/.env, so a contributor's saved EXA/PARALLEL key made grounding "available" and suppressed the web promo. Also missing X made the "x" promo preempt "web". Set LAST30DAYS_CONFIG_DIR="", subprocess cwd=tmpdir, XAI_API_KEY stub.
96 lines
3.6 KiB
Python
96 lines
3.6 KiB
Python
# ruff: noqa: E402
|
|
"""Tests for the BRAVE/SERPER web-promo suppression when hosting-model-driven."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(REPO_ROOT / "skills" / "last30days" / "scripts"))
|
|
|
|
|
|
def _engine() -> Path:
|
|
return REPO_ROOT / "skills" / "last30days" / "scripts" / "last30days.py"
|
|
|
|
|
|
class FooterNudgeSuppressionTests(unittest.TestCase):
|
|
def _run(self, *argv: str, topic: str) -> subprocess.CompletedProcess:
|
|
cmd = [
|
|
sys.executable,
|
|
str(_engine()),
|
|
topic,
|
|
"--mock",
|
|
"--emit=md",
|
|
*argv,
|
|
]
|
|
env = {
|
|
**os.environ,
|
|
"LAST30DAYS_SKIP_PREFLIGHT": "1",
|
|
# Skip ~/.config/last30days/.env so a contributor's saved
|
|
# BRAVE/EXA/SERPER/PARALLEL key doesn't make grounding "available"
|
|
# and suppress the promo we're checking for.
|
|
"LAST30DAYS_CONFIG_DIR": "",
|
|
# Pin X as available so _missing_sources_for_promo selects "web"
|
|
# (otherwise the "x" promo wins and the BRAVE_API_KEY string never
|
|
# appears).
|
|
"XAI_API_KEY": "test-stub",
|
|
}
|
|
# Strip any grounded-web keys the host might have so the promo path
|
|
# triggers deterministically in mock + no-backend. Also strip X cookie
|
|
# credentials so XAI_API_KEY is the unambiguous X backend.
|
|
for key in ("BRAVE_API_KEY", "EXA_API_KEY", "SERPER_API_KEY",
|
|
"PARALLEL_API_KEY", "OPENROUTER_API_KEY",
|
|
"AUTH_TOKEN", "CT0", "LAST30DAYS_X_BACKEND"):
|
|
env.pop(key, None)
|
|
# Run from a tmpdir so _find_project_env() can't walk up into any
|
|
# .claude/last30days.env above the repo on the contributor's machine.
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
return subprocess.run(
|
|
cmd, capture_output=True, text=True, env=env, cwd=tmp,
|
|
)
|
|
|
|
def test_bare_run_emits_web_promo(self):
|
|
result = self._run(topic="OpenAI")
|
|
combined = result.stdout + result.stderr
|
|
# Mock mode still shows the promo when nothing indicates a hosting
|
|
# model is driving. Check both streams since the UI may emit to stderr.
|
|
self.assertIn("BRAVE_API_KEY", combined)
|
|
|
|
def test_competitors_plan_suppresses_web_promo(self):
|
|
result = self._run(
|
|
"--competitors-list", "Anthropic",
|
|
"--competitors-plan",
|
|
'{"Anthropic":{"x_handle":"AnthropicAI","subreddits":["ClaudeAI"]}}',
|
|
topic="OpenAI",
|
|
)
|
|
combined = result.stdout + result.stderr
|
|
self.assertNotIn(
|
|
"unlock native grounded web search",
|
|
combined,
|
|
msg="web promo should be suppressed when --competitors-plan is passed",
|
|
)
|
|
|
|
def test_plan_suppresses_web_promo(self):
|
|
plan = (
|
|
'{"intent":"concept","freshness_mode":"balanced_recent",'
|
|
'"cluster_mode":"none","subqueries":[{"label":"primary",'
|
|
'"search_query":"OpenAI","ranking_query":"OpenAI",'
|
|
'"sources":["grounding"]}],"source_weights":{"grounding":1.0}}'
|
|
)
|
|
result = self._run("--plan", plan, topic="OpenAI")
|
|
combined = result.stdout + result.stderr
|
|
self.assertNotIn(
|
|
"unlock native grounded web search",
|
|
combined,
|
|
msg="web promo should be suppressed when --plan is passed",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|