vera2-core 0.12.16-aristoddle.1

Core engine for Vera: parsing, indexing, retrieval, storage, and embedding
Documentation
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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
//! Index statistics collection.
//!
//! Provides functions to collect and report statistics about the Vera index,
//! including file count, chunk count, index size on disk, and language breakdown.

use std::collections::{BTreeMap, HashMap, HashSet};
use std::path::Path;

use anyhow::{Context, Result};
use serde::Serialize;

use crate::indexing::index_dir;
use crate::storage::metadata::{IndexHealth, MetadataStore, is_entry_point_path};

/// Architecture overview of an indexed repository.
#[derive(Debug, Clone, Serialize)]
pub struct ProjectOverview {
    /// Total files in the index.
    pub file_count: u64,
    /// Total chunks (symbols/blocks).
    pub chunk_count: u64,
    /// Approximate total lines of code.
    pub total_lines: u64,
    /// Index size on disk.
    pub index_size_human: String,
    /// Languages with file counts, sorted by file count descending.
    pub languages: Vec<LanguageOverview>,
    /// Top-level directories with file counts.
    pub top_directories: Vec<DirectoryStat>,
    /// Symbol type breakdown (function, struct, class, etc.).
    pub symbol_types: Vec<SymbolTypeStat>,
    /// Likely entry point files (main.*, index.*, app.*, etc.).
    pub entry_points: Vec<String>,
    /// Files with the most chunks (complexity hotspots).
    pub hotspots: Vec<HotspotFile>,
    /// Detected project conventions (frameworks, patterns, config files).
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub conventions: Vec<String>,
}

/// Language info for the overview.
#[derive(Debug, Clone, Serialize)]
pub struct LanguageOverview {
    pub language: String,
    pub files: u64,
    pub chunks: u64,
}

/// A top-level directory with its file count.
#[derive(Debug, Clone, Serialize)]
pub struct DirectoryStat {
    pub directory: String,
    pub files: u64,
}

/// Symbol type with count.
#[derive(Debug, Clone, Serialize)]
pub struct SymbolTypeStat {
    pub symbol_type: String,
    pub count: u64,
}

/// A file identified as a complexity hotspot.
#[derive(Debug, Clone, Serialize)]
pub struct HotspotFile {
    pub file_path: String,
    pub chunks: u64,
}

/// Complete statistics about an indexed repository.
#[derive(Debug, Clone, Serialize)]
pub struct IndexStats {
    /// Number of distinct source files in the index.
    pub file_count: u64,
    /// Total number of chunks (symbols/blocks) in the index.
    pub chunk_count: u64,
    /// Total index size on disk in bytes.
    pub index_size_bytes: u64,
    /// Human-readable index size (e.g., "12.3 MB").
    pub index_size_human: String,
    /// Language breakdown: language name -> chunk count.
    pub languages: Vec<LanguageStat>,
    /// Persisted index health from file-level parse diagnostics.
    pub index_health: IndexHealth,
}

/// Statistics for a single programming language.
#[derive(Debug, Clone, Serialize)]
pub struct LanguageStat {
    /// Language name (e.g., "rust", "python").
    pub language: String,
    /// Number of chunks in this language.
    pub chunk_count: u64,
    /// Percentage of total chunks (0.0–100.0).
    pub percentage: f64,
}

/// Collect statistics about the index stored at the given repository path.
///
/// # Arguments
/// - `repo_path` — Path to the repository root (index lives in `.vera/`).
///
/// # Errors
/// Returns an error if the index doesn't exist or can't be read.
pub fn collect_stats(repo_path: &Path) -> Result<IndexStats> {
    let idx_dir = index_dir(repo_path);

    if !idx_dir.exists() {
        anyhow::bail!(
            "no index found at: {}\nRun `vera index <path>` first to create an index.",
            idx_dir.display()
        );
    }

    // Open metadata store. Read-only: a missing database must be an error,
    // never an empty database fabricated by the read itself.
    let metadata_path = idx_dir.join("metadata.db");
    let metadata_store =
        MetadataStore::open_existing(&metadata_path).context("failed to open metadata store")?;

    // Collect counts.
    let file_count = metadata_store
        .file_count()
        .context("failed to get file count")?;
    let chunk_count = metadata_store
        .chunk_count()
        .context("failed to get chunk count")?;

    // Compute index size on disk.
    let index_size_bytes = compute_dir_size(&idx_dir).context("failed to compute index size")?;
    let index_size_human = format_bytes(index_size_bytes);

    // Collect language breakdown.
    let raw_lang_stats = metadata_store
        .language_stats()
        .context("failed to get language stats")?;

    let languages: Vec<LanguageStat> = raw_lang_stats
        .into_iter()
        .map(|(language, count)| {
            let percentage = if chunk_count > 0 {
                (count as f64 / chunk_count as f64) * 100.0
            } else {
                0.0
            };
            LanguageStat {
                language,
                chunk_count: count,
                percentage,
            }
        })
        .collect();
    let index_health = metadata_store
        .index_health()
        .context("failed to get index health")?;

    Ok(IndexStats {
        file_count,
        chunk_count,
        index_size_bytes,
        index_size_human,
        languages,
        index_health,
    })
}

/// Collect an architecture overview of the indexed repository, optionally
/// filtered to an exact set of file paths.
///
/// Returns a high-level summary: languages, directories, entry points,
/// symbol types, and complexity hotspots. Designed for agent onboarding.
pub fn collect_overview_filtered(
    repo_path: &Path,
    exact_paths: Option<&HashSet<String>>,
) -> Result<ProjectOverview> {
    let idx_dir = index_dir(repo_path);

    if !idx_dir.exists() {
        anyhow::bail!(
            "no index found at: {}\nRun `vera index <path>` first to create an index.",
            idx_dir.display()
        );
    }

    let metadata_path = idx_dir.join("metadata.db");
    let store =
        MetadataStore::open_existing(&metadata_path).context("failed to open metadata store")?;

    let index_size_bytes = compute_dir_size(&idx_dir)?;
    let index_size_human = format_bytes(index_size_bytes);

    if exact_paths.is_none() {
        return collect_full_overview(&store, index_size_human);
    }

    let mut files = store.indexed_files()?;
    if let Some(exact_paths) = exact_paths {
        files.retain(|path| exact_paths.contains(path));
    }

    if files.is_empty() {
        return Ok(ProjectOverview {
            file_count: 0,
            chunk_count: 0,
            total_lines: 0,
            index_size_human,
            languages: Vec::new(),
            top_directories: Vec::new(),
            symbol_types: Vec::new(),
            entry_points: Vec::new(),
            hotspots: Vec::new(),
            conventions: Vec::new(),
        });
    }

    // Two grouped queries replace one content-fetching query per file: the
    // overview only needs counts, line spans, languages, and symbol types.
    let summaries = store.file_chunk_summaries(&files)?;
    let symbol_type_totals = store.symbol_type_counts(&files)?;

    let mut language_files: BTreeMap<String, u64> = BTreeMap::new();
    let mut language_chunks: BTreeMap<String, u64> = BTreeMap::new();
    let mut top_directories: HashMap<String, u64> = HashMap::new();
    let mut hotspots: Vec<(String, u64)> = Vec::with_capacity(files.len());
    let mut entry_points = Vec::new();
    let mut total_lines = 0u64;
    let mut chunk_count = 0u64;

    for file in &files {
        // Files retained by the filter but absent from the index contribute
        // nothing, exactly as when their chunk fetch used to come back empty.
        let Some(summary) = summaries.get(file) else {
            continue;
        };

        chunk_count += summary.chunk_count;
        hotspots.push((file.clone(), summary.chunk_count));

        if is_entry_point_path(file) {
            entry_points.push(file.clone());
        }

        let top_dir = file
            .split('/')
            .next()
            .filter(|dir| !dir.is_empty())
            .unwrap_or(".")
            .to_string();
        *top_directories.entry(top_dir).or_default() += 1;

        *language_files.entry(summary.language.clone()).or_default() += 1;
        *language_chunks.entry(summary.language.clone()).or_default() += summary.chunk_count;

        total_lines += summary.max_line_end as u64;
    }

    let mut languages: Vec<LanguageOverview> = language_chunks
        .into_iter()
        .map(|(language, chunks)| LanguageOverview {
            files: language_files.get(&language).copied().unwrap_or(0),
            language,
            chunks,
        })
        .collect();
    languages.sort_by(|left, right| {
        right
            .files
            .cmp(&left.files)
            .then(right.chunks.cmp(&left.chunks))
            .then(left.language.cmp(&right.language))
    });

    let mut top_directories: Vec<DirectoryStat> = top_directories
        .into_iter()
        .map(|(directory, files)| DirectoryStat { directory, files })
        .collect();
    top_directories.sort_by(|left, right| {
        right
            .files
            .cmp(&left.files)
            .then(left.directory.cmp(&right.directory))
    });
    top_directories.truncate(15);

    let mut symbol_types: Vec<SymbolTypeStat> = symbol_type_totals
        .into_iter()
        .map(|(symbol_type, count)| SymbolTypeStat { symbol_type, count })
        .collect();
    symbol_types.sort_by(|left, right| {
        right
            .count
            .cmp(&left.count)
            .then(left.symbol_type.cmp(&right.symbol_type))
    });

    hotspots.sort_by(|left, right| right.1.cmp(&left.1).then(left.0.cmp(&right.0)));
    hotspots.truncate(10);
    let hotspots = hotspots
        .into_iter()
        .map(|(file_path, chunks)| HotspotFile { file_path, chunks })
        .collect();

    entry_points.sort();
    let conventions = detect_conventions_from_files(&files);

    Ok(ProjectOverview {
        file_count: files.len() as u64,
        chunk_count,
        total_lines,
        index_size_human,
        languages,
        top_directories,
        symbol_types,
        entry_points,
        hotspots,
        conventions,
    })
}

fn collect_full_overview(
    store: &MetadataStore,
    index_size_human: String,
) -> Result<ProjectOverview> {
    let file_count = store.file_count()?;
    let chunk_count = store.chunk_count()?;
    let total_lines = store.total_lines()?;

    let chunk_stats = store.language_stats()?;
    let file_stats = store.language_file_counts()?;
    let file_map: HashMap<&str, u64> = file_stats
        .iter()
        .map(|(lang, count)| (lang.as_str(), *count))
        .collect();
    let languages = chunk_stats
        .iter()
        .map(|(lang, chunks)| LanguageOverview {
            language: lang.clone(),
            files: file_map.get(lang.as_str()).copied().unwrap_or(0),
            chunks: *chunks,
        })
        .collect();

    let top_directories = store
        .top_directories(15)?
        .into_iter()
        .map(|(directory, files)| DirectoryStat { directory, files })
        .collect();

    let symbol_types = store
        .symbol_type_stats()?
        .into_iter()
        .map(|(symbol_type, count)| SymbolTypeStat { symbol_type, count })
        .collect();

    let entry_points = store.entry_points()?;
    let hotspots = store
        .hotspot_files(10)?
        .into_iter()
        .map(|(file_path, chunks)| HotspotFile { file_path, chunks })
        .collect();
    let conventions = detect_conventions_from_files(&store.indexed_files()?);

    Ok(ProjectOverview {
        file_count,
        chunk_count,
        total_lines,
        index_size_human,
        languages,
        top_directories,
        symbol_types,
        entry_points,
        hotspots,
        conventions,
    })
}

fn detect_conventions_from_files(files: &[String]) -> Vec<String> {
    // Lowercase each path once and split it into components up front; matching
    // then compares whole components, so `src/myterraform/mod.rs` can never
    // satisfy a `terraform` pattern and nothing allocates per pattern x file.
    let lowered_components: Vec<Vec<String>> = files
        .iter()
        .map(|file| {
            file.split(['/', '\\'])
                .filter(|component| !component.is_empty())
                .map(str::to_ascii_lowercase)
                .collect()
        })
        .collect();

    indicators()
        .iter()
        .filter(|(patterns, _label)| {
            patterns
                .iter()
                .any(|pattern| matches_convention_pattern(pattern, &lowered_components))
        })
        .map(|(_patterns, label)| (*label).to_string())
        .collect()
}

/// Whether any indexed path satisfies a convention pattern.
///
/// Single-segment patterns must equal a whole path component; dot-prefixed
/// patterns may instead match a filename suffix (`.proto` matches
/// `schema.proto`). Slash-separated patterns must appear as consecutive
/// components, so `.github/workflows` neither fires on `.github/workflows-old`
/// nor on a bare `.github` directory. Components are pre-lowercased by the
/// caller; comparisons are ASCII case-insensitive so mixed-case pattern
/// literals (`Cargo.toml`, `Dockerfile`) match without allocating.
fn matches_convention_pattern(pattern: &str, files: &[Vec<String>]) -> bool {
    if let Some((head, tail)) = pattern.split_once('/') {
        let parts: Vec<&str> = std::iter::once(head).chain(tail.split('/')).collect();
        return files.iter().any(|components| {
            components.windows(parts.len()).any(|window| {
                window
                    .iter()
                    .zip(&parts)
                    .all(|(component, part)| component.eq_ignore_ascii_case(part))
            })
        });
    }
    files.iter().any(|components| {
        components.iter().any(|component| {
            if pattern.starts_with('.') && component.len() >= pattern.len() {
                let suffix = &component[component.len() - pattern.len()..];
                suffix.eq_ignore_ascii_case(pattern)
            } else {
                component.eq_ignore_ascii_case(pattern)
            }
        })
    })
}

const fn indicators() -> &'static [(&'static [&'static str], &'static str)] {
    &[
        (&["Cargo.toml"], "Rust/Cargo project"),
        (&["package.json"], "Node.js/npm project"),
        (
            &["pyproject.toml", "setup.py", "setup.cfg"],
            "Python project",
        ),
        (&["go.mod"], "Go module"),
        (
            &["pom.xml", "build.gradle", "build.gradle.kts"],
            "Java/JVM project",
        ),
        (&["Gemfile"], "Ruby/Bundler project"),
        (
            &["Dockerfile", "docker-compose.yml", "docker-compose.yaml"],
            "Docker containerization",
        ),
        (&[".github/workflows"], "GitHub Actions CI"),
        (&[".gitlab-ci.yml"], "GitLab CI"),
        (&["Makefile"], "Make build system"),
        (&["tsconfig.json"], "TypeScript project"),
        (
            &[
                ".eslintrc",
                ".eslintrc.json",
                ".eslintrc.js",
                "eslint.config",
            ],
            "ESLint linting",
        ),
        (&[".prettierrc", "prettier.config"], "Prettier formatting"),
        (&["jest.config", "vitest.config"], "JS test framework"),
        (&["next.config"], "Next.js framework"),
        (&["nuxt.config"], "Nuxt.js framework"),
        (&["vite.config"], "Vite build tool"),
        (&["webpack.config"], "Webpack bundler"),
        (&["tailwind.config"], "Tailwind CSS"),
        (&[".env", ".env.example"], "Environment variable config"),
        (&["terraform"], "Terraform infrastructure"),
        (&["k8s", "kubernetes", "helm"], "Kubernetes deployment"),
        (&["proto", ".proto"], "Protocol Buffers"),
        (&["openapi", "swagger"], "OpenAPI/Swagger spec"),
        (&["migrations"], "Database migrations"),
        (&["prisma"], "Prisma ORM"),
        (&[".storybook"], "Storybook UI"),
    ]
}

// ── Call graph queries ───────────────────────────────────────────────

pub use crate::storage::metadata::{CalleeRef, CallerRef, DeadSymbol};

/// Open the metadata store for a repo, or error if no index exists.
fn open_metadata(repo_path: &Path) -> Result<MetadataStore> {
    let idx_dir = index_dir(repo_path);
    if !idx_dir.exists() {
        anyhow::bail!(
            "no index found at: {}\nRun `vera index <path>` first.",
            idx_dir.display()
        );
    }
    MetadataStore::open_existing(&idx_dir.join("metadata.db"))
        .context("failed to open metadata store")
}

/// Find all call sites that reference a given symbol name.
pub fn find_callers(repo_path: &Path, symbol: &str) -> Result<Vec<CallerRef>> {
    open_metadata(repo_path)?.find_callers(symbol)
}

/// Find all symbols called by a given symbol.
pub fn find_callees(repo_path: &Path, symbol: &str) -> Result<Vec<CalleeRef>> {
    open_metadata(repo_path)?.find_callees(symbol)
}

/// Find defined symbols with zero callers (potential dead code).
pub fn find_dead_symbols(repo_path: &Path) -> Result<Vec<DeadSymbol>> {
    open_metadata(repo_path)?.find_dead_symbols()
}

// ── Helpers ─────────────────────────────────────────────────────────

/// Recursively compute the total size of files in a directory.
fn compute_dir_size(dir: &Path) -> Result<u64> {
    let mut total = 0u64;
    if dir.is_file() {
        return Ok(dir.metadata().map(|m| m.len()).unwrap_or(0));
    }
    let entries = std::fs::read_dir(dir)
        .with_context(|| format!("failed to read directory: {}", dir.display()))?;
    for entry in entries {
        let entry = entry.context("failed to read directory entry")?;
        let path = entry.path();
        if path.is_dir() {
            total += compute_dir_size(&path)?;
        } else {
            total += path.metadata().map(|m| m.len()).unwrap_or(0);
        }
    }
    Ok(total)
}

/// Format a byte count into a human-readable string.
fn format_bytes(bytes: u64) -> String {
    const KB: u64 = 1024;
    const MB: u64 = KB * 1024;
    const GB: u64 = MB * 1024;

    if bytes >= GB {
        format!("{:.1} GB", bytes as f64 / GB as f64)
    } else if bytes >= MB {
        format!("{:.1} MB", bytes as f64 / MB as f64)
    } else if bytes >= KB {
        format!("{:.1} KB", bytes as f64 / KB as f64)
    } else {
        format!("{bytes} B")
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::config::VeraConfig;
    use crate::embedding::test_helpers::MockProvider;
    use crate::indexing::index_repository;
    use std::collections::HashSet;

    #[test]
    fn format_bytes_units() {
        assert_eq!(format_bytes(0), "0 B");
        assert_eq!(format_bytes(500), "500 B");
        assert_eq!(format_bytes(1024), "1.0 KB");
        assert_eq!(format_bytes(1536), "1.5 KB");
        assert_eq!(format_bytes(1_048_576), "1.0 MB");
        assert_eq!(format_bytes(1_073_741_824), "1.0 GB");
    }

    #[test]
    fn collect_stats_missing_index() {
        let dir = std::env::temp_dir().join("vera-stats-test-missing");
        let result = collect_stats(&dir);
        assert!(result.is_err());
        let err = result.unwrap_err().to_string();
        assert!(err.contains("no index found"), "error was: {err}");
    }

    #[test]
    fn collect_stats_missing_metadata_db_errors_without_creating_it() {
        // A `.vera/` directory without `metadata.db` means a crashed or
        // truncated index: the read must fail with the re-index hint and must
        // not fabricate the database (issue #155).
        let dir = tempfile::TempDir::new().unwrap();
        std::fs::create_dir_all(dir.path().join(".vera")).unwrap();

        let result = collect_stats(dir.path());
        assert!(result.is_err(), "all-zero success for a missing index");
        let err = format!("{:#}", result.unwrap_err());
        assert!(err.contains("no index metadata found"), "error was: {err}");
        assert!(
            !dir.path().join(".vera/metadata.db").exists(),
            "the read created metadata.db"
        );
    }

    #[test]
    fn entry_point_predicate_matches_final_components() {
        assert!(is_entry_point_path("src/main.rs"));
        assert!(is_entry_point_path("server.ts"));
        assert!(!is_entry_point_path("src/main"));
        assert!(!is_entry_point_path("src/domain.rs"));
    }

    #[test]
    fn conventions_match_whole_components_not_substrings() {
        let detect = |files: &[&str]| {
            detect_conventions_from_files(
                &files
                    .iter()
                    .map(|file| file.to_string())
                    .collect::<Vec<_>>(),
            )
        };
        let has_label = |labels: &Vec<String>, label: &str| labels.iter().any(|l| l == label);

        // Real markers still fire, case-insensitively.
        assert!(has_label(
            &detect(&["Cargo.toml", "src/lib.rs"]),
            "Rust/Cargo project"
        ));
        assert!(has_label(
            &detect(&["infra/terraform/main.tf"]),
            "Terraform infrastructure"
        ));
        assert!(has_label(
            &detect(&["deploy/k8s/app.yaml"]),
            "Kubernetes deployment"
        ));
        assert!(has_label(
            &detect(&["src/api/schema.proto"]),
            "Protocol Buffers"
        ));

        // Substring hits must not fire (issue #173).
        assert!(!has_label(
            &detect(&["src/myterraform/mod.rs"]),
            "Terraform infrastructure"
        ));
        assert!(!has_label(
            &detect(&["src/kubernetes_client.go"]),
            "Kubernetes deployment"
        ));
        assert!(!has_label(
            &detect(&["src/protocol.rs"]),
            "Protocol Buffers"
        ));
        assert!(!has_label(
            &detect(&["docs/contrib.md"]),
            "Protocol Buffers"
        ));

        // Multi-segment patterns match consecutive components only: a bare
        // `.github` directory and a `.github/workflows-old` near-miss stay
        // silent, while real workflow files are detected.
        assert!(has_label(
            &detect(&[".github/workflows/ci.yml"]),
            "GitHub Actions CI"
        ));
        assert!(!has_label(
            &detect(&[".github/dependabot.yml"]),
            "GitHub Actions CI"
        ));
        assert!(!has_label(
            &detect(&[".github/workflows-old/ci.yml"]),
            "GitHub Actions CI"
        ));

        // Windows separators split into components like Unix ones.
        assert!(has_label(
            &detect(&["packages\\app\\Dockerfile"]),
            "Docker containerization"
        ));
        assert!(has_label(
            &detect(&["src\\proto\\client.ts"]),
            "Protocol Buffers"
        ));
    }

    #[tokio::test]
    async fn filtered_overview_aggregates_match_per_file_numbers() {
        // The exact-path set must cover every indexed file so the filtered
        // path runs both aggregate queries; asserting against per-file reads
        // keeps the test independent of parser chunking details.
        let dir = tempfile::TempDir::new().unwrap();
        std::fs::create_dir_all(dir.path().join("src")).unwrap();
        std::fs::write(
            dir.path().join("src").join("main.rs"),
            "fn main() {}\nstruct Config { name: String }\n",
        )
        .unwrap();
        std::fs::write(
            dir.path().join("src").join("lib.py"),
            "def hello():\n    pass\n",
        )
        .unwrap();

        let provider = MockProvider::new(8);
        let config = VeraConfig::default();
        index_repository(dir.path(), &provider, &config, "mock-model")
            .await
            .unwrap();

        let store = MetadataStore::open_existing(&dir.path().join(".vera/metadata.db")).unwrap();
        let files = [String::from("src/main.rs"), String::from("src/lib.py")];
        let expected_chunks: u64 = files
            .iter()
            .map(|file| store.get_chunks_by_file(file).unwrap().len() as u64)
            .sum();
        let expected_lines: u64 = files
            .iter()
            .map(|file| {
                store
                    .get_chunks_by_file(file)
                    .unwrap()
                    .iter()
                    .map(|chunk| u64::from(chunk.line_end))
                    .max()
                    .unwrap_or(0)
            })
            .sum();
        let expected_functions: u64 = files
            .iter()
            .map(|file| {
                store
                    .get_chunks_by_file(file)
                    .unwrap()
                    .iter()
                    .filter(|chunk| chunk.symbol_type == Some(crate::types::SymbolType::Function))
                    .count() as u64
            })
            .sum();
        drop(store);

        let exact_paths: HashSet<String> = files.iter().cloned().collect();
        let overview = collect_overview_filtered(dir.path(), Some(&exact_paths)).unwrap();
        assert_eq!(overview.file_count, 2);
        assert_eq!(overview.chunk_count, expected_chunks);
        assert_eq!(overview.total_lines, expected_lines);
        assert_eq!(overview.languages.len(), 2);
        for language in &overview.languages {
            assert_eq!(language.files, 1);
            assert!(language.chunks > 0, "{} has no chunks", language.language);
        }
        let function_total = overview
            .symbol_types
            .iter()
            .find(|stat| stat.symbol_type == "function")
            .map(|stat| stat.count)
            .unwrap_or(0);
        assert_eq!(function_total, expected_functions);
        assert!(overview.entry_points.contains(&String::from("src/main.rs")));
    }
}