Skip to content

fix(ci): the BQL harness compares column names - #2223

Merged
robcohen merged 1 commit into
mainfrom
fix/bql-harness-compares-headers
Sep 1, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/bql-harness-compares-headers

Conversation

@robcohen

@robcohen robcohen commented Sep 1, 2026

Copy link
Copy Markdown
Member

Closes #2220.

The harness diffed bean-query against rledger row by row and dropped the header before comparing, so any difference in column names passed as a match. Column names are user-visible output, and every piece of work this repo has done on them — #2164, #2175, #2176, #2217 — was invisible to the corpus that exists to catch exactly that.

The obvious fix doesn't work

The default table truncates a header to its data column width:

$ bean-query f.bean "SELECT account, sum(number) GROUP BY account"
account   sum(n          <- narrow values, header cut
--------  -----

# same query, values 1234567.89:
account   sum(number)    <- wide values, header intact

Our number padding differs from bean-query's, so comparing tabular headers would manufacture mismatches that are not divergences.

So both tools are asked for -f csv, which never truncates — same number of invocations. Rows are now parsed as CSV and normalized per field rather than per line, which is strictly better: a value containing a comma stays intact because the reader has already split on the right ones.

Two real divergence classes were hiding under the old comparison

Both filed, not papered over:

#2221 — BALANCES / JOURNAL column naming. bean-query heads SUM((position)) and MAXWIDTH(payee, 48); ours are the plain names. Rows agree. Worth noting: our AT UNITS and AT COST headers are identical to each other, where bean-query's record which valuation ran — so that pair loses information regardless of which convention wins.

#2222 — multi-currency SUM(position). bean-query returns one field holding a slot per currency seen across the whole result, empties included (100 CORP { 1 USD}, against our 100 CORP { 1 USD}). Whitespace collapsing in the tabular reader hid it entirely.

Registering them needed a query wildcard

("*", query) marks a divergence that is a property of the query rather than any ledger. A column-naming difference holds on all 735 corpus files, and spelling that as 735 paths would be mass-masking wearing a list.

The pre-existing bare-name guard — which catches registry keys that could never match — now exempts "*" while still flagging a genuinely bare filename. Verified both ways.

The design already prevents these entries from becoming permanent cover: stale_divergence_entries fails the run if a registered pair starts matching again.

Validation

Against a baseline, which is what the gate actually uses:

exit
with the registry entries 0 — no regressions vs the pre-change baseline
with one entry removed 1 — regression detected

My first attempt at that control ran without --baseline and returned 0 either way, so it proved nothing. Worth stating because the harness only gates on baseline regressions, not on absolute mismatches — a run with no baseline never fails.

Harness self-test passes; py_compile and typos clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

Copilot AI lite review requested due to automatic review settings September 1, 2026 17:45
@robcohen
robcohen requested a review from a team as a code owner September 1, 2026 17:45

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.

🟡 Changes recommended

The new CSV-based comparison still has correctness holes (ambiguous row/header re-serialization and wildcard entries not being stale-checked), which can allow false matches and weaken the harness’s guarantees.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR tightens the BQL compatibility harness so it can detect user-visible column-name divergences that were previously invisible, by switching both tools to CSV output and comparing headers in addition to data rows. It also introduces a wildcard mechanism to register divergences that are properties of the query across the whole corpus.

Changes:

  • Switches bean-query and rledger query invocations to -f csv, parses results as CSV, and normalizes fields before comparison.
  • Adds explicit header extraction/comparison and includes header mismatch details in JSONL output only when they differ.
  • Extends KNOWN_RUST_DIVERGENCES to support ("*", query_name) entries and exempts "*" from the bare-filename registry guard.
File summaries
File Description
scripts/compat-bql-test.py Convert harness comparison from tabular line-based parsing to CSV field-based parsing, add header comparison, and support query-wide divergence registry entries.
Review details

Suppressed comments (2)

scripts/compat-bql-test.py:1050

  • Data rows are re-serialized with ",".join(...), which reintroduces ambiguity when any field contains a comma (the exact case CSV parsing was meant to handle) and can yield false matches/mismatches.
    data = [",".join(r) for r in rows[1:]]

scripts/compat-bql-test.py:995

  • _SEPARATOR_RE and the preceding comment describe tabular (dashed-separator) parsing, but the harness now parses CSV and no longer uses this regex; leaving it behind makes the extraction logic look more complex than it is.
_SEPARATOR_RE = re.compile(r"^[-\s]+$")
  • Files reviewed: 1/1 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/compat-bql-test.py Resolved
Comment thread scripts/compat-bql-test.py Resolved
Comment thread scripts/compat-bql-test.py Resolved
Comment thread scripts/compat-bql-test.py Resolved
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Column names are user-visible output and nothing compared them: the
harness dropped everything above the tabular separator, so a run whose
headers differed reported a clean match. The pivot-header divergence in
#2217 sat in the corpus and passed. Closes #2220.

Headers are read from a second, CSV-formatted invocation. The default
table truncates a header to its data column width -- `sum(number)` over
five-character values prints `sum(n` -- so tabular headers disagree for
reasons that say nothing about either tool's column naming.

Values stay on the TEXT surface. The two are not interchangeable: CSV is
a machine surface, so `DisplayContext::for_surface` suppresses thousands
separators there absolutely (#1892). An earlier revision of this commit
compared values as CSV, which stopped exercising every `render_commas`
divergence in the registry and turned nine of those masks stale -- not
because rledger and bean-query had come to agree, but because the
harness had stopped looking. Verified against main over 71 corpus files
/ 1349 runs: verdicts are identical pair-for-pair, and 204 header
divergences are newly detected across four queries.

Known header divergences live in their own registry. An entry there
excuses a differing header and nothing else; the row comparison for the
same run still gates. Putting them in `KNOWN_RUST_DIVERGENCES` -- as the
first revision did -- masks the whole run, so a future DATA regression
in `JOURNAL` on any of the 735 corpus files would have been absorbed by
a mask only ever meant to cover a column's name.

Also fixes the stale-mask check, which resolved only `(file, "*")` and
not `("*", query)`. Every wildcard entry of that shape was reported
dangling on each run and never stale-checked, so it could outlive its
divergence indefinitely -- the exact failure the check exists to
prevent. Both directions now resolve, and the bare-name guard derives
its registry list from the same table so a registry added later cannot
escape it.

Each new behavior has a negative control in `--self-test`: mutating the
wildcard resolution, the header predicate wiring, the skipped-header
rule, or the guard's registry list makes the suite fail.
@robcohen
robcohen force-pushed the fix/bql-harness-compares-headers branch from 50aaafc to 4938c43 Compare September 1, 2026 18:53
@robcohen

robcohen commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

All four review findings were real and are fixed — and chasing the first one surfaced a defect in the PR's own premise that CI had already caught.

The compat job was failing, and it was right to. Switching the value comparison to -f csv turned nine render_commas masks stale. Not because rledger and bean-query had come to agree, but because CSV is a machine surface where DisplayContext::for_surface suppresses thousands separators absolutely (#1892) — so the harness had stopped looking at the very thing those masks document. Deleting the nine to get green would have been exactly backwards.

Values are back on the text surface; only the header pass uses CSV, as a second invocation. Verified against main over 71 corpus files / 1349 runs: verdicts identical pair-for-pair (0 differences), and 204 header divergences newly detected across four queries. Runtime ~1.7x, not 2x — the header pass is skipped when either tool already failed.

Findings

  1. ("*", query) never stale-checked — correct, and the CI log showed all nine warning as dangling on every run. _stale_registry_entries now resolves both wildcard directions (plus ("*", "*")).

  2. Comma-joined headers can compare equal — correct. extract_header returns a list[str]; nothing is re-joined.

  3. header_match True when either header is None — correct. A None now means "we did not look" and is tracked as header_skipped, reported in the summary rather than scored as agreement.

  4. Stale "separator to anchor on" comment — fixed.

One more, self-inflicted. Parking the header wildcards in KNOWN_RUST_DIVERGENCES masks the whole run, so a future data regression in JOURNAL on any of the 735 corpus files would have been absorbed by a mask only ever meant to cover a column's name. They now live in KNOWN_HEADER_DIVERGENCES, consulted only when scoring headers; rows still gate. Confirmed it gates: removing one entry takes real mismatches 21 → 69, and re-running against the clean baseline reports exactly 48 regressions.

Only four of the original nine wildcards survive. The other five were the #2222 inventory-slot padding, which the text surface legitimately does not see.

Negative controls. Every new behavior has one in --self-test: mis-wiring the header predicate, counting a skipped header as agreement, dropping the ("*", query) direction, or hardcoding the bare-name guard's registry list each make the suite fail (exit 1). The guard now derives its list from the same table that pairs each registry with its predicate — KNOWN_HEADER_DIVERGENCES escaped that guard when I first added it, and the self-test plants a bare key in each registry in turn to prove it can't happen again.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 99% (raw 93%, 169 masked)
Full AST Match 100%
Total Files 812
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@robcohen
robcohen merged commit 24c9032 into main Sep 1, 2026
42 of 44 checks passed
@robcohen
robcohen deleted the fix/bql-harness-compares-headers branch September 1, 2026 19:17
robcohen added a commit that referenced this pull request Sep 3, 2026
…ort (#2247)

* fix(ci): restore the nightly compat budget and stop a false stale report

Two unrelated problems behind the same health issue (#2232).

## compat.yml was timing out -- my regression

#2223 added a second CSV invocation per run to compare column names.
Measured at ~1.7x on a 71-file sample and judged acceptable; I never
checked it against the job's cap. On the full corpus the BQL step went
18m37s -> 34m36s and the job hit `timeout-minutes: 45`. The 09-02 and
09-03 nightlies were killed after BQL and never reached "Commit results
to compatibility branch", so the trend lost two days -- the exact
failure the concurrency comment in that workflow warns about.

Headers are compared on a SAMPLE of files per query now. A header is the
rendered target expression, so it depends on the query and not the
ledger: measured across the corpus, every query yields exactly one
distinct header pair however many files it runs on, which is also why
the divergence registry keys these `("*", query)`. The cost is
`queries x N` regardless of corpus size -- 380 header passes against 735
files rather than ~14000 -- so the sample is generous rather than
minimal.

Two guards, because a cap that hides a divergence is worse than the
runtime it saves:

* If a query's sampled files disagree about its headers, the property
  the sample rests on is false and the run errors. That is what would
  happen if a `PIVOT BY` query were added, since a pivot names its
  columns after the data.
* If a query ends up with NO usable comparison -- every sampled file
  failing in one of the tools, which ~28% of runs do -- the run errors
  rather than reporting a silent zero.

Verified: verdicts unchanged (58/0/21 over 71 files), the same four
queries still report header divergences, and both guards fire when
forced. Runtime went from 1m44s back to 1m10s against a 1m02s baseline.

## nightly-health called a healthy workflow stale

Separately, the report claimed `bench.yml` had not run in 10 days and
linked a real run from 2026-08-24. It had in fact run six hours earlier,
successfully, as it had every day.

`latest_scheduled_run` took element zero of `gh run list`; it now takes
the maximum by `createdAt`. This does NOT claim to fix a diagnosed bug:
the same command by hand returns the correct run, so the cause was not
reproducible. What it removes is the dependence on list ORDER, the only
assumption that could produce that output. The self-test feeds a
deliberately out-of-order page, since a correctly-ordered fixture cannot
tell the two implementations apart.

A false alarm matters more here than the diff size suggests: a health
reporter exists to be believed, and one that cries wolf gets muted --
which is the failure it was written to prevent.

* fix(ci): the header-sampling guards fail the run, not just annotate it

Both guards printed `::error::` and returned 0. An annotation does not
fail a GitHub Actions step, so a run whose header sampling was unsound
would have reported SUCCESS -- and the comments I wrote beside them said
"the run errors", which was simply untrue.

That is the failure this harness exists to prevent, reintroduced by the
change meant to protect it: a check that cannot fail.

`main` now returns 1 when either guard trips, last so every other
diagnostic still prints. Verified by exit code rather than by reading
the output: a healthy run exits 0, a query with no usable header
comparison exits 1, and headers varying across sampled files exits 1.

Caught in review of #2247.
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.

BQL compat harness compares data rows only, so column-name divergences are invisible

2 participants