Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-code-quality-reviewer.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions pkg/workflow/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

var templateLog = logger.New("workflow:template")
var inlineSubAgentPattern = regexp.MustCompile("(?m)^##[ \t]+agent:[ \t]+`[a-z][a-z0-9_-]*`[ \t]*$")

// wrapExpressionsInTemplateConditionals transforms template conditionals by wrapping
// expressions in ${{ }}. For example:
Expand Down Expand Up @@ -99,16 +100,17 @@ func (c *Compiler) generateInterpolationAndTemplateStep(yaml *strings.Builder, e
// Check if we need template rendering
hasTemplatePattern := strings.Contains(data.MarkdownContent, "{{#if ")
hasGitHubContext := hasGitHubTool(data.ParsedTools)
hasTemplates := hasTemplatePattern || hasGitHubContext
hasInlineSubAgents := inlineSubAgentPattern.MatchString(data.MarkdownContent)
hasTemplates := hasTemplatePattern || hasGitHubContext || hasInlineSubAgents

// Skip if neither interpolation nor template rendering is needed
if !hasExpressions && !hasTemplates {
templateLog.Print("No interpolation or template rendering needed, skipping step generation")
return
}

templateLog.Printf("Generating interpolation and template step: expressions=%d, hasPattern=%v, hasGitHubContext=%v",
len(expressionMappings), hasTemplatePattern, hasGitHubContext)
templateLog.Printf("Generating interpolation and template step: expressions=%d, hasPattern=%v, hasGitHubContext=%v, hasInlineSubAgents=%v",
len(expressionMappings), hasTemplatePattern, hasGitHubContext, hasInlineSubAgents)

yaml.WriteString(" - name: Interpolate variables and render templates\n")
fmt.Fprintf(yaml, " uses: %s\n", getCachedActionPin("actions/github-script", data))
Expand Down
19 changes: 19 additions & 0 deletions pkg/workflow/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,22 @@ func TestGenerateInterpolationAndTemplateStep_GeneratePath(t *testing.T) {
assert.Contains(t, result, "interpolate_prompt.cjs", "interpolate_prompt script should be referenced in the step")
assert.Contains(t, result, "setupGlobals", "setupGlobals helper should be called to initialise GitHub Actions objects")
}

// TestGenerateInterpolationAndTemplateStep_WithInlineSubAgent ensures inline sub-agent
// workflows still run interpolate_prompt.cjs even when github context templates are absent.
// ParsedTools uses an empty map (no github key) so hasGitHubTool returns false,
// confirming that the inline sub-agent marker alone is sufficient to trigger the step.
func TestGenerateInterpolationAndTemplateStep_WithInlineSubAgent(t *testing.T) {
compiler := &Compiler{}
data := &WorkflowData{
MarkdownContent: "Main prompt\n\n## agent: `planner`\nDo planning.",
ParsedTools: NewTools(map[string]any{}),
}
Comment thread
Copilot marked this conversation as resolved.

var yaml strings.Builder
compiler.generateInterpolationAndTemplateStep(&yaml, nil, data)

result := yaml.String()
assert.Contains(t, result, "Interpolate variables and render templates", "step should be present when inline sub-agents are defined")
assert.Contains(t, result, "interpolate_prompt.cjs", "interpolate_prompt script should run to extract inline sub-agents")
}
Loading