()
| 248 | |
| 249 | #[test] |
| 250 | fn test_cache_stores_failed_reads() { |
| 251 | let temp = TempDir::new().unwrap(); |
| 252 | let project_root = temp.path(); |
| 253 | |
| 254 | // Write requirements.txt so detect will call get_file_content on it. |
| 255 | // get_file_content caches None for any path it cannot read; here the file |
| 256 | // exists, so the cache entry will be Some. A separate missing path is |
| 257 | // never even attempted by detect (collect_package_names guards on |
| 258 | // metadata.paths first), so we assert its absence from the cache to |
| 259 | // confirm detect does not speculatively read non-existent paths. |
| 260 | let requirements_path = project_root.join("requirements.txt"); |
| 261 | fs::write(&requirements_path, "requests\n").unwrap(); |
| 262 | |
| 263 | let detector = catalog_detector(); |
| 264 | let mut cache = ContentCache::new(); |
| 265 | let _detections = detector.detect(project_root, &mut cache).unwrap(); |
| 266 | |
| 267 | // The requirements.txt that was read must be present in the cache. |
| 268 | // get_file_content stores entries under the canonicalized path, so resolve |
| 269 | // it the same way before asserting. |
| 270 | let canonical_requirements = requirements_path |
| 271 | .canonicalize() |
| 272 | .expect("requirements.txt should be canonicalizable"); |
| 273 | assert!( |
| 274 | cache.contains_key(&canonical_requirements), |
| 275 | "ContentCache should contain an entry for requirements.txt after detect" |
| 276 | ); |
| 277 | assert!( |
| 278 | cache[&canonical_requirements].is_some(), |
| 279 | "Cache entry for requirements.txt should be Some (file was readable)" |
| 280 | ); |
| 281 | |
| 282 | // A path that was never attempted must be absent (detect does not |
| 283 | // speculatively populate None entries for files it never reads). |
| 284 | let missing_path = project_root.join("nonexistent_dep_file.txt"); |
| 285 | assert!( |
| 286 | !cache.contains_key(&missing_path), |
| 287 | "ContentCache must not contain an entry for a path detect never attempted" |
| 288 | ); |
| 289 | } |
nothing calls this directly
no test coverage detected