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
262 changes: 174 additions & 88 deletions .github/workflows/ci-coach.lock.yml

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions pkg/workflow/compiler_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tools:
github:
allowed: [list_issues]
---`,
expectedOn: `"on": push`,
expectedOn: `on: push`,
},
{
name: "custom on workflow_dispatch",
Expand All @@ -43,7 +43,7 @@ tools:
github:
allowed: [list_issues]
---`,
expectedOn: `"on":
expectedOn: `on:
workflow_dispatch:`,
},
{
Expand All @@ -58,7 +58,7 @@ tools:
github:
allowed: [list_issues]
---`,
expectedOn: `"on":
expectedOn: `on:
pull_request:
branches:
- main
Expand All @@ -79,7 +79,7 @@ tools:
github:
allowed: [list_issues]
---`,
expectedOn: `"on":
expectedOn: `on:
issues:
types:
- opened
Expand Down Expand Up @@ -276,7 +276,7 @@ tools:
allowed: [list_issues]
---`,
filename: "command-with-dispatch.md",
expectedOn: "\"on\":\n discussion:\n types:\n - created\n - edited\n discussion_comment:\n types:\n - created\n - edited\n issue_comment:\n types:\n - created\n - edited\n issues:\n types:\n - opened\n - edited\n - reopened\n pull_request:\n types:\n - opened\n - edited\n - reopened\n pull_request_review_comment:\n types:\n - created\n - edited\n workflow_dispatch:",
expectedOn: "on:\n discussion:\n types:\n - created\n - edited\n discussion_comment:\n types:\n - created\n - edited\n issue_comment:\n types:\n - created\n - edited\n issues:\n types:\n - opened\n - edited\n - reopened\n pull_request:\n types:\n - opened\n - edited\n - reopened\n pull_request_review_comment:\n types:\n - created\n - edited\n workflow_dispatch:",
expectedIf: "github.event_name == 'issues'",
expectedCommand: "test-bot",
shouldError: false,
Expand All @@ -294,7 +294,7 @@ tools:
allowed: [list_issues]
---`,
filename: "command-with-schedule.md",
expectedOn: "\"on\":\n discussion:\n types:\n - created\n - edited\n discussion_comment:\n types:\n - created\n - edited\n issue_comment:\n types:\n - created\n - edited\n issues:\n types:\n - opened\n - edited\n - reopened\n pull_request:\n types:\n - opened\n - edited\n - reopened\n pull_request_review_comment:\n types:\n - created\n - edited\n schedule:\n - cron: \"0 9 * * 1\"",
expectedOn: "on:\n discussion:\n types:\n - created\n - edited\n discussion_comment:\n types:\n - created\n - edited\n issue_comment:\n types:\n - created\n - edited\n issues:\n types:\n - opened\n - edited\n - reopened\n pull_request:\n types:\n - opened\n - edited\n - reopened\n pull_request_review_comment:\n types:\n - created\n - edited\n schedule:\n - cron: \"0 9 * * 1\"",
expectedIf: "github.event_name == 'issues'",
expectedCommand: "schedule-bot",
shouldError: false,
Expand All @@ -313,7 +313,7 @@ tools:
allowed: [list_issues]
---`,
filename: "command-with-multiple.md",
expectedOn: "\"on\":\n discussion:\n types:\n - created\n - edited\n discussion_comment:\n types:\n - created\n - edited\n issue_comment:\n types:\n - created\n - edited\n issues:\n types:\n - opened\n - edited\n - reopened\n pull_request:\n types:\n - opened\n - edited\n - reopened\n pull_request_review_comment:\n types:\n - created\n - edited\n push:\n branches:\n - main\n workflow_dispatch:",
expectedOn: "on:\n discussion:\n types:\n - created\n - edited\n discussion_comment:\n types:\n - created\n - edited\n issue_comment:\n types:\n - created\n - edited\n issues:\n types:\n - opened\n - edited\n - reopened\n pull_request:\n types:\n - opened\n - edited\n - reopened\n pull_request_review_comment:\n types:\n - created\n - edited\n push:\n branches:\n - main\n workflow_dispatch:",
expectedIf: "github.event_name == 'issues'",
expectedCommand: "multi-bot",
shouldError: false,
Expand Down
11 changes: 11 additions & 0 deletions pkg/workflow/compiler_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package workflow
import (
"os"
"path/filepath"
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -292,6 +293,16 @@ This is a test workflow.
if !strings.HasPrefix(firstContentLine, "name:") {
t.Errorf("First non-comment line should start with 'name:', but got: %s", firstContentLine)
}

quotedTopLevelOn := regexp.MustCompile(`(?m)^"on":(?:\s|$)`)
unquotedTopLevelOn := regexp.MustCompile(`(?m)^on:(?:\s|$)`)

if quotedTopLevelOn.MatchString(lockContent) {
t.Errorf("Expected top-level on key to be unquoted, but found quoted form in generated YAML:\n%s", lockContent)
}
if !unquotedTopLevelOn.MatchString(lockContent) {
t.Errorf("Expected generated YAML to contain unquoted top-level on key, but it did not:\n%s", lockContent)
}
}

func TestValidateWorkflowSchema(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/workflow/compiler_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func (c *Compiler) generateWorkflowBody(yaml *strings.Builder, data *WorkflowDat
// can receive caller metadata (repo, run_id, actor, etc.) from dispatch_workflow.
// String-based injection preserves existing YAML comments and formatting.
onSection = injectAwContextIntoOnYAML(onSection)
onSection = UnquoteYAMLTopLevelKey(onSection, "on")
yaml.WriteString(onSection)
yaml.WriteString("\n\n")

Expand Down
2 changes: 1 addition & 1 deletion pkg/workflow/slash_command_centralized_compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ tools:
require.NoError(t, err)
compiled := string(lockContent)

require.Contains(t, compiled, "\"on\":\n workflow_dispatch:")
require.Contains(t, compiled, "on:\n workflow_dispatch:")
require.Contains(t, compiled, "workflow_dispatch:")
require.NotContains(t, compiled, "\n issues:\n types:")
require.Contains(t, compiled, "github.event_name == 'workflow_dispatch'")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "basic-copilot-test"
"on":
on:
workflow_dispatch:
inputs:
aw_context:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "claude-with-network-test"
"on":
on:
workflow_dispatch:

permissions: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Test Playwright CLI Mode"
"on":
on:
workflow_dispatch:
inputs:
aw_context:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Smoke Copilot"
"on":
on:
pull_request:
# names: # Label filtering applied via job conditions
# - smoke # Label filtering applied via job conditions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Agent Container Smoke Test"
"on":
on:
pull_request:
# names: # Label filtering applied via job conditions
# - smoke # Label filtering applied via job conditions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "with-imports-test"
"on":
on:
workflow_dispatch:
inputs:
aw_context:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "basic-copilot-test"
"on":
on:
workflow_dispatch:
inputs:
aw_context:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "with-imports-test"
"on":
on:
workflow_dispatch:
inputs:
aw_context:
Expand Down
28 changes: 28 additions & 0 deletions pkg/workflow/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,34 @@ func UnquoteYAMLKey(yamlStr string, key string) string {
return re.ReplaceAllString(yamlStr, "${1}${2}"+key+":")
}

// UnquoteYAMLTopLevelKey removes quotes from a YAML key only when it appears
// at the very start of the YAML content.
//
// This intentionally leaves nested quoted keys unchanged.
// Example:
//
// "on":
// push:
//
// becomes:
//
// on:
// push:
//
// but:
//
// parent:
// "on":
//
// remains unchanged.
func UnquoteYAMLTopLevelKey(yamlStr string, key string) string {
quotedPrefix := `"` + key + `":`
if strings.HasPrefix(yamlStr, quotedPrefix) {
return key + ":" + yamlStr[len(quotedPrefix):]
}
return yamlStr
}

// MarshalWithFieldOrder marshals a map to YAML with fields in a specific order.
//
// This function ensures deterministic field ordering in the generated YAML by using
Expand Down
46 changes: 46 additions & 0 deletions pkg/workflow/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,52 @@ on:
}
}

func TestUnquoteYAMLTopLevelKey(t *testing.T) {
tests := []struct {
name string
input string
key string
expected string
}{
{
name: "unquotes top-level on key",
input: `"on":
workflow_dispatch:`,
key: "on",
expected: `on:
workflow_dispatch:`,
},
{
name: "does not unquote nested key",
input: `parent:
"on":
value: true`,
key: "on",
expected: `parent:
"on":
value: true`,
},
{
name: "no change when top-level key already unquoted",
input: `on:
push:`,
key: "on",
expected: `on:
push:`,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := UnquoteYAMLTopLevelKey(tt.input, tt.key)
if result != tt.expected {
t.Errorf("UnquoteYAMLTopLevelKey() failed\nInput:\n%s\n\nExpected:\n%s\n\nGot:\n%s",
tt.input, tt.expected, result)
}
})
}
}

func TestMarshalWithFieldOrder(t *testing.T) {
tests := []struct {
name string
Expand Down