@@ -215,6 +215,78 @@ mod proof_tests {
215215 Some ( & b"value3" . to_vec( ) )
216216 ) ;
217217 }
218+
219+ #[ test]
220+ fn get_keys_at_ref_errors_when_committed_hash_mappings_are_missing ( ) {
221+ let temp_dir = TempDir :: new ( ) . expect ( "Failed to create temp dir" ) ;
222+ let repo_path = temp_dir. path ( ) . to_str ( ) . unwrap ( ) ;
223+
224+ std:: process:: Command :: new ( "git" )
225+ . args ( [ "init" ] )
226+ . current_dir ( repo_path)
227+ . output ( )
228+ . expect ( "Failed to initialize git repo" ) ;
229+ std:: process:: Command :: new ( "git" )
230+ . args ( [ "config" , "user.name" , "Test User" ] )
231+ . current_dir ( repo_path)
232+ . output ( )
233+ . expect ( "Failed to set git user name" ) ;
234+ std:: process:: Command :: new ( "git" )
235+ . args ( [ "config" , "user.email" , "test@example.com" ] )
236+ . current_dir ( repo_path)
237+ . output ( )
238+ . expect ( "Failed to set git user email" ) ;
239+
240+ let dataset_path = temp_dir. path ( ) . join ( "dataset" ) ;
241+ std:: fs:: create_dir ( & dataset_path) . expect ( "Failed to create dataset directory" ) ;
242+
243+ let _cwd_guard = CwdGuard :: set ( & dataset_path) ;
244+ let mut store =
245+ GitVersionedKvStore :: < 32 > :: init ( & dataset_path) . expect ( "Failed to initialize store" ) ;
246+
247+ store
248+ . insert ( b"key1" . to_vec ( ) , b"value1" . to_vec ( ) )
249+ . expect ( "Failed to insert key1" ) ;
250+ let good_commit = store. commit ( "Add key1" ) . expect ( "Failed to commit" ) ;
251+ let good_keys = store
252+ . get_keys_at_ref ( & good_commit. to_hex ( ) . to_string ( ) )
253+ . expect ( "good commit should be readable" ) ;
254+ assert_eq ! ( good_keys. get( & b"key1" . to_vec( ) ) , Some ( & b"value1" . to_vec( ) ) ) ;
255+
256+ drop ( store) ;
257+
258+ let rm_output = std:: process:: Command :: new ( "git" )
259+ . args ( [ "rm" , "dataset/prolly_hash_mappings" ] )
260+ . current_dir ( repo_path)
261+ . output ( )
262+ . expect ( "git rm failed to run" ) ;
263+ assert ! (
264+ rm_output. status. success( ) ,
265+ "git rm failed: {}" ,
266+ String :: from_utf8_lossy( & rm_output. stderr)
267+ ) ;
268+ let commit_output = std:: process:: Command :: new ( "git" )
269+ . args ( [ "commit" , "-m" , "Remove hash mappings" ] )
270+ . current_dir ( repo_path)
271+ . output ( )
272+ . expect ( "git commit failed to run" ) ;
273+ assert ! (
274+ commit_output. status. success( ) ,
275+ "git commit failed: {}" ,
276+ String :: from_utf8_lossy( & commit_output. stderr)
277+ ) ;
278+
279+ let store =
280+ GitVersionedKvStore :: < 32 > :: open ( & dataset_path) . expect ( "corrupt store still opens" ) ;
281+ let err = store
282+ . get_keys_at_ref ( "HEAD" )
283+ . expect_err ( "missing committed mappings must not look like an empty store" ) ;
284+
285+ assert ! (
286+ err. to_string( ) . contains( "prolly_hash_mappings" ) ,
287+ "unexpected error: {err}"
288+ ) ;
289+ }
218290}
219291
220292#[ cfg( test) ]
0 commit comments