Skip to content

Add init command regression coverage for custom agent creation#44656

Merged
pelikhan merged 1 commit into
mainfrom
copilot/review-init-command
Jul 10, 2026
Merged

Add init command regression coverage for custom agent creation#44656
pelikhan merged 1 commit into
mainfrom
copilot/review-init-command

Conversation

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

gh aw init is expected to materialize the default custom agent under .github/agents/, but that behavior was only covered indirectly. This change adds command-level regression coverage so the default init path is explicitly exercised and the agent artifact is verified.

  • What changed

    • Added a regression test that executes gh aw init through NewInitCommand() rather than calling lower-level helpers directly.
    • Verifies the default command path creates .github/agents/agentic-workflows.md.
    • Asserts the generated file contains the expected Agentic Workflows agent identity, keeping the test anchored to the user-visible artifact.
  • Why this matters

    • Covers the actual CLI entrypoint, not just InitRepository.
    • Guards against future flag/default wiring regressions where the init command stops creating the custom agent even if the helper logic still works.
  • Example

    cmd := NewInitCommand()
    cmd.SetArgs([]string{})
    if err := cmd.Execute(); err != nil {
        t.Fatalf("init command failed: %v", err)
    }
    
    agentContent, err := os.ReadFile(filepath.Join(".github", "agents", "agentic-workflows.md"))
    if err != nil {
        t.Fatalf("expected custom agent file to be created: %v", err)
    }

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan July 10, 2026 05:14
@pelikhan pelikhan marked this pull request as ready for review July 10, 2026 05:15
Copilot AI review requested due to automatic review settings July 10, 2026 05:15
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories (41 additions, threshold is 100).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds explicit command-level regression coverage for gh aw init to ensure the default init path creates the expected custom agent file under .github/agents/.

Changes:

  • Adds a unit test that executes NewInitCommand() with default args and runs cmd.Execute().
  • Verifies .github/agents/agentic-workflows.md is created and contains the expected Agentic Workflows name marker.
Show a summary per file
File Description
pkg/cli/init_command_test.go Adds a command-level regression test asserting default init creates the Agentic Workflows custom agent artifact.

Review details

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment on lines +198 to +200
if err := exec.Command("git", "init").Run(); err != nil {
t.Skip("Git not available")
}
Comment on lines +219 to +221
if !strings.Contains(string(agentContent), "name: Agentic Workflows") {
t.Error("Expected Agentic Workflows custom agent file to use the Agentic Workflows name")
}

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new test is well-structured and consistent with existing patterns in the file. It correctly covers the NewInitCommand() entrypoint, sets up a real git repo, and verifies the expected agent artifact and identity string. No issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 12.2 AIC · ⌖ 4.92 AIC · ⊞ 4.8K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /tdd — two issues to address before merge.

📋 Key Themes & Highlights

Issues Found

  • Missing inverse test (line 208): The PR claims to guard against flag wiring regressions, but --no-agent suppression is never tested. A regression on that path would go undetected.
  • Potential os.Chdir race (line 183): The test omits t.Parallel() while sibling tests in the file run in parallel; if the scheduler interleaves them the working directory mutation will corrupt other tests.

Positive Highlights

  • ✅ Tests the real CLI entrypoint (NewInitCommand) rather than lower-level helpers — good regression anchor.
  • ✅ Asserts the user-visible artifact content (name: Agentic Workflows), not just file existence.
  • ✅ Proper temp-dir setup via testutil.TempDir and deferred os.Chdir restore.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 31.8 AIC · ⌖ 4.62 AIC · ⊞ 6.6K
Comment /matt to run again

t.Fatalf("Failed to set git user.email: %v", err)
}

cmd := NewInitCommand()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/tdd] The PR description says this guards against flag wiring regressions, but only the positive case (default path creates the agent) is tested — the inverse is missing.

💡 Suggested inverse test

Add a companion test that passes --no-agent and asserts the agent file is not created:

cmd := NewInitCommand()
cmd.SetArgs([]string{"--no-agent"})
if err := cmd.Execute(); err != nil {
    t.Fatalf("init command failed: %v", err)
}

agentPath := filepath.Join(".github", "agents", "agentic-workflows.md")
if _, err := os.Stat(agentPath); !os.IsNotExist(err) {
    t.Error("Expected --no-agent to suppress custom agent file creation")
}

Without this, the flag wiring can silently break in the other direction (e.g., --no-agent stops suppressing) and no test will catch it.

@copilot please address this.

}
}

func TestInitCommandCreatesCustomAgentByDefault(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/tdd] The new test mutates global process state (os.Chdir) without t.Parallel(), while several sibling tests do run in parallel — this creates a race condition if the Go test runner schedules them concurrently.

💡 Why this matters and how to fix it

Tests that call os.Chdir change the working directory for the entire process, not just the current goroutine. If two such tests run concurrently one will silently operate in the wrong directory.

The safest fix is to not use os.Chdir at all. Pass the working directory explicitly to the command, or use t.Chdir(tmpDir) (Go 1.24+) which automatically serialises directory changes and restores on cleanup.

If the command API requires the cwd to be implicit, mark the test with a serial-safe pattern or accept that the suite must run with -p 1.

Existing tests in this file (TestInitRepositoryBasic, etc.) follow the same os.Chdir pattern, so this is a pre-existing issue — but the new test should not perpetuate it without a comment.

@copilot please address this.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review

The existing review comments already cover the two meaningful issues in this change (the overly broad t.Skip and the fragile YAML string assertion). No additional blocking concerns — the rest of the test structure is consistent with the file's existing patterns.

🔎 Code quality review by PR Code Quality Reviewer · 27.7 AIC · ⌖ 4.28 AIC · ⊞ 5.4K
Comment /review to run again

@github-actions

Copy link
Copy Markdown
Contributor

Test Quality Sentinel Report

Score: 60/100 - Acceptable

Analyzed 1 test(s): 1 design, 0 implementation, 0 violations.

See details below.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🧪 Test quality analysis by Test Quality Sentinel · 36 AIC · ⌖ 11.5 AIC · ⊞ 6.8K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 60/100. 0% implementation tests (threshold: 30%). No violations. One high-value design test added — happy-path only, no edge-case coverage.

@pelikhan pelikhan merged commit f36549b into main Jul 10, 2026
92 of 103 checks passed
@pelikhan pelikhan deleted the copilot/review-init-command branch July 10, 2026 05:31
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.8

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.

3 participants