Skip to content

test(api): pin the enum ordinals - #840

Merged
andiwand merged 1 commit into
mainfrom
test/pin-enum-ordinals
Sep 6, 2026
Merged

test(api): pin the enum ordinals#840
andiwand merged 1 commit into
mainfrom
test/pin-enum-ordinals

Conversation

@andiwand

@andiwand andiwand commented Sep 6, 2026

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

PR 10 of the v7 API plan.
Stacked on #839. Non-breaking — a test and a doc amendment.

The rule this enforces

27 public enums cross a binding by ordinal. JNI resolves constants with
values()[code] (jni_style.cpp:91); the apple and wasm mirrors are
positional too. Four headers say so, in comments:

// New entries go at the end: the bindings mirror this enum by ordinal.
// appended rather than sorted in, for the same reason as FileType
// Last because the bindings map this enum by ordinal.

A comment is not a guard. Reordering FileType compiles, links, passes the
suite, and then silently mis-maps in a consumer that was built against the old
jar. This pins all 214 enumerators so that fails here instead.

Appending stays silent by design — a new enumerator adds a line. Inserting or
reordering fails loudly, in the same commit.

Why not explicit values in the headers

The plan originally said to write = 0, 1, 2, … into the enums. Doing it, I
don't think that earns its place, and I have amended the plan rather than
leave the two disagreeing:

  • 214 enumerators across 27 enums is a lot of noise in the public headers.
  • It does not actually stop anyone. Someone reordering renumbers as they go and
    the header still compiles.

A test is what catches it. wasm/tests/enums.test.mjs already does exactly
this on the JS side; this is the C++ half, and the file says so.

Proof it works

Swapping soft and hard in HtmlTableGridlines — a two-line, entirely
plausible tidy-up:

test/src/enum_ordinals_test.cpp:232: Failure
test/src/enum_ordinals_test.cpp:233: Failure
[  FAILED  ] EnumOrdinals.html_table_gridlines

(reverted; the swap was only to check the guard bites)

Notes

The list was generated from the headers, not typed, so it cannot disagree with
them by transcription. 27 tests, one per enum, and they run in 0 ms.

@andiwand
andiwand force-pushed the refactor/one-way-to-edit branch from 0b80ffd to 6a8c287 Compare September 6, 2026 14:12
Base automatically changed from refactor/one-way-to-edit to main September 6, 2026 14:21
Twenty-seven public enums cross a binding by ordinal - jni resolves constants
with values()[code], and the apple and wasm mirrors are positional too - and
the only thing saying so was a comment in four headers. This pins all 214
enumerators, so inserting or reordering fails in the same commit rather than
in a consumer months later. Appending stays silent by design.

Not explicit values in the headers: that is noise, and it does not stop
anyone who reorders from renumbering as they go. wasm/tests/enums.test.mjs
already does this on the JS side; this is the C++ half.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016hxDa2rev11eLUEJZJ5nmz
@andiwand
andiwand force-pushed the test/pin-enum-ordinals branch from 5316deb to 8ad4ad0 Compare September 6, 2026 14:26
@andiwand
andiwand merged commit 86228ba into main Sep 6, 2026
25 checks passed
@andiwand
andiwand deleted the test/pin-enum-ordinals branch September 6, 2026 14:28
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