Skip to content

Deduplicate AW import normalization in source policy lint rules - #71887

Merged
pelikhan merged 5 commits into
mainfrom
copilot/duplicate-code-aw-import-normalization
Oct 25, 2026
Merged

pelikhan merged 5 commits into
mainfrom
copilot/duplicate-code-aw-import-normalization

Conversation

Copilot AI commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Authored-policy deferral and conditional-import linting duplicated import-shape handling, risking inconsistent validation as supported forms evolve.

  • Shared normalization: Extract authoredImportEntries to resolve imports or imports.aw, normalize []any and []string, and return entries, effective path, presence, and shape errors.
  • Compatibility: Preserve caller-specific diagnostics. Missing aw remains absent; aw: null remains invalid. Top-level imports: null retains its intentional caller-specific treatment.
  • Regression coverage: Add table-driven shape tests and verify import-deferral behavior across all five downstream rules.
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate code in AW import shape normalization Oct 25, 2026
Copilot AI requested a review from pelikhan October 25, 2026 13:03
@pelikhan
pelikhan marked this pull request as ready for review October 25, 2026 13:05
Copilot AI max review requested due to automatic review settings October 25, 2026 13:05

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.

🟢 Approval recommended

The focused refactor preserves existing behavior and diagnostics, with regression coverage and no blocking issues identified.

No open issues 🎉

What changed in this PR

This PR centralizes AW import normalization in the source-policy lint rules, addressing #71499 while preserving caller-specific behavior and diagnostics.

Changes:

  • Extracts authoredImportEntries to normalize direct and mapping-form imports.
  • Updates both consumers while preserving absent-versus-null handling.
  • Adds regression coverage for import shapes and all five downstream deferral rules.
File Description
pkg/​workflow/​lint/​source_policy.go Shares import normalization between policy deferral and conditional-import checks.
pkg/​workflow/​lint/​source_policy_test.go Covers supported shapes, null handling, and downstream rule behavior.

Review effort: Max

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · sonnet50 · ~12 AIC · ⌖ ~16 AIC · ◇ ~5 AIC · ⊞ 12.7K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Oct 25, 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 Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Commit pushed: bf2d489

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Oct 25, 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 Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · gpt56 · ~9 AIC · ⌖ ~6 AIC · ⊞ 14.8K · ◷

Generated by Ponytail Reviewer for #71887

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

Verdict: COMMENT

No actionable blocking issues found in the changed import normalization and deferral logic. The reviewed behavior preserves the existing caller-specific handling for top-level and imports.aw null values, and the added tests cover the supported shapes and downstream deferral rules.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR adds more than 100 new lines under pkg/ (169 lines across pkg/workflow/lint/source_policy.go and source_policy_test.go), but it does not link an Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/71887-shared-aw-import-normalization-for-source-policy-lint.md. Please review and finish it before merging.

Decision captured: AW import-shape handling (imports / imports.aw, []any / []string) is moved into one helper, authoredImportEntries. Callers such as authoredImportsPending and checkConditionalImports keep their own diagnostics, including the existing special handling of top-level imports: null.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch. It was generated from the PR diff.
  2. Fill in what the draft could not infer: confirm who made the decision and refine the alternatives. The draft lists inline switches per rule, a typed import model at the parser level, and a helper that makes the full decision.
  3. Commit the finalized ADR to docs/adr/ on your branch.
  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-71887: Shared AW Import Normalization for Source Policy Lint Rules

Once the PR body links an ADR, this gate re-runs and checks that the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

ADRs create a searchable, permanent record of why the codebase looks the way it does.

📋 Michael Nygard ADR Format Reference
  • Context: What is the problem? What forces are at play?
  • Decision: What did you decide? Why?
  • Alternatives Considered: What else could have been done?
  • Consequences: What are the trade-offs (positive and negative)?

ADRs are stored in docs/adr/ as Markdown files named by PR number.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · opus55 · ~24 AIC · ⌖ ~36 AIC · ⊞ 1.9K · ◷
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.

Skills-Based Review 🧠

Applied /codebase-design (pr-triage was skipped in favor of direct classification: this is a clean refactor/dedup change) — one non-blocking suggestion, otherwise solid.

📋 Key Themes & Highlights

Key Themes

  • Shared helper, preserved semantics: authoredImportEntries cleanly unifies the imports / imports.aw resolution and []any/[]string normalization previously duplicated across authoredImportsPending and checkConditionalImports, while preserving each caller's distinct error messages.
  • Minor fragility: the path == "imports" string comparison (source_policy.go:66) used to detect "top-level null" vs "imports.aw null" is an implicit coupling to the helper's path-formatting convention rather than an explicit signal — flagged inline with a concrete alternative.

Positive Highlights

  • ✅ Excellent regression coverage: new table-driven TestAuthoredImportEntries covers absent/null/empty/malformed/conditional-entry cases, and TestAuthoredImportDeferralRules exercises the shared logic across all five downstream rules (ToolScopeRule, PushTargetRule, CheckoutModeRule, PullRequestTargetCheckoutRule, NeedsConsistencyRule).
  • ✅ Error messages don't leak user-controlled values (PRIVATE_VALUE assertions confirm this).
  • ✅ []string normalization avoids unnecessary allocation when the list is nil/empty.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · ~31 AIC · ⌖ ~15 AIC · ⊞ 10.2K
Comment /matt to run again

Comment thread pkg/workflow/lint/source_policy.go Outdated
entries, path, _, err := authoredImportEntries(input.Document.Frontmatter)
if errors.Is(err, errNullImportList) {
// Top-level null has historically meant no inherited configuration.
if path == "imports" {

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] The path == "imports" string comparison is a fragile way to distinguish top-level-null from imports.aw-null. It silently breaks if authoredImportEntries ever changes its path format (e.g., adds a third level), and the coupling between the two functions isn't obvious from the signature.

💡 Suggested fix

Have authoredImportEntries return a distinguishable sentinel (e.g., a small importLocation enum/bool like isNestedAw bool) alongside path, so callers branch on an explicit value rather than re-parsing the string the function itself produced. This keeps the 'top-level null is historically OK' special case robust to future path changes.

entries, path, nested, present, err := authoredImportEntries(frontmatter)
...
if nested { // imports.aw
    return false, errors.New(...)
}
return false, nil // top-level imports: null

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

Added explicit nested-import metadata to authoredImportEntries, removing the path-string check while preserving top-level imports: null and nested imports.aw: null behavior. Fixed in de945ee.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot address the following outstanding work in one pass:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/workflow/lint/source_policy.go:66): [/codebase-design] The path == "imports" string comparison is a fragile way to distinguish top-level-null from imports.aw-null. It silently breaks if authoredImportEntries ever changes its path format (e.g., adds a third level), and the coupling between the two functions isn't obvious from the signature. - Deduplicate AW import normalization in source policy lint rules #71887 (comment)

Push the necessary fixes, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved. Use the pr-finisher skill and stop when only human review or CI remains; do not trigger CI.

Sous-chef head: bf2d489
Sous-chef work: 32559d369bfce44eeefea5f668576004128f406f65aeb15d6225e6f59b79d0f3
Sous-chef state: 76f6dd8f594d130e9c581f03605d255e75b23298777886eb64f197e3dab8a256

Generated by 👨‍🍳 PR Sous Chef · pi · haiku45 · ~8 AIC · ⌖ ~9 AIC · ⊞ 1.1K · ◷
Comment /souschef to run again

Copilot AI and others added 2 commits October 25, 2026 14:36
…e-aw-import-normalization

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI requested a review from gh-aw-bot October 25, 2026 14:50
@pelikhan
pelikhan merged commit ba02dd8 into main Oct 25, 2026
36 checks passed
@pelikhan
pelikhan deleted the copilot/duplicate-code-aw-import-normalization branch October 25, 2026 16:52
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.93.5

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

Labels

None yet

4 participants