Repository navigation
Conversation
Validate the full -n argument before producing output instead of silently falling back to ten lines or accepting a numeric prefix. Cover missing and empty expansions, malformed and overflowing counts, file input, and valid head/tail slices. Amp-Thread-ID: https://ampcode.com/threads/T-3199f5c9-6253-45b6-9ec8-ac369ffab8b6 Co-authored-by: Amp <amp@ampcode.com>
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.
Issue
Fixes OPE-100.
Implementation thread: https://ampcode.com/threads/T-3199f5c9-6253-45b6-9ec8-ac369ffab8b6
Diagnosis
The
-nbranches used uncheckedfmt.Sscanf. Missing arguments fell through to shorthand parsing; invalid values left the default count of 10 untouched; numeric prefixes such as3abcwere accepted. Both commands could therefore emit plausible but incorrect slices with exit status 0.The new regression test failed on unchanged production code:
seq 1 15 | head -nreturned lines 1–10 with no error, andtail -n +returned lines 10–15. Malformed counts also reproduced the silent fallback for file input.Fix
-nin head and tail.strconv.Atoi, rejecting malformed, overflowing, or negative counts with a diagnostic, exit status 1, and no stdout.+Nselection, byte-mode overrides, and existing shorthand behavior. Negative-count GNU extensions are not implemented, consistent with the existing byte-count validation.+, overflow, file input, and exact successful slices.Pipeline status semantics are intentionally unchanged: a trailing
wcstill supplies the pipeline status, so check the failing head/tail command itself rather than expecting pipefail.Verification
Passed in the Nix development environment:
go test ./pkg/shell/... -count=1go test -race ./pkg/shell/... -count=1go test ./pkg/openlore -run 'Test(MCPHTTPAPI_Shell|MCPHTTPSessionShellCommandFailureIsResult|MCPShellErrorClassification|ExecShellTranscriptPreservesStreams)' -count=1go vet ./pkg/shell/...go build ./...gofmtcheck on changed Go files andgit diff --checkNo UI changes. This PR is left open and unmerged.