Skip to content

feat: template hyphen auto-fix, config imports, and pipeline template linting#202

Merged
intel352 merged 4 commits intomainfrom
feat/template-safety-config-imports
Feb 27, 2026
Merged

feat: template hyphen auto-fix, config imports, and pipeline template linting#202
intel352 merged 4 commits intomainfrom
feat/template-safety-config-imports

Conversation

@intel352
Copy link
Contributor

Summary

Three features to make workflow configs safer and more maintainable:

  • Template hyphen auto-fix: {{ .steps.my-step.field }} just works — the engine auto-rewrites to index syntax before Go's template parser sees it. Also adds step/trigger helper functions as clean alternatives.
  • Config imports: imports: field in WorkflowConfig for splitting large configs (like ratchet.yaml at 2500+ lines) into domain-specific files. Recursive with circular detection, main-file-wins precedence.
  • Pipeline template linting: wfctl template validate --config now lints template expressions — catches undefined step references, forward references, and suggests preferred syntax.

Changes

Template Engine (module/pipeline_template.go)

  • preprocessTemplate() — regex-based rewriter that converts hyphenated dot-access chains to (index ...) before template.Parse()
  • funcMapWithContext() — adds step and trigger context-aware helper functions
  • 16 new tests

Config Imports (config/config.go)

  • Imports []string field on WorkflowConfig
  • loadFromFileWithImports() — recursive loader with seen map for circular detection
  • processImports() — merges imported modules (append) and maps (no-overwrite)
  • 8 new tests

Pipeline Template Linting (cmd/wfctl/template_validate.go)

  • validatePipelineTemplates() — scans step configs for {{ }} expressions
  • Validates step references across three syntaxes: dot-access, index, and step function
  • validateStepRef() — checks existence and ordering
  • collectTemplateStrings() — recursive string collector
  • 5 new tests

Documentation (DOCUMENTATION.md)

  • Template data context table (.steps, .trigger, .meta)
  • Hyphenated step name handling guide (auto-fix, step function, index)
  • Config imports syntax, merge rules, and comparison with ApplicationConfig

Test plan

  • go test ./module/... — 36 template tests pass (16 new)
  • go test ./config/... — 60+ config tests pass (8 new)
  • go test ./cmd/wfctl/... — 18 validation tests pass (5 new)
  • go build ./... — clean

🤖 Generated with Claude Code

… linting

Three features to make workflow configs safer and more maintainable:

Template engine:
- preprocessTemplate() auto-rewrites hyphenated dot-access to index syntax
  before Go's parser sees it (e.g., .steps.my-step.field just works)
- step/trigger helper functions for clean syntax without quoting issues
  (e.g., {{ step "parse-request" "path_params" "id" }})
- 16 new tests covering preprocessor, helpers, and end-to-end

Config imports:
- imports: field in WorkflowConfig for splitting large configs into
  domain-specific files with recursive loading and circular detection
- Main file definitions take precedence; modules concatenated in order
- 8 new tests covering basic imports, precedence, nesting, and errors

Pipeline template validation (wfctl template validate --config):
- Lints template expressions for undefined step references
- Warns on forward references (step referenced before it executes)
- Suggests step function syntax for hyphenated dot-access patterns
- 5 new tests for the linter

Documentation updated with template data context, hyphen handling guide,
import syntax and merge rules, and ApplicationConfig comparison.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 27, 2026 13:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces three complementary features to make workflow configurations more robust and maintainable: automatic template hyphen handling, config file imports for splitting large configurations, and template expression linting.

Changes:

  • Template engine automatically rewrites hyphenated dot-access patterns (.steps.my-step.field) to Go-compatible index syntax, plus new step/trigger helper functions
  • Config import system allowing recursive file composition with circular detection and main-file-wins precedence
  • Pipeline template validator that lints step references, detects undefined/forward references, and suggests best practices

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
module/pipeline_template.go Adds preprocessTemplate() regex rewriter and funcMapWithContext() for step/trigger helpers
module/pipeline_template_test.go 16 new tests covering preprocessing, helper functions, and end-to-end hyphenated step resolution
config/config.go Implements imports field, loadFromFileWithImports() with circular detection, and processImports() merge logic
config/config_import_test.go 8 comprehensive tests for import scenarios: basic, precedence, circular, nested, missing, relative paths
cmd/wfctl/template_validate.go Adds validatePipelineTemplates(), collectTemplateStrings(), and validateStepRef() for expression linting
cmd/wfctl/template_validate_test.go 5 new tests for step reference validation (missing, forward, hyphenated, step function)
DOCUMENTATION.md Documents template data context, hyphen handling approaches, config imports syntax and merge rules

intel352 and others added 2 commits February 27, 2026 09:10
- Fix diamond import bug: use stack-based (defer delete) circular detection
  so shared dependencies imported via multiple paths don't false-positive
- Fix hyphenDotRe regex to match full chains (e.g. .steps.my-step.field)
- Tighten stepRefFuncRe regex to avoid false positives on non-function contexts
- Use unique placeholder sentinel instead of bare \x00 for string literal stripping
- Differentiate self-reference from forward-reference in validation warnings
- Add diamond import test case
- Add self-reference validation test case
- Document depth-first import merge order and ambiguous hyphen/subtraction behavior
- Add clarifying comments on collectTemplateStrings and stringLiteralRe

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 27, 2026 14:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.

- Fix validation step numbering to match execution order (1-5)
- Add RE2 note to stringLiteralRe (Go regex has no backtracking/ReDoS)
- Optimize placeholder restoration: use strings.Index instead of O(n*m) scan
- Deduplicate modules in diamond imports (first definition wins)
- Clarify comment detection: only pure block comments are skipped
- Document step/trigger function nil-return semantics
- Fix DOCUMENTATION.md escaped pipes in trimPrefix/trimSuffix examples
- Add tests: unclosed template action, escaped quotes in string literals
- Diamond import test now verifies no duplicate modules

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@intel352 intel352 merged commit cd10c72 into main Feb 27, 2026
14 checks passed
@intel352 intel352 deleted the feat/template-safety-config-imports branch February 27, 2026 14:42
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