From e44ccfb34340b922f42fe7d7626ca8fc93b4e247 Mon Sep 17 00:00:00 2001 From: Jordan Coin Jackson Date: Thu, 13 Aug 2026 08:05:34 -0400 Subject: [PATCH] fix: clarify empty typed SEC searches --- openfoia/cli.py | 10 ++++++++ tests/test_records_search.py | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/test_records_search.py diff --git a/openfoia/cli.py b/openfoia/cli.py index 49e79b9..4b0af62 100644 --- a/openfoia/cli.py +++ b/openfoia/cli.py @@ -3942,6 +3942,16 @@ def records_search( if not result.entities: if result.error: rprint(f"[red]Search error ({source}): {result.error}[/red]") + elif source == "sec" and filing_type: + rprint( + f"[yellow]{source} returned {result.total_results} total results for '{query}'.[/yellow]" + ) + rprint(f"[dim]Showing 0 of {result.total_results} results.[/dim]") + rprint(f"[dim]Applied SEC filing type filter: {filing_type}[/dim]") + rprint( + "[yellow]SEC EDGAR full-text search can be incomplete for a company or form type; " + "0 results is not proof that no filing exists.[/yellow]" + ) else: rprint(f"[yellow]No results found for '{query}' on {source}.[/yellow]") return diff --git a/tests/test_records_search.py b/tests/test_records_search.py new file mode 100644 index 0000000..605d811 --- /dev/null +++ b/tests/test_records_search.py @@ -0,0 +1,50 @@ +"""Regression tests for public-records search output.""" + +from __future__ import annotations + +from typer.testing import CliRunner + +from openfoia.cli import app +from openfoia.records.base import SearchResult + + +def test_typed_sec_empty_search_reports_scope_and_coverage_limit(monkeypatch): + """A zero typed SEC result must not look like proof that no filing exists.""" + + class Adapter: + async def search(self, query, **kwargs): + assert query == "Webull Corp" + assert kwargs == {"filing_type": "F-3"} + return SearchResult(source="sec", query=query, total_results=0, entities=[]) + + monkeypatch.setattr("openfoia.records.get_adapter", lambda source: Adapter()) + + result = CliRunner().invoke( + app, + ["records", "search", "Webull Corp", "--source", "sec", "--type", "F-3"], + ) + + assert result.exit_code == 0 + output = " ".join(result.output.lower().split()) + assert "sec returned 0 total results for 'webull corp'" in output + assert "showing 0 of 0 results" in output + assert "applied sec filing type filter: f-3" in output + assert "0 results is not proof that no filing exists" in output + + +def test_non_sec_empty_search_keeps_existing_message(monkeypatch): + """The typed SEC warning must not change other sources' output.""" + + class Adapter: + async def search(self, query, **kwargs): + return SearchResult(source="opencorporates", query=query, total_results=0, entities=[]) + + monkeypatch.setattr("openfoia.records.get_adapter", lambda source: Adapter()) + + result = CliRunner().invoke( + app, + ["records", "search", "No Such Company", "--source", "opencorporates"], + ) + + assert result.exit_code == 0 + assert "No results found for 'No Such Company' on opencorporates." in result.output