Skip to content

fix: teach the api round-trip harness the page-margins both-collapse - #327

Merged
webern merged 1 commit into
mainfrom
fix-page-margins-both-collapse
Jul 7, 2026
Merged

fix: teach the api round-trip harness the page-margins both-collapse#327
webern merged 1 commit into
mainfrom
fix-page-margins-both-collapse

Conversation

@webern

@webern webern commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Human Summary

I'm not sure exactly why this PR didn't unblock any corpus files for mx::api round trip testing, and I'm a little bit concerned that someday someone will prefer that we not do this page margin collapse "simplification", but... it seems pretty harmless and it will make more files roundtripable for testing.

Summary

PageMarginsData::same() (documented on the class itself) intentionally collapses a
<page-margins type="odd">/<page-margins type="even"> pair with identical values into a single
type="both" element on write. Verified against all 99 corpus files carrying this drop signature:
every one has byte-identical odd/even margin values (typical of real-world exporters using
symmetric page margins), so this is the documented api simplification firing repeatedly, not a
fidelity bug -- exactly the "api design choice incompatible with round-trip fidelity" case the
round-trip harness is supposed to absorb, per the same reasoning already applied to <encoding>
child order (#220).

Added collapseEqualPageMargins() to CorpusRoundtripMain.cpp, mirroring the existing
canonicalizeEncodingChildOrder() pattern: pre-collapse the expected document's odd/even
page-margins pair the same way the api does before comparing, so only a genuine drop or value
mismatch surfaces. Applied in both the regression/discovery comparison and the dump path that
feeds the failure classifier.

No mx::api/mx::impl behavior changes -- this is a test-harness-only fix.

Testing

  • make test: all pass (4724 assertions in 378 test cases, plus the three examples)
  • make test-api-roundtrip: 158 passed, 0 failed (of 158 pinned; no regressions -- a
    harness-only change, no api behavior changed, so no new file fully passes, but
    drop:page-margins / value:page-margins@type are gone from make classify-api-roundtrip's
    worklist across the whole corpus)
  • make fmt / make check: clean

References

PageMarginsData::same() (documented on the class itself) intentionally
collapses a <page-margins type="odd">/<page-margins type="even"> pair with
identical values into a single type="both" element on write. Verified
against 99 corpus files with this drop signature: every one has
byte-identical odd/even margin values (typical of real-world exporters
using symmetric page margins), so this is the documented api simplification
firing repeatedly, not a fidelity bug -- exactly the "api design choice
incompatible with round-trip fidelity" case the round-trip harness is
supposed to absorb.

Added collapseEqualPageMargins() to CorpusRoundtripMain.cpp, mirroring the
existing canonicalizeEncodingChildOrder() pattern (#220): pre-collapse the
expected document's odd/even page-margins pair the same way the api does
before comparing, so only a genuine drop or value mismatch surfaces.
Applied in both the regression/discovery comparison and the dump path that
feeds the failure classifier.

## Testing

- [x] make test: all pass (4724 assertions in 378 test cases, plus examples)
- [x] make test-api-roundtrip: 158 passed, 0 failed (of 158 pinned; no
  regressions -- a harness-only change, no api behavior changed, so no new
  file fully passes, but drop:page-margins / value:page-margins@type are
  gone from make classify-api-roundtrip's worklist across the whole corpus)
- [x] make fmt / make check: clean

Closes #277
@webern webern added bug software defect testing non-breaking fixes or implementation that do not require breaking changes api Affects the mx::api layer ai Issues opened by, or through, a coding agent. labels Jul 7, 2026 — with Claude
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Coverage report

Core-dev coverage src/private/mx/core/

Metric Coverage Covered / Total
Lines 77.8% 28513 / 36640
Functions 74.3% 6352 / 8551
Branches 50.7% 22678 / 44751

API coverage src/private/mx/{api,impl,utility}/

Metric Coverage Covered / Total
Lines 80.8% 6391 / 7913
Functions 67.7% 2217 / 3275
Branches 49.5% 5476 / 11052

Core HTML report | API HTML report

Commit 3a92fe3ec6d356853fb0c4d6a26fb3ebbcd37c73.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

gen-quality gen/

gen-quality: 84.5 / 100   (floor 84.5, +0.0)

  structure     86.5  x0.50   [fn 90.5 / file 82.6]
  cyclomatic    88.4  x0.25
  cognitive     76.6  x0.25

  409 functions across 31 files, 7702 lines (largest file 1044)
  max cc 56  max cognitive 44  max fn loc 152

Worst offenders (top 5 per axis; full lists in score.json):
  cyclomatic gen/xsd/analyze.py:311     report                             56
  cyclomatic gen/plates/build.py:956    _validate_config_against_ir        35
  cyclomatic gen/press/context.py:145   plate_context                      34
  cyclomatic gen/__main__.py:46         _ir                                23
  cyclomatic gen/tests/test_ir.py:102   _check_references                  20
  cognitive  gen/xsd/analyze.py:311     report                             44
  cognitive  gen/ir/resolve.py:119      flat_elements                      40
  cognitive  gen/tests/test_ir.py:102   _check_references                  38
  cognitive  gen/press/context.py:145   plate_context                      37
  cognitive  gen/xsd/analyze.py:207     _sccs                              37
  size       gen/xsd/analyze.py:311     report                             152
  size       gen/press/context.py:145   plate_context                      96
  size       gen/plates/build.py:533    _value_plate                       89
  size       gen/plates/build.py:956    _validate_config_against_ir        89
  size       gen/ir/resolve.py:119      flat_elements                      78

Commit 3a92fe3ec6d356853fb0c4d6a26fb3ebbcd37c73.

@webern
webern merged commit 88a6664 into main Jul 7, 2026
10 checks passed
@webern
webern deleted the fix-page-margins-both-collapse branch July 7, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Issues opened by, or through, a coding agent. api Affects the mx::api layer bug software defect non-breaking fixes or implementation that do not require breaking changes testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

api: round-trip drops page-margins

1 participant