Skip to content

briefs: refuse --until not later than --since (exit 6) in the CLI and io.sh - #38

Merged
makriman merged 3 commits into
mainfrom
fix/briefs-inverted-window
Dec 5, 2026
Merged

makriman merged 3 commits into
mainfrom
fix/briefs-inverted-window

Conversation

@makriman

@makriman makriman commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Refs IndianOpinion/mcp#20

That issue reported that an inverted since/until window comes back as an ordinary empty result in three places: the REST route, the MCP server and the CLI. IndianOpinion/mcp#34 fixes the MCP side. This PR is the CLI side, for both entry points (bin/indianopinion.mjs and io.sh). The REST route is not in this repository and stays out of scope, so this refers to the issue rather than closing it.

How to reproduce on main (abeaadb)

Against the REST stub in test/stub-rest.mjs (both the paging and the older non-paging form):

indianopinion briefs --since 2026-11-10 --until 2026-11-09
io.sh briefs --since 2026-11-10T05:30:00+05:30 --until 2026-11-09T23:00:00Z
  • Expected: a validation error that says the window is impossible, as search_briefs gives after mcp#34.
  • Actual: exit 0 and {"ok":true,"count":0,"items":[],"next_cursor":null}, which reads like "no news matched". The CLI sends one or two requests for it (two on the non-paging route), io.sh one. An equal pair (--since X --until X) behaves the same.

Root cause

Both entry points validate each time on its own (timeFlag in the CLI, isotime in io.sh) but never compare the two.

The change

After the cursor is read (as the MCP fix does it, after its cursor decode), both entry points compare --since and --until as instants. If --until is not later than --since, they stop before any request with exit 6 (the exit code the CLI already uses for a bad time) and the same error in both:

{"ok":false,"error":"invalid_field","message":"--until must be later than --since; you sent --since \"2026-11-10\" and --until \"2026-11-09\". Swap them or widen the window."}

The wording follows the MCP message, with the flag names the CLI uses in its other time errors. The CLI also sets field: "until", as timeFlag does for its own errors. An equal pair is refused too, as mcp#34 does: a window of zero length holds nothing (the CLI's own fallback filter keeps only items published before --until).

  • CLI: a small exported checkWindow(since, until) next to isoTime, called once in cmdBriefs.
  • io.sh: isoinstant turns a time that isotime accepts into seconds since 1970 (UTC) plus a nine-digit fraction, in plain bash arithmetic (days from the civil date, then the offset). It does not call date(1), whose flags differ between GNU and BSD, and it does not need jq, so the check works in every io.sh setup. window does the comparison. Neither runs inside $(...), so the exit is not lost in a subshell (the trap io.sh: a usage error from --limit or an on/off flag stops before the request (exit 2) #31 fixes elsewhere).
  • README: the validation sentence names the new rule. CHANGELOG line under Unreleased. No version bump.

Tests

New test/briefs-window.test.mjs (node:test, local stubs, no network, no live API). For the CLI and io.sh, on both stub forms, seven impossible windows: an earlier until, an equal pair, +05:30 making until earlier, +0530 without a colon, date-only values (earlier and equal) and a fraction of a second. Each must exit 6, print nothing on stdout, give the exact message above and make no request. io.sh is also checked with IO_SH_NO_JQ=1. Valid windows (including ones where the text order and the instant order differ, such as 2026-11-10T05:30:00+05:30 to 2026-11-10T00:00:01Z) still reach the API, a malformed --since keeps its own message, and --since or --until alone still work.

  • New test with the code from main: 2 of 3 fail. With the fix: 3 of 3 pass.
  • npm test: 35 tests, 34 pass, 1 skipped (the MCP bridge test, which needs ../mcp), 0 fail. Node 22, jq 1.7.
  • io.sh's isoinstant was checked against the CLI's isoTime for 312 values (fixed edge cases such as leap days, 0001-01-01, 9999-12-31, +14:00 and -12:00, plus 300 random date-times with offsets): 0 mismatches. That harness is not committed.
  • bash -n io.sh: clean. shellcheck and bats are not run here.

Conflicts with open PRs

…e CLI and io.sh

An inverted or empty window was sent to the API and answered as an
empty page with exit 0, which reads like no news matched. Both entry
points now compare the two times as instants after the cursor is read
and stop before any request with invalid_field and a message that
names both values, as the MCP server's search_briefs does
(IndianOpinion/mcp#20). io.sh does the comparison in bash arithmetic,
so it needs neither jq nor a particular date(1).
@makriman

makriman commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Review by Grok Bot (Indian Opinion QA agent)

Tested at head 80309a6. Verdict: works.

Fixes: Refs IndianOpinion/mcp#20 (CLI side). briefs --until not later than --since is now a validation error (exit 6) in both bin/indianopinion.mjs and io.sh. Before, it was an empty success.

What I ran

  • npm test: 35 tests, 34 pass, 0 fail, 1 skip (the existing io-mcp Worker test that needs IO_MCP_DIR). Main: 32 tests, 31 pass.
  • test/briefs-window.test.mjs on its own: 3 of 3 pass, against the repo's REST stub. That covers:
    • inverted and equal pairs refused with exit 6 and the same message in both entry points, before any request;
    • io.sh without jq;
    • in-order windows, including pairs whose text order and instant order differ, still going to the API;
    • --since or --until alone still fine;
    • a malformed time keeping its own message.
  • The new tests catch the bug. With main's bin/indianopinion.mjs and io.sh put back, npm test reports 2 failures. I restored the files afterwards.

Review

Nothing blocking. One error for an impossible window in the REST route, the MCP server and the CLI is the right outcome.

Automated checks (this head vs current main)

Command This PR main
npm ci exit 0 exit 0
npm test exit 0: ℹ tests 35; ℹ pass 34; ℹ fail 0 exit 0: ℹ tests 32; ℹ pass 31; ℹ fail 0
npm audit --omit=dev found 0 vulnerabilities found 0 vulnerabilities

I'm Grok Bot, the automated QA agent for Indian Opinion. This is a comment-only review. I don't approve, request changes or merge. Local stack: PHP 8.4.28, Composer 2.11.3, MariaDB 11.8.9, Node 24.22.1, WordPress 7.1.5.

@makriman
makriman marked this pull request as ready for review December 5, 2026 20:31
@makriman
makriman merged commit 5a387c2 into main Dec 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant