Skip to content

refactor: extract helpers from buildHandlerManagerStep in compiler_safe_outputs_steps.go - #49971

Open
pelikhan with Copilot wants to merge 5 commits into
mainfrom
copilot/refactor-buildhandler-manager-step
Open

refactor: extract helpers from buildHandlerManagerStep in compiler_safe_outputs_steps.go#49971
pelikhan with Copilot wants to merge 5 commits into
mainfrom
copilot/refactor-buildhandler-manager-step

Conversation

Copilot AI commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

buildHandlerManagerStep was a ~250-line function mixing app-token minting, env-var assembly, and token-resolution concerns in a single body, rated 74/100 in the daily code quality check.

Changes

  • addAppTokenMintingSteps (~60 lines) — extracts per-handler and dispatch-repository GitHub App token minting steps
  • addSafeOutputCoreEnvVars (~64 lines) — extracts core env vars: agent output reference, allowed-domains, URL policy, custom handler registration maps, and delegated config helpers
  • addSafeOutputTokenEnvVars (~86 lines) — extracts token env vars: CI-trigger token, project URL/token, assign-to-agent, agent-session, and GITHUB_TOKEN override for cross-repo PR operations
  • buildHandlerManagerStep reduced to 41 lines — now a pure orchestration function:
func (c *Compiler) buildHandlerManagerStep(data *WorkflowData) ([]string, error) {
    steps = append(steps, c.addAppTokenMintingSteps(data)...)
    // step header...
    if err := c.addSafeOutputCoreEnvVars(&steps, data); err != nil { ... }
    c.addSafeOutputTokenEnvVars(&steps, data)
    // with: section...
}
  • 20 new tests in compiler_safe_outputs_steps_test.go covering the three extracted helpers directly (TestAddAppTokenMintingSteps, TestAddSafeOutputCoreEnvVars, TestAddSafeOutputTokenEnvVars)

Behavior is identical — pure refactor.

Copilot AI and others added 2 commits August 3, 2026 12:32
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…fe_outputs_steps.go

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor oversized buildHandlerManagerStep function in compiler_safe_outputs_steps.go refactor: extract helpers from buildHandlerManagerStep in compiler_safe_outputs_steps.go Aug 3, 2026
Copilot AI requested a review from pelikhan August 3, 2026 12:46
@pelikhan
pelikhan marked this pull request as ready for review August 3, 2026 12:51
Copilot AI review requested due to automatic review settings August 3, 2026 12:51
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ failed during design decision gate check.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Testing safe outputs

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

Refactors safe-output handler step generation into focused helpers while preserving behavior.

Changes:

  • Extracts app-token, core-env, and token-env helpers.
  • Adds direct helper tests.
  • Updates an unrelated workflow skill inventory entry.
Show a summary per file
File Description
pkg/workflow/compiler_safe_outputs_steps.go Decomposes handler-step generation.
pkg/workflow/compiler_safe_outputs_steps_test.go Adds helper-focused tests.
.github/skills/agentic-workflows/SKILL.md Adds an unrelated reference entry.

Review details

Tip

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment on lines +132 to +136
// addAppTokenMintingSteps adds per-handler and dispatch-repository GitHub App token minting
// steps that must precede the handler manager step. For each registered handler that has a
// per-handler github-app configured, a dedicated token step is minted whose permissions are
// scoped to only that handler's needs (principle of least privilege).
func (c *Compiler) addAppTokenMintingSteps(data *WorkflowData) []string {
Comment on lines +589 to +590
// TestAddAppTokenMintingSteps tests GitHub App token minting step generation
func TestAddAppTokenMintingSteps(t *testing.T) {
- `.github/aw/test-coverage.md`
- `.github/aw/test-expression.md`
- `.github/aw/token-optimization-caching-budgets.md`
- `.github/aw/token-optimization-observability.md`

@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.

Clean refactor — helper extraction is correct, *[]string pointer receivers are consistent across env-var helpers, value return is appropriate for the token-minting helper, and the new unit tests give direct coverage of each extracted function. No functional or behavioral changes detected.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 23.1 AIC · ⌖ 7.32 AIC · ⊞ 5.4K

@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 Report

Test Quality Score: 82/100 — Excellent

Analyzed 20 test cases: 18 design, 2 implementation, 0 violations.

Key observations:

  • All 3 extracted helper functions are pure design tests (behavioral contracts).
  • 20 table-driven test cases with comprehensive edge-case coverage (nil inputs, feature presence/absence, token fallbacks, staged filtering).
  • No mocking violations; proper error handling with require.NoError(t, err).
  • Build tag compliant (//go:build !integration on line 1).
  • Test inflation (2.5:1) justified by helper extraction from monolithic function.

Verdict: 90% design tests (threshold: 70%). No violations. APPROVE ✅

@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.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 52.2 AIC · ⌖ 27.5 AIC · ⊞ 7.1K
Comment /matt to run again

// manager step: the agent output reference, allowed-domains configuration, URL policy,
// GitHub server/API URLs, custom handler registration maps, and the delegated per-handler
// config env vars.
func (c *Compiler) addSafeOutputCoreEnvVars(steps *[]string, data *WorkflowData) error {

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.

[/codebase-design] addSafeOutputCoreEnvVars lacks a nil guard for data.SafeOutputs — lines 202–203 always append env vars even if SafeOutputs is nil. addAppTokenMintingSteps does guard early (line 137); this function should follow the same pattern to make the precondition explicit and prevent silent misbehaviour for future callers.

💡 Suggested fix

Add a nil guard at the top, consistent with addAppTokenMintingSteps:

func (c *Compiler) addSafeOutputCoreEnvVars(steps *[]string, data *WorkflowData) error {
	if data.SafeOutputs == nil {
		return nil
	}
	// ...
}

@copilot please address this.

…erManagerStep

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🔍 PR Triage

Category: refactor · Risk: low · Total score: 48/100
Batch: batch-quality-1 (grouped with #49962, #49972 — low-risk quality/tooling PRs)

Impact Urgency Quality
22/50 8/30 18/20

Pure refactor extracting helpers from buildHandlerManagerStep; behavior unchanged, 20 new tests added.

Recommended action: batch_review — low-risk internal refactor with strong test coverage; batch with similar quality-improvement PRs.

Generated by 🔧 PR Triage Agent · auto · 55.7 AIC · ⌖ 4.24 AIC · ⊞ 8K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code Quality] Refactor oversized buildHandlerManagerStep function in compiler_safe_outputs_steps.go

3 participants