Skip to content

refactor: extract shared model schemas, profile and parser helpers#38

Merged
benjamineckstein merged 1 commit into
mainfrom
refactor/fallow-round-3
Jun 4, 2026
Merged

refactor: extract shared model schemas, profile and parser helpers#38
benjamineckstein merged 1 commit into
mainfrom
refactor/fallow-round-3

Conversation

@benjamineckstein

Copy link
Copy Markdown
Contributor

Summary

Extraction of duplicated code blocks across model, profile, and parser modules. No behavior changes: golden snapshots byte-exact, validation/parse behavior identical, public API untouched.

Changes

Model: Extracted IBANSchema + BICSchema (byte-identical in schema.ts and pain008.ts) into new src/model/shared.ts. Deliberately LEFT sepaText/sepaIdentifier un-merged because their error messages differ (not true duplicates).

Profiles: Extracted checkBicPresent + checkIbanBicCountryConsistency helpers, de-duplicating 4 sites each in requireBic and ibanBicCountryMatch. Identical messages preserved.

Parser: Extracted extractGrpHdr (30-line GrpHdr navigation block that was byte-identical in parsePain001 and parsePain008). Every error string and extraction path preserved verbatim.

Verification

  • Golden snapshots: 23/23 byte-exact, no regeneration required
  • Stress tested: 8x clean runs
  • Validation/parse behavior: identical before/after
  • Public API (src/index.ts): untouched
  • Duplication reduced: 17.2% → 16.6%

Testing

  • Run pnpm test to verify all suites pass
  • Check golden snapshots remain byte-identical
  • Validate type coverage unchanged

…preserving)

Priority 1 (model): IBANSchema and BICSchema were byte-for-byte identical in
schema.ts and pain008.ts. Extracted into src/model/shared.ts and imported by
both. sepaText and sepaIdentifier were NOT merged: their error messages differ
(schema.ts carries the long charset hint, pain008.ts uses the short form), so
they are not true duplicates per the CLAUDE.md rule.

Priority 2 (profiles): Extracted two private helpers in profiles.ts:
  - checkBicPresent: encapsulates the "if bic undefined, push issue" pattern
    used 4 times across requireBic.checkCreditTransfer and .checkDirectDebit.
  - checkIbanBicCountryConsistency: encapsulates the IBAN/BIC country mismatch
    check used 4 times across ibanBicCountryMatch.checkCreditTransfer and
    .checkDirectDebit. Exact same issue messages, same logic, behavior identical.

Priority 3 (parser): Extracted extractGrpHdr() helper from the 30-line block
that was byte-for-byte identical in parsePain001 and parsePain008 (GrpHdr nav,
MsgId, CreDtTm, InitgPty/Nm, PmtInf array guard). Returns a discriminated union
GrpHdrExtracted | ParseFailure; callers branch on .ok. All error messages and
extraction order are preserved. Parser round-trip tests (xsd-oracle, coexistence)
cover this path; 8-run stress shows zero flakes.

Duplication: 17.2% -> 16.6%. 668 tests pass. Golden snapshots byte-exact.
src/index.ts unchanged.
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Fallow audit report

Found 4 findings.

Details
Severity Rule Location Description
minor fallow/code-duplication src/model/pain008.ts:22 Code clone group 1 (46 lines, 2 instances)
minor fallow/code-duplication src/model/schema.ts:13 Code clone group 1 (46 lines, 2 instances)
minor fallow/code-duplication src/profile/profiles.ts:177 Code clone group 2 (11 lines, 2 instances)
minor fallow/code-duplication src/profile/profiles.ts:262 Code clone group 2 (11 lines, 2 instances)

Generated by fallow.

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

Fallow audit report

4 inline findings selected for GitHub review.

Comment thread src/model/pain008.ts
CategoryPurposeSchema,
} from './schema.js'
import { isValidCreditorId } from './creditor-id.js'
import { IBANSchema, BICSchema } from './shared.js'

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.

warn fallow/code-duplication: Code clone group 1 (46 lines, 2 instances)

Comment thread src/model/schema.ts
import { isValidIban, isValidIso11649Ref } from './iban.js'
import { isValidIso11649Ref } from './iban.js'
import { isSepaCharset } from './charset.js'
import { IBANSchema, BICSchema } from './shared.js'

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.

warn fallow/code-duplication: Code clone group 1 (46 lines, 2 instances)

Comment thread src/profile/profiles.ts
message: 'BIC is required by the selected bank profile but is missing on the creditor',
})
}
checkBicPresent(issues, 'creditor.bic', doc.creditor.bic, 'creditor')

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.

warn fallow/code-duplication: Code clone group 2 (11 lines, 2 instances)

Comment thread src/profile/profiles.ts
checkIbanBicCountryConsistency(
issues,
'creditor',
doc.creditor.iban,

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.

warn fallow/code-duplication: Code clone group 2 (11 lines, 2 instances)

@benjamineckstein benjamineckstein merged commit 8062afc into main Jun 4, 2026
2 checks passed
@benjamineckstein benjamineckstein deleted the refactor/fallow-round-3 branch June 6, 2026 20:57
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.

1 participant