cora-code 0.13.0

CLI-first AI code review — BYOK, diff/scan/branch, pre-commit hooks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
/// Index-powered deterministic scanners — rules that require symbol graph intelligence.
///
/// Unlike regex-based scanners (secrets, security), these scanners query the
/// symbol index to detect issues impossible with pattern matching alone:
/// - Unused imports (needs cross-reference between imports and usages)
/// - Dead code in changed files (needs caller graph)
/// - Breaking changes (needs cross-file caller resolution)
use tracing::debug;

use crate::engine::Severity;
use crate::engine::diff_parser::{DiffLineType, FileChunk};
use crate::engine::rules::types::RuleFinding;
use crate::index::graph;

/// Check if a file path matches any of the skip patterns.
/// Supports simple glob patterns:
/// - Exact: `"src/main.ts"` → full path match
/// - Suffix: `"*.config.ts"` → basename ends with `.config.ts`
/// - Prefix: `"vite.config.*"` → basename starts with `vite.config.`
/// - Any-dir name: `"**/something"` → basename or path suffix match
/// - Any-dir wildcard: `"**/phaser/**"` → any path component equals `phaser`
/// - Prefix-dir: `"src/engine/**"` → file under `src/engine/`
/// - Double wildcard ext: `"**/*.test.ts"` → basename ends with `.test.ts`
pub fn should_skip_file(file_path: &str, skip_patterns: &[String]) -> bool {
    if skip_patterns.is_empty() {
        return false;
    }

    let basename = std::path::Path::new(file_path)
        .file_name()
        .map(|n| n.to_string_lossy().to_string())
        .unwrap_or_default();

    for pattern in skip_patterns {
        // Exact match (e.g. "src/main.ts")
        if file_path == pattern {
            return true;
        }
        // Basename exact match
        if basename == *pattern {
            return true;
        }
        if !pattern.contains('*') {
            continue;
        }

        // "**/*.ext" → suffix match on basename (any directory)
        if let Some(rest) = pattern.strip_prefix("**/") {
            if let Some(ext) = rest.strip_prefix("*.") {
                if basename.ends_with(ext) {
                    return true;
                }
            }
        }

        // "*.ext" → suffix match on basename
        if pattern.starts_with("*.") {
            let suffix = &pattern[1..]; // ".config.ts"
            if basename.ends_with(suffix) {
                return true;
            }
        }

        // "name.*" → prefix match on basename
        if pattern.ends_with(".*") {
            let prefix = &pattern[..pattern.len() - 2]; // "vite.config"
            if basename.starts_with(prefix) {
                return true;
            }
        }

        // "**/name/**" → any path component equals "name"
        if let Some(dir) = pattern
            .strip_prefix("**/")
            .and_then(|s| s.strip_suffix("/**"))
        {
            let components: Vec<&str> = file_path.split('/').collect();
            if components.contains(&dir) {
                return true;
            }
        }

        // "dir/**" → file under dir/
        if let Some(dir) = pattern.strip_suffix("/**") {
            if file_path.starts_with(&format!("{dir}/")) || file_path == dir {
                return true;
            }
        }

        // "**/name" → match basename or path suffix
        if let Some(rest) = pattern.strip_prefix("**/") {
            if rest.contains('*') {
                continue;
            }
            if basename == rest || file_path.ends_with(&format!("/{rest}")) {
                return true;
            }
        }
    }

    false
}

/// Scan for unused imports across all changed files using the symbol index.
///
/// For each file with IMPORTS edges, checks if each imported symbol is actually
/// referenced in the file. Works only when a symbol index is available.
///
/// Returns `Vec<RuleFinding>` with severity `Minor` for each unused import.
pub fn scan_unused_imports(
    chunks: &[FileChunk],
    project_root: &std::path::Path,
    max_findings: usize,
    skip_patterns: &[String],
) -> Vec<RuleFinding> {
    let conn = match crate::index::open_global_index() {
        Ok(c) => c,
        Err(_) => {
            debug!("no global index available — skipping unused import scan");
            return Vec::new();
        }
    };

    let project_id = match crate::index::ensure_project(&conn, project_root) {
        Ok(id) => id,
        Err(_) => {
            debug!("failed to get project_id — skipping unused import scan");
            return Vec::new();
        }
    };

    let mut findings = Vec::new();

    // Collect unique changed files
    let mut seen_files = std::collections::HashSet::new();
    for chunk in chunks {
        let file = chunk
            .new_path
            .as_deref()
            .or(chunk.old_path.as_deref())
            .unwrap_or("unknown");

        // Skip deleted files (no new_path) and unknown
        if chunk.new_path.is_none() {
            continue;
        }

        // Skip files matching skip patterns
        if should_skip_file(file, skip_patterns) {
            continue;
        }

        // Only check files with actual additions
        let has_additions = chunk
            .chunks
            .iter()
            .any(|h| h.lines.iter().any(|l| l.line_type == DiffLineType::Add));
        if !has_additions {
            continue;
        }

        if seen_files.insert(file.to_string()) {
            match graph::find_unused_imports(&conn, file, project_id) {
                Ok(unused) => {
                    for u in &unused {
                        findings.push(RuleFinding {
                            rule_id: "index-unused-import".to_string(),
                            file: u.file.clone(),
                            line: u.line,
                            severity: Severity::Minor,
                            title: format!("[index-unused-import] Unused import: {}", u.target),
                            body: format!(
                                "Import `{}` is never used in this file. \
                                 Consider removing it to keep imports clean.",
                                u.target
                            ),
                        });
                    }
                }
                Err(e) => {
                    debug!("unused import scan failed for {}: {}", file, e);
                }
            }
        }

        if findings.len() >= max_findings {
            break;
        }
    }

    // Cap findings
    findings.truncate(max_findings);

    debug!(count = findings.len(), "unused import scan complete");
    findings
}

/// Scan for dead code (unreachable symbols) in changed files using the symbol index.
///
/// For each changed file, finds functions/methods with zero callers in the
/// project. Excludes well-known names (main, new, drop, etc.) and test functions.
///
/// Returns `Vec<RuleFinding>` with severity `Info` for each dead symbol.
pub fn scan_dead_code_in_review(
    chunks: &[FileChunk],
    project_root: &std::path::Path,
    max_findings: usize,
    skip_patterns: &[String],
) -> Vec<RuleFinding> {
    let conn = match crate::index::open_global_index() {
        Ok(c) => c,
        Err(_) => {
            debug!("no global index available — skipping dead code scan");
            return Vec::new();
        }
    };

    let project_id = match crate::index::ensure_project(&conn, project_root) {
        Ok(id) => id,
        Err(_) => {
            debug!("failed to get project_id — skipping dead code scan");
            return Vec::new();
        }
    };

    let mut findings = Vec::new();

    let mut seen_files = std::collections::HashSet::new();
    for chunk in chunks {
        let file = chunk
            .new_path
            .as_deref()
            .or(chunk.old_path.as_deref())
            .unwrap_or("unknown");

        if chunk.new_path.is_none() {
            continue;
        }

        if should_skip_file(file, skip_patterns) {
            continue;
        }

        if seen_files.insert(file.to_string()) {
            match graph::find_dead_code_in_file(&conn, file, project_id, false) {
                Ok(dead) => {
                    for d in &dead {
                        findings.push(RuleFinding {
                            rule_id: "index-dead-code".to_string(),
                            file: d.file.clone(),
                            line: d.line,
                            severity: Severity::Info,
                            title: format!("[index-dead-code] Potentially dead code: {}", d.name),
                            body: format!(
                                "Function `{}` ({}) has no callers in the \
                                 project. Verify it's not called via reflection, \
                                 trait dispatch, or external entry points.",
                                d.name, d.kind
                            ),
                        });
                    }
                }
                Err(e) => {
                    debug!("dead code scan failed for {}: {}", file, e);
                }
            }
        }

        if findings.len() >= max_findings {
            break;
        }
    }

    findings.truncate(max_findings);

    debug!(count = findings.len(), "dead code scan complete");
    findings
}

/// Scan for potential breaking changes — removed or modified public symbols
/// that have existing callers in the project.
///
/// Analyzes the diff for removed lines containing public symbol definitions,
/// then cross-references the index to find callers.
///
/// Returns `Vec<RuleFinding>` with severity `Major` for each breaking change.
pub fn scan_breaking_changes(
    chunks: &[FileChunk],
    project_root: &std::path::Path,
    max_findings: usize,
    skip_patterns: &[String],
) -> Vec<RuleFinding> {
    let conn = match crate::index::open_global_index() {
        Ok(c) => c,
        Err(_) => {
            debug!("no global index available — skipping breaking change scan");
            return Vec::new();
        }
    };

    let project_id = match crate::index::ensure_project(&conn, project_root) {
        Ok(id) => id,
        Err(_) => {
            debug!("failed to get project_id — skipping breaking change scan");
            return Vec::new();
        }
    };

    let mut findings = Vec::new();

    // Patterns for public symbol removal across languages.
    // These are heuristic — not all removed lines match, but high-signal ones do.
    let removal_patterns: &[&str] = &[
        // Rust: pub fn/struct/enum/mod
        r"(?m)^(?:pub\s+)?(?:fn|struct|enum|trait|mod|type|const|static)\s+(\w+)",
        // TypeScript/JS: export function/const/class
        r"(?m)^export\s+(?:async\s+)?(?:function|const|class|interface|type)\s+(\w+)",
        // Go: func and type declarations
        r"(?m)^(?:func|type|var|const)\s+(\w+)",
        // Python: def and class
        r"(?m)^(?:async\s+)?(?:def|class)\s+(\w+)",
    ];

    let compiled: Vec<std::sync::Arc<regex::Regex>> = removal_patterns
        .iter()
        .filter_map(|p| regex::Regex::new(p).ok())
        .map(std::sync::Arc::new)
        .collect();

    for chunk in chunks {
        let file = chunk
            .new_path
            .as_deref()
            .or(chunk.old_path.as_deref())
            .unwrap_or("unknown");

        if should_skip_file(file, skip_patterns) {
            continue;
        }

        for hunk in &chunk.chunks {
            for line in &hunk.lines {
                // Only look at removed lines (old code being deleted)
                if line.line_type != DiffLineType::Remove {
                    continue;
                }

                // Try to match a public symbol definition being removed
                for re in &compiled {
                    if let Some(caps) = re.captures(&line.content) {
                        let symbol_name = &caps[1];

                        // Skip trivially short names
                        if symbol_name.len() < 3 {
                            continue;
                        }

                        let line_no = line.old_line_no.unwrap_or(0);

                        // Check if this symbol has callers in the index
                        match graph::find_callers(&conn, project_id, symbol_name, 10) {
                            Ok(callers) if !callers.is_empty() => {
                                let caller_list = callers
                                    .iter()
                                    .take(3)
                                    .map(|c| format!("{} ({}:{})", c.caller, c.file, c.line))
                                    .collect::<Vec<_>>()
                                    .join(", ");

                                findings.push(RuleFinding {
                                    rule_id: "index-breaking-change".to_string(),
                                    file: file.to_string(),
                                    line: line_no,
                                    severity: Severity::Major,
                                    title: format!(
                                        "[index-breaking-change] Removing `{}` \
                                         breaks {} caller(s)",
                                        symbol_name,
                                        callers.len()
                                    ),
                                    body: format!(
                                        "Symbol `{}` is being removed but has {} \
                                         caller(s): {}. This is a breaking change.",
                                        symbol_name,
                                        callers.len(),
                                        caller_list
                                    ),
                                });
                            }
                            _ => continue,
                        }
                    }
                }
            }
        }

        if findings.len() >= max_findings {
            break;
        }
    }

    findings.truncate(max_findings);

    debug!(count = findings.len(), "breaking change scan complete");
    findings
}

/// Scan a full project for index-based findings (unused imports + dead code).
/// Designed for `cora scan` which operates on file paths, not diffs.
/// Returns findings for any file in the project that has an index DB.
pub fn scan_project_index(
    root: &std::path::Path,
    files: &[crate::engine::scanner::FileEntry],
    max_findings: usize,
    skip_patterns: &[String],
) -> Vec<crate::engine::ReviewIssue> {
    use crate::engine::ReviewIssue;

    let mut findings = Vec::new();

    let conn = match crate::index::open_global_index() {
        Ok(c) => c,
        Err(_) => {
            debug!("no global index available — skipping project index scan");
            return findings;
        }
    };

    let project_id = match crate::index::ensure_project(&conn, root) {
        Ok(id) => id,
        Err(_) => {
            debug!("failed to get project_id — skipping project index scan");
            return findings;
        }
    };

    // Scan for unused imports across all files in the scan set
    let mut seen_files = std::collections::HashSet::new();
    for entry in files {
        if should_skip_file(&entry.path, skip_patterns) {
            continue;
        }
        if seen_files.insert(entry.path.clone()) {
            match graph::find_unused_imports(&conn, &entry.path, project_id) {
                Ok(unused) => {
                    for u in &unused {
                        findings.push(ReviewIssue {
                            file: u.file.clone(),
                            line: Some(u.line),
                            severity: crate::engine::Severity::Minor,
                            issue_type: Some("index".into()),
                            title: format!("[index-unused-import] Unused import: {}", u.target),
                            body: format!(
                                "Import `{}` is never used in this file. \
                                 Consider removing it to keep imports clean.",
                                u.target
                            ),
                            suggested_fix: None,
                        });
                    }
                }
                Err(e) => {
                    debug!("unused import scan failed for {}: {}", entry.path, e);
                }
            }
        }
        if findings.len() >= max_findings {
            break;
        }
    }

    if findings.len() >= max_findings {
        return findings;
    }

    // Scan for dead code in the indexed project
    let opts = graph::DeadCodeOptions::default();
    match graph::find_dead_code(&conn, project_id, &opts) {
        Ok(dead) => {
            for func in dead.into_iter().take(max_findings - findings.len()) {
                findings.push(ReviewIssue {
                    file: func.file.clone(),
                    line: Some(func.line),
                    severity: crate::engine::Severity::Info,
                    issue_type: Some("index".into()),
                    title: format!("[index-dead-code] Potentially dead code: {}", func.name),
                    body: format!(
                        "Function `{}` ({}) has no callers in the \
                         project. Verify it's not called via reflection, \
                         trait dispatch, or external entry points.",
                        func.name, func.kind
                    ),
                    suggested_fix: None,
                });
            }
        }
        Err(e) => {
            debug!("dead code scan failed: {}", e);
        }
    }

    findings
}

#[cfg(test)]
mod tests {
    use super::*;

    /// Helper to create a minimal FileChunk for testing.
    fn make_chunk(new_path: &str, content: &str) -> FileChunk {
        FileChunk {
            old_path: Some(new_path.to_string()),
            new_path: Some(new_path.to_string()),
            language: "rust".to_string(),
            chunks: vec![crate::engine::diff_parser::DiffHunk {
                old_start: 1,
                old_count: 0,
                new_start: 1,
                new_count: 0,
                header: "@@ -1 +1 @@".to_string(),
                lines: content
                    .lines()
                    .map(|l| crate::engine::diff_parser::DiffLine {
                        content: l.to_string(),
                        line_type: if l.starts_with('+') {
                            DiffLineType::Add
                        } else if l.starts_with('-') {
                            DiffLineType::Remove
                        } else {
                            DiffLineType::Context
                        },
                        old_line_no: None,
                        new_line_no: None,
                    })
                    .collect(),
            }],
            is_binary: false,
            is_deleted: false,
            is_new: false,
        }
    }

    #[test]
    fn scan_unused_imports_no_index_graceful() {
        // No index available — should return empty, not panic
        let chunks = vec![make_chunk("src/main.rs", "+use std::collections::HashMap;")];
        let findings = scan_unused_imports(&chunks, std::path::Path::new("/nonexistent"), 10, &[]);
        assert!(
            findings.is_empty(),
            "should gracefully return empty without index"
        );
    }

    #[test]
    fn scan_dead_code_no_index_graceful() {
        let chunks = vec![make_chunk("src/main.rs", "+fn foo() {}")];
        let findings =
            scan_dead_code_in_review(&chunks, std::path::Path::new("/nonexistent"), 10, &[]);
        assert!(
            findings.is_empty(),
            "should gracefully return empty without index"
        );
    }

    #[test]
    fn scan_breaking_changes_no_index_graceful() {
        let chunks = vec![make_chunk("src/main.rs", "-pub fn important_api() {}")];
        let findings =
            scan_breaking_changes(&chunks, std::path::Path::new("/nonexistent"), 10, &[]);
        assert!(
            findings.is_empty(),
            "should gracefully return empty without index"
        );
    }

    #[test]
    fn scan_breaking_changes_detects_removed_pub_fn() {
        let chunks = vec![make_chunk(
            "src/lib.rs",
            "-pub fn important_api() {}\n+pub fn new_api() {}",
        )];
        // No index, so no callers detected — but the pattern should still compile
        let findings =
            scan_breaking_changes(&chunks, std::path::Path::new("/nonexistent"), 10, &[]);
        assert!(findings.is_empty(), "no index means no caller data");
    }

    // --- should_skip_file tests ---

    #[test]
    fn skip_empty_patterns() {
        assert!(!should_skip_file("src/main.ts", &[]));
        assert!(!should_skip_file("vitest.config.ts", &[]));
    }

    #[test]
    fn skip_exact_match() {
        let patterns = vec!["src/main.ts".into(), "src/index.ts".into()];
        assert!(should_skip_file("src/main.ts", &patterns));
        assert!(!should_skip_file("src/app.ts", &patterns));
    }

    #[test]
    fn skip_wildcard_suffix() {
        let patterns = vec!["*.config.ts".into()];
        assert!(should_skip_file("vitest.config.ts", &patterns));
        assert!(should_skip_file("vite.config.ts", &patterns));
        assert!(should_skip_file("webpack.config.ts", &patterns));
        assert!(!should_skip_file("src/app.ts", &patterns));
        assert!(!should_skip_file("config.ts", &patterns)); // basename = "config.ts", doesn't end with ".config.ts"
    }

    #[test]
    fn skip_wildcard_prefix() {
        let patterns = vec!["vite.config.*".into()];
        assert!(should_skip_file("vite.config.ts", &patterns));
        assert!(should_skip_file("vite.config.js", &patterns));
        assert!(!should_skip_file("webpack.config.ts", &patterns));
    }

    #[test]
    fn skip_doublestar_prefix() {
        let patterns = vec!["**/main.ts".into()];
        assert!(should_skip_file("src/main.ts", &patterns));
        assert!(should_skip_file("main.ts", &patterns));
        assert!(!should_skip_file("src/app.ts", &patterns));
    }

    #[test]
    fn skip_basename_exact() {
        // "src/main.ts" pattern — basename match works too
        let patterns = vec!["main.ts".into()];
        assert!(should_skip_file("src/main.ts", &patterns));
        assert!(should_skip_file("main.ts", &patterns));
        assert!(!should_skip_file("src/app.ts", &patterns));
    }

    #[test]
    fn skip_default_list_blocks_common_entry_points() {
        use crate::engine::rules::types::default_index_skip_files;
        let defaults = default_index_skip_files();

        // These should all be skipped
        assert!(should_skip_file("vitest.config.ts", &defaults));
        assert!(should_skip_file("vite.config.js", &defaults));
        assert!(should_skip_file("webpack.config.ts", &defaults));
        assert!(should_skip_file("src/main.ts", &defaults));
        assert!(should_skip_file("src/index.tsx", &defaults));
        assert!(should_skip_file("src/app.tsx", &defaults));

        // These should NOT be skipped
        assert!(!should_skip_file("src/lib.rs", &defaults));
        assert!(!should_skip_file("src/utils.ts", &defaults));
        assert!(!should_skip_file("src/components/Button.tsx", &defaults));
    }

    // --- New glob pattern tests (#453) ---

    #[test]
    fn skip_doublestar_dir_doublestar() {
        // "**/phaser/**" → match any path containing "phaser" as a component
        let patterns = vec!["**/phaser/**".into()];
        assert!(should_skip_file(
            "src/scenes/phaser/GameScene.ts",
            &patterns
        ));
        assert!(should_skip_file("phaser/GameScene.ts", &patterns));
        assert!(should_skip_file("src/phaser/utils.ts", &patterns));
        assert!(!should_skip_file("src/utils/phaserHelper.ts", &patterns));
        assert!(!should_skip_file("src/app.ts", &patterns));
    }

    #[test]
    fn skip_prefix_dir_doublestar() {
        // "src/engine/**" → files under src/engine/
        let patterns = vec!["src/engine/**".into()];
        assert!(should_skip_file("src/engine/physics.rs", &patterns));
        assert!(should_skip_file("src/engine/core/mod.rs", &patterns));
        assert!(!should_skip_file("src/app/engine.rs", &patterns));
    }

    #[test]
    fn skip_doublestar_wildcard_ext() {
        // "**/*.test.ts" → any .test.ts file anywhere
        let patterns = vec!["**/*.test.ts".into()];
        assert!(should_skip_file("src/utils/helpers.test.ts", &patterns));
        assert!(should_skip_file("tests/integration.test.ts", &patterns));
        assert!(!should_skip_file("src/utils/helpers.ts", &patterns));
        assert!(!should_skip_file("src/utils/helpers.test.js", &patterns));
    }

    #[test]
    fn skip_nested_doublestar_dir() {
        // "**/node_modules/**" → match nested node_modules
        let patterns = vec!["**/node_modules/**".into()];
        assert!(should_skip_file("node_modules/lodash/index.js", &patterns));
        assert!(should_skip_file(
            "packages/app/node_modules/lodash/index.js",
            &patterns
        ));
        assert!(!should_skip_file("src/node_modulesHelper.ts", &patterns));
    }

    #[test]
    fn skip_multiple_patterns_any_match() {
        let patterns = vec![
            "**/phaser/**".into(),
            "*.config.ts".into(),
            "src/main.ts".into(),
        ];
        assert!(should_skip_file(
            "src/scenes/phaser/GameScene.ts",
            &patterns
        ));
        assert!(should_skip_file("vite.config.ts", &patterns));
        assert!(should_skip_file("src/main.ts", &patterns));
        assert!(!should_skip_file("src/lib.rs", &patterns));
    }
}