Skip to content

Refactor safe-output repo target accessors - #53838

Open
pelikhan with Copilot wants to merge 8 commits into
mainfrom
copilot/refactor-repo-target-extraction
Open

Refactor safe-output repo target accessors#53838
pelikhan with Copilot wants to merge 8 commits into
mainfrom
copilot/refactor-repo-target-extraction

Conversation

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Safe-output schema generation repeated AllowedRepos and TargetRepoSlug extraction across a large tool-name switch, making new tool support easy to implement inconsistently.

  • Registry-based targeting

    • Replaced the switch with a tool-name-to-accessor registry.
    • Centralized repo-parameter eligibility and description generation.
    accessor := repoTargetAccessors[toolName]
    targetConfig := accessor(safeOutputs)
  • Coverage guard

    • Added a focused test that verifies the registry contains exactly the supported repo-target tools.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 33.2 AIC · ⌖ 9.48 AIC · ⊞ 6.9K ·
Comment /souschef to run again


Generated by PR Sous Chef run https://github.com/github/gh-aw/actions/runs/32249206937> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 23.7 AIC · ⌖ 8.26 AIC · ⊞ 9.3K ·

Comment /souschef to run again

Copilot AI and others added 2 commits August 18, 2026 22:11
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] Refactor repeated repo-target extraction in safe output tool schema generation Refactor safe-output repo target accessors Aug 18, 2026
Copilot AI requested a review from pelikhan August 18, 2026 22:14
@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

Registry-based refactor with a coverage guard test. Part of the safe-output parsing refactor cluster — batch review recommended.

Generated by 🔧 PR Triage Agent · auto · 58.5 AIC · ⌖ 2.15 AIC · ⊞ 8.3K ·

@github-actions

Copy link
Copy Markdown
Contributor

Triage: category=refactor · risk=medium · score=38/100 (impact 18/50, urgency 10/30, quality 10/20)
Recommended action: batch_review

Part of the B1-safeoutput-refactor batch (with #53841, #53840). Draft, no CI yet, no reviews. Undraft once ready and review together with the batch.

Generated by 🔧 PR Triage Agent · auto · 58.8 AIC · ⌖ 2.56 AIC · ⊞ 8.3K ·

@pelikhan
pelikhan marked this pull request as ready for review August 19, 2026 09:48
Copilot AI balanced review requested due to automatic review settings August 19, 2026 09:48

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 repository targeting into a registry, reducing duplicated tool dispatch logic.

Changes:

  • Adds tool-specific repository-target accessors.
  • Preserves centralized repo parameter generation.
  • Adds registry coverage validation.
Show a summary per file
File Description
pkg/workflow/safe_outputs_tools_repo_params.go Replaces the switch with an accessor registry.
pkg/workflow/safe_outputs_tools_generation_test.go Verifies the registry’s supported tool set.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

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

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@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: Infrastructure-only PR (test refactoring). The new assert.Len assertion strengthens coverage of the repoTargetAccessors map. No violations detected.

@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 /codebase-design and /tdd — one suggestion on test depth, otherwise approving.

📋 Key Themes & Highlights

Key Themes

  • Test depth: The new coverage guard confirms the registry has the right keys but does not verify each accessor reads the correct config field. A copy-paste error at the accessor body level would go undetected. See the inline comment for a concrete suggestion.

Positive Highlights

  • ✅ The registry-based approach is a textbook deep-module improvement: the interface (one map lookup) is simpler than the old O(n) switch, and the behaviour is identical.
  • ✅ Consistent use of *repoTargetConfig as a nil-able return value cleanly replaces the dual hasAllowedRepos/targetRepoSlug variables, reducing the chance of divergence.
  • ✅ The coverage guard test is a good pattern; it just needs one more layer of assertion.
  • ✅ The old nested switch-within-switch for add_labels through set_issue_field is gone — a real readability win.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 25.3 AIC · ⌖ 9.98 AIC · ⊞ 7.8K
Comment /matt to run again


func TestParseUpdateIssuesConfigWithWildcardTargetRepo(t *testing.T) {
compiler := &Compiler{}
outputMap := map[string]any{

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 coverage guard verifies that registry keys exist but not that each key maps to the correct SafeOutputsConfig field — a copy-paste error like "close_issue"config.CloseDiscussions would silently pass.

💡 Suggested approach

Consider calling each accessor with a fully-populated SafeOutputsConfig and asserting the returned repoTargetConfig is non-nil and contains expected values. Spot-checking a few distinct config types (issue, discussion, PR, label) would catch misrouted accessors:

func TestRepoTargetAccessorsReturnCorrectField(t *testing.T) {
    cfg := &SafeOutputsConfig{
        CloseIssues: &SafeOutputTargetConfig{AllowedRepos: []string{"org/repo"}, TargetRepoSlug: "org/repo"},
        CloseDiscussions: &SafeOutputTargetConfig{AllowedRepos: []string{"org/other"}, TargetRepoSlug: "org/other"},
    }
    got := repoTargetAccessors["close_issue"](cfg)
    require.NotNil(t, got)
    assert.Equal(t, []string{"org/repo"}, got.allowedRepos, "close_issue must read CloseIssues, not another field")
}

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in ec1120a. The metadata-driven test now creates a distinct configuration for every eligible handler and verifies each accessor returns that handler’s own AllowedRepos and TargetRepoSlug values.

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-08-19T00:00:00Z
review_event: REQUEST_CHANGES
top_themes:
  - duplicated repo-target registry can drift from real safe-output tool definitions
files_reviewed:
  - pkg/workflow/safe_outputs_tools_repo_params.go
  - pkg/workflow/safe_outputs_tools_generation_test.go
comment_count: 1

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 19.9 AIC · ⌖ 6.93 AIC · ⊞ 7K ·
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.

Request changes

The refactor is moving in the right direction, but it still leaves repo-target support wired through a second handwritten registry. That creates an easy-to-miss failure mode where future repo-aware safe-output tools compile without exposing the repo schema parameter the runtime expects.

Blocking theme
  • repoTargetAccessors is now another source of truth that must stay in sync with the real safe-output tool/handler set.
  • The added test only compares one hard-coded list to another, so it will not catch the more important regression: adding a new repo-target-capable tool/config path without registering it here.

That is exactly the sort of drift this refactor was supposed to remove, so I would not merge it until the accessor mapping is derived from existing metadata or at least validated against the real handler registry instead of a duplicated literal.

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 19.9 AIC · ⌖ 6.93 AIC · ⊞ 7K
Comment /review to run again


type repoTargetAccessor func(*SafeOutputsConfig) *repoTargetConfig

var repoTargetAccessors = map[string]repoTargetAccessor{

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.

This registry refactor still leaves repo-target support dangerously manual: adding a new repo-aware safe-output tool now requires updating both the handler registry and this separate repoTargetAccessors map, and the new test only checks a hard-coded list rather than deriving it from the actual tool definitions. That means a newly added cross-repo tool can silently ship without a repo schema parameter even though the runtime supports target-repo/allowed-repos, which breaks agent behavior in exactly the kind of incremental feature addition this refactor is supposed to simplify.

💡 Why this matters and how to fix it

Right now the source of truth is split:

var repoTargetAccessors = map[string]repoTargetAccessor{ ... }

and separately the enabled/tool registries live elsewhere. The test only proves the handwritten list matches another handwritten list today; it does not fail when someone adds a new repo-target-capable config type but forgets to register it here.

A safer design is to co-locate the accessor with the tool/handler metadata, or derive the accessor map from the same registry used to generate safe-output handlers/tools. Short of that, add a failing test that compares against the real repo-target-capable handler set instead of a duplicated slice literal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in ec1120a. Accessors are now derived from safeOutputHandlers and their config types; no independent tool-name list remains.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Current head 94b6b00 derives accessors by iterating canonical safeOutputHandlers; eligibility is inferred from each handler’s config type and fields, so no separate repo-tool list remains. TestRepoTargetAccessorsMatchHandlerMetadata exercises every eligible handler’s routed AllowedRepos and TargetRepoSlug values.

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

Ponytail review: over-engineering only.

net: -40 lines possible.

Generated by ✂️ Ponytail Reviewer for #53838 · auto · 35.6 AIC · ⌖ 4.38 AIC · ⊞ 7.3K
Comment /ponytail to run again

Comments that could not be inline-anchored

pkg/workflow/safe_outputs_tools_repo_params.go:44

L44-213: yagni: 28 near-identical closures (if output := config.X; output != nil { return &amp;repoTargetConfig{...} }) replacing a 149-line switch with a 189-line map — net +40 lines for the same duplication, just per-entry instead of per-case.

pkg/workflow/safe_outputs_tools_generation_test.go:10

L10-19: delete: hardcoded 28-tool slice duplicates the keys already listed in repoTargetAccessors. Assert len(repoTargetAccessors) &gt; 0 and a couple of spot checks instead of re-listing all 28 tool names.

)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please address the latest maintainer-visible blockers on this PR and then run the pr-finisher skill.

Current maintainer-visible blockers:

  • There is still a blocking github-actions review requesting that repo-target support stop depending on a second handwritten registry that can drift from the real safe-output tool definitions.
  • Please make the accessor mapping derive from existing metadata, or validate it against the real handler registry rather than another duplicated literal list.
  • A branch refresh was attempted by sous-chef as well.

Generated by 👨🍳 PR Sous Chef

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 33.2 AIC · ⌖ 9.48 AIC · ⊞ 6.9K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please address the latest maintainer-visible blockers on this PR and then run the pr-finisher skill.

Current maintainer-visible blockers:...

Addressed in ec1120a. Repository-target accessors now derive from the canonical safe-output handler metadata, and the test verifies accessor routing for every eligible handler.

Copilot AI requested a review from gh-aw-bot August 19, 2026 11:03
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please address the latest maintainer-visible blockers on this PR, refresh the branch if needed, and then run the pr-finisher skill before handing back for maintainer review.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 25 AIC · ⌖ 8.11 AIC · ⊞ 9.3K ·
Comment /souschef to run again

…-target-extraction

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please address the latest maintainer-visible blockers on this PR, refresh the branch if needed, and then run the pr-finisher skill before handing back for maintainer review.

Generated by...

Verified the accessor mapping remains derived from safeOutputHandlers (ec1120a) and refreshed the branch with current main in a596fb6. Scoped validation passes.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please address the remaining maintainer-visible blockers on this PR in one pass.

  • There is still a blocking github-actions review requesting maintainer-visible confirmation that repo-target support is derived from canonical handler metadata rather than a second handwritten registry.
  • Please restate the current-head resolution concisely for reviewers.
  • Please refresh the branch if needed.
  • Then run the pr-finisher skill before handing back for maintainer review.

Generated by 👨🍳 PR Sous Chef

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 23.7 AIC · ⌖ 8.26 AIC · ⊞ 9.3K ·
Comment /souschef to run again

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please address the remaining maintainer-visible blockers on this PR in one pass.

  • There is still a blocking github-actions review requesting maintainer-visible confirmation that repo-targ...

Current head 94b6b00 builds accessors by iterating canonical safeOutputHandlers; eligibility is inferred from each handler’s config type and fields, with no handwritten repo-tool list. TestRepoTargetAccessorsMatchHandlerMetadata verifies every eligible handler routes its own repo settings. The branch includes current main.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot The branch has author follow-up, but the blocking review thread is still unresolved.

  • Please reply directly on the open review thread with the current-head resolution (derived from canonical safeOutputHandlers, metadata-driven test coverage) so reviewers can resolve it quickly.
  • Refresh the branch if needed.
  • Then run the pr-finisher skill before handing back for maintainer review.

Generated by 👨🍳 PR Sous Chef

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 14 AIC · ⌖ 8.19 AIC · ⊞ 9.3K ·
Comment /souschef to run again

@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: refactor
  • Risk: medium
  • Priority score: 45/100 (impact 20 + urgency 10 + quality 15)
  • Recommended action: batch_review
  • Batch: B1-small-fixes-refactors

Registry-based refactor for safe-output repo target accessors. Reduces duplication in schema switch.

Generated by 🔧 PR Triage Agent · auto · 44.3 AIC · ⌖ 2.78 AIC · ⊞ 8.3K ·

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.

[duplicate-code] Refactor repeated repo-target extraction in safe output tool schema generation

4 participants