Skip to content

Fix/rust deterministic order#21

Open
corepacket wants to merge 3 commits intoSBOMit:masterfrom
corepacket:fix/rust-deterministic-order
Open

Fix/rust deterministic order#21
corepacket wants to merge 3 commits intoSBOMit:masterfrom
corepacket:fix/rust-deterministic-order

Conversation

@corepacket
Copy link
Copy Markdown

@corepacket corepacket commented Apr 6, 2026

Fixes #22

Background

Previously, the RustResolver iterated directly over the chosenByName map to build the final list of resolved packages. Because Go does not guarantee a consistent map iteration order, running SBOM extraction multiple times on the same target could result in non-deterministic structural outputs. While the generated data remained accurate, the changing order caused headaches when diffing SBOMs, performing auditing, or enforcing reproducibility across builds.

Changes

  • Extracted the keys from the chosenByName map.
  • Applied sort.Strings() to ensure lexicographical sorting of the crate names prior to array append.
  • Added pkg/resolver/rust_test.go with unit test assertions explicitly validating deterministic ordering and output stability across multiple identical runs.

Testing

  • TestRustResolver_DeterministicOrder: Validates that crates output sequentially according to alphabetical sorting.
  • TestRustResolver_StableOutput: Verifies that multiple parsing executions on the same inputs emit the exact same package structures.
  • All standard go test ./... test suites passed downstream.

As requested during code review:

- The '--exclude' flag is entirely removed from the CLI interface.

- Pattern matching now utilizes 'doublestar' correctly across path boundaries.

- Instead of silently dropping files, anomalous files (e.g. '.git/', '*.log') generate a warning to stderr while preserving output integrity.

Signed-off-by: corepacket <wbn453177@gmail.com>
Signed-off-by: corepacket <wbn453177@gmail.com>
This change ensures reproducible SBOM output by replacing non-deterministic Go map iteration with sorted iteration of package names.

Signed-off-by: corepacket <wbn453177@gmail.com>
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.

Rust resolver produces non-deterministic package ordering

2 participants