Repository navigation
Phase: release --version reaches the command - #1673
Merged
neuromechanist merged 27 commits intoOct 8, 2026
Merged
neuromechanist merged 27 commits into
neuromechanist merged 27 commits into
Conversation
The root program's '-v, --version' is recognised anywhere on the command
line, so 'nemar dataset release <id> --version 2.0.0' -- the form the
release help documents -- printed the CLI version and exited 0, and a
scripted release (-y) silently did nothing. The '=' form already worked
because the root option is boolean.
Before parsing, bindShadowedOptionValues joins a value-taking option of the
addressed subcommand to its value when an ancestor command declares the
same flag ('--version 2.0.0' -> '--version=2.0.0'). Global flags keep
working anywhere (no enablePositionalOptions); a bare '--version', values
that look like flags, anything after '--', and boolean collisions (#1220)
are left alone.
nemar dataset release <id> --version (or --version -y) still let the root -v, --version claim the bare flag, print the CLI version and exit 0: the #1493 silent no-op for a scripted -y release. When the leaf command declares a required-value option whose long flag an ancestor also declares and it appears with no value (last token, or followed by another flag), bindShadowedOptionValues now throws MissingShadowedValueError. index.ts reports it through the declaring command, so stderr and exit code are Commander's own: error: option '--version <version>' argument missing, exit 1. The "leaves everything else alone" test pinned the old pass-through for the valueless forms; those cases moved into a new error test on purpose. nemar --version and nemar -v are unchanged.
test.yml sorts a file into the live-API tier when its text matches testRequest, TEST_API_URL or runCli(. The helper and the env var here did, so the #1493 regression test ran only in the soft integration-dev tier and never in unit-pure. Rename the helper to spawnCli and point the CLI at a closed local port through config.json in the isolated config dir, as the offline CLI tests do. Strip TEST_* variables from the child env so an ambient setting cannot override the config. The file no longer matches the tier grep.
The comment said every ancestor option is a boolean; admin recover declares --recover-file <path> on a command that also has subcommands. Say what actually holds, and note why the join is harmless when the ancestor's option takes a value too.
The test kept a hand-written copy of the command tree, which keeps passing after a flag changes in src/commands. Build the tree from the command groups src/index.ts registers, under a root declared the way index.ts declares it, and restore the shared groups' parents after. Add an invariant over every command in that tree: each value-taking option whose long flag an ancestor also declares must be joined to its value. It finds two today, dataset release --version and admin recover status --recover-file; the second is shared with a value-taking group, so a test pins that it still resolves through optsWithGlobals(). A drift test compares the test root with `nemar --help`, so a new root option or top-level command in index.ts fails it until the tree is updated. Optional-value shadowed options are rejected by a test, since a bare flag cannot be delivered past the ancestor.
dataset validate declares -v, --verbose and the root declares --verbose; both are booleans, so the token after the flag is a positional. Joining them would make the path --verbose=./x and validate the current directory instead. Assert dataset validate --verbose ./x is unchanged, and that Commander then hands ./x to validate as its path. Removing the value-taking guard in bindShadowedOptionValues fails this test.
The valueless --version entry-point test passed even when index.ts stopped reporting the error through Commander, because main()'s generic catch prints the same message. The observable difference is the bug-report nudge that only a non-Commander exit gets. Assert it is absent, so the failure stays a usage error.
Only the throwaway root had exitOverride(), so a usage error raised by a shared command (a missing <dataset-id>) called process.exit(1) and ended the whole bun test run. Trap process.exit and stderr for the length of the parse and surface the exit as a failure, with a test that proves it. Commander 12 never clears parsed option values, and the shared groups outlive this file: clear what each parse stored, and give each case values no other case uses.
Each spawn now has a kill timer and an explicit test timeout, and the child env drops proxy variables: an unroutable proxy made a loopback spawn hang for the whole kill window. The CLI is pointed at a local stand-in backend instead of a closed port, and the release test asserts the stand-in saw the notices call, so a config apiUrl that stops being honored fails the test instead of sending the call to the real API. The spawn tests used the live dataset id nm000104; use nm099999.
A boolean ancestor option takes the flag and strands its value, which is what the join repairs. An ancestor option that takes a value (admin recover --recover-file) consumes the flag and its value together and the leaf reads it through optsWithGlobals(), so the join was unneeded there, and it made `admin recover status --recover-file --json` newly fail. Shadow only when the outermost ancestor option of that long flag is a boolean. Only dataset release --version is rewritten now. The tree invariant separates the two kinds of collision, keeps a non-vacuity check for each, and pins the admin recover shapes as unchanged and still resolving.
`dataset release nm1 --version "" --type patch -y` silently did a patch bump, and without --type it opened a prompt that hangs on a closed stdin: the release handler tested `options.version` for truthiness, so an empty value read as no --version. Fix both layers. The pre-pass treats an empty next token as a missing value (Commander's "argument missing", exit 1). The handler tests `!== undefined`, so the `--version=` spelling, which reaches it as "", gets the existing "Invalid version" exit 1. Entry-point tests run the real CLI against a stand-in backend whose dataset names a repository that does not exist, so a regression fails at the clone instead of touching a real dataset repository.
`release --help --version` and `release nm1 --version --help` now fail with "argument missing" instead of showing the help that was asked for, because the missing-value error fired first. When --help or -h appears before `--`, drop the bare shadowed flag instead of throwing. Left in the argv, the root would claim it and print the CLI version, so it has to go. A flag that has a value is still joined, and `--help` after `--` is an operand and does not count.
Commander reads a lone "-" as an option value (the usual spelling of stdin), but the pre-pass counted it as a flag and rejected `--version -` as a missing value. A lone "-" now joins like any value. Any other dash-leading token is still read as a flag, so a value that starts with "-" has to be spelled --flag=value; a test and the code comment say so.
`dataset --version 2.0.0 release nm1 -y` and `dataset --version release nm1 -y` printed the CLI version and exited 0: the leaf walk stopped at the flag's value, and `dataset` does not declare the flag, so the root claimed it. The `=` spelling cannot be rewritten into place either; Commander has `dataset` reject it as an unknown option. Remember a shadowed flag typed below the root and ahead of the command that takes it, step over its value so the walk still finds that command, and throw MisplacedShadowedOptionError. index.ts reports it through the command like the missing-value error. At the root the flag stays the root's own (`nemar --version dataset release ...` prints the version), and a flag after the command's name is unaffected. Pins `--` ahead of command names and the root-level shapes.
An unexpected throw from bindShadowedOptionValues escaped main() as a bare message that read like a failure of the command the user typed. Rethrow it as "argv pre-pass failed: <message>" with the original as the cause, and leave the bug-report nudge on it, since that is a bug. Explain at the catch that command.error() exits, and that going through it runs the exitOverride whose markUsageExit() suppresses the nudge for the mistyped-option errors. Checked by hand with an injected throw: the pre-pass has no input that fails unexpectedly, so no automated test can reach this branch.
Removing the alias lookup in the leaf walk failed nothing: the only alias in the real tree, dataset status|view, has no shadowed option, and no real option takes an optional value or collides on a short flag. Run the join over every alias spelling of each real path, and add a minimal tree of real Commander objects that has an aliased command, a short-flag collision, an optional-value collision and a flag claimed by both the root and a group. Each of those branches now fails a test when it is mutated away.
A crashed `--help` spawn read as drift, an aliased command printed as `name|alias` broke the name comparison, and a cosmetic reorder of the root options in index.ts failed it. Assert the spawn exits 0, split names on whitespace and `|`, and compare the root flags as sorted sets. The comment now says the test compares flag strings and top-level names only.
Rewrite the argv-shadowing comments as present-tense statements of the hazard instead of a narration of what used to happen. They now say the shadowing ancestor can be any command, not only the root; that an ancestor option that takes a value needs no join; why a flag-looking next token counts as missing (Commander itself would take it) and how to spell a dash-leading value; why the errors are thrown and the message rebuilt; and that short flags cannot be rescued by rewriting. Correct the leaf-walk comment: its assumption is that no command with subcommands takes a value option, which only admin recover does, and the walk then ends at recover, which shadows nothing.
Say what each case in "leaves everything else alone" is: dataset is a command that does not declare --version, and validate -v collides with the root's short flag (#1220). The boolean-collision comment claimed the path would silently become the current directory; validate allows unknown options, so Commander passes `--verbose=./x` through as the path and validate checks a bogus one (confirmed by parsing it). State hazards in the present tense instead of narrating what changed, say the root has the same flags rather than being identical, and drop the claim that the inline root commands collide with nothing, which nothing re-checks. The tier note now says integration-dev is soft on dev but required at the dev-to-main gate, and that the grep matches comments, so none of the three names may appear in the file.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1673Version: 🤖 Updated on each push. |
The ancestor map was keyed by long and short flags but only ever read with an option's long flag, and a `--x` key can never equal a `-x` key, so the short keys were dead. Key it on long flags, drop the helper that listed both, drop the casts Commander's typings make redundant, and shorten isValue. Behavior is unchanged: the old and new function agree on 300k random argv over the real tree and 300k over a minimal tree (result, error class, message, command and option).
`--` was handled in three places: a break in the leaf walk, a slice for the help check, and a push-the-rest branch in the join loop. Compute the boundary once, run both loops up to it, take the help check from the same slice, and append what follows it at the end. The empty help branch goes away, and the lookahead in the walk moves into the branch that uses it. Behavior is unchanged: the old and new function agree on random argv over the real tree and a minimal tree (result, error class, message, command and option).
Cut the catch-block comment in index.ts to three lines and the header paragraph on the misplaced-flag error to its two facts; the class doc already carries the rest. Say why the shadowed-flag set is computed over the whole tree: the walk meets a flag before it knows which command will take it.
reach() kept a module-level array that it cleared before each parse and read back after it. Put the snapshot on the error the preAction hook throws instead, and clear the parsed option values in the finally block with the other restores.
Add bind (the pre-pass over a tree), unchanged (every case returns as it went in) and thrown (the error the pre-pass throws, or a failure if it returns), and use them where the cases repeated a multi-line call, a for-expect loop, or a try/catch/instanceof block. No case changed.
The oracle's ancestor map listed long and short flags but was only read with a long flag, so the short keys were dead. Key it on long flags and drop the helper. The oracle stays independent of the production code: it does not import the pre-pass's own helper, so a mistake there cannot be mirrored here.
Replace the hand-made kill flag and timer with spawn's timeout option, read both pipes and the exit code together, and put the proxy and color-forcing variables in one scrub list instead of assigning undefined. CLI_ENTRY is built from REPO_ROOT. proc.killed is true after any exit (checked on a fast and a slow process), so a timeout is detected by proc.signalCode, which is only set when the process was ended by a signal.
Five spawn tests asserted the same four things about a Commander-style usage error: the message on stderr, no bug-report nudge, not the CLI version, exit 1. Name that as expectUsageError. The lone-dash and dash-leading-value cases and the equals-before-command case now get the nudge and version checks too, which hold for them. Drop the inner describe, which added a level with no hooks of its own.
Contributor
Author
Review recordOne pass of the PR review toolkit (Sonnet agents): code review, test analysis, silent-failure hunt, comment analysis, then a propose-only simplifier. No critical findings. Every finding below was fixed unless it is listed under "Not done". Tip at the time of writing: Important
Suggestions and nice-to-have (all applied)
Process noteDuring development a probe of the release handler used a stand-in backend that named the real Verification
Not done (tracked follow-ups)
|
neuromechanist
merged commit Oct 8, 2026
7febf98
into
feature/issue-1671-epic-bru-upload-fixes
14 checks passed
This was referenced Oct 8, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The root program declares
-v, --version, which Commander recognizes anywhere on the line, sonemar dataset release <id> --version 2.0.0(the documented form) printed the CLI version and exited 0, and a scripted-yrelease silently did nothing (issue #1493, P0).A pre-pass now joins a value-taking option to its value (
--version 2.0.0becomes--version=2.0.0) for the subcommand named on the line when an ancestor declares the same long flag as a boolean, and every way of leaving the value out is a usage error instead of the root printing the CLI version.The first commit is the contributor's original fix (PR #1653, bruAristimunha), preserved with authorship.
The commits on top are review refinements:
dataset release --version); when an ancestor option takes a value (admin recover --recover-file) Commander's ancestor already consumes both tokens, so nothing is rewritten and there is no behavior change thereerror: option '--version <version>' argument missing, covering the last token, an empty string, and a following flag; a lone-counts as a value; a value that starts with-must be spelled--flag=value;--helpor-hbefore--still shows help--version ""or--version=) no longer falls through to--typeor an interactive prompt: the release handler now testsoptions.version !== undefined, so it reaches the existingInvalid versionexitdataset --version 2.0.0 release ...) is a usage error (must come after 'release') instead of printing the CLI version and exiting 0argv pre-pass failedand keeps its causetest.ymluses to route a file to the live-API tier, so the P0 regression test runs inunit-pure(it ran only inintegration-dev, which is red on fork pull requests)src/index.ts, with an invariant walk over every command (including alias spellings), a small tree of real Commander objects for the paths the real tree does not exercise, and a drift test againstnemar --helpreach()trapsprocess.exitand resets Commander's stored option values, so a usage error fails an assertion instead of ending the shared test processnm099999; the stand-in backend names only a repository that does not exist (nemarOrg/argv-shadowing-1493-no-such-repo), so no test can clone, push or open a PR on a real repositoryPart of epic #1671. Supersedes #1653 (contributor PR retargeted to the epic branch). Issue: #1493.
Behavior to know about
nemar --versionandnemar -vprint the CLI version, anything after--, boolean collisions such as-v/--verbose(issue Subcommand -v/--verbose shadowed by root -v (version) and global --verbose #1220), and everyadmin recover statusshape.dataset --version=2.0.0 release ...stays Commander's ownunknown option '--version=2.0.0'error; a rewritten form cannot be delivered there.release nm1 --version 2.0.0withoutdatasetis an unknown top-level command and behaves as before.--flag [value]) shadowed options are not handled; none exists today, and tests on a small real Commander tree pin that.Invalid versionexits end with the generic bug-report nudge, as every handler-level exit here does.Test plan
bun run typecheck(root and backend),biome checkon the 4 changed filestest/release-version-flag.test.ts: 30 pass, 0 fail, also with an ambientTEST_API_URLand an unroutable proxy set; run in one process with five other unit files: 126 pass, 0 failgrep -Eq 'testRequest|TEST_API_URL|runCli\(' test/release-version-flag.test.tsdoes not match (it matched at the contributor's commit)nemar --versionand-vprint the version and exit 0; help wins over a missing valueFollow-ups (not in this PR)
index.tsinto a buildable module so the invariant also covers the six inline root shortcutsadmin recover --recover-file <value> statusends the walk atrecover, which shadows nothing)-v, --verbosecollisions (Subcommand -v/--verbose shadowed by root -v (version) and global --verbose #1220), including the long-flag-onlydataset search --verbosevariant