Skip to content

fix(bap): emit Best of Show and custom awards - #14

Merged
tmack8001 merged 3 commits into
mainfrom
fix/bap-best-of-show
Oct 27, 2026
Merged

tmack8001 merged 3 commits into
mainfrom
fix/bap-best-of-show

Conversation

@tmack8001

Copy link
Copy Markdown
Owner

Description

The BAP parser dropped Best of Show entirely: the API path read only results.miniBos (with an explicit "Skip Best of Show for now"), and the saved-HTML path skipped Best of Show headings and custom award lines. BAP keeps the overall Best of Show in results.bos.positions and extra awards (e.g. "Best of Show - Mead & Cider") in results.custom.awards, so a Brü Club Best of Show winner at Boneyard and Copper State Cup 2026 never reached the output. This matters for circuit scoring, where only the 1st place Best of Show earns the multiplier.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Changes Made

  • API path: also reads results.bos.positions (category Best of Show, blank entry count) and results.custom.awards (category = award name; position strings of the form entry \ M2A - Style \ Brewer, City, ST, USA \ Club: X). Filters (--club, --brewers) apply to both.
  • Saved-HTML path: no longer skips Best of Show headings or one-line custom awards; same rows as the API path. The overall Best of Show card's count is always blank to match the API.
  • Unrecognised custom award wording (the 2025 fixture uses a different format) is skipped with a stderr notice and counted in the final message. If the unreadable string mentions the active --club/--brewers filter it fails loudly with BapUnrecognizedAwardError instead, so a medal is never silently lost behind a misleading "no medals matched".
  • Null/odd shapes in bos, miniBos and custom are tolerated; parseApiData complexity reduced (extracted collectCustomAwards).
  • Place mapping is unchanged (BAP position 4 stays HM, so a Best of Show "4th" prints as HM).
  • A miniBos table literally named Best of Show... is now emitted as an ordinary table (it was skipped before).
  • Trimmed test fixtures gain bos/custom taken from the real 2026 Boneyard and Copper State captures (names, styles, brewer, club only; no personal data).
  • Docs (docs/BAP_IMPLEMENTATION.md) and CHANGELOG updated.

Platform(s) Affected

  • BAP

Testing

  • Existing tests pass (npm test): 605 passing (557 on main)
  • Added new tests for new functionality
  • Manually tested with real competition URLs (real API captures replayed through a fake fetcher)
  • Tested both JSON and CSV output (row-level parser output; formatting untouched)

Real captures, club "The Brü Club" (new rows only; every pre-existing row is byte-identical to main on both paths, with and without filters):

Boneyard   Best of Show|1st||One Bad Apple...|Cyser|Scott Estlund|The Brü Club
Copper     Best of Show|1st||Bamberg|Rauchbier|Stephen Schmitt|The Brü Club
Copper     Best of Show|2nd||Tripel|Belgian Tripel|Stephen Schmitt|The Brü Club
Copper     Best of Show - Mead & Cider|1st||ONE BAAAAD APPLE....|Cyser|Scott Estlund|The Brü Club

Review: went through the repo's adversarial-review-loop (opus correctness review, sonnet test-adequacy review with ~80 mutants, then a scoped opus re-review of the fixes); all verdicts SAFE TO MERGE, every surviving mutant found along the way now has a killing test.

Known limits, left as follow-ups: the "mentions the filter" check is a loose substring match (a short --club such as ASH can trip it for an old-wording award that merely contains that text), and hidePositions on custom awards is ignored.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes

Documentation

  • Updated relevant docs in docs/ folder
  • Updated CHANGELOG.md

Generated by Claude Code

Copy link
Copy Markdown
Owner Author

Automated review of this PR (Claude Code /code-review, high effort). These findings have not been individually verified against the code, so treat each as a lead to confirm. The first two matter most for backfilling older BAP competitions.

Worth addressing

  1. A fatal error discards every medal (src/parsers/bap-parser.ts ~L264). An unrecognized legacy custom-award line that names the active --club/--brewers makes parseResults rethrow BapUnrecognizedAwardError, so no output is produced, including the valid mini-BOS medals already parsed. Example: a 2024/2025 competition with Brewer / Club: The Bru Club - Entry (style) under --club "The Brü Club". Before this PR that competition returned its table medals. Suggest emitting the parsed rows plus a warning, with an opt-in strict flag if loud failure is wanted.
  2. Possible duplicate Best of Show rows (~L409). The guard that skipped miniBos tables named Best of Show was removed without de-duplicating against results.bos. If a response has both, the API path emits Best of Show|1st|12|X|… (from miniBos) and Best of Show|1st||X|… (from bos), which double-counts in a scoring sheet. The HTML path also blanks the count only for the exact category Best of Show, so the two paths can disagree. Suggest de-duping on brewer + entry name + place.
  3. Loose filter match (~L378). mentionsFilter is a raw substring match over the whole unrecognized line, so a short value such as --club ASH matches CASH CIDER and raises the fatal error for a line that names nobody asked for. (Already listed under known limits; noting it because it feeds finding 1.)
  4. Collaboration lines (~L431). parseCustomAward only accepts 3–4 \ parts, so Entry \ M2A - Cyser \ Scott Estlund, WI, USA \ Collaboration with X \ Club: The Brü Club (5 parts) counts as unrecognized, and with a matching club filter it is fatal.

Smaller

  1. HTML path (~L485): a custom-award row uses the raw heading as its category, including any N Entries / (N) suffix, while the API path uses the award name verbatim and the table path strips the count. Tests only cover headings without a count.
  2. HTML path (~L484): heading.text.includes(BEST_OF_SHOW) turns a damaged one-line row under any heading containing "Best of Show" into a quiet "unrecognized custom award" skip, where it previously raised BapHtmlStructureError. A truncated page can now drop a medal silently.
  3. skippedAwards is mutable per-instance state with a skippedByApi save/restore in parseResults (~L73). Overlapping calls on one parser share the counter, and when the API returns nothing and the saved-page fallback re-reads the lines, each notice prints twice (the PR's own test asserts 4 notices for 2 lines). Returning {rows, skipped} from the collectors would remove the state.
  4. The new Filters type duplicates the exported ResultFilters in filters.ts, and mentionsFilter re-implements the comma-split/normalize logic of shouldIncludeEntry (~L33). Reuse the existing type and move the name-list parsing into filters.ts.
  5. Tests (~L510): the new captureStderr helper isn't used by the existing tests in the same file, which still hand-roll console.error save/restore.

Generated by Claude Code

Copy link
Copy Markdown
Owner Author

Addressed the automated review. I checked each finding against the code and real BAP captures first; results below (pushed through ca5bb4b, 606 tests passing, 0 eslint errors, bap-parser.ts at 0 warnings, real Boneyard/Copper output byte-identical before and after this round).

  1. Fatal error discarded every medal — real, fixed. BapUnrecognizedAwardError is gone. An unreadable custom-award line is never fatal on the API path: all readable rows are emitted, and a line that names the requested --club/--brewers prints a prominent WARNING: ... its medal could NOT be read and is missing from this output. The 2025 old-wording fixture now returns its table medals plus warnings. I did not add a --strict flag (YAGNI); happy to add one as a follow-up.
  2. Duplicate Best of Show rows — no real capture has both a Best of Show miniBos table and results.bos, but a double count in scoring is costly and the fix is small. A bos/custom row is dropped when it equals a row from a table named Best of Show... (category, place, entry, style, brewer, club; compared ignoring case, accents and spacing; the table row, with its entry count, is kept). Ties and distinct rows are kept.
  3. Loose filter match — mentionsFilter now matches whole words on normalizeForMatch text (ASH no longer matches CASH CIDER; Brü/Bru still match). Since a miss only affects warning wording now, this is low stakes.
  4. Collaboration lines — Collaboration with ... parts after the brewer are accepted and ignored, so 5-part strings parse.
  5. HTML custom-award category with a count suffix — stripped, count column blank, matching the API path.
  6. Damaged one-line row under a "Best of Show" heading — tightened: on a saved page a single-line row is read as a custom award only if it contains \ or / Club:; anything else raises BapHtmlStructureError as before. Docs/CHANGELOG now say precisely where unreadable lines are non-fatal (API path) and that this saved-page error is deliberate.
  7. skippedAwards per-instance state — removed; collectors return { items, skipped } and parseResults owns counting/printing. Distinct skipped lines are reported once even when the saved-page fallback re-reads them; a test runs two overlapping calls on one parser and checks independent counts.
  8. Duplicate Filters type / filter parsing — now uses ResultFilters; the --brewers list parsing is an exported wantedBrewers() in filters.ts, shared by shouldIncludeEntry and the mention check.
  9. captureStderr helper — the older hand-rolled console.error save/restore tests use it now.

A scoped adversarial re-review of these changes (opus, plus ~90 mutants across the rounds) came back safe to merge. Its remaining notes, left as they are: the saved-page path also strips a trailing (N) from a custom-award name (e.g. Pro-Am Cup (2026)), unlike the API path (cosmetic; real BAP headings don't carry one); and on a saved page a table named exactly Best of Show is indistinguishable from the overall card, so it can't be deduped there.

One downstream note from the review: the CLI still exits 0 when a medal's line is unreadable, with the warning only on stderr. The TBC archive's capture.mjs discarded that stderr; it now records those lines under warnings in its fetch log (tmack8001/tbc-competition-circuit#2).


Generated by Claude Code

Export wantedBrewers() so the comma-separated, normalized, blank-dropping
parsing of --brewers lives in one place. shouldIncludeEntry uses it and its
behaviour is unchanged. The BAP parser reuses it in the next commit to decide
whether an unreadable award line mentions a requested brewer.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012GP39ZPN7EzLLdoKcJkGD4
The BAP parser dropped Best of Show entirely: the API path read only
results.miniBos and skipped any category named "Best of Show", and the saved
page path skipped Best of Show headings and custom award lines. BAP keeps the
overall Best of Show in results.bos and extra awards (for example "Best of Show
- Mead & Cider") in results.custom.awards, so a Brü Club Best of Show winner
never reached the output.

Both the API path and the saved-page path now emit:
- results.bos positions as category "Best of Show" (blank entry count; the
  saved-page card's count is always blank to match)
- results.custom.awards positions, one display string per place
  ("entry \ M2A - Style \ Brewer, City, ST, USA \ Club: X", with optional
  "Collaboration with ..." parts), category = the award name; --club and
  --brewers apply to them like any other row

Details that matter:
- An unreadable custom award line never fails the run on the API path: every
  readable row is still emitted, the line is reported on stderr, and a line
  that mentions the requested club or brewer (whole-word match) gets a
  prominent WARNING that its medal is missing. Skipped lines are counted and
  mentioned in the final message. On a saved page a single-line row with
  neither " \ " nor " / Club:" still raises BapHtmlStructureError.
- A bos or custom row identical to a row from a table named "Best of Show..."
  (compared ignoring case, accents and spacing) is dropped so a response that
  lists both never double counts.
- Null or oddly shaped bos, miniBos and custom data is tolerated.
- Place mapping is unchanged, so a Best of Show "4th" prints as HM.
- Collectors return their rows and skipped lines instead of keeping state on
  the parser, so overlapping calls on one parser are independent.

Fixtures: the trimmed 2026 Boneyard and Copper State Cup API fixtures gain bos
and custom taken from the real captures (names, styles, brewer and club only).
Tests cover both paths agreeing on those pages, the custom award wording cases,
dedupe, filters, stderr output and the shapes above; behaviour was checked with
mutation testing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012GP39ZPN7EzLLdoKcJkGD4
Describe where Best of Show and custom awards come from, the row shapes both
paths produce, how unreadable custom award lines are handled (non-fatal on the
API path, WARNING when they name the requested club or brewer), the dedupe, and
the saved-page limits. Add the CHANGELOG entry under Unreleased.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012GP39ZPN7EzLLdoKcJkGD4
@tmack8001
tmack8001 force-pushed the fix/bap-best-of-show branch from ca5bb4b to 654132c Compare October 27, 2026 11:00
@tmack8001
tmack8001 merged commit 9fb1902 into main Oct 27, 2026
10 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.

2 participants