Skip to content

feat: evaluate only the parameter/preset/tag closure, with an opt-out - #226

Open
Emyrk wants to merge 3 commits into
mainfrom
steven/closure
Open

feat: evaluate only the parameter/preset/tag closure, with an opt-out#226
Emyrk wants to merge 3 commits into
mainfrom
steven/closure

Conversation

@Emyrk

@Emyrk Emyrk commented Sep 11, 2026

Copy link
Copy Markdown
Member

Evaluates only the coder_parameter / coder_workspace_preset / coder_workspace_tags closure when rendering, with an opt-out. Supersedes #221 (thanks @PushTheLimit); the trivy side is coder/trivy#74.

  • Bumps the trivy pin to a commit with OptionWithResourceClosure, and passes it by default so root resources nothing in the closure references are skipped. On the motivating template EvaluateAll drops from ~2s to ~0.16s.
  • Preview takes opts ...Option. OptionFullEvaluation() evaluates every resource, so coderd can turn the optimization off behind a setting without a new preview release if a template misbehaves.
  • Test_Extract runs every vector in both modes against the same expectations, pinning that parameters, presets, tags, and variables are identical either way. Test_OptionFullEvaluation observes the difference through Output.ModuleOutput.

Behavior notes:

  • Output.ModuleOutput may contain unknown values for root outputs that read pruned resources. Nothing in coderd consumes it.
  • Templates containing .tf.json files skip pruning entirely (trivy's JSON reference extraction is not reliable enough to prune on).

Test coverage for the reference shapes the pruner must see through landed separately in #223 and #224.

Prepared with Coder Agents assistance.

Preview now passes OptionWithResourceClosure to the parser by default so
root resources nothing in the parameter, preset, or tag closure references
are skipped. Preview takes variadic options; OptionFullEvaluation restores
evaluating every resource, so a caller can turn the optimization off
without a new preview release if a template misbehaves.

Test_Extract runs every vector in both modes against the same
expectations. Test_OptionFullEvaluation observes the difference through
Output.ModuleOutput, which is the one output the closure changes.
@Emyrk Emyrk changed the title Steven/closure feat: evaluate only the parameter/preset/tag closure, with an opt-out Sep 11, 2026
@Emyrk
Emyrk marked this pull request as ready for review September 11, 2026 20:42
@Emyrk
Emyrk requested a review from geokat September 11, 2026 20:43

@geokat geokat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm, other than the possible race (see comment).

Comment thread preview_test.go
Comment on lines +888 to +893
if tc.unknownTags == nil {
tc.unknownTags = []string{}
}
if tc.expTags == nil {
tc.expTags = map[string]string{}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We might have a race here now that we have parallel subtests sharing tc.

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