Skip to content

Add additional test for hasher#6198

Merged
pditommaso merged 5 commits intonextflow-io:masterfrom
rcannood:fix-hashing-bis
Jun 19, 2025
Merged

Add additional test for hasher#6198
pditommaso merged 5 commits intonextflow-io:masterfrom
rcannood:fix-hashing-bis

Conversation

@rcannood
Copy link
Contributor

@rcannood rcannood commented Jun 18, 2025

This PR is related to a bug that was introduced by merging #6197 in order to fix #6112.

By making hashDirSha256 invariant to the order in which data is processed, the link between the file path and its hash is lost.

This PR adds a unit test where the filename of two files are swapped, resulting in hashDirSha256 returning the same hash (while it shouldn't).

Credits go to @DriesSchaumont for noticing the issue.


Running the tests added by this PR yields:

$ ./gradlew :nf-commons:test

> Task :nf-commons:test

HashBuilderTest > directories with same content but different structure should yield different hashes FAILED
    org.spockframework.runtime.ConditionNotSatisfiedError at HashBuilderTest.groovy:154

806 tests completed, 1 failed

> Task :nf-commons:test FAILED

[Incubating] Problems report is available at: file:///home/rcannood/workspace/rcannood/nextflow/build/reports/problems/problems-report.html

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':nf-commons:test'.
> There were failing tests. See the report at: file:///home/rcannood/workspace/rcannood/nextflow/modules/nf-commons/build/reports/tests/test/index.html

* Try:
> Run with --scan to get full insights.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.14/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 9s
24 actionable tasks: 2 executed, 6 from cache, 16 up-to-date

I tried going over the different versions of HashBuilder.java in the commits in #6113 but for all of these commits, the tests are passing:

Co-authored-by: DriesSchaumont <5946712+DriesSchaumont@users.noreply.github.com>
Signed-off-by: Robrecht Cannoodt <rcannood@gmail.com>
@netlify
Copy link

netlify bot commented Jun 18, 2025

Deploy Preview for nextflow-docs-staging canceled.

Name Link
🔨 Latest commit 1aefe65
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs-staging/deploys/6853c653a160d100088a4b5c

Co-authored-by: DriesSchaumont <5946712+DriesSchaumont@users.noreply.github.com>
Signed-off-by: Robrecht Cannoodt <rcannood@gmail.com>
@rcannood
Copy link
Contributor Author

rcannood commented Jun 18, 2025

I added a fix to this PR as well. Let me know if it's acceptable.

Check whether this fix solves the issue:

$ ./gradlew :nf-commons:test

> Task :nextflow:compileGroovy
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

[Incubating] Problems report is available at: file:///home/rcannood/workspace/rcannood/nextflow/build/reports/problems/problems-report.html

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.14/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 26s
25 actionable tasks: 9 executed, 16 up-to-date

Signed-off-by: Ben Sherman <bentshermann@gmail.com>
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
Signed-off-by: Robrecht Cannoodt <rcannood@gmail.com>
Copy link
Member

@pditommaso pditommaso left a comment

Choose a reason for hiding this comment

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

Well done

@pditommaso pditommaso merged commit ae07c96 into nextflow-io:master Jun 19, 2025
5 of 7 checks passed
@rcannood rcannood deleted the fix-hashing-bis branch June 19, 2025 09:00
pditommaso added a commit that referenced this pull request Aug 20, 2025
This implements improved order-independent hashing for directories and
unordered collections, controlled by the NXF_PATCH_UNORDERED_DIR environment
variable.

Key improvements:
- Directory traversal order no longer affects hash values
- Unordered collections (Sets, Bags) produce consistent hashes
- Addresses edge cases with similar directory contents (fixes #6198)
- Uses commutative byte addition for order independence
- Maintains backward compatibility (disabled by default)

The patch can be enabled by setting NXF_PATCH_UNORDERED_DIR=true.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
pditommaso added a commit that referenced this pull request Sep 3, 2025
This implements improved order-independent hashing for directories and
unordered collections, controlled by the NXF_PATCH_DIRECTORY_HASH environment
variable.

Key improvements:
- Directory traversal order no longer affects hash values
- Unordered collections (Sets, Bags) produce consistent hashes
- Addresses edge cases with similar directory contents (fixes #6198)
- Uses commutative byte addition for order independence
- Maintains backward compatibility (disabled by default)

The patch can be enabled by setting NXF_PATCH_DIRECTORY_HASH =true.



Co-authored-by: Claude <noreply@anthropic.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.

Incorrect hash when staging repository directory

3 participants