Skip to content

fix: address PR #47 review findings — column resolver, guard alerts, test coverage#49

Merged
Sam-Aitech merged 2 commits into
mainfrom
fix/pr47-review-findings
Jun 12, 2026
Merged

fix: address PR #47 review findings — column resolver, guard alerts, test coverage#49
Sam-Aitech merged 2 commits into
mainfrom
fix/pr47-review-findings

Conversation

@Sam-Aitech

Copy link
Copy Markdown
Owner

Follow-up to #47 (merged before review fixes landed). Addresses all Important findings from the multi-agent review.

Fixes

  • sponsorCsvColumns: ratingIdx no longer aliases the TierRating column already claimed by typeIdx — predicate now excludes tier, so it returns -1 on the current format and deriveSponsorRowEnums falls back to typeRating (the correct source).
  • sponsorStateMachine: admin alert fires when the fingerprint set is below the 50K trust threshold and Phases C2/D2 are skipped (operators were previously log-only blind to this degraded mode, and GRACE_PERIOD sponsors strand while it persists).
  • sponsorStateMachine: circuit-breaker message corrected — Phase C2 resurrections committed earlier in the run remain committed; only removals are aborted.
  • sponsorListFetcher: removed the dead legacy-only column resolver (resolveColumnIndexes/rowToRecord — zero callers, matched only the pre-May-2026 layout). downloadAndStreamToArray kept: it delegates to parseCsvFile, which uses the shared resolver.
  • csvArchiver / sponsorMonitorJob: three silent .catch(() => {}) (validation alert, abort alert, FAILED-status write) replaced with logged catches.
  • tests: qsvValidate/qsvCount mock shapes corrected to match real contracts.

New coverage (22 tests, all green — 241/241 suite-wide)

  • sponsorCsvColumns.test.ts (9): both register layouts, predicate precedence, ratingIdx-alias regression, unknown-header fallback
  • stateMachineGuards.test.ts (7): mass-removal circuit breaker (trip / under-threshold / SPONSOR_ALLOW_MASS_REMOVAL=1 bypass), Phase C2 self-heal sweep (event + suppressed mass-repair branches), trust gate on C2/D2, Phase D2 second-miss removal
  • sponsorCsvNewFormat.test.ts (+2): parseCsvFile throws on mass row rejection; buildFingerprintedCsv throws and deletes the gutted output file

Test plan

  • npx vitest run — 241/241 across 26 files (pre-commit hook)
  • npx tsc --noEmit — clean
  • Deploy-day check: confirm the next monitor run's diff baseline is a post-migration fingerprinted CSV; if not, expect one deliberate circuit-breaker trip (or a supervised SPONSOR_ALLOW_MASS_REMOVAL=1 run)

… coverage

Review fixes for the GOV.UK CSV schema-change PR:

- sponsorCsvColumns: ratingIdx no longer aliases the TierRating column
  already claimed by typeIdx (returns -1 on the new format so callers
  fall back to typeRating, the correct source)
- sponsorStateMachine: send admin alert when the fingerprint set is
  below the trust threshold and Phases C2/D2 are skipped; correct the
  circuit-breaker message (Phase C2 resurrections remain committed)
- sponsorListFetcher: remove dead legacy-only column resolver
  (resolveColumnIndexes/rowToRecord had no callers and only matched
  the pre-May-2026 layout)
- csvArchiver/sponsorMonitorJob: replace silent .catch(() => {}) on
  admin alerts and the FAILED-status write with logged catches
- tests: fix qsvValidate/qsvCount mock shapes to match real contracts

New coverage (22 tests):
- sponsorCsvColumns.test.ts: both register layouts, predicate
  precedence, ratingIdx-alias regression, unknown-header fallback
- stateMachineGuards.test.ts: mass-removal circuit breaker (trip,
  under-threshold, SPONSOR_ALLOW_MASS_REMOVAL=1 bypass), Phase C2
  self-heal sweep (event + suppressed/mass-repair branches), trust
  gate on C2/D2, Phase D2 second-miss removal
- sponsorCsvNewFormat.test.ts: parseCsvFile throws on mass row
  rejection; buildFingerprintedCsv throws and deletes gutted output
Resolves SonarQube typescript:S4325 (unnecessary type assertion) on the
db.execute mock casts; converted all nine ReturnType<typeof vi.fn> casts
to vi.mocked() for consistency.
@sonarqubecloud

Copy link
Copy Markdown

@Sam-Aitech Sam-Aitech merged commit c4b09b9 into main Jun 12, 2026
13 checks passed
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