Skip to content

Expand test coverage for campaign injection logic#12310

Merged
pelikhan merged 3 commits intomainfrom
copilot/improve-test-quality-injection
Jan 28, 2026
Merged

Expand test coverage for campaign injection logic#12310
pelikhan merged 3 commits intomainfrom
copilot/improve-test-quality-injection

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

The campaign injection logic in pkg/campaign/injection.go had minimal test coverage (60 lines) despite handling complex edge cases around campaign detection, ID inference, governance policies, bootstrap configuration, and safe-output wiring.

Changes

  • Edge case coverage: nil handling, campaign ID inference paths (WorkflowID → Name → default fallback), explicit vs inferred IDs

  • Configuration scenarios: Governance max overrides, bootstrap seeder workers, worker metadata with payload schemas

  • Safe-output wiring: dispatch-workflow configuration, concurrency control injection vs preservation

  • Default application logic: TrackerLabel, MemoryPaths, MetricsGlob, CursorGlob with explicit override tests

  • ID normalization expansion: 10 edge cases covering empty strings, whitespace, special characters, unicode, leading/trailing hyphens

Example

New table-driven test structure covering actual implementation behavior:

func TestInjectOrchestratorFeatures_EdgeCases(t *testing.T) {
    tests := []struct {
        name               string
        workflowData       *workflow.WorkflowData
        expectInjection    bool
        expectedCampaignID string
    }{
        {
            name: "infer campaign ID from WorkflowID",
            workflowData: &workflow.WorkflowData{
                WorkflowID: "security-alert-burndown",
                ParsedFrontmatter: &workflow.FrontmatterConfig{
                    Project: &workflow.ProjectConfig{
                        URL: "https://github.com/orgs/githubnext/projects/144",
                    },
                },
            },
            expectInjection:    true,
            expectedCampaignID: "security-alert-burndown",
        },
        // ... 5 more edge cases
    }
}

Result: 60 → 460 lines, 8 new test functions, proper require.* vs assert.* usage throughout.

Original prompt

This section details on the original issue you should resolve

<issue_title>[testify-expert] Improve Test Quality: pkg/campaign/injection_test.go</issue_title>
<issue_description>The test file pkg/campaign/injection_test.go has been selected for quality improvement by the Testify Uber Super Expert. This issue provides specific, actionable recommendations to enhance test quality, coverage, and maintainability using testify best practices.

Current State

  • Test File: pkg/campaign/injection_test.go
  • Source File: pkg/campaign/injection.go
  • Test Functions: 3 test functions (60 lines)
  • Exported Functions: 1 (InjectOrchestratorFeatures)
  • Lines of Code: 60 lines (test), 261 lines (source)

Test Quality Analysis

Strengths ✅

  1. Already using testify: The test file consistently uses require.* and assert.* throughout
  2. Good assertion messages: All assertions include helpful context messages (e.g., "campaign injection should succeed")
  3. Clear test organization: Test names are descriptive and follow good naming patterns

Areas for Improvement 🎯

1. Missing Edge Case Coverage

Current Gap: The source file has complex logic for detecting campaign vs. project-tracking workflows (lines 40-79), but tests only cover 2 scenarios.

Missing Test Cases:

  • Campaign with explicit ID vs. inferred ID from WorkflowID
  • Campaign with explicit ID vs. inferred ID from Name
  • Empty/whitespace campaign ID fallback to "campaign" default
  • Nil ParsedFrontmatter handling (line 33)
  • Nil Project handling (line 33)
  • Campaign with Governance settings but no Bootstrap
  • Campaign with Bootstrap but no Workers
  • Campaign with Workers payload schema conversion (lines 154-185)
  • Safe-outputs configuration edge cases (lines 229-250)
  • Concurrency control injection (lines 253-256)

Recommended Test Cases:

func TestInjectOrchestratorFeatures_EdgeCases(t *testing.T) {
    tests := []struct {
        name              string
        workflowData      *workflow.WorkflowData
        shouldErr         bool
        expectInjection   bool
        expectedCampaignID string
    }{
        {
            name: "nil frontmatter - should skip",
            workflowData: &workflow.WorkflowData{
                Name:            "Test",
                WorkflowID:      "test",
                MarkdownContent: "# Test",
                ParsedFrontmatter: nil,
            },
            shouldErr:       false,
            expectInjection: false,
        },
        {
            name: "nil project - should skip",
            workflowData: &workflow.WorkflowData{
                Name:            "Test",
                WorkflowID:      "test",
                MarkdownContent: "# Test",
                ParsedFrontmatter: &workflow.FrontmatterConfig{
                    Project: nil,
                },
            },
            shouldErr:       false,
            expectInjection: false,
        },
        {
            name: "infer campaign ID from WorkflowID",
            workflowData: &workflow.WorkflowData{
                Name:            "Security Alert Burndown",
                WorkflowID:      "security-alert-burndown",
                MarkdownContent: "# Test",
                ParsedFrontmatter: &workflow.FrontmatterConfig{
                    Project: &workflow.ProjectConfig{
                        URL: "https://github.com/orgs/githubnext/projects/144",
                    },
                },
            },
            shouldErr:          false,
            expectInjection:    true,
            expectedCampaignID: "security-alert-burndown",
        },
        {
            name: "infer campaign ID from Name when WorkflowID empty",
            workflowData: &workflow.WorkflowData{
                Name:            "Security Alert Burndown",
                WorkflowID:      "",
                MarkdownContent: "# Test",
                ParsedFrontmatter: &workflow.FrontmatterConfig{
                    Project: &workflow.ProjectConfig{
                        URL: "https://github.com/orgs/githubnext/projects/144",
                    },
                },
            },
            shouldErr:          false,
            expectInjection:    true,
            expectedCampaignID: "security-alert-burndown",
        },
        {
            name: "fallback to default campaign ID",
            workflowData: &workflow.WorkflowData{
                Name:            "",
                WorkflowID:      "",
                MarkdownContent: "# Test",
                ParsedFrontmatter: &workflow.FrontmatterConfig{
                    Project: &workflow.ProjectConfig{
                        URL: "https://github.com/orgs/githubnext/projects/144",
                    },
                },
            },
            shouldErr:          false,
            expectInjection:    true,
            expectedCampaignID: "campaign",
        },
    }

    for _, tt := range test...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes githubnext/gh-aw#12236

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 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](https://gh.io/copilot-coding-agent-tips) in the docs.

- Added edge case tests for nil handling and campaign ID inference
- Added tests for complex configuration scenarios (Governance, Bootstrap, Workers)
- Added tests for SafeOutputs and concurrency injection
- Expanded normalizeCampaignID test coverage with 10 edge cases
- Added tests for default value application

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve test quality for injection_test.go Expand test coverage for campaign injection logic Jan 28, 2026
Copilot AI requested a review from pelikhan January 28, 2026 17:24
@pelikhan pelikhan marked this pull request as ready for review January 28, 2026 17:30
@pelikhan pelikhan merged commit 02aa05e into main Jan 28, 2026
56 checks passed
@pelikhan pelikhan deleted the copilot/improve-test-quality-injection branch January 28, 2026 17:36
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.

2 participants