Repository navigation
refactor(vis): route native commands through a table - #246
Conversation
Records, for about three thousand invocations, where the dispatch in main() sends them: every case of the shared routing fixture, every manifest command and alias, each routed command word on its own and with a subcommand, a positional, help flags, a `--` separator and a leading global flag, and the version flags. The expected answer is written out from the dispatch as it stands, so the next change to it can show that no route moved. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
main() was one match with the same help guard written about thirty times. The routes are now rows of (command path, help policy, entry) in route.rs, looked up by longest path; the odd shapes (`complete --`, `run <target>`, `__pm-shim`, the version flags) stay explicit arms. Routing is a pure function, pinned by a snapshot of every row of the shared routing fixture, every manifest command and alias, and each table word with subcommands, help flags and leading global flags. Also drops the stale dead-code allowance on `mod targets`, which three commands use. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The VIS_VERSION-else-crate-version rule was written out in the help surface, the config cache and the HTTP user agent as well as the version command. Self-update keeps its own check, which wants an empty or missing value to mean "not native". Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… help surface - term::ColourFlag::parse is the one reader of colour flags; the detection, the "looks like a colour flag" hand-off and the surface's global-flag rule use it instead of three separate matchers. - term::Style is the one SGR painter for the help text and the deps report (the deps copy re-opened a style after a nested close; the help text is byte-identical with that rule, checked over every help page with colour on and off). - surface::answer picks its output from an Intent enum instead of four booleans, and completion splits its words with the surface's Request. - The "no group" help section is an Option key, not a magic string. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The "printable ASCII" and "printable ASCII without a space" checks that gate a pail block were written out in cache hash, cache clean, clean, sbom and sort-package-json, with two spellings of the same rule. They now live in pail next to the layout, whose module documentation states the contract between the layout and its callers; pail's colour painter uses the shared Style. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoRefactor native vis dispatch into a command routing table
AI Description
Merge Risk
|
|
Thank you for following the naming conventions! 🙏 |
Code Review by QodoResolved findings 1.
|
Four routes (`hook validate`, `implode`, `cache clean`, `cache prune`) are compiled only on Unix, but the committed snapshot and the list of command paths name them unconditionally. On Windows the row-count test and the snapshot comparison therefore fail, because those invocations reach the surface there. Gate both tests with cfg(unix) and say why in a comment. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
|
ⓘ Qodo did not review this PR because this workspace reached its daily trial limit of 100 reviews. Reviews start again at 00:00 UTC. Choose a plan to continue now. |
Pure refactor of the native
visfront-end: no route, output or exit code changes.Routing table
main()was one ~185-linematchwith the!asks_for_helpguard written about thirty times. The routes are now rows of(command path, help policy, entry)inroute.rs, looked up by longest path. The help policy is applied once. Explicit arms remain only for shapes that are not a path:__native-info,--version/-V,complete --,run <target>(exactly two arguments) and__pm-shim.hook run/list/validate(unix)advisories bloom status,ignore,clean,implode(unix)cache list/size,clean/prune(unix),hash,whylist,replay,task-why,affected,sbom,secrets,sort-package-json,optimize,deps,self-update,add,dlxsync ci-workflow,security list/keys-refresh,shim statusinstall/i,info/viewexec,pm,x,remove,dedupe,link,unlink,outdated,why--helpHow the routes are pinned
test(vis): pin which entry answers each native invocation) addstests/fixtures/native-routes.snap(about 3100 invocations: every case ofrouting.json, every manifest command and alias, each routed word alone and with a subcommand, positional,--help/-h,--, leading global flags, version flags) and a test that checks it against a transcription of the oldmatch, on the oldmain.rs.routes_match_the_snapshotnow checksroute()against the same, untouched snapshot, so a moved route fails with a was/now line.routing.json(stub Node, emptyPATH): exit code, stdout and stderr identical, except the sixsbomcases whose output carries a timestamp and a random UUID.Finding (not changed here):
--helpis not the manifest's for eight commandsexec,pm,remove,dedupe,link,unlink,outdatedandwhyskip the help guard. The launcher always sends them to the binary, and their entries pass--helpon to the package manager (vis exec --helpwith no pnpm onPATHprintsfailed to run 'pnpm').node dist/bin.js <cmd> --helpprints vis's own help for each of them.x --helpis the same in both engines (both treat it as a file name). This looks unintended;Help::Entrydocuments it and keeps it.Other changes
node_contract::version()replaces theVIS_VERSION-else-crate-version rule in the version command, the help surface, the config cache and the HTTP user agent.self_updatekeeps its own check: it needs a missing or empty value to mean "not native".mod targets.surface::answerpicks its output from anIntentenum; completion splits words withsurface::Request.term::ColourFlag::parseis the one reader of colour flags (detection and the "looks like a colour flag" hand-off). The surface's global-flag rule stays the two exact spellings--color/--no-color, now namedColourFlag::is_global_option; widening it would change routing.term::Styleis the one SGR painter for help, pail and the deps report. The deps copy re-opens a style after a nested close; to check the help text is unaffected I renderedvis --help,vis help <cmd>andvis <cmd> --helpfor every manifest command (1160 renders) withFORCE_COLOR=3,FORCE_COLOR=0,NO_COLOR=1and a CI provider, old binary against new: byte-identical.Optionkey.pail::printable,plainandplain_pathreplace the copies in cache hash, cache clean, clean, sbom and sort-package-json.Layout::blockstill returns aString:cache prunedeliberately prints an em dash that a printable-ASCII check would refuse, so a checkedblockneeds a per-caller rule first.Ran locally
cargo fmt --check,cargo clippy -p vis-core -p vis-cli --all-targets -- -D warnings,cargo test --workspace: pass (includingtests/{cli,golden,routing,hook,node_parity}.rs).vitest run __tests__/nativewithFORCE_COLOR=3, with the task-runner, secret-scanner and vis addons built (pnpm build:native:debug) and the PR's binary copied tovis-native-cli: 5620 tests, 5615 passed, 0 failed, 5 skipped by the suites themselves.🤖 Generated with Claude Code