Skip to content

fix(shell): expand globs in for-loop word lists (OPE-89) - #237

Merged
aakarim merged 2 commits into
mainfrom
fix/ope-89-for-loop-globs
Nov 6, 2026
Merged

aakarim merged 2 commits into
mainfrom
fix/ope-89-for-loop-globs

Conversation

@aakarim

@aakarim aakarim commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

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 expandGlobWords expansion 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:

  • Before the implementation change: go test ./pkg/shell/cmds -run '^TestForLoopGlobExpansion$' -count=1 reproduced seven failing expansion cases; literal/unmatched controls passed.
  • After: 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).
  • gofmt and git 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.

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>
@linear-code

linear-code Bot commented Nov 2, 2026

Copy link
Copy Markdown

OPE-89

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread pkg/shell/shell.go Outdated
Comment on lines +818 to +820
expanded, globPattern, hasGlob := s.expandGlobWord(word)
if hasGlob {
matches := s.globExpand(globPattern)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@aakarim
aakarim merged commit 93db1ef into main Nov 6, 2026
7 checks passed
@aakarim
aakarim deleted the fix/ope-89-for-loop-globs branch November 6, 2026 14:54
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