Skip to content

Refactor parser config-field extraction into composable helpers to satisfy largefunc limits#36664

Merged
pelikhan merged 3 commits into
mainfrom
copilot/lint-monster-function-length-refactoring
Jun 3, 2026
Merged

Refactor parser config-field extraction into composable helpers to satisfy largefunc limits#36664
pelikhan merged 3 commits into
mainfrom
copilot/lint-monster-function-length-refactoring

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 3, 2026

The lint-monster sweep identified widespread function-length violations; in this PR, we take a focused slice in pkg/parser by refactoring a 71-line config extractor into smaller units without changing behavior. This keeps first-wins import semantics and merged-field accumulation intact while bringing the target function under the 60-line threshold.

  • Config extraction decomposition (pkg/parser/import_field_extractor.go)

    • Split extractConfigFields into focused helpers:
      • extractFirstWinsJSONField
      • appendJSONBuilderField
      • appendJSONSliceField
      • appendYAMLBuilderField
    • Preserved existing semantics for:
      • first-wins fields (max-turns, max-runs, max-effective-tokens, max-daily-effective-tokens)
      • append/merge fields (mcp-servers, safe-outputs, mcp-scripts, steps, runtimes, services, network, permissions, secret-masking)
  • Behavior lock-in for refactor (pkg/parser/import_field_extractor_test.go)

    • Added TestExtractConfigFields_FirstWinsAndAccumulates to assert:
      • first import wins for scalar max-* fields
      • multi-import accumulation for builder/slice-backed config fields
func (acc *importAccumulator) extractConfigFields(fm map[string]any, fullPath string) {
	acc.extractFirstWinsJSONField(fm, fullPath, "max-turns", &acc.mergedMaxTurns)
	acc.extractFirstWinsJSONField(fm, fullPath, "max-runs", &acc.mergedMaxRuns)
	acc.appendJSONBuilderField(fm, "mcp-servers", "{}", &acc.mcpServersBuilder)
	acc.appendJSONSliceField(fm, "safe-outputs", "{}", &acc.safeOutputs)
	acc.appendYAMLBuilderField(fm, "steps", &acc.stepsBuilder)
}

Copilot AI and others added 2 commits June 3, 2026 15:58
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 changed the title [WIP] Refactor functions exceeding 60-line limit in pkg workflow, cli, and parser Refactor parser config-field extraction into composable helpers to satisfy largefunc limits Jun 3, 2026
Copilot AI requested a review from gh-aw-bot June 3, 2026 16:08
@pelikhan pelikhan marked this pull request as ready for review June 3, 2026 16:29
Copilot AI review requested due to automatic review settings June 3, 2026 16:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors pkg/parser import frontmatter config extraction by decomposing a previously large extractConfigFields function into smaller, composable helpers to satisfy function-length linting limits, while aiming to preserve first-wins and accumulation semantics across imports.

Changes:

  • Split extractConfigFields into targeted helpers for first-wins scalar extraction and append/merge field accumulation.
  • Added a regression test to lock in “first import wins” for scalar max-* fields and accumulation for several builder/slice fields.
  • Renamed the “Install GitHub Copilot SDK” workflow step label across many locked workflows to clarify it’s the Node.js SDK.
Show a summary per file
File Description
pkg/parser/import_field_extractor.go Refactors config-field extraction into helper methods while keeping existing extraction strategies.
pkg/parser/import_field_extractor_test.go Adds a regression test for first-wins scalar fields and multi-import accumulation.
.github/workflows/smoke-copilot-sdk.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/q.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/python-data-charts.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/pr-triage-agent.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/pr-nitpick-reviewer.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/pr-code-quality-reviewer.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/plan.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/pdf-summary.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/org-health-report.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/metrics-collector.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/mergefest.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/mcp-inspector.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/linter-miner.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/layout-spec-maintainer.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/jsweep.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/firewall.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/firewall-escape.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/draft-pr-cleanup.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/docs-noob-tester.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/discussion-task-miner.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/dictation-prompt.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/dev-hawk.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/deployment-incident-monitor.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/delight.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/dead-code-remover.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-workflow-updater.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-testify-uber-super-expert.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-syntax-error-quality.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-spdd-spec-planner.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-skill-optimizer.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-sentrux-report.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-security-observability.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-secrets-analysis.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-safe-output-integrator.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-repo-chronicle.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-performance-summary.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-model-inventory.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-mcp-concurrency-analysis.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-malicious-code-scan.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-issues-report.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-geo-optimizer.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-experiment-report.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-compiler-threat-spec-optimizer.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-compiler-quality.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-cli-performance.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-assign-issue-to-user.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-architecture-diagram.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/daily-agent-of-the-day-blog-writer.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/craft.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/copilot-pr-prompt-analysis.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/copilot-pr-nlp-analysis.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/copilot-pr-merged-report.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/copilot-opt.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/copilot-cli-deep-research.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/code-scanning-fixer.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/cli-consistency-checker.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/ci-coach.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/breaking-change-checker.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/brave.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/artifacts-summary.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/architecture-guardian.lock.yml Clarifies Copilot SDK install step name (Node.js).
.github/workflows/agent-performance-analyzer.lock.yml Clarifies Copilot SDK install step name (Node.js).

Copilot's findings

Tip

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

  • Files reviewed: 64/64 changed files
  • Comments generated: 3

Comment on lines +656 to +660
"runtimes": map[string]any{"node": map[string]any{"version": "20"}},
"network": map[string]any{"allow": []any{"github.com"}},
"permissions": map[string]any{"contents": "read"},
"secret-masking": map[string]any{"enabled": true},
}
Comment on lines +669 to +673
"runtimes": map[string]any{"python": map[string]any{"version": "3.12"}},
"network": map[string]any{"allow": []any{"api.github.com"}},
"permissions": map[string]any{"issues": "write"},
"secret-masking": map[string]any{"log-mask": true},
}
Comment on lines +687 to +691
assert.Contains(t, acc.runtimesBuilder.String(), "node")
assert.Contains(t, acc.runtimesBuilder.String(), "python")
assert.Contains(t, acc.networkBuilder.String(), "github.com")
assert.Contains(t, acc.networkBuilder.String(), "api.github.com")
assert.Contains(t, acc.permissionsBuilder.String(), "contents")
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

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

No ADR enforcement needed: PR #36664 does not have the 'implementation' label (has_implementation_label=false) and has 93 new lines of code in business logic directories, which is at or below the 100-line threshold (requires_adr_by_default_volume=false).

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

🧪 Test Quality Sentinel completed test quality analysis.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

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

@github-actions github-actions Bot mentioned this pull request Jun 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

🧪 Test Quality Sentinel Report

⚠️ Test Quality Score: 70/100 — Acceptable

Analyzed 1 test: 1 design test (behavioral contract), 0 implementation tests, 0 guideline violations.

📊 Metrics & Test Classification (1 test analyzed)
Metric Value
New/modified tests analyzed 1
✅ Design tests (behavioral contracts) 1 (100%)
⚠️ Implementation tests (low value) 0 (0%)
Tests with error/edge cases 0 (0%)
Duplicate test clusters 0
Test inflation detected No (52 test lines / 41 prod lines = 1.27×)
🚨 Coding-guideline violations 0

Test Classification Details

Test File Classification Issues Detected
TestExtractConfigFields_FirstWinsAndAccumulates pkg/parser/import_field_extractor_test.go:644 ✅ Design Happy-path only — no error/edge-case scenarios

Language Support

Tests analyzed:

  • 🐹 Go (*_test.go): 1 test — unit (//go:build !integration)
  • 🟨 JavaScript (*.test.cjs, *.test.js): 0 tests
⚠️ Flagged Tests — Requires Review (1 issue)

⚠️ TestExtractConfigFields_FirstWinsAndAccumulates (pkg/parser/import_field_extractor_test.go:644)

Classification: Design test — behavioral contract verified ✅
Issue: Happy-path only. The test exercises two valid inputs (first and second) and verifies first-wins semantics and accumulation, but includes no error or edge-case scenarios: no nil map input, no empty map, no conflicting type for a field, no zero-value numeric fields.
What design invariant does this test enforce? The first-wins rule for scalar config fields and accumulation semantics for map config fields (MCP servers, network rules, permissions, etc.).
What would break if deleted? A regression in extractConfigFields that changed first-wins to last-wins, or broke accumulation of map fields, would go undetected.
Suggested improvement: Add at least one error/edge-case table row (e.g., a nil map input, an empty config, or a zero-value max-turns to confirm zero is treated as "not set" or honoured):

// Example edge case: empty second config should not override first
acc2 := newImportAccumulator()
acc2.extractConfigFields(first, "first.md")
acc2.extractConfigFields(map[string]any{}, "empty.md")
assert.Equal(t, "10", acc2.mergedMaxTurns, "empty second config should not overwrite first-wins value")

Verdict

Check passed. 0% of new tests are implementation tests (threshold: 30%). Score is 70/100 because the single new test covers no error or edge-case paths — consider adding edge-case coverage before merging.

📖 Understanding Test Classifications

Design Tests (High Value) verify what the system does:

  • Assert on observable outputs, return values, or state changes
  • Cover error paths and boundary conditions
  • Would catch a behavioral regression if deleted
  • Remain valid even after internal refactoring

Implementation Tests (Low Value) verify how the system does it:

  • Assert on internal function calls (mocking internals)
  • Only test the happy path with typical inputs
  • Break during legitimate refactoring even when behavior is correct
  • Give false assurance: they pass even when the system is wrong

Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.

References: §26898532136

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 1.5M ·

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 70/100. Test quality is acceptable — 0% of new tests are implementation tests (threshold: 30%). The single new test (TestExtractConfigFields_FirstWinsAndAccumulates) is a behavioral design test with descriptive assertion messages and no guideline violations. Consider adding edge-case coverage (nil/empty inputs, zero-value numeric fields) to raise the score above 80.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

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 and /zoom-out — one minor coverage gap to address, otherwise solid work.

📋 Key Themes & Highlights

Key Themes

  • Coverage gap: appendYAMLBuilderField (the steps and services paths) is the only new helper not exercised by TestExtractConfigFields_FirstWinsAndAccumulates. All three JSON-flavored helpers are well covered.
  • Refactor fidelity: The extraction of first-wins logic (extractFirstWinsJSONField) correctly replicates the original *target != "" guard and the "null" check. No semantic drift detected.

Positive Highlights

  • ✅ Clean decomposition — each helper has a single, obvious responsibility
  • extractConfigFields is now a readable index of all nine fields in the accumulator
  • ✅ Test uses concrete, differentiated values for first vs. second import, making failures easy to diagnose
  • ✅ Net line reduction confirms no dead code was introduced

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 942.9K

Comments that could not be inline-anchored

pkg/parser/import_field_extractor_test.go:927

[/tdd] steps and services (both appendYAMLBuilderField call sites) are absent from the test fixtures and assertions, leaving the only new helper that calls extractYAMLFieldFromMap uncovered by this test.

<details>
<summary>💡 Suggested addition</summary>

Add YAML-valued fields to both first and second, then assert accumulation:

first := map[string]any{
    // ... existing fields ...
    &quot;steps&quot;:    []any{map[string]any{&quot;name&quot;: &quot;step-a&quot;, &quot;run&quot;: &quot;echo first&quot;}},
    &quot;servi</details>

@pelikhan pelikhan merged commit b81ac43 into main Jun 3, 2026
72 of 83 checks passed
@pelikhan pelikhan deleted the copilot/lint-monster-function-length-refactoring branch June 3, 2026 16:56
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.

[lint-monster] Function-length refactoring: 635 functions exceed 60-line limit

4 participants