Skip to content

feat(historical): start takes --window-days, text output shows the time range - #279

Merged
alanjds merged 6 commits into
developfrom
historical-hunt-window
Oct 21, 2026
Merged

alanjds merged 6 commits into
developfrom
historical-hunt-window

Conversation

@alanjds

@alanjds alanjds commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

  • historical start takes --window-days {30,60,90,180}: how many days back the hunt reaches. Omit it and nothing changes; the hunt reaches the platform maximum.
  • Text output of a historical hunt gains a Time Range: line right after Created at:: Last N days, or Platform maximum when no window was requested.
  • Raises the SDK floor to polyswarm_api>=4.8.0, the first version with historical_create(window_days=) and HistoricalHunt.window_days.

Semantics

  • The flag is a closed choice that mirrors the server's enum, so a bad value (--window-days 45) is a usage error (exit 2) before any request. It is forwarded as an int and only when passed, so an invocation without it makes the same SDK call as before.
  • Time Range uses the same two labels as the web UI. None (a hunt created without a window, or a response without the key) reads Platform maximum; no day count is named for it, because the server owns that value.
  • JSON output is unchanged: it already dumps the raw resource, so window_days shows up in it as an int or null.
  • Release note for the develop to master PR: an unchanged invocation now prints one more line. Every text-format hunt block (historical start, view, cancel, list, delete, delete-list) gets Time Range:, including hunts that predate the field, which read Platform maximum.

Requires

  • feat: expose window_days on historical hunts polyswarm-api#332, which adds historical_create(window_days=) and HistoricalHunt.window_days, and declares 4.8.0. It merges first.
  • CI installs the SDK from the GitHub archive of the same-named branch (historical-hunt-window, see .gitlab-ci.yml), so this PR is tested against that change, and it fails loudly if the branch does not exist.
  • The SDK 4.8.0 release must reach PyPI before this repo's develop to master release: the new floor cannot be satisfied from PyPI until then. Merging here to develop does not need it.

Testing

  • Full suite, pytest -s -v, against the SDK branch at 4.8.0 (editable install of the sibling checkout): 240 passed, which is the 226 on develop plus 14 new.
  • New tests/historical_window_test.py:
    • command wiring through autospec'd SDK mocks: each of 30/60/90/180 forwarded as an int, no flag forwards no window_days, --rule-id 5 --window-days 90, --window-days 45 exits 2 without calling the SDK, and --help;
    • the formatter on real HistoricalHunt resources: Last 30 days, Platform maximum for both null and a missing key, placement after Created at:, and hunt_deletion;
    • the command reaching the formatter for both arms, and the unchanged JSON.
  • Snapshots: the three text snapshots that render a historical hunt (create, delete, list) were regenerated by deleting each .click and re-running its test, because their recorded responses carry no window_days. Each differs from before only by the added Time Range: Platform maximum line, checked by parsing the YAML. PyYAML re-folds the long create and delete scalars, so those two textual diffs show more changed lines than the one inserted. No existing .vcr file was touched and no existing JSON snapshot changed.
  • Live against the staging API (--stage): historical start … --window-days 30 is stored and returned as window_days: 30 and renders Time Range: Last 30 days; without the flag the server returns null and the block reads Platform maximum; historical view and historical list render both hunts the same way; --window-days 45 exits 2 before any request.
  • Live round trip, recorded: test_historical_hunt_create_window_json and _text (cli_test.py) run historical start eicar.yara --window-days 30 against the e2e stack. The recorded request carries window_days: 30, the server echoes it, and the text block reads Time Range: Last 30 days. Every cassette in this suite pins an API hostname the e2e stack no longer uses, so that name was pointed at the stack for the recording run only.

claude and others added 3 commits October 20, 2026 17:52
…ate(window_days=)

CI installs the SDK from the same-named branch archive, so the floor names
the version the paired SDK change declares: 4.8.0, the next version above
the 4.7.0 the SDK's develop already declares. It is mergeable once that
change is on the SDK's develop, and releasable once 4.8.0 is on PyPI.

Co-Authored-By: Alan Justino <alan.justino@yahoo.com.br>
-w/--window-days picks how many days back a historical hunt reaches: a
closed choice of 30, 60, 90 or 180, mirroring the server's enum so a bad
value is a usage error before any request. It is forwarded to
historical_create as an int, and only when passed, so a script that
omits it makes the same SDK call as before and the hunt reaches the
platform maximum. The help does not name a day count for that maximum,
because the server owns it.

Tests drive the command through autospec'd SDK mocks, which also check
the signature against the installed SDK.

Co-Authored-By: Alan Justino <alan.justino@yahoo.com.br>
The hunt block prints a Time Range line right after Created at: "Last N
days" for a hunt created with a window, "Platform maximum" for one created
without (the key is null, or a server that predates it never sent it).
The web UI uses the same two labels. The JSON formatter already dumps the
resource's own JSON, so it carries the raw key and needed no change.

The three text snapshots that render a historical hunt gain the one new
line, because their recorded responses carry no window: regenerated by
deleting each .click and re-running its test, with every .vcr untouched.
The JSON snapshots and every other text snapshot are unchanged.

Co-Authored-By: Alan Justino <alan.justino@yahoo.com.br>
@claude

claude Bot commented Oct 20, 2026

Copy link
Copy Markdown

Clean against AGENTS.md and specs/: base is develop, no version bump, SDK floor raised in pyproject.toml and §Current floor together, ## Requires links the SDK PR, specs 02/03/05 updated, output.hunt is only called from historical.py (so the always-on Time Range: line is correctly scoped), and the .click snapshots were re-recorded rather than hand-edited. No action needed.

The option keeps only its long name. It has not been released, so no
invocation depends on the short form.

Co-Authored-By: Alan Justino <alan.justino@yahoo.com.br>
@claude

This comment has been minimized.

Comment thread src/polyswarm/client/historical.py Outdated
claude and others added 2 commits October 21, 2026 10:56
Applies the review suggestion; the help test now checks the new wording.

Co-Authored-By: Alan Justino <alan.justino@yahoo.com.br>
`historical start --window-days 30`, in text and JSON, recorded against a live
e2e stack: the request carries window_days 30 and the server echoes it, which
renders as `Time Range: Last 30 days`. The suite's API host was mapped to the
stack for the run, so these cassettes pin the same host as every other one.

Co-Authored-By: Alan Justino <alan.justino@yahoo.com.br>
@claude

claude Bot commented Oct 21, 2026

Copy link
Copy Markdown

Reviewed against AGENTS.md and specs/02, 03, 04 and 05: no issues found. The PR targets develop, the SDK floor is raised and recorded in 05-sdk-contract §Current floor, the SDK PR is linked under ## Requires, the cassettes were re-recorded rather than hand-edited, and output.hunt/hunt_deletion are only called from historical.py, so the new Time Range: line is scoped correctly.

@alanjds
alanjds marked this pull request as ready for review October 21, 2026 14:42
@alanjds
alanjds requested a review from a team October 21, 2026 14:42
@mjbradford89

Copy link
Copy Markdown
Contributor

Findings (round 1)

Adds --window-days to historical start and a Time Range line to the text output. Nothing blocking found.

Part of a change across 3 PRs — merge polyswarm/polyswarm-api#332 → #279 → polyswarm/portal#2577.

Reviewed at 4e19019. Fixes are suggestions; nothing was run.

@mjbradford89 mjbradford89 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing open from this review.

@alanjds
alanjds merged commit 91504a9 into develop Oct 21, 2026
2 checks passed
@alanjds
alanjds deleted the historical-hunt-window branch October 21, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants