@@ -286,3 +286,102 @@ def test_modules_version_snapshot_content_valid(self):
286286 # reset the file
287287 with open (snap_file , "w" ) as fh :
288288 fh .write (content )
289+
290+ @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
291+ def test_modules_version_snapshot_content_sha_hash (self ):
292+ """Test linting a nf-test module with version information as SHA hash, which should fail.
293+
294+ Related to: https://github.com/nf-core/modules/issues/6505
295+ Fixed in: https://github.com/nf-core/tools/pull/3676
296+ """
297+ snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
298+ snap = json .load (snap_file .open ())
299+ content = snap_file .read_text ()
300+
301+ # Add a version entry with SHA hash format (should be flagged)
302+ snap ["my test" ]["content" ][0 ]["versions" ] = (
303+ "versions.yml:sha256,e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
304+ )
305+
306+ with open (snap_file , "w" ) as fh :
307+ json .dump (snap , fh )
308+
309+ module_lint = nf_core .modules .lint .ModuleLint (directory = self .nfcore_modules )
310+ module_lint .lint (print_results = False , module = "bpipe/test" )
311+
312+ # Should fail because version is using SHA hash instead of actual content
313+ version_content_failures = [x for x in module_lint .failed if x .lint_test == "test_snap_version_content" ]
314+ assert len (version_content_failures ) == 1 , (
315+ f"Expected 1 test_snap_version_content failure, got { len (version_content_failures )} "
316+ )
317+
318+ # reset the file
319+ with open (snap_file , "w" ) as fh :
320+ fh .write (content )
321+
322+ @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
323+ def test_modules_version_snapshot_content_mixed_scenario (self ):
324+ """Test linting with mixed version content - some valid, some hash format.
325+
326+ Related to: https://github.com/nf-core/modules/issues/6505
327+ Fixed in: https://github.com/nf-core/tools/pull/3676
328+ """
329+ snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
330+ snap = json .load (snap_file .open ())
331+ content = snap_file .read_text ()
332+
333+ # Create a scenario with multiple tests - one with hash, one with valid content
334+ snap ["test_with_hash" ] = {"content" : [{"versions" : "versions.yml:md5,949da9c6297b613b50e24c421576f3f1" }]}
335+ snap ["test_with_valid_content" ] = {"content" : [{"versions" : {"BPIPE" : {"bpipe" : "0.9.11" }}}]}
336+
337+ with open (snap_file , "w" ) as fh :
338+ json .dump (snap , fh )
339+
340+ module_lint = nf_core .modules .lint .ModuleLint (directory = self .nfcore_modules )
341+ module_lint .lint (print_results = False , module = "bpipe/test" )
342+
343+ # Should have failure for the hash test
344+ version_content_failures = [x for x in module_lint .failed if x .lint_test == "test_snap_version_content" ]
345+ assert len (version_content_failures ) >= 1 , "Expected at least 1 failure for hash format"
346+
347+ # Should have pass for the valid content test
348+ version_content_passed = [
349+ x
350+ for x in module_lint .passed
351+ if (hasattr (x , "lint_test" ) and x .lint_test == "test_snap_version_content" )
352+ or (isinstance (x , tuple ) and len (x ) > 0 and x [0 ] == "test_snap_version_content" )
353+ ]
354+ assert len (version_content_passed ) >= 1 , "Expected at least 1 pass for valid content"
355+
356+ # reset the file
357+ with open (snap_file , "w" ) as fh :
358+ fh .write (content )
359+
360+ @pytest .mark .issue ("https://github.com/nf-core/modules/issues/6505" )
361+ def test_modules_version_snapshot_no_version_content (self ):
362+ """Test linting when no version information is present - should not trigger version content check.
363+
364+ Related to: https://github.com/nf-core/modules/issues/6505
365+ Fixed in: https://github.com/nf-core/tools/pull/3676
366+ """
367+ snap_file = self .bpipe_test_module_path / "tests" / "main.nf.test.snap"
368+ snap = json .load (snap_file .open ())
369+ content = snap_file .read_text ()
370+
371+ # Remove version information entirely
372+ if "content" in snap ["my test" ] and snap ["my test" ]["content" ]:
373+ snap ["my test" ]["content" ][0 ].pop ("versions" , None )
374+
375+ with open (snap_file , "w" ) as fh :
376+ json .dump (snap , fh )
377+
378+ module_lint = nf_core .modules .lint .ModuleLint (directory = self .nfcore_modules )
379+ module_lint .lint (print_results = False , module = "bpipe/test" )
380+
381+ # Should not have version content check failures when no version data present
382+ version_content_failures = [x for x in module_lint .failed if x .lint_test == "test_snap_version_content" ]
383+ assert len (version_content_failures ) == 0 , "Should not have version content failures when no versions present"
384+
385+ # reset the file
386+ with open (snap_file , "w" ) as fh :
387+ fh .write (content )
0 commit comments