Skip to content

Commit d21a90a

Browse files
authored
Emit unquoted top-level on: in compiled .lock.yml workflows (#32357)
1 parent 47516f6 commit d21a90a

14 files changed

Lines changed: 102 additions & 16 deletions

pkg/workflow/compiler_events_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tools:
3232
github:
3333
allowed: [list_issues]
3434
---`,
35-
expectedOn: `"on": push`,
35+
expectedOn: `on: push`,
3636
},
3737
{
3838
name: "custom on workflow_dispatch",
@@ -43,7 +43,7 @@ tools:
4343
github:
4444
allowed: [list_issues]
4545
---`,
46-
expectedOn: `"on":
46+
expectedOn: `on:
4747
workflow_dispatch:`,
4848
},
4949
{
@@ -58,7 +58,7 @@ tools:
5858
github:
5959
allowed: [list_issues]
6060
---`,
61-
expectedOn: `"on":
61+
expectedOn: `on:
6262
pull_request:
6363
branches:
6464
- main
@@ -79,7 +79,7 @@ tools:
7979
github:
8080
allowed: [list_issues]
8181
---`,
82-
expectedOn: `"on":
82+
expectedOn: `on:
8383
issues:
8484
types:
8585
- opened
@@ -276,7 +276,7 @@ tools:
276276
allowed: [list_issues]
277277
---`,
278278
filename: "command-with-dispatch.md",
279-
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:",
279+
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:",
280280
expectedIf: "github.event_name == 'issues'",
281281
expectedCommand: "test-bot",
282282
shouldError: false,
@@ -294,7 +294,7 @@ tools:
294294
allowed: [list_issues]
295295
---`,
296296
filename: "command-with-schedule.md",
297-
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\"",
297+
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\"",
298298
expectedIf: "github.event_name == 'issues'",
299299
expectedCommand: "schedule-bot",
300300
shouldError: false,
@@ -313,7 +313,7 @@ tools:
313313
allowed: [list_issues]
314314
---`,
315315
filename: "command-with-multiple.md",
316-
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:",
316+
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:",
317317
expectedIf: "github.event_name == 'issues'",
318318
expectedCommand: "multi-bot",
319319
shouldError: false,

pkg/workflow/compiler_validation_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package workflow
55
import (
66
"os"
77
"path/filepath"
8+
"regexp"
89
"strings"
910
"testing"
1011

@@ -292,6 +293,16 @@ This is a test workflow.
292293
if !strings.HasPrefix(firstContentLine, "name:") {
293294
t.Errorf("First non-comment line should start with 'name:', but got: %s", firstContentLine)
294295
}
296+
297+
quotedTopLevelOn := regexp.MustCompile(`(?m)^"on":(?:\s|$)`)
298+
unquotedTopLevelOn := regexp.MustCompile(`(?m)^on:(?:\s|$)`)
299+
300+
if quotedTopLevelOn.MatchString(lockContent) {
301+
t.Errorf("Expected top-level on key to be unquoted, but found quoted form in generated YAML:\n%s", lockContent)
302+
}
303+
if !unquotedTopLevelOn.MatchString(lockContent) {
304+
t.Errorf("Expected generated YAML to contain unquoted top-level on key, but it did not:\n%s", lockContent)
305+
}
295306
}
296307

297308
func TestValidateWorkflowSchema(t *testing.T) {

pkg/workflow/compiler_yaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ func (c *Compiler) generateWorkflowBody(yaml *strings.Builder, data *WorkflowDat
268268
// can receive caller metadata (repo, run_id, actor, etc.) from dispatch_workflow.
269269
// String-based injection preserves existing YAML comments and formatting.
270270
onSection = injectAwContextIntoOnYAML(onSection)
271+
onSection = UnquoteYAMLTopLevelKey(onSection, "on")
271272
yaml.WriteString(onSection)
272273
yaml.WriteString("\n\n")
273274

pkg/workflow/slash_command_centralized_compile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ tools:
7676
require.NoError(t, err)
7777
compiled := string(lockContent)
7878

79-
require.Contains(t, compiled, "\"on\":\n workflow_dispatch:")
79+
require.Contains(t, compiled, "on:\n workflow_dispatch:")
8080
require.Contains(t, compiled, "workflow_dispatch:")
8181
require.NotContains(t, compiled, "\n issues:\n types:")
8282
require.Contains(t, compiled, "github.event_name == 'workflow_dispatch'")

pkg/workflow/testdata/TestWasmGolden_CompileFixtures/basic-copilot.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "basic-copilot-test"
2-
"on":
2+
on:
33
workflow_dispatch:
44
inputs:
55
aw_context:

pkg/workflow/testdata/TestWasmGolden_CompileFixtures/claude-with-network.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "claude-with-network-test"
2-
"on":
2+
on:
33
workflow_dispatch:
44

55
permissions: {}

pkg/workflow/testdata/TestWasmGolden_CompileFixtures/playwright-cli-mode.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "Test Playwright CLI Mode"
2-
"on":
2+
on:
33
workflow_dispatch:
44
inputs:
55
aw_context:

pkg/workflow/testdata/TestWasmGolden_CompileFixtures/smoke-copilot.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "Smoke Copilot"
2-
"on":
2+
on:
33
pull_request:
44
# names: # Label filtering applied via job conditions
55
# - smoke # Label filtering applied via job conditions

pkg/workflow/testdata/TestWasmGolden_CompileFixtures/smoke-test-tools.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "Agent Container Smoke Test"
2-
"on":
2+
on:
33
pull_request:
44
# names: # Label filtering applied via job conditions
55
# - smoke # Label filtering applied via job conditions

pkg/workflow/testdata/TestWasmGolden_CompileFixtures/with-imports.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "with-imports-test"
2-
"on":
2+
on:
33
workflow_dispatch:
44
inputs:
55
aw_context:

0 commit comments

Comments
 (0)