Repository navigation
io.sh: a usage error from --limit or an on/off flag stops before the request (exit 2) - #31
Conversation
limit_of and onoff called usage (exit 2) but were run inside a command substitution, where exit ends only the subshell. io.sh has no set -e, so it printed the usage error, carried on with an empty value and exited 0. They now set LIMIT and ONOFF and are called directly, and --limit is checked before the request on digest, topics list and breaking recent. The CLI also checks --limit before the request on those three commands. Tests: test/usage-exit.test.mjs (CLI and io.sh against the stub) and test/io-sh.bats (io.sh with a fake curl).
|
Review by Grok Bot (Indian Opinion QA agent) Tested at head Fixes: #28. A bad What I checked
Not checked
Review
Automated checks (this head vs current main)
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. |
Problem
io.sh briefs --limit 999(alsoabc,0) prints the usage error on stderr, then runs the query anyway and exits 0. The CLI exits 2 and sends nothing. An agent that mistypes a limit gets exit 0 and a plausible page of results.Root cause
limit_ofandonoffreport a bad value by callingusage, which exits 2. But every caller ran them inside a command substitution, for examplel=$(limit_of 10).exitinside$(...)ends only the subshell, andio.shruns withset -uo pipefailand no-e, so the parent shell carried on with an empty value.The same pattern was at five more call sites, not only
briefs:digest --limit,topics list --limit,breaking recent --limit: the request had already gone out (validation came after it), thenjq --argjson n ""failed and the command exited 0.prefs set --digest maybeand--nudges maybe: the usage error was printed and a malformed body,{"digest":{"on":}}, was sent with PATCH. The exit code then depended on how the API answered that body.Change
limit_ofsetsLIMITandonoffsetsONOFF; both are called directly, sousageexits the script. A comment at the definitions says why they must never go inside$(...).digest,topics listandbreaking recentcheck--limitbefore the request, so a usage error sends nothing.digest,topics listandbreaking recentit checked--limitafter the request. It now checks first, so both clients send nothing on a usage error.CHANGELOG.md(Unreleased) and aCONTRIBUTING.mdline about the bats file.Tests
test/usage-exit.test.mjs(innpm test): for the CLI andio.sh, every invalid--limitcase and both on/off flags exit 2, print nothing on stdout, give theusageerror, and the REST stub records no request. Valid values still work, and the PATCH body is checked. Before the fix: 2 of 3 tests fail (io.sh prefs set --digest maybeexits 6 after sending the malformed body; the CLI'sdigest --limit 0reaches the API).test/io-sh.bats(bats test/io-sh.bats): the sameio.shcases with a fakecurlon PATH that logs each call, plus a check that no validator appears inside$(...). Before the fix: 4 of 6 fail. After: 6 of 6 pass, with jq and withIO_SH_NO_JQ=1.Commands run on this branch:
npm test(Node 22.23.4, jq 1.7, with../mcpinstalled): 35 tests, 35 pass, 0 skipped.bats test/io-sh.bats(bats 1.14.0): 6 of 6 pass;IO_SH_NO_JQ=1 bats test/io-sh.bats: 6 of 6 pass.npm pack --dry-run: the same 6 files. The version-strings check fromci/workflows/test.ymlpasses.For the reviewer
npm testor the parked workflow yet, because bats is not a Node dependency. The Node test covers the same cases and does run innpm test.topics list --limitwithout jq is still accepted and ignored (the trim needs jq). That is a separate parity gap, not this bug; it is not changed here.Fixes #28