Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
pelikhan
March 15, 2026 19:37
View session
5 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors workflow compilation helpers by consolidating duplicate/misplaced functions into shared helper files to reduce duplication and improve organization.
Changes:
- Moved
formatYAMLValuefromruntime_step_generator.gointoyaml.go. - Consolidated
containsWorkflowDispatch/containsWorkflowCalllogic via newcontainsTriggerhelper invalidation_helpers.go. - Centralized
safeUint64ToIntintomap_helpers.goand updated callers (removing local duplicates).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/yaml.go | Adds shared formatYAMLValue YAML scalar formatting helper. |
| pkg/workflow/validation_helpers.go | Introduces containsTrigger helper for on: trigger checks. |
| pkg/workflow/runtime_step_generator.go | Removes local formatYAMLValue after moving to yaml.go. |
| pkg/workflow/mcp_scripts_parser.go | Switches timeout uint64 conversion to shared safeUint64ToInt. |
| pkg/workflow/map_helpers.go | Adds shared safeUint64ToInt numeric conversion helper. |
| pkg/workflow/frontmatter_extraction_metadata.go | Removes local safeUint64ToInt duplicate. |
| pkg/workflow/dispatch_workflow_validation.go | Delegates dispatch trigger detection to containsTrigger. |
| pkg/workflow/call_workflow_validation.go | Delegates call trigger detection to containsTrigger. |
Comments suppressed due to low confidence (1)
pkg/workflow/yaml.go:360
- formatYAMLValue is now a shared YAML-serialization helper but there are no unit tests covering its quoting/escaping behavior (especially values containing single quotes,
${{ ... }}expressions, and numeric-looking strings). Adding focused tests in yaml_test.go would help prevent regressions and ensure the generated YAML remains valid.
// formatYAMLValue formats a value for YAML output, quoting strings and rendering
// booleans/numbers as unquoted scalars.
func formatYAMLValue(value any) string {
switch v := value.(type) {
case string:
// Quote strings if they contain special characters or look like non-string types
if v == "true" || v == "false" || v == "null" {
return fmt.Sprintf("'%s'", v)
}
// Check if it's a number
if _, err := fmt.Sscanf(v, "%f", new(float64)); err == nil {
return fmt.Sprintf("'%s'", v)
}
// Return as-is for simple strings, quote for complex ones
return fmt.Sprintf("'%s'", v)
case bool:
if v {
return "true"
}
return "false"
case int:
return strconv.Itoa(v)
case int8:
return strconv.Itoa(int(v))
case int16:
return strconv.Itoa(int(v))
case int32:
return strconv.Itoa(int(v))
case int64:
return strconv.FormatInt(v, 10)
case uint:
return strconv.FormatUint(uint64(v), 10)
case uint8:
return strconv.FormatUint(uint64(v), 10)
case uint16:
return strconv.FormatUint(uint64(v), 10)
case uint32:
return strconv.FormatUint(uint64(v), 10)
case uint64:
return strconv.FormatUint(v, 10)
case float32:
return fmt.Sprintf("%v", v)
case float64:
return fmt.Sprintf("%v", v)
default:
// For other types, convert to string and quote
return fmt.Sprintf("'%v'", v)
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+312
to
+326
| // formatYAMLValue formats a value for YAML output, quoting strings and rendering | ||
| // booleans/numbers as unquoted scalars. | ||
| func formatYAMLValue(value any) string { | ||
| switch v := value.(type) { | ||
| case string: | ||
| // Quote strings if they contain special characters or look like non-string types | ||
| if v == "true" || v == "false" || v == "null" { | ||
| return fmt.Sprintf("'%s'", v) | ||
| } | ||
| // Check if it's a number | ||
| if _, err := fmt.Sscanf(v, "%f", new(float64)); err == nil { | ||
| return fmt.Sprintf("'%s'", v) | ||
| } | ||
| // Return as-is for simple strings, quote for complex ones | ||
| return fmt.Sprintf("'%s'", v) |
…alue Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
Author
Added in 160d0f9:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three functions were either exact duplicates across files or semantically misplaced relative to their containing file.
Changes
safeUint64ToInt(exact duplicate):safeUint64ToIntForTimeoutinmcp_scripts_parser.gowas identical tosafeUint64ToIntinfrontmatter_extraction_metadata.go. Moved the canonical version tomap_helpers.go(the existing home for numeric type conversion utilities), removed both local copies, updated callers.containsWorkflowDispatch/containsWorkflowCall(near-duplicate): Identical 15-line type-switch differing only by trigger string constant. ExtractedcontainsTrigger(onSection any, triggerName string) boolintovalidation_helpers.go; both functions now delegate:formatYAMLValue(outlier): A 46-line YAML value serializer lived inruntime_step_generator.go. Moved toyaml.goalongsideMarshalWithFieldOrder,OrderMapFields, andCleanYAMLNullValues.Tests
Added table-driven tests for all three refactored functions:
TestSafeUint64ToInt(map_helpers_test.go) — covers zero, normal values, max int boundary, and overflow cases (max uint64 and max int+1 both return 0).TestContainsTrigger(validation_helpers_test.go) — covers all threeon:section forms (string /[]any/map[string]any), nil input, unsupported types, and bothworkflow_dispatch/workflow_calltrigger names.TestFormatYAMLValue(yaml_test.go) — covers every type branch: YAML keyword strings, numeric strings, booleans, all signed/unsigned integer widths, floats, and the default fallback.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.