Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 2, 2025

The compiler enforced command trigger conflicts at runtime (compiler.go:1221), but the schema didn't validate them. This moves validation to parse time using JSON Schema conditionals and adds custom validation with clear, helpful error messages.

Changes

  • Schema (main_workflow_schema.json): Added allOf constraint using if/then/not pattern to reject command triggers combined with issues, issue_comment, pull_request, or pull_request_review_comment events

  • Custom validation (schema.go): Added validateCommandTriggerConflicts function that runs before schema validation to provide clear, helpful error messages explaining why the conflict exists

  • Parser tests (schema_test.go): Added 9 test cases covering invalid conflicts and valid combinations

  • Compiler tests (compiler_test.go): Updated error expectations to match new custom validation error messages

Error Messages

Previously, generic schema errors were shown:

error: at '': 'allOf' failed
- at '/on': 'not' failed

Now, clear and helpful messages explain the conflict:

command trigger cannot be used with 'issues' event in the same workflow. 
Command triggers are designed to respond to slash commands in comments 
and should not be combined with event-based triggers for issues or pull requests

For multiple conflicts:

command trigger cannot be used with these events in the same workflow: issues, pull_request. 
Command triggers are designed to respond to slash commands in comments 
and should not be combined with event-based triggers for issues or pull requests

Example

Previously accepted at parse time, caught at compile time:

on:
  command:
    name: test-bot
  issues:
    types: [opened]

Now rejected at parse time with a clear error message.

Valid combinations still work:

on:
  command:
    name: scheduler-bot
  workflow_dispatch:
  schedule:
    - cron: "0 9 * * 1"
Original prompt

This section details on the original issue you should resolve

<issue_title>[task] Add JSON Schema conditionals for command trigger conflicts</issue_title>
<issue_description>## Objective
Implement JSON Schema conditionals to enforce that command triggers cannot be used with certain event types (issues, issue_comment, pull_request, pull_request_review_comment).

Context

This addresses Issue #4 from discussion #2969. The compiler enforces this rule at runtime (pkg/workflow/compiler.go:1221), but the schema doesn't validate it. The MCP schemas already use JSON Schema conditionals correctly as a "gold standard" - this task applies that pattern to the main schema.

Approach

  1. Study the conditional pattern used in pkg/parser/schemas/mcp_config_schema.json
  2. Add if/then/else or not conditionals to main_workflow_schema.json
  3. Enforce that when on.command is present, the conflicting events cannot be used
  4. Add clear error messages in schema annotations

Files to Modify

  • pkg/parser/schemas/main_workflow_schema.json - Add conditionals for command conflicts

Example Pattern

{
  "if": {
    "properties": {
      "on": {"properties": {"command": {"type": "object"}}}
    }
  },
  "then": {
    "not": {
      "properties": {
        "on": {
          "anyOf": [
            {"required": ["issues"]},
            {"required": ["issue_comment"]},
            {"required": ["pull_request"]},
            {"required": ["pull_request_review_comment"]}
          ]
        }
      }
    }
  }
}

Reference Files

  • pkg/workflow/compiler.go:1221 - Runtime enforcement logic
  • pkg/parser/schemas/mcp_config_schema.json - Gold standard conditional examples

Acceptance Criteria

AI generated by Plan Command for discussion #2969</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Added allOf conditional to main_workflow_schema.json to enforce that command triggers cannot be used with issues, issue_comment, pull_request, or pull_request_review_comment events
- Added comprehensive test cases in schema_test.go to validate both invalid and valid command trigger configurations
- Updated compiler_test.go to expect schema validation errors instead of compiler errors
- Verified schema validation catches conflicts before compilation

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add JSON Schema conditionals for command trigger conflicts Add JSON Schema conditionals for command trigger conflicts Nov 2, 2025
Copilot AI requested a review from pelikhan November 2, 2025 05:52
@pelikhan
Copy link
Contributor

pelikhan commented Nov 2, 2025

@copilot improve the error message

- Added custom validation with clear, helpful error messages
- Moved command conflict validation before schema validation
- Error messages now explain why the conflict exists and what command triggers are for
- Removed unsupported errorMessage field from schema
- Updated test expectations to match new error messages

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

Copilot AI commented Nov 2, 2025

@copilot improve the error message

Improved error message in commit 1df047e.

Before:

error: at '': 'allOf' failed
- at '/on': 'not' failed

After:

command trigger cannot be used with 'issues' event in the same workflow. 
Command triggers are designed to respond to slash commands in comments 
and should not be combined with event-based triggers for issues or pull requests

The error message now:

  • Clearly identifies which event conflicts with the command trigger
  • Explains why the conflict exists (command triggers are for slash commands)
  • Uses natural language instead of generic schema validation errors

Copilot AI changed the title Add JSON Schema conditionals for command trigger conflicts Add JSON Schema conditionals for command trigger conflicts with improved error messages Nov 2, 2025
@pelikhan pelikhan marked this pull request as ready for review November 2, 2025 14:05
Copilot AI review requested due to automatic review settings November 2, 2025 14:05
@pelikhan pelikhan enabled auto-merge (squash) November 2, 2025 14:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves error messaging for command trigger validation by adding custom validation and updating error messages to be more descriptive. The changes ensure that when a command trigger is used with conflicting events (issues, issue_comment, pull_request, pull_request_review_comment), users receive clear, helpful error messages explaining why the combination is invalid.

Key changes:

  • Added custom validation function validateCommandTriggerConflicts that runs before JSON schema validation to provide clearer error messages
  • Updated test expectations to match the new, more descriptive error messages
  • Added comprehensive test coverage for command trigger conflict scenarios

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/parser/schema.go Added validateCommandTriggerConflicts function and integrated it into the validation pipeline to provide better error messages for command trigger conflicts
pkg/parser/schema_test.go Added test cases covering various command trigger conflict scenarios and valid command trigger usage patterns
pkg/parser/schemas/main_workflow_schema.json Added JSON schema validation rules using allOf/if-then to enforce command trigger conflict constraints at the schema level
pkg/workflow/compiler_test.go Updated expected error messages in existing tests to match the new, more descriptive error format

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pelikhan pelikhan merged commit 9472d28 into main Nov 2, 2025
50 checks passed
@pelikhan pelikhan deleted the copilot/add-json-schema-conditionals branch November 2, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[task] Add JSON Schema conditionals for command trigger conflicts

2 participants