Repository navigation
fix(shell): expand globs in for-loop word lists (OPE-89) - #237
Conversation
Reuse quote-aware command-argument glob expansion while preserving unmatched patterns and literal quoted wildcards. Amp-Thread-ID: https://ampcode.com/threads/T-b690d55f-1323-4a49-aaa2-b79365b291f1 Co-authored-by: Amp <amp@ampcode.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unquoted substitutions are globbed before field splitting, producing literal patterns or incorrectly grouped filenames instead of the required expanded fields.
1 open issue
What changed in this PR
This PR addresses OPE-89 by reusing the shell’s quote-aware glob expansion for for-loop word lists.
Changes:
- Expands matching patterns into sorted absolute paths, preserving filenames with spaces as whole loop items.
- Retains the existing fallback when patterns do not match.
- Adds regression coverage for relative and absolute patterns, variables, quoting, escaping, and mixed lists.
| File | Description |
|---|---|
pkg/shell/shell.go |
Applies glob expansion when collecting loop items. |
pkg/shell/cmds/shell_test.go |
Adds table-driven tests for loop glob expansion and literal handling. |
Review effort: Balanced
| expanded, globPattern, hasGlob := s.expandGlobWord(word) | ||
| if hasGlob { | ||
| matches := s.globExpand(globPattern) |
There was a problem hiding this comment.
Confirmed and fixed in a473d9d. Added regression cases that fail on the prior head for multi-pattern variables, command substitutions, and split-before-glob ordering. The shared expander now retains quote/escape information while splitting only unquoted substitutions and globs each resulting field; matched filenames stay intact. Also covered mixed quoted suffixes, whitespace boundaries, and empty variables. Shell race tests, repository-wide short race tests, vet, build, and diff checks all pass. Command-argument field splitting behavior is unchanged.
Preserve quote and escape information across field boundaries, then glob each resulting loop item. Keep command-argument splitting behavior unchanged. Addresses the OPE-89 PR review with variable, command-substitution, whitespace-boundary, and mixed-quote regression cases. Amp-Thread-ID: https://ampcode.com/threads/T-b690d55f-1323-4a49-aaa2-b79365b291f1 Co-authored-by: Amp <amp@ampcode.com>

Linear issue
Fixes OPE-89.
Working Amp thread: https://ampcode.com/threads/T-b690d55f-1323-4a49-aaa2-b79365b291f1
Diagnosis
For-loop word lists used plain word expansion, bypassing the quote-aware glob expansion already used for command arguments. As a result, relative and absolute matching patterns executed once as literal strings with exit code 0.
Fix
Use shared
expandGlobWordsexpansion when collecting loop items: split unquoted substitutions into fields while retaining quote/escape information, then glob each field. Command arguments keep their existing non-splitting behavior. Append matching paths as whole items (including filenames with spaces), and retain the previous fallback for unmatched patterns. Quoted and escaped wildcards remain literal. Matching paths use the same canonical absolute-path representation and sorting as command arguments.Add regression coverage for relative, absolute, and bare globs; quoted prefixes; variable patterns; question-mark wildcards; unmatched patterns; quoting and escaping; filenames with spaces; and mixed literal/glob lists.
Verification
All commands ran through
nix develop --command:go test ./pkg/shell/cmds -run '^TestForLoopGlobExpansion$' -count=1reproduced seven failing expansion cases; literal/unmatched controls passed.go test -race ./pkg/shell/... -count=1— passed all shell packages, including the regression cases.go test -race -short ./...— passed repository-wide short suite.go vet ./...— passed.go build ./...— passed (Go compilation/type checking).gofmtandgit diff --check— clean.Docker integration suites and dashboard checks were not run locally; no frontend changes.
Selection
Chosen oldest actionable bug by Linear creation date. Skipped older unresolved OPE-65 (historical transport failure lacks server evidence), OPE-74 (comment confirms distinct on-disk files, requiring a content/case-policy decision rather than analytics deduplication), and OPE-77/OPE-88 (already In Progress).
Not merged; ready for review and CI.
Review follow-up
Addressed the split-before-glob review in a473d9d. New regression cases reproduced four failures before the follow-up: multiple patterns from variables and command substitutions, unquoted space-containing patterns, and mixed quoted suffixes. All loop regression cases now pass, including whitespace boundaries and empty quoted/unquoted variables. Re-ran the shell race suite, repository-wide short race suite, vet, build, and diff checks successfully. Fresh CI is subscribed for this head; the original head passed all seven CI checks.