Skip to content

test(commons): add golden fixture corpus for LongEncoding - #3146

Merged
imbajin merged 3 commits into
apache:masterfrom
dpol1:feat/3145-longencoding-golden-fixtures
Sep 17, 2026
Merged

imbajin merged 3 commits into
apache:masterfrom
dpol1:feat/3145-longencoding-golden-fixtures

Conversation

@dpol1

@dpol1 dpol1 commented Aug 8, 2026

Copy link
Copy Markdown
Member

Visual summary

LongEncoding compatibility corpus

Purpose of the PR

LongEncoding encodes ids and sortable keys, so its exact behavior is a compatibility contract, including the intentional overflow wrapping around Long.MIN_VALUE and inputs the decoder accepts but the encoder never produces. Today that contract exists only implicitly in the implementation. This PR pins it in a committed, implementation-independent corpus that any port or refactor can be checked against line by line.

Main Changes

  • LongEncodingGoldenGenerator (test scope): produces the corpus by running the current implementation and recording, for each input, the exact output or the exception class. Deterministic: fixed value sets plus a fixed random seed, duplicate lines dropped.
  • longencoding-golden.txt (test resource): 3940 cases, plain ASCII, tab separated with \uXXXX escapes. Covers full-range round trips including Long.MIN_VALUE/MAX_VALUE, non-canonical decode inputs (00 decodes to MIN while encode produces 010), arbitrary UTF-16 decode input including surrogates, the error taxonomy (IllegalArgumentException vs NumberFormatException vs NPE), and length limits.
  • LongEncodingGoldenTest: two checks. It replays every corpus line against the implementation, and it regenerates the corpus in memory to assert the committed file matches the generator output exactly, so generator and resource cannot drift apart.
  • Both tests registered in UnitTestSuite so commons CI executes them.

Review guide: the review surface is the generator (case selection, ~370 lines), the corpus format documented in the file header, and the two-way check mechanics. The corpus file is generated output verified by testCorpusMatchesGenerator and does not need line-by-line review.

Contract boundaries: six operations (encodeSortable/decodeSortable, encodeB64/decodeB64, encodeSignedB64/decodeSignedB64). Exact output strings and decoded values are contract; the exception class is contract, the exception message deliberately is not. No production code changes.

Verifying these changes

  • Need tests and can be verified as follows:
    • mvn test -pl hugegraph-commons/hugegraph-common -Dtest=UnitTestSuite -DskipCommonsTests=false on JDK 11 (the commons CI toolchain): 345 tests, the only errors are 2 environment NPEs in MachineInfoTest that reproduce identically on a clean master checkout in the same environment.
    • Tamper check: altering one byte of the corpus fails both new tests; regenerating restores green.
    • apache-rat:check, checkstyle:check and git diff --check are clean.

Does this PR potentially affect the following parts?

  • Nope

Documentation Status

Lock down the current encode/decode behavior of LongEncoding as a
compatibility contract: exact outputs across the full value range
including the wrapping arithmetic around Long.MIN_VALUE, accepted
non-canonical inputs, and the exception class for each rejected input.
Exception messages are deliberately not part of the contract.

The corpus is generated by running the current implementation
(LongEncodingGoldenGenerator, deterministic seed) and verified two
ways: LongEncodingGoldenTest replays every line against the current
implementation, and regenerates the corpus in memory to check the
committed file matches the generator, so the two cannot drift apart.
Both tests are registered in UnitTestSuite so commons CI runs them.
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. tests Add or improve test cases labels Aug 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Due to the lack of activity, the current pr is marked as stale and will be closed after 180 days, any update will remove the stale label

@dpol1

dpol1 commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

@imbajin seeing your interest in my proposal wdyt here?

@github-actions github-actions Bot removed the inactive label Sep 15, 2026
@imbajin

imbajin commented Sep 16, 2026

Copy link
Copy Markdown
Member

@dpol1 Sorry I haven't replied to your proposal directly sooner. We've been focused on getting 1.8.0 released as soon as possible, and we're looking to take the Rust work forward in the 1.9–2.0 timeframe.

As the release work wraps up, we'll discuss the proposal together with the other PMC members and follow up here and in the related issues. A Rust refactor touches quite a few areas, so we do need some additional time to research the options and confirm the scope and compatibility requirements. Thanks for the proposal and the groundwork in this PR.

The community is very interested in your proposal and supportive of your involvement and this direction. As the release progresses, we'll follow up as soon as possible to exchange ideas and discuss the next steps, including through IM or Discord for quicker back-and-forth.

- pin the corpus to LF across checkouts
- preserve byte-exact generator comparisons
- prevent autocrlf false failures
@imbajin

imbajin commented Sep 17, 2026

Copy link
Copy Markdown
Member

Completed six independent review lanes and pushed a small portability fix in c6cf10b: pin the golden corpus to LF in .gitattributes. With core.autocrlf=true, checkout previously converted it to CRLF and broke the byte-exact generator comparison; the fixed checkout now matches the committed corpus byte for byte.

Java 11 validation passed: 19 focused tests and all 345 commons UnitTestSuite tests, with no failures or skips. The final three-line fix received an independent check. No production code or corpus content changed.

Review score: 9.0/10. No remaining actionable code findings within the six-operation contract; final-head CI is running, so approval is pending those results.

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.15%. Comparing base (4f1a8b3) to head (ed67283).
⚠️ Report is 31 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3146      +/-   ##
============================================
+ Coverage     39.30%   41.15%   +1.84%     
- Complexity      264     7217    +6953     
============================================
  Files           771      802      +31     
  Lines         65915    69393    +3478     
  Branches       8754     9237     +483     
============================================
+ Hits          25910    28558    +2648     
- Misses        37241    37572     +331     
- Partials       2764     3263     +499     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Consolidate early wraps in the golden fixture Java sources.
- Preserve aligned multiline arguments and wrap the regeneration command.
- Keep Java tokens and golden corpus bytes unchanged.

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, approved. @dpol1, thank you for the compatibility groundwork in this PR.

The repository's updated AGENTS.md and .editorconfig specify a 120-column maximum for Java. I have adjusted the two new Java files in ed67283c2 accordingly, keeping multiline arguments aligned. The aim is to make the code easier for both people and LLMs to read and work on; 120 is an upper limit, not a target every line must reach. The formatting change preserves the Java tokens and corpus bytes; all 19 focused tests and the full clean compile passed.

If useful, a separate formatting-only PR can apply this convention more broadly across the repository, starting with the core code and keeping functional changes separate.

We very much welcome your continued work on testing, correctness, compatibility fixtures, and the foundations for a future Rust refactor in #3145. This groundwork is important to the community regardless of which components eventually move to Rust. We would be glad to see you build deeper expertise and take an ongoing ownership role in this area, with other contributors participating in the design and reviews.

@imbajin
imbajin merged commit fbbeaa9 into apache:master Sep 17, 2026
22 checks passed
@dpol1
dpol1 deleted the feat/3145-longencoding-golden-fixtures branch September 17, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files. tests Add or improve test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants