Skip to content

io.sh: topics list --limit without jq is a usage error (exit 2), not an ignored flag - #37

Merged
makriman merged 2 commits into
mainfrom
fix/topics-list-limit-no-jq
Dec 5, 2026
Merged

makriman merged 2 commits into
mainfrom
fix/topics-list-limit-no-jq

Conversation

@makriman

@makriman makriman commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

No issue is filed for this.

Problem

io.sh topics list --limit N ignores the limit when jq is not installed. It prints every suggestion and exits 0, so a script that asked for one suggestion gets all of them with no sign that the flag did nothing. The CLI and io.sh with jq both cut suggested to N.

How to reproduce on main (abeaadb)

Hide jq from PATH (a directory of links to bash, curl and the other tools, without jq) and run against the REST stub in test/stub-rest.mjs, which returns two suggestions:

PATH=<dir without jq> IO_API=<stub> IO_TOKEN=<stub token> bash io.sh topics list --limit 1
  • Expected: either one suggestion, or a usage error that says --limit needs jq.
  • Actual: exit 0, suggested has 2 entries, nothing on stderr. --limit abc is also accepted silently, because the validator only runs when jq is present.

With jq on PATH the same command gives one suggestion. Open PR #31 has the same behaviour without jq (it validates --limit but still skips the cut).

Root cause

The topics list branch only applied the limit inside if [ "$HAVE_JQ" = 1 ], with no else. digest --limit and breaking recent --limit call needjq for this case; topics list did not.

The change

A correct limit without jq is not feasible in POSIX shell: suggested is a JSON array of objects whose string fields may hold commas, brackets and escaped quotes, so cutting it needs a JSON parser. So the flag fails clearly instead, exactly as digest --limit does: io.sh topics list --limit N without jq exits 2 with topics list --limit needs jq (...) before any request. Without --limit, topics list still prints the API's JSON unchanged, as documented. With jq nothing changes.

The header comment of io.sh and the README sentence that lists the flags that need jq now name topics list --limit. CHANGELOG line under Unreleased. No version bump.

Tests

New test/topics-limit-no-jq.test.mjs (node:test, local stub, no network). It builds a PATH without jq (links to every other command) and checks: --limit 1, 100 and abc exit 2 with the needs-jq message, print nothing on stdout and make no request to the stub; IO_SH_NO_JQ=1 gives the same; topics list without --limit and without jq still prints the API JSON; with jq, io.sh and the CLI return the same suggested.

  • node --test test/topics-limit-no-jq.test.mjs with io.sh from main: 2 of 5 fail (the two no-jq --limit cases). With the fix: 5 of 5 pass.
  • npm test: 37 tests, 36 pass, 1 skipped (the MCP bridge test, which needs ../mcp), 0 fail. Node 22, jq 1.7.
  • bash -n io.sh: clean. shellcheck and bats are not run here.

Conflicts with open PRs

Owner decision

Making --limit fail without jq is the choice that leaves every working call as it was: topics list with no --limit still works without jq. The alternative is to accept --limit without jq and print a warning on stderr while returning the full list; that keeps exit 0 for scripts that pass --limit today, but a script that relies on the cut still gets the wrong answer. This PR follows the existing digest --limit rule instead.

…d flag

Without jq, io.sh topics list --limit N printed every suggestion and
exited 0. Slicing the suggested array needs a JSON parser, so the flag
now fails before the request with the needs-jq usage error (exit 2),
as digest --limit already does.
@makriman

makriman commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Review by Grok Bot (Indian Opinion QA agent)

Tested at head cd94068. Verdict: works.

Fixes: no issue (as the PR says). Without jq, topics list --limit is now a usage error (exit 2) and is no longer silently ignored.

What I ran

  • npm test: 37 tests, 36 pass, 0 fail (main: 32 tests, 31 pass). shellcheck on the changed scripts: clean.
  • The new test file catches the bug. I ran it against main's io.sh: 2 of 5 fail. On this branch: 5 of 5 pass.
  • Probe with jq hidden (IO_SH_NO_JQ), using a stub API that returns two suggestions:
Command main this PR
topics list --limit 1 exit 0, 2 suggestions (limit ignored) exit 2, usage error saying --limit needs jq
topics list --limit abc exit 0, 2 suggestions exit 2, same usage error
topics list (no limit) exit 0, 2 suggestions exit 0, 2 suggestions

Review

Automated checks (this head vs current main)

Command This PR main
npm ci exit 0 exit 0
npm test exit 0: ℹ tests 37; ℹ pass 36; ℹ 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:30
@makriman
makriman merged commit 0f91ac6 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