Support multiple root directories in cat discovery mode#10
Merged
Conversation
…the first When shell glob expansion produced multiple directories (e.g. `nats-pi-*` expanding to `nats-pi-a nats-pi-b`), discovery mode only passed args[0] to the engine, silently dropping all subsequent roots. Changed the engine Cat() signature from `root string` to `roots []string` so discovery iterates over every root. Files within each root are sorted deterministically; root order is preserved across roots. Size and file count limits apply globally across all roots. Added four regression tests for multi-root discovery: basic multi-root, root-order preservation, per-root relative paths, and cross-root shared limits. Added AST meta-test (TestVariadicCommandsUseFullArgs) that flags any cobra command using MinimumNArgs(1) whose RunE body subscripts args[N] instead of passing the full slice — this would have caught the original bug at test time. https://claude.ai/code/session_01A2PxvVZoRPBQY7csGzKJfA
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
This change extends the
Catengine method to support multiple root directories in discovery mode, allowing glob expansion patterns (e.g.,nats-pi-*) to be processed as separate discovery roots rather than silently dropping extra arguments.Key Changes
Engine.Cat()signature to acceptroots []stringinstead ofroot string, enabling discovery across multiple directoriesresp.Rootis only set when exactly one root is providedcatFilestruct to pair absolute paths with their relative paths (relative to their discovery root), enabling correct path computation in multi-root scenariosMaxTotalSizeandMaxFileslimits now apply across all roots collectivelyImplementation Details
cmd_cat.goto pass the fullargsslice toCat()instead ofargs[0], fixing the glob expansion bugcatDiscover()to return[]catFilewith pre-computed relative pathscatReadFiles()to accept[]catFileand use stored relative pathsRootargument to[]stringfor backward compatibilityTesting
TestVariadicCommandsUseFullArgsto prevent regression of the args subscripting bug via AST analysisTestCatDiscoveryMultipleRoots,TestCatDiscoveryMultipleRootsPreservesRootOrder,TestCatDiscoveryMultipleRootsRelPaths, andTestCatDiscoveryMultipleRootsSharedLimitshttps://claude.ai/code/session_01A2PxvVZoRPBQY7csGzKJfA