Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 21, 2026

Add compile-time validation for safe-outputs target field

Problem

The compiler previously accepted invalid values for the target field in safe-outputs configuration (e.g., target: event), which failed at runtime instead of during compilation.

Solution

Added compile-time validation in the compiler to catch invalid target values early:

Valid target values:

  • "triggering" (default) - targets the triggering issue/PR/discussion
  • "*" - targets any item specified in the output
  • A positive integer like "123"
  • A GitHub Actions expression like "${{ github.event.issue.number }}"

Invalid values rejected:

  • Random strings (e.g., "event", "invalid")
  • Zero ("0")
  • Negative numbers ("-1")
  • Numbers with leading zeros ("007")
  • Malformed expressions

Implementation Details

  • Created safe_outputs_target_validation.go with validation logic
  • Added IsPositiveInteger utility function to pkg/stringutil package
  • Added comprehensive unit tests in safe_outputs_target_validation_test.go and stringutil_test.go
  • Added integration tests in safe_outputs_target_validation_integration_test.go
  • Integrated validation into compiler flow in compiler.go
  • Merged latest changes from main branch

Example Error Message

error: invalid target value for update-issue: "event"

Valid target values are:
  - "triggering" (default) - targets the triggering issue/PR/discussion
  - "*" - targets any item specified in the output
  - A positive integer (e.g., "123")
  - A GitHub Actions expression (e.g., "${{ github.event.issue.number }}")

Did you mean to use "${{ github.event.issue.number }}" instead of "event"?

This provides clear, actionable guidance to users when they make a mistake.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 21, 2026 22:21
…puts target field

Co-authored-by: eaftan <4733401+eaftan@users.noreply.github.com>
- Validates target values during compilation to catch errors early
- Valid values: "triggering", "*", positive integers, GitHub expressions
- Rejects invalid values like "event", "0", negative numbers, random strings
- Includes comprehensive unit and integration tests

Co-authored-by: eaftan <4733401+eaftan@users.noreply.github.com>
Co-authored-by: eaftan <4733401+eaftan@users.noreply.github.com>
- Make suggestion for "event" conditional (only shown for event-related invalid values)
- Improve GitHub expression validation to check for proper bracket order
- Add comprehensive tests for edge cases in expression validation

Co-authored-by: eaftan <4733401+eaftan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add compiler validation for input frontmatter format Validate safe-outputs target field at compile time Jan 21, 2026
Copilot AI requested a review from eaftan January 21, 2026 22:43

// isGitHubExpression checks if a string is a valid GitHub Actions expression
// A valid expression must have properly balanced ${{ and }} markers
func isGitHubExpression(s string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot use expression parser to validate correct expression, there should be a validator already

@pelikhan
Copy link
Contributor

@copilot look for existing isPositiveInteger helper otherwise move to stringutils package, move tests too

@pelikhan
Copy link
Contributor

https://gh.io/copilot-coding-agent-docs look for existing isPositiveInteger helper otherwise move to stringutils package, move tests too

@pelikhan
Copy link
Contributor

@copilot look for existing isPositiveInteger helper otherwise move to stringutils package, move tests too

- Moved IsPositiveInteger function from workflow validation to pkg/stringutil
- Moved associated tests to stringutil_test.go
- Updated safe_outputs_target_validation.go to use stringutil.IsPositiveInteger
- Removed strconv import from validation file (no longer needed)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 21, 2026

@copilot look for existing isPositiveInteger helper otherwise move to stringutils package, move tests too

Moved IsPositiveInteger to pkg/stringutil package along with its tests (commit 80b3318). No existing helper was found in the codebase.

@pelikhan pelikhan added the smoke label Jan 21, 2026
@pelikhan pelikhan marked this pull request as ready for review January 22, 2026 00:11
@pelikhan
Copy link
Contributor

@copilot format the code, then merge main, then format and lint.

Copilot AI and others added 2 commits January 22, 2026 00:21
- Resolved merge conflicts in pkg/stringutil files
- Kept both IsPositiveInteger and StripANSIEscapeCodes functions
- Recompiled all workflows successfully
- All tests passing after merge

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 22, 2026

@copilot look for existing isPositiveInteger helper otherwise move to stringutils package, move tests too

No existing helper found. Moved IsPositiveInteger and its tests to pkg/stringutil package (commit 80b3318). Completed code formatting, main branch merge, and final lint (commit 64f8453). All tests passing.

@pelikhan pelikhan merged commit 3560a28 into main Jan 22, 2026
83 checks passed
@pelikhan pelikhan deleted the copilot/validate-input-frontmatter-format branch January 22, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants