Skip to content

Phase: release --version reaches the command - #1673

Merged
neuromechanist merged 27 commits into
feature/issue-1671-epic-bru-upload-fixesfrom
feature/issue-1493-argv-shadowing
Oct 8, 2026
Merged

neuromechanist merged 27 commits into
feature/issue-1671-epic-bru-upload-fixesfrom
feature/issue-1493-argv-shadowing

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The root program declares -v, --version, which Commander recognizes anywhere on the line, so nemar dataset release <id> --version 2.0.0 (the documented form) printed the CLI version and exited 0, and a scripted -y release silently did nothing (issue #1493, P0).
A pre-pass now joins a value-taking option to its value (--version 2.0.0 becomes --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:

  • the join applies only when the outermost ancestor option is a boolean (today only 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 there
  • a shadowed value option with no value is Commander's own usage error, exit 1: error: 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; --help or -h before -- still shows help
  • an empty version (--version "" or --version=) no longer falls through to --type or an interactive prompt: the release handler now tests options.version !== undefined, so it reaches the existing Invalid version exit
  • a shadowed flag typed before the subcommand (dataset --version 2.0.0 release ...) is a usage error (must come after 'release') instead of printing the CLI version and exiting 0
  • an unexpected pre-pass error is labeled argv pre-pass failed and keeps its cause
  • the test file no longer contains the tokens test.yml uses to route a file to the live-API tier, so the P0 regression test runs in unit-pure (it ran only in integration-dev, which is red on fork pull requests)
  • the test builds the real command tree under a root declared like 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 against nemar --help
  • reach() traps process.exit and resets Commander's stored option values, so a usage error fails an assertion instead of ending the shared test process
  • spawned-CLI tests have a kill timeout, scrub proxy variables, and use nm099999; 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 repository

Part of epic #1671. Supersedes #1653 (contributor PR retargeted to the epic branch). Issue: #1493.

Behavior to know about

  • Unchanged: nemar --version and nemar -v print 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 every admin recover status shape.
  • dataset --version=2.0.0 release ... stays Commander's own unknown option '--version=2.0.0' error; a rewritten form cannot be delivered there.
  • release nm1 --version 2.0.0 without dataset is an unknown top-level command and behaves as before.
  • Short flags and optional-value (--flag [value]) shadowed options are not handled; none exists today, and tests on a small real Commander tree pin that.
  • The handler's own Invalid version exits end with the generic bug-report nudge, as every handler-level exit here does.

Test plan

  • bun run typecheck (root and backend), biome check on the 4 changed files
  • test/release-version-flag.test.ts: 30 pass, 0 fail, also with an ambient TEST_API_URL and an unroutable proxy set; run in one process with five other unit files: 126 pass, 0 fail
  • grep -Eq 'testRequest|TEST_API_URL|runCli\(' test/release-version-flag.test.ts does not match (it matched at the contributor's commit)
  • Real CLI, empty config dir or stand-in backend naming the no-such repository: the documented form reaches the handler; valueless, empty, flag-following, and misplaced shapes fail with the messages above and exit 1; nemar --version and -v print the version and exit 0; help wins over a missing value
  • 34 mutations applied one at a time and restored, each caught by at least one test, except the two deliberate non-failures (a root-option reorder and an alias on a root command must not fail the drift test) and one inert change (short keys left in the ancestor map after the long-only keying)
  • Equivalence of the final pre-pass against the pre-simplification one on 1.2 million random argv inputs over the real tree and a small tree: 0 mismatches in results, error class, command and option; narrowing or widening the logic on purpose produced thousands of mismatches, so the harness detects changes
  • The unexpected-error label has no automated test (the pre-pass has no input that throws unexpectedly); checked by hand with an injected throw

Follow-ups (not in this PR)

  • extract the program assembly from index.ts into a buildable module so the invariant also covers the six inline root shortcuts
  • make the leaf walk skip the values of all value-taking options (today only shadowed flags are skipped; admin recover --recover-file <value> status ends the walk at recover, which shadows nothing)
  • boolean -v, --verbose collisions (Subcommand -v/--verbose shadowed by root -v (version) and global --verbose #1220), including the long-flag-only dataset search --verbose variant
  • add a line about the new usage errors to the 0.10.16 release notes (this repository writes the changelog at release time)

bruAristimunha and others added 19 commits October 7, 2026 15:38
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.
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1673

Version: 0.10.15-PR1673.ca8e1b1
Commit: ca8e1b1


🤖 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.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review record

One 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: ca8e1b1e.

Important

  • Empty version fell through (silent-failure hunt, test analysis, code review; reproduced against the real CLI): release nm1 --version "$V" --type patch -y with $V unset silently did a patch bump, and without --type it hung on an interactive prompt. The pre-pass now treats an empty value as missing and the handler tests options.version !== undefined.
  • A leaf-level usage error in the test killed the whole bun test process (code review, reproduced): reach() now traps process.exit and stderr, restores them in finally, and a test proves a leaf usage error fails an assertion.
  • admin recover status --recover-file --json changed behavior without need (code review): the join is now applied only when the outermost ancestor option is a boolean, so that command is no longer touched and its special-case test is gone.
  • A shadowed flag before the subcommand still printed the CLI version and exited 0 (silent-failure hunt): dataset --version 2.0.0 release ... is now a usage error. This is about 30 non-comment lines in its own commit (c7704cb1), a few over the budget I had set; it breaks no existing shape and six mutations of it each fail a test.
  • Alias branch untested (test analysis): alias spellings now run over every real path, and a small tree of real Commander objects exercises aliased commands, short-flag and optional-value collisions, and an outermost-ancestor case.
  • Live dataset id in spawned tests (code review): nm000104 is live (AGENTS.md); the tests use nm099999, and the stand-in backend names a repository that does not exist.

Suggestions and nice-to-have (all applied)

  • Drift test: splits on name|alias, asserts the --help spawn exits 0, compares root options as a set; spawn tests have a kill timeout and scrubbed proxy variables; --help beats a valueless --version; a lone - is a value; unexpected pre-pass errors are labeled; stale Commander parse state is reset after each parse; about 15 comments corrected (a false claim that joining would validate the current directory, history narration, "recognises", mislabeled cases, the explanation for treating dash-leading tokens as missing values).
  • Simplifier: -- is handled once, dead short-flag keys removed from the ancestor map, reach() carries its snapshot on the stop error, shared bind/unchanged/thrown helpers, Bun's own spawn timeout (using signalCode, since proc.killed is true after any exit), one expectUsageError. A proposal to drop shadowedFlagsInTree was rejected after fuzzing showed it changes behavior on some inputs.

Process note

During development a probe of the release handler used a stand-in backend that named the real nemarDatasets/nm099999 repository, and the handler opened a PR there. It was closed and its branch deleted the same day; the repository was otherwise untouched. The tests and probes now name only a repository that does not exist.

Verification

  • 34 mutations, each caught by at least one test (plus the drift-test cases that must not fail); 1.2 million random argv inputs show the simplified pre-pass equals the pre-simplification one with 0 mismatches.
  • Typecheck, Biome, 30 tests in the file and 126 together with five neighbors in one process, tier grep clean.

Not done (tracked follow-ups)

@neuromechanist
neuromechanist merged commit 7febf98 into feature/issue-1671-epic-bru-upload-fixes Oct 8, 2026
14 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-1493-argv-shadowing branch October 8, 2026 00:41
@neuromechanist neuromechanist changed the title Phase: release --version reaches the command (#1493) Phase: release --version reaches the command Oct 8, 2026

This branch was previously deployed

1 inactive deployment
npm — ca8e1b1e Deployed Oct 8, 2026 by neuromechanist via publish #3233
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.

2 participants