Skip to content

Add comprehensive test coverage for compiler_safe_outputs.go#11587

Merged
pelikhan merged 3 commits intomainfrom
copilot/create-test-file-for-compiler-safe-outputs
Jan 24, 2026
Merged

Add comprehensive test coverage for compiler_safe_outputs.go#11587
pelikhan merged 3 commits intomainfrom
copilot/create-test-file-for-compiler-safe-outputs

Conversation

Copy link
Contributor

Copilot AI commented Jan 24, 2026

The compiler_safe_outputs.go file (491 lines) had zero test coverage despite handling safety-critical functionality: command triggers, reaction parsing, agent locking, and security configurations.

Changes

Created compiler_safe_outputs_test.go with comprehensive coverage:

  • 1,515 lines of tests (3.1x test-to-source ratio)
  • 83+ test scenarios across 20+ test functions
  • All 7 functions covered with table-driven tests

Test Coverage

Core Functions

  • parseOnSection: Command/reaction triggers, stop-after, lock-for-agent, conflict detection (18 cases)
  • generateJobName: Sanitization, special chars, Unicode, edge cases (14 cases)
  • mergeSafeJobsFromIncludes: JSON parsing, conflicts, malformed structures (6 cases)
  • mergeSafeJobsFromIncludedConfigs: Multi-config merging, invalid inputs (5 cases)
  • applyDefaultTools: GitHub/bash/edit tools, sandbox, firewall, git commands (15 cases)
  • needsGitCommands: PR workflow detection (6 cases)
  • isSandboxEnabled: All sandbox types, precedence rules, auto-enable (12 cases)

Example Test Pattern

func TestParseOnSection(t *testing.T) {
    tests := []struct {
        name              string
        frontmatter       map[string]any
        expectedCommand   []string
        expectedReaction  string
        expectedError     bool
    }{
        {
            name: "slash_command with numeric +1 reaction",
            frontmatter: map[string]any{
                "on": map[string]any{
                    "slash_command": map[string]any{},
                    "reaction":      1,  // YAML parser converts +1 to int
                },
            },
            expectedCommand:  []string{"test"},
            expectedReaction: "+1",
        },
        // ... 17 more test cases
    }
    // ...
}

All tests follow existing patterns with table-driven design, clear assertions, and comprehensive edge case coverage including malformed inputs, type mismatches, and nil handling.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Code Quality] Create test file for compiler_safe_outputs.go</issue_title>
<issue_description>## Description

The file pkg/workflow/compiler_safe_outputs.go (491 lines) currently has NO test file, representing a critical gap in test coverage for safety-critical code that handles command triggers and security configurations.

Background

This issue was identified during the Daily Compiler Code Quality Report analysis on 2026-01-22. The file handles:

  • Parsing trigger events (slash commands, reactions)
  • Agent locking configuration
  • Stop-after behavior
  • Security-sensitive functionality

Current state:

  • File size: 491 lines
  • Test file: None (0% coverage)
  • Quality score: 68/100 (below "Good" threshold)

Suggested Changes

Create pkg/workflow/compiler_safe_outputs_test.go with comprehensive table-driven tests:

Minimum Required Tests

  1. TestParseOnSection - Test command, reaction, stop-after parsing

    • Valid slash command configurations
    • Reaction-based triggers ("+1", "-1", "heart", "rocket", "eyes", "none")
    • Stop-after behavior
    • Malformed input handling
  2. TestParseReactionValue - Test string and map formats

    • String format: reaction: "+1"
    • Map format: reaction: { type: "heart" }
    • Invalid reaction values
    • Edge cases
  3. TestIsValidReaction - Test all valid/invalid reactions

    • Valid: "+1", "-1", "heart", "rocket", "eyes", "none"
    • Invalid: "thumbsup", "invalid", empty string
    • Case sensitivity
  4. TestLockForAgentParsing - Test agent locking configuration

    • Lock-for-agent from different trigger sources
    • Boolean and map formats
    • Conflict detection
  5. Edge Cases

    • Conflicting events (command + other triggers)
    • Malformed YAML structures
    • Type assertion failures
    • Nil/empty values

Files Affected

  • pkg/workflow/compiler_safe_outputs.go (existing, no changes)
  • pkg/workflow/compiler_safe_outputs_test.go (new file to create)

Success Criteria

  • Test file created with ≥370 lines (0.75x test-to-source ratio)
  • All 7 functions have table-driven tests
  • Edge cases covered (malformed inputs, type mismatches)
  • All tests pass: make test-unit
  • Quality score improves from 68/100 to ≥75/100

Priority

CRITICAL - Safety-critical code requires test coverage

Estimated effort: 1-2 days

Source

Extracted from Daily Compiler Code Quality Report discussion githubnext/gh-aw#11176

Analysis quote:

"NO TEST FILE - CRITICAL PRIORITY 🚨

  • Impact: Zero test coverage for safety-critical code
  • Risk Level: HIGH - this file handles command triggers and security configurations
  • File Purpose: Parses trigger events, reactions, agent locking - all security-sensitive"

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 5, 2026, 12:26 PM UTC

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


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

Copilot AI and others added 2 commits January 24, 2026 03:38
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add test file for compiler_safe_outputs.go Add comprehensive test coverage for compiler_safe_outputs.go Jan 24, 2026
Copilot AI requested a review from pelikhan January 24, 2026 03:53
@pelikhan pelikhan marked this pull request as ready for review January 24, 2026 05:20
@pelikhan pelikhan merged commit b4169e2 into main Jan 24, 2026
118 checks passed
@pelikhan pelikhan deleted the copilot/create-test-file-for-compiler-safe-outputs branch January 24, 2026 05:30
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.

[Code Quality] Create test file for compiler_safe_outputs.go

2 participants