11#![ allow( clippy:: unwrap_used, clippy:: expect_used) ]
22use std:: io:: Write ;
3+ use std:: path:: Path ;
34use std:: path:: PathBuf ;
45
56use codex_core:: find_conversation_path_by_id_str;
@@ -8,8 +9,8 @@ use uuid::Uuid;
89
910/// Create sessions/YYYY/MM/DD and write a minimal rollout file containing the
1011/// provided conversation id in the SessionMeta line. Returns the absolute path.
11- fn write_minimal_rollout_with_id ( codex_home : & TempDir , id : Uuid ) -> PathBuf {
12- let sessions = codex_home. path ( ) . join ( "sessions/2024/01/01" ) ;
12+ fn write_minimal_rollout_with_id ( codex_home : & Path , id : Uuid ) -> PathBuf {
13+ let sessions = codex_home. join ( "sessions/2024/01/01" ) ;
1314 std:: fs:: create_dir_all ( & sessions) . unwrap ( ) ;
1415
1516 let file = sessions. join ( format ! ( "rollout-2024-01-01T00-00-00-{id}.jsonl" ) ) ;
@@ -40,11 +41,41 @@ fn write_minimal_rollout_with_id(codex_home: &TempDir, id: Uuid) -> PathBuf {
4041async fn find_locates_rollout_file_by_id ( ) {
4142 let home = TempDir :: new ( ) . unwrap ( ) ;
4243 let id = Uuid :: new_v4 ( ) ;
43- let expected = write_minimal_rollout_with_id ( & home, id) ;
44+ let expected = write_minimal_rollout_with_id ( home. path ( ) , id) ;
4445
4546 let found = find_conversation_path_by_id_str ( home. path ( ) , & id. to_string ( ) )
4647 . await
4748 . unwrap ( ) ;
4849
4950 assert_eq ! ( found. unwrap( ) , expected) ;
5051}
52+
53+ #[ tokio:: test]
54+ async fn find_handles_gitignore_covering_codex_home_directory ( ) {
55+ let repo = TempDir :: new ( ) . unwrap ( ) ;
56+ let codex_home = repo. path ( ) . join ( ".codex" ) ;
57+ std:: fs:: create_dir_all ( & codex_home) . unwrap ( ) ;
58+ std:: fs:: write ( repo. path ( ) . join ( ".gitignore" ) , ".codex/**\n " ) . unwrap ( ) ;
59+ let id = Uuid :: new_v4 ( ) ;
60+ let expected = write_minimal_rollout_with_id ( & codex_home, id) ;
61+
62+ let found = find_conversation_path_by_id_str ( & codex_home, & id. to_string ( ) )
63+ . await
64+ . unwrap ( ) ;
65+
66+ assert_eq ! ( found, Some ( expected) ) ;
67+ }
68+
69+ #[ tokio:: test]
70+ async fn find_ignores_granular_gitignore_rules ( ) {
71+ let home = TempDir :: new ( ) . unwrap ( ) ;
72+ let id = Uuid :: new_v4 ( ) ;
73+ let expected = write_minimal_rollout_with_id ( home. path ( ) , id) ;
74+ std:: fs:: write ( home. path ( ) . join ( "sessions/.gitignore" ) , "*.jsonl\n " ) . unwrap ( ) ;
75+
76+ let found = find_conversation_path_by_id_str ( home. path ( ) , & id. to_string ( ) )
77+ . await
78+ . unwrap ( ) ;
79+
80+ assert_eq ! ( found, Some ( expected) ) ;
81+ }
0 commit comments