1- use anyhow:: { Context , Result , bail } ;
1+ use anyhow:: { bail , Context , Result } ;
22use md5:: { Digest , Md5 } ;
33use serde:: { Deserialize , Serialize } ;
44use std:: collections:: HashMap ;
@@ -175,10 +175,7 @@ pub fn validate_checksums(
175175///
176176/// * `Result<()>` - Ok if the live version matches the stored one, Err otherwise
177177pub fn validate_haddock3_version_live ( checksum_file : & Path ) -> Result < ( ) > {
178- let stored_content =
179- fs:: read_to_string ( checksum_file) . context ( "Failed to read checksum file" ) ?;
180- let stored_data: ChecksumData =
181- serde_json:: from_str ( & stored_content) . context ( "Failed to parse checksum file" ) ?;
178+ let stored_data = read_checksum_data ( checksum_file) ?;
182179
183180 let live_version = crate :: utils:: get_haddock3_version ( ) ?;
184181
@@ -193,6 +190,20 @@ pub fn validate_haddock3_version_live(checksum_file: &Path) -> Result<()> {
193190 Ok ( ( ) )
194191}
195192
193+ fn read_checksum_data ( checksum_file : & Path ) -> Result < ChecksumData > {
194+ let stored_content =
195+ fs:: read_to_string ( checksum_file) . context ( "Failed to read checksum file" ) ?;
196+ serde_json:: from_str ( & stored_content) . context ( "Failed to parse checksum file" )
197+ }
198+
199+ /// Returns the haddock3 version recorded in `checksum.json` when the benchmark started.
200+ ///
201+ /// Used to embed the expected version into a generated SLURM job script so it can be
202+ /// re-checked from inside the job itself, after `slurm_prologue` has run.
203+ pub fn expected_haddock3_version ( checksum_file : & Path ) -> Result < String > {
204+ Ok ( read_checksum_data ( checksum_file) ?. haddock3_version )
205+ }
206+
196207fn find_modified (
197208 current_checksums : HashMap < String , String > ,
198209 stored_checksums : HashMap < String , String > ,
@@ -265,7 +276,7 @@ mod tests {
265276 use super :: * ;
266277 use std:: collections:: HashMap ;
267278 use std:: io:: Write ;
268- use tempfile:: { NamedTempFile , tempdir } ;
279+ use tempfile:: { tempdir , NamedTempFile } ;
269280
270281 #[ test]
271282 fn test_calculate_checksum ( ) {
@@ -433,7 +444,7 @@ mod tests {
433444 let mut stored = HashMap :: new ( ) ;
434445 stored. insert ( "file1.txt" . to_string ( ) , "checksum1_changed" . to_string ( ) ) ; // Changed
435446 stored. insert ( "file4.txt" . to_string ( ) , "checksum4" . to_string ( ) ) ; // Removed
436- // file2.txt and file3.txt are new
447+ // file2.txt and file3.txt are new
437448
438449 // Find modified files
439450 let error_msg = find_modified ( current, stored) ;
@@ -570,4 +581,19 @@ mod tests {
570581 let result = validate_haddock3_version_live ( & checksum_file) ;
571582 assert ! ( result. is_err( ) ) ;
572583 }
584+
585+ #[ test]
586+ fn test_expected_haddock3_version ( ) {
587+ let temp_dir = tempdir ( ) . unwrap ( ) ;
588+ let checksum_file = temp_dir. path ( ) . join ( "checksum.json" ) ;
589+
590+ let data = ChecksumData {
591+ files : HashMap :: new ( ) ,
592+ haddock3_version : "2026.3.0" . to_string ( ) ,
593+ } ;
594+ fs:: write ( & checksum_file, serde_json:: to_string_pretty ( & data) . unwrap ( ) ) . unwrap ( ) ;
595+
596+ let version = expected_haddock3_version ( & checksum_file) . unwrap ( ) ;
597+ assert_eq ! ( version, "2026.3.0" ) ;
598+ }
573599}
0 commit comments