Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.d/1562-investigation-numeric-ranges.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- **`pyrite investigation` options declare valid numeric ranges (#1562).**
Numeric CLI options across `pyrite investigation` subcommands now declare their
ranges and refuse out-of-range values as usage errors (exit 2) before executing:
`--min-importance` (0 to 10), `--limit` (minimum 1), `ownership --depth` (minimum 1),
`money-flow --hops` (minimum 1), `qa --stale-days` (minimum 0), and `dedup --threshold`
(0.0 to 1.0).
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ def timeline(
event_type: str = typer.Option(
"", "--type", help="Filter by type: investigation_event, transaction, legal_action"
),
min_importance: int = typer.Option(0, "--min-importance", help="Minimum importance (1-10)"),
limit: int = typer.Option(50, "--limit", help="Max results"),
min_importance: int = typer.Option(
0, "--min-importance", min=0, max=10, help="Minimum importance (1-10)"
),
limit: int = typer.Option(50, "--limit", min=1, help="Max results"),
output_json: bool = typer.Option(False, "--json", help="Output as JSON"),
):
"""Query investigation events by date range, actor, and type."""
Expand Down Expand Up @@ -122,8 +124,10 @@ def entities(
"", "--type", help="Filter by type: person, organization, asset, account"
),
jurisdiction: str = typer.Option("", "--jurisdiction", help="Filter by jurisdiction"),
min_importance: int = typer.Option(0, "--min-importance", help="Minimum importance (1-10)"),
limit: int = typer.Option(50, "--limit", help="Max results"),
min_importance: int = typer.Option(
0, "--min-importance", min=0, max=10, help="Minimum importance (1-10)"
),
limit: int = typer.Option(50, "--limit", min=1, help="Max results"),
output_json: bool = typer.Option(False, "--json", help="Output as JSON"),
):
"""Query investigation entities by type, importance, and jurisdiction."""
Expand Down Expand Up @@ -169,7 +173,7 @@ def sources(
),
from_date: str = typer.Option("", "--from", help="Start date (YYYY-MM-DD)"),
to_date: str = typer.Option("", "--to", help="End date (YYYY-MM-DD)"),
limit: int = typer.Option(50, "--limit", help="Max results"),
limit: int = typer.Option(50, "--limit", min=1, help="Max results"),
output_json: bool = typer.Option(False, "--json", help="Output as JSON"),
):
"""Query source documents by reliability and classification."""
Expand Down Expand Up @@ -224,8 +228,10 @@ def claims(
help="Filter: unverified, partially_verified, corroborated, disputed, retracted",
),
confidence: str = typer.Option("", "--confidence", help="Filter: high, medium, low"),
min_importance: int = typer.Option(0, "--min-importance", help="Minimum importance (1-10)"),
limit: int = typer.Option(50, "--limit", help="Max results"),
min_importance: int = typer.Option(
0, "--min-importance", min=0, max=10, help="Minimum importance (1-10)"
),
limit: int = typer.Option(50, "--limit", min=1, help="Max results"),
output_json: bool = typer.Option(False, "--json", help="Output as JSON"),
):
"""Query claims by status and confidence level."""
Expand Down Expand Up @@ -366,7 +372,7 @@ def evidence_chain(
def qa_report(
kb_name: str = typer.Option(..., "--kb", "-k", help="KB name"),
stale_days: int = typer.Option(
30, "--stale-days", help="Days before unverified claims are stale"
30, "--stale-days", min=0, help="Days before unverified claims are stale"
),
output_json: bool = typer.Option(False, "--json", help="Output as JSON"),
):
Expand Down Expand Up @@ -445,7 +451,7 @@ def search_all(
False, "--correlate", "-c", help="Correlate results by entity identity across KBs"
),
entry_type: str = typer.Option("", "--type", help="Filter by entry type"),
limit: int = typer.Option(50, "--limit", help="Max results"),
limit: int = typer.Option(50, "--limit", min=1, help="Max results"),
output_json: bool = typer.Option(False, "--json", help="Output as JSON"),
):
"""Search across all KBs with optional entity correlation."""
Expand Down Expand Up @@ -638,7 +644,7 @@ def investigation_status(
def ownership_chain(
entity_id: str = typer.Argument(..., help="Entity entry ID to trace ownership for"),
kb_name: str = typer.Option(..., "--kb", "-k", help="KB name"),
depth: int = typer.Option(5, "--depth", help="Maximum chain depth (default 5)"),
depth: int = typer.Option(5, "--depth", min=1, help="Maximum chain depth (default 5)"),
output_json: bool = typer.Option(False, "--json", help="Output as JSON"),
):
"""Trace ownership chains to find beneficial owners and shell companies."""
Expand Down Expand Up @@ -696,7 +702,7 @@ def money_flow(
direction: str = typer.Option(
"both", "--direction", "-d", help="Flow direction: outbound, inbound, or both"
),
hops: int = typer.Option(3, "--hops", help="Max transaction hops to follow"),
hops: int = typer.Option(3, "--hops", min=1, help="Max transaction hops to follow"),
from_date: str = typer.Option("", "--from", help="Start date (YYYY-MM-DD)"),
to_date: str = typer.Option("", "--to", help="End date (YYYY-MM-DD)"),
output_json: bool = typer.Option(False, "--json", help="Output as JSON"),
Expand Down Expand Up @@ -791,7 +797,7 @@ def export_pack(
False, "--redact-sources", help="Redact source URLs and titles"
),
min_importance: int = typer.Option(
0, "--min-importance", help="Minimum importance filter (1-10)"
0, "--min-importance", min=0, max=10, help="Minimum importance filter (1-10)"
),
):
"""Export investigation as a self-contained pack."""
Expand Down Expand Up @@ -1154,7 +1160,7 @@ def dedup(
[], "--kb", "-k", help="KB names to scan (repeat for multiple; omit for all)"
),
threshold: float = typer.Option(
0.85, "--threshold", help="Minimum fuzzy match ratio (0.0-1.0)"
0.85, "--threshold", min=0.0, max=1.0, help="Minimum fuzzy match ratio (0.0-1.0)"
),
link: bool = typer.Option(
False, "--link", help="Auto-link high-confidence matches (confidence >= 0.95)"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Tests verifying numeric CLI options in journalism-investigation reject out-of-range values (#1562)."""

import pytest
from pyrite_journalism_investigation.cli import investigation_app
from typer.testing import CliRunner

runner = CliRunner()


@pytest.mark.parametrize(
("args", "expected_err"),
[
# timeline: --min-importance (0-10), --limit (min 1)
(["timeline", "--kb", "test", "--min-importance", "-1"], "--min-importance"),
(["timeline", "--kb", "test", "--min-importance", "11"], "--min-importance"),
(["timeline", "--kb", "test", "--limit", "0"], "--limit"),
(["timeline", "--kb", "test", "--limit", "-5"], "--limit"),
# entities: --min-importance (0-10), --limit (min 1)
(["entities", "--kb", "test", "--min-importance", "-1"], "--min-importance"),
(["entities", "--kb", "test", "--min-importance", "11"], "--min-importance"),
(["entities", "--kb", "test", "--limit", "0"], "--limit"),
# sources: --limit (min 1)
(["sources", "--kb", "test", "--limit", "0"], "--limit"),
(["sources", "--kb", "test", "--limit", "-1"], "--limit"),
# claims: --min-importance (0-10), --limit (min 1)
(["claims", "--kb", "test", "--min-importance", "-1"], "--min-importance"),
(["claims", "--kb", "test", "--min-importance", "11"], "--min-importance"),
(["claims", "--kb", "test", "--limit", "0"], "--limit"),
# qa: --stale-days (min 0)
(["qa", "--kb", "test", "--stale-days", "-1"], "--stale-days"),
# search: --limit (min 1)
(["search", "query", "--limit", "0"], "--limit"),
# ownership: --depth (min 1)
(["ownership", "ent1", "--kb", "test", "--depth", "0"], "--depth"),
(["ownership", "ent1", "--kb", "test", "--depth", "-2"], "--depth"),
# money-flow: --hops (min 1)
(["money-flow", "ent1", "--kb", "test", "--hops", "0"], "--hops"),
(["money-flow", "ent1", "--kb", "test", "--hops", "-1"], "--hops"),
# export: --min-importance (0-10)
(["export", "--kb", "test", "--min-importance", "-1"], "--min-importance"),
(["export", "--kb", "test", "--min-importance", "11"], "--min-importance"),
# dedup: --threshold (0.0-1.0)
(["dedup", "--threshold", "-0.01"], "--threshold"),
(["dedup", "--threshold", "1.01"], "--threshold"),
],
)
def test_investigation_numeric_options_reject_out_of_range(args, expected_err):
result = runner.invoke(investigation_app, args)
assert result.exit_code == 2
assert expected_err in result.output
16 changes: 1 addition & 15 deletions tests/test_cli_numeric_options_declare_a_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,28 +290,14 @@ def registry() -> dict[str, object]:
# pyrite/read_cli.py
("pyrite-read timeline", "min_importance"),
("pyrite-read timeline", "limit"),
# extensions/journalism-investigation/src/pyrite_journalism_investigation/cli.py
("pyrite investigation timeline", "min_importance"),
("pyrite investigation timeline", "limit"),
("pyrite investigation entities", "min_importance"),
("pyrite investigation entities", "limit"),
("pyrite investigation sources", "limit"),
("pyrite investigation claims", "min_importance"),
("pyrite investigation claims", "limit"),
("pyrite investigation qa", "stale_days"),
("pyrite investigation search", "limit"),
("pyrite investigation ownership", "depth"),
("pyrite investigation money-flow", "hops"),
("pyrite investigation export", "min_importance"),
("pyrite investigation dedup", "threshold"),
# extensions/social/src/pyrite_social/cli.py
("pyrite social newest", "limit"),
("pyrite social top", "limit"),
}

#: May shrink, never grow (#1541). Lower it in the same commit that deletes rows
#: from NOT_YET; raising it is the thing this test exists to refuse.
NOT_YET_PINNED_SIZE = 29
NOT_YET_PINNED_SIZE = 16

FIX = "declare min= or max= in the option where it is declared, see #1541"

Expand Down
Loading