Fix lockfile metadata serialization order#29
Merged
laulauland merged 4 commits intomainfrom May 5, 2026
Merged
Conversation
Wire minish v0.3.0 into the build as a test-only module. Seed defaults to the first 16 hex chars of the current git HEAD so each commit explores a fresh slice of the state space; override with -Dminish-seed=<u64> to reproduce a specific failing run. Plumbed through helpers.minish_seed so property tests share one source of truth. Smoke test runs 25 iterations of a trivial int property to catch regressions in the wiring (import, module shape, seed plumbing). DRIFT-mshkigwb
Bindings were serialized with metadata fields in insertion order (per `Binding.setField` at lockfile.zig:33-45), which meant two branches that converged on the same semantic state through different `setField` sequences produced different byte strings for the same binding — and git/jj flagged those as spurious textual merge conflicts. Sort metadata by key in `renderLineToWriter` so the on-disk form is a function of semantic state only. The sort buffer reuses the `scratch` allocator that `serializeToWriter` already threads through, so no new lifetime surface. Unblocks the upcoming serialization-under-reorder property test. DRIFT-hoocxemw
…ld reorder Property: semantic_eq(L1, L2) ⟹ serialize(L1) == serialize(L2). The generator builds a lockfile state with up to 6 bindings, each with 0–6 metadata fields drawn uniquely from a fixed key pool; the property builds two `[]Binding` slices from that state (forward order, forward fields vs. reverse order, reverse fields) and asserts byte-equal serialize outputs. Runs 200 iterations, seeded from helpers.minish_seed (git HEAD by default; -Dminish-seed=<u64> to reproduce). Verified that the test catches the insertion-order bug by temporarily reverting the canonicalization fix — property fails with a counterexample showing differing serializations within the first few iterations. DRIFT-zvfkxuyr
28c5aee to
db2eca1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a lockfile serialization bug where equivalent metadata could be written in different field orders depending on how the binding was built. That made semantically identical lockfile states produce different bytes, which in turn created avoidable textual merge conflicts.
The fix canonicalizes metadata field order during serialization and adds a property test that reproduces the class of bug: two lockfiles with the same bindings and fields, but different binding/field iteration order, must serialize to byte-identical output.
What changed
minishfor property-based tests — test-only dependency, with deterministic seed support via-Dminish-seed=<u64>.serializenow emits metadata fields sorted by key.serializeis invariant under binding and field reorder.The broader merge-resistance measurements and format experiments have been split out of this PR and kept for follow-up work.
Test plan
zig build test