Skip to content

Split parser import field extraction into focused modules - #76898

Merged
pelikhan merged 6 commits into
mainfrom
copilot/refactor-import-field-extractor
Nov 11, 2026
Merged

pelikhan merged 6 commits into
mainfrom
copilot/refactor-import-field-extractor

Conversation

Copilot AI commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

pkg/parser/import_field_extractor.go had grown to 1,190 lines, mixing import orchestration, configuration extraction, activation merging, model normalization, and result building.

  • Organize by responsibility: Move accumulator/result construction, frontmatter handling, engine/config, activation, models, and step/feature extraction into six focused files, each under 300 lines.
  • Share strict JSON decoding: Replace string-to-byte unmarshalling with a helper that rejects trailing JSON while avoiding the conversion:
    if err := decoder.Decode(target); err != nil {
        return err
    }
    if err := decoder.Decode(&trailing); err != io.EOF {
        // Reject malformed or additional JSON values.
    }
  • Cover decoding behavior: Add focused tests for trailing whitespace and invalid trailing content.

Copilot AI changed the title [WIP] Refactor pkg/parser/import_field_extractor.go into focused files Split parser import field extraction into focused modules Nov 11, 2026
Copilot AI requested a review from gh-aw-bot November 11, 2026 16:23
@pelikhan
pelikhan marked this pull request as ready for review November 11, 2026 16:51
Copilot AI adaptive review requested due to automatic review settings November 11, 2026 16:51
@github-actions

github-actions Bot commented Nov 11, 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 · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

PR Specification 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 PR Specification Reviewer · gpt56 · ~2 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

Generated by PR Specification Reviewer for #76898

@github-actions

github-actions Bot commented Nov 11, 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 Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #76898

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 11, 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 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.

What this change does: It splits import field extraction across focused files and adds a JSON decoding helper.

Should fix

  1. Remove the redundant JSON helper (pkg/parser/import_extract_helpers.go:10)

    • What this is: The helper decodes each imported JSON value and checks for trailing content.
    • Problem: json.Unmarshal already accepts trailing whitespace and rejects extra or malformed content, so the helper and its tests duplicate standard library behavior.
    • Fix: Restore json.Unmarshal at the six callers and remove the helper and its tests.
    • If we skip it: There is extra parsing code and a test suite to maintain.

Verdict: Ship.
Lean: -46 lines possible.

Generated by ✂️ Ponytail Reviewer for #76898 · codex · routed: gpt61 medium · ~7 AIC · ⌖ ~1 AIC · ⊞ 181
Comment /ponytail to run again

Comment thread pkg/parser/import_extract_helpers.go Outdated
"strings"
)

func unmarshalJSONFromString(content string, target any) 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.

Should fix: Restore json.Unmarshal([]byte(content), target) at these six callers and remove this helper and its tests: json.Unmarshal already accepts trailing whitespace and rejects extra or malformed content, so the second decode duplicates existing behavior. (~46 lines saved.)

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.

Replaced the local decoder with the existing jsonutil.UnmarshalString at all six call sites and removed the duplicate helper/tests. It avoids string-to-byte copies while retaining whole-document validation. Commit: 5f73b853.

@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 the changed parser files; no actionable correctness, performance, or security issues found in the diff. The specialist pass was unavailable due to its file-access restriction, so this verdict is based on the independent static review.

Review scope

The change is a responsibility split of the existing import extractor plus strict trailing-JSON validation tests. No behavioral regression was identifiable from the changed lines.

🔎 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 makes significant changes to core business logic (>100 new lines in pkg/) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/76898-split-parser-import-field-extraction-into-focused-files.md — review and complete it before merging.

🔒 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. Complete the missing sections — resolve the [TODO: verify] items, refine the rationale, and list real alternatives you considered

  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-76898: Split Parser Import Field Extraction into Focused Files (link unavailable: invalid HTTPS URL)

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

❓ Why ADRs Matter

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • 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)?

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

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: sonnet55 high · ~20 AIC · ⌖ ~2 AIC · ⊞ 8.5K · ◷
Comment /review to run again

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

No active review issues are blocking the workflow import refactor.

No open issues 🎉

What changed in this PR

Refactors workflow import processing in pkg/parser into focused modules, addressing #76861 without changing public APIs.

Changes:

  • Splits the 1,190-line extractor into six responsibility-focused files, each under 300 lines.
  • Adds shared string-based JSON decoding that preserves rejection of trailing content.
  • Adds tests for trailing whitespace, additional JSON values, and malformed trailing content.
File Description
pkg/​parser/​import_field_extractor.go Removes the monolithic implementation after redistribution.
pkg/​parser/​import_extract_steps.go Groups step, job, environment, and feature extraction.
pkg/​parser/​import_extract_models.go Isolates model aliases, policies, and pricing normalization.
pkg/​parser/​import_extract_helpers.go Adds shared strict JSON decoding from strings.
pkg/​parser/​import_extract_helpers_test.go Tests JSON trailing-content handling.
pkg/​parser/​import_extract_frontmatter.go Houses import orchestration and frontmatter processing.
pkg/​parser/​import_extract_engine.go Groups engine and configuration extraction.
pkg/​parser/​import_extract_activation.go Groups activation, authentication, and list merging.
pkg/​parser/​import_accumulator.go Houses accumulated state and result construction.

Review effort: Balanced (auto)

@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 /improve-codebase-architecture. The file split is sound: I rebuilt the deleted 1,190-line file from the diff and every line maps to a new file, with only the six JSON call sites changed. go build, go vet, gofmt, the new helper test, and the full pkg/parser suite all pass.

Requesting changes for three items:

  • Redundant helper: unmarshalJSONFromString adds no behaviour. json.Unmarshal already rejects trailing values, and the helper is about 15–20% slower with more allocations.
  • Stale doc references: the copied package comment in import_accumulator.go and the file map in import_processor.go still refer to the deleted file.
📋 Key Themes & Highlights

Key Themes

  • Pure refactor, verified: the split preserves logic line for line.
  • Redundant abstraction: the new JSON helper duplicates stdlib behaviour.
  • Stale references: two comments still point at import_field_extractor.go.

Positive Highlights

  • ✅ Each new module is focused and under 300 lines.
  • ✅ The new helper test covers the trailing-content cases.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~10 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again

Comment thread pkg/parser/import_extract_helpers.go Outdated
"strings"
)

func unmarshalJSONFromString(content string, target any) 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] The trailing-content check is redundant: json.Unmarshal already rejects trailing values (checked for {} {}, {} invalid and {} null). This helper is slower and allocates more than the call it replaces, and it decodes into target before rejecting, so partial output can remain on error.

💡 Suggested change

Revert the six call sites to json.Unmarshal([]byte(content), &target) and delete this helper. The PR description says the helper is needed to reject trailing JSON, but json.Unmarshal already does that.

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

Replaced the local decoder with the existing jsonutil.UnmarshalString at all six call sites and removed the duplicate helper/tests. It avoids string-to-byte copies while retaining whole-document validation. Commit: 5f73b853.

Comment thread pkg/parser/import_accumulator.go Outdated
@@ -0,0 +1,214 @@
// Package parser provides functions for parsing and processing workflow markdown files.

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] This copies the package doc from the deleted import_field_extractor.go, which duplicates pkg/parser/doc.go. The comment directly above package parser (lines 3-4) now reads as a package doc but does not start with "Package parser".

💡 Suggested change

Drop line 1. Keep the file description as a plain comment, separated from package parser by a blank line.

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

Removed the duplicate package documentation comment, leaving the file-specific description as a regular comment. Commit: 643119f3.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/parser/import_extract_helpers.go:10): address unresolved feedback - Review comment
  3. Review (pkg/parser/import_extract_helpers.go:10): address unresolved feedback - Review comment
  4. Review (pkg/parser/import_accumulator.go:1): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "c97da5537ceb4a2f7b089f851e9d59b65910e8e0",
  "kind": "requested",
  "schema_version": "1",
  "state": "cb2289b8cc197637ea5ce619f3fe5bd024e0b1ea366e8ad243e844cbf8fa73a2",
  "work": [
    "26d5e90fefb41544c408a26ad72e3de4f6753d1dbd63552d294217982c2c05da",
    "8d4751f603158c0cd5c153f9d22b0be9e480e605a0260724bbb7301422ca631a",
    "cc98ca1e5d5e6aab04391fdd0992c7c3f33dcf1157a87a57316156a7ef370f11"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~4 AIC · ⌖ ~2 AIC · ⊞ 6.9K · ◷
Comment /souschef to run again

@pelikhan
pelikhan merged commit ca1203d into main Nov 11, 2026
73 checks passed
@pelikhan
pelikhan deleted the copilot/refactor-import-field-extractor branch November 11, 2026 18:08
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.3

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.

[file-diet] Refactor pkg/parser/import_field_extractor.go (1190 lines)

4 participants