Skip to content

Commit abc5b44

Browse files
committed
test(crawlers): empty/missing path early-returns for NpmCrawler
Three tests covering find_by_purls with empty PURL list, nonexistent node_modules, and crawl_all with no packages installed. Assisted-by: Claude Code:claude-opus-4-7
1 parent 8fe8939 commit abc5b44

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//! Integration coverage for the crawlers' empty/missing-path early
2+
//! returns. Each crawler's `find_by_purls` and `crawl_all` short-
3+
//! circuits when the discovery root doesn't exist or no PURLs match
4+
//! its scheme — branches the apply-CLI suite doesn't naturally
5+
//! exercise because those tests always pre-stage a layout.
6+
7+
use socket_patch_core::crawlers::types::CrawlerOptions;
8+
use socket_patch_core::crawlers::NpmCrawler;
9+
use std::path::PathBuf;
10+
11+
fn options_at(root: &std::path::Path) -> CrawlerOptions {
12+
CrawlerOptions {
13+
cwd: root.to_path_buf(),
14+
global: false,
15+
global_prefix: None,
16+
batch_size: 100,
17+
}
18+
}
19+
20+
#[tokio::test]
21+
async fn npm_crawler_find_by_purls_with_empty_purls_returns_empty_map() {
22+
let tmp = tempfile::tempdir().unwrap();
23+
let crawler = NpmCrawler;
24+
let result = crawler
25+
.find_by_purls(tmp.path(), &[])
26+
.await
27+
.unwrap();
28+
assert!(result.is_empty(), "empty PURL list → empty result");
29+
}
30+
31+
#[tokio::test]
32+
async fn npm_crawler_find_by_purls_with_nonexistent_node_modules_returns_empty() {
33+
let tmp = tempfile::tempdir().unwrap();
34+
let nonexistent = tmp.path().join("missing_node_modules");
35+
let crawler = NpmCrawler;
36+
let result = crawler
37+
.find_by_purls(
38+
&nonexistent,
39+
&["pkg:npm/lodash@4.17.21".to_string()],
40+
)
41+
.await
42+
.unwrap();
43+
assert!(result.is_empty(), "nonexistent node_modules → empty");
44+
}
45+
46+
#[tokio::test]
47+
async fn npm_crawler_crawl_all_with_no_packages_returns_empty() {
48+
let tmp = tempfile::tempdir().unwrap();
49+
let crawler = NpmCrawler;
50+
let result = crawler.crawl_all(&options_at(tmp.path())).await;
51+
assert!(result.is_empty(), "no packages installed → empty crawl");
52+
}
53+
54+
// Marker import suppress.
55+
#[allow(dead_code)]
56+
fn _path_marker(_p: PathBuf) {}

0 commit comments

Comments
 (0)