Skip to content

refactor: replace line-number matching with section-header extraction in verify-protocol-extracts.sh #159

@michael-wojcik

Description

@michael-wojcik

Context

Deferred from PACT v3 Phase D. Tracked for v3.1+.

Description

The verify-protocol-extracts.sh script uses hardcoded line ranges (e.g., sed -n '1303,1459p') to extract protocol sections from pact-protocols.md and compare them against source files. This is brittle — any content change above a section shifts all downstream line numbers, requiring manual updates.

Replace with section-header-based extraction that finds sections by their markdown heading (e.g., ## Scope Contract) and extracts content between headings. This would:

  • Eliminate line-range maintenance on every protocol change
  • Make the verification script resilient to content additions/removals
  • Reduce the most common PR friction point (updating line ranges)

Current State

  • 16 protocol extracts verified via line ranges
  • Line ranges must be manually updated whenever protocol content changes (happened in Phase C, D, and E)
  • The script otherwise works reliably — this is a maintainability improvement, not a bug fix

Implementation Notes

  • Could use awk or sed with heading pattern matching
  • Need to handle nested headings (sections contain ### subsections)
  • The --- separator between sections is a reliable boundary marker
  • Must preserve the byte-for-byte comparison behavior

Priority

Medium — reduces ongoing maintenance burden.

References

  • scripts/verify-protocol-extracts.sh
  • pact-plugin/protocols/pact-protocols.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions