Skip to content

fix(templater): keep unresolved dynamic vars in globs - #3103

Closed
Tyagiquamar wants to merge 1 commit into
go-task:mainfrom
Tyagiquamar:fix/unresolved-glob-vars
Closed

Tyagiquamar wants to merge 1 commit into
go-task:mainfrom
Tyagiquamar:fix/unresolved-glob-vars

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Summary

Fixes #2400. When a task's sources use a shell-derived (dynamic) variable, for example {{.PARENT}}/**/*, the fingerprint phase expanded the glob from the filesystem root (/**/*) and could hang on symlink cycles. The placeholder is now preserved when its variable has not been evaluated yet.

Root Cause & Problem

FastCompiledTask() uses Compiler.FastGetVariables, which deliberately leaves sh: variables unevaluated and stores them with an empty string value so templates can still be parsed. templater.ReplaceGlobs then rendered {{.PARENT}}/**/* with that empty value; ReplaceWithExtra additionally strips <no value> to an empty string. The result was an absolute /**/* pattern. After the switch to mvdan/sh/expand.Fields for glob expansion, that pattern recursively follows symlinks and can loop forever. The task never starts and there is no useful error, only repeated ELOOP in strace.

Technical Solution

In internal/templater/templater.go, ReplaceGlobs now checks whether a glob references a variable that is missing or still unevaluated (Sh set with an empty value). For those globs it keeps the original pattern instead of replacing it with an empty prefix. Fully resolved variables, including static variables, are replaced exactly as before. This keeps the pattern relative and prevents root-level traversal; it does not change compilation with CompiledTask(), where dynamic variables are available and substitution proceeds normally.

Test Plan

Added TestReplaceGlobsKeepsUnresolvedDynamicVariables in internal/templater/glob_test.go:

  • an unevaluated sh: variable keeps {{.PARENT}}/**/* unchanged;
  • a static variable still renders to parent/**/*.

Validation in Docker (golang:1.27-bookworm; repo go.mod requires go 1.26.4):

  • gofmt -l on LF-normalized copies of both changed files: no output, clean.
  • go vet ./internal/templater/...: no findings.
  • go test -count=1 -run TestReplaceGlobsKeepsUnresolvedDynamicVariables ./internal/templater/...: PASS.
  • Same test with only the production change reverted: FAIL with expected: "{{.PARENT}}/**/*", actual: "/**/*", confirming the regression is guarded.
  • git diff --check: clean.

Full task lint / full test suite are deferred to GitHub Actions CI.

AI disclosure

AI assistance was used to analyze the glob substitution path and to draft the fix and the regression test. I reviewed the diff and executed all validation commands listed above.

@vmaerten

Copy link
Copy Markdown
Member

AI slop

@vmaerten vmaerten closed this Nov 18, 2026
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.

Dynamic variables in sources cause glob expansion to hang due to unpopulated placeholders and symlink loops

2 participants