forgekit-core 0.5.0

Deterministic code intelligence SDK - Core library
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
//! Incremental indexing for processing file changes.
//!
//! This module provides change-based incremental indexing to avoid full
//! re-scans when files are modified.

use crate::storage::UnifiedGraphStore;
use crate::watcher::WatchEvent;
use std::collections::HashSet;
use std::path::{Path, PathBuf};
use std::sync::Arc;

/// Path filter for controlling which files get indexed.
///
/// By default, only files in `src/` and `tests/` directories are indexed.
#[derive(Clone, Debug)]
pub struct PathFilter {
    /// Include patterns (files must match at least one)
    include_patterns: Vec<String>,
    /// Exclude patterns (files matching these are rejected)
    exclude_patterns: Vec<String>,
    /// File extensions to include (empty = all)
    extensions: Vec<String>,
}

impl Default for PathFilter {
    fn default() -> Self {
        Self::new_with_defaults()
    }
}

impl PathFilter {
    /// Creates an empty path filter with no patterns.
    /// Use `PathFilter::default()` or `PathFilter::new_with_defaults()` for the standard filter.
    pub fn new() -> Self {
        Self {
            include_patterns: vec![],
            exclude_patterns: vec![],
            extensions: vec![],
        }
    }

    /// Creates a path filter with default settings (src/ and tests/ only).
    pub fn new_with_defaults() -> Self {
        Self {
            // Only index src/ and tests/ directories
            include_patterns: vec!["**/src/**".to_string(), "**/tests/**".to_string()],
            // Exclude common non-source directories and files
            exclude_patterns: vec![
                "**/target/**".to_string(),
                "**/node_modules/**".to_string(),
                ".git/**".to_string(),
                "**/.forge/**".to_string(),
                "**/Cargo.lock".to_string(),
                "**/package-lock.json".to_string(),
                "**/yarn.lock".to_string(),
                "**/*.min.js".to_string(),
                "**/*.min.css".to_string(),
            ],
            // Only index source code files
            extensions: vec![
                "rs".to_string(),   // Rust
                "py".to_string(),   // Python
                "js".to_string(),   // JavaScript
                "ts".to_string(),   // TypeScript
                "jsx".to_string(),  // React JSX
                "tsx".to_string(),  // React TSX
                "go".to_string(),   // Go
                "java".to_string(), // Java
                "c".to_string(),    // C
                "cpp".to_string(),  // C++
                "h".to_string(),    // C header
                "hpp".to_string(),  // C++ header
                "mod".to_string(),  // Go module
            ],
        }
    }

    /// Creates a path filter that only includes specific directories.
    ///
    /// # Arguments
    ///
    /// * `dirs` - Directories to include (e.g., ["src", "tests"])
    pub fn include_dirs(dirs: &[&str]) -> Self {
        Self {
            include_patterns: dirs.iter().map(|d| format!("**/{}/**", d)).collect(),
            ..Self::default()
        }
    }

    /// Checks if a path should be indexed.
    ///
    /// A path is indexed if:
    /// 1. It matches at least one include pattern
    /// 2. It does NOT match any exclude pattern
    /// 3. It has an allowed extension (if extensions are specified)
    ///
    /// # Arguments
    ///
    /// * `path` - The file path to check
    pub fn should_index(&self, path: &Path) -> bool {
        let path_str = path.to_string_lossy();

        // Check exclude patterns first
        for pattern in &self.exclude_patterns {
            if Self::match_glob(&path_str, pattern) {
                return false;
            }
        }

        // Check include patterns
        let mut included = false;
        for pattern in &self.include_patterns {
            if Self::match_glob(&path_str, pattern) {
                included = true;
                break;
            }
        }
        if !included {
            return false;
        }

        // Check extension
        if !self.extensions.is_empty() {
            if let Some(ext) = path.extension() {
                let ext = ext.to_string_lossy().to_lowercase();
                if !self.extensions.contains(&ext) {
                    return false;
                }
            } else {
                // No extension and we require one
                return false;
            }
        }

        true
    }

    /// Simple glob matching (supports * and ** wildcards).
    fn match_glob(path: &str, pattern: &str) -> bool {
        // Handle **/dir/** pattern (matches dir anywhere in path, with contents)
        if pattern.starts_with("**/") && pattern.ends_with("/**") {
            let dir = &pattern[3..pattern.len() - 3]; // Extract "dir" from "**/dir/**"
                                                      // Path should contain the directory
            return path.contains(&format!("{}/", dir)) || path.starts_with(&format!("{}/", dir));
        }

        // Handle **/suffix pattern (matches suffix anywhere in path)
        if let Some(suffix) = pattern.strip_prefix("**/") {
            // Remove "**/"
            return path.contains(suffix) || path.ends_with(suffix);
        }

        // Handle pattern with ** in the middle (e.g., "src/**/test.rs")
        if pattern.contains("/**/") {
            let parts: Vec<&str> = pattern.split("/**/").collect();
            if parts.len() == 2 {
                let prefix = parts[0];
                let suffix = parts[1];
                return path.starts_with(prefix) && path.contains(suffix);
            }
        }

        // Handle single * wildcard (matches within a path component)
        if pattern.contains('*') {
            // Convert glob pattern to regex
            let mut regex_str = String::with_capacity(pattern.len() * 2);
            regex_str.push('^');

            for c in pattern.chars() {
                match c {
                    '*' => regex_str.push_str(".*"),
                    '.' => regex_str.push_str("\\."),
                    '?' => regex_str.push('.'),
                    '+' => regex_str.push_str("\\+"),
                    '(' | ')' | '[' | ']' | '{' | '}' | '^' | '$' | '|' | '\\' => {
                        regex_str.push('\\');
                        regex_str.push(c);
                    }
                    _ => regex_str.push(c),
                }
            }
            regex_str.push('$');

            if let Ok(re) = regex::Regex::new(&regex_str) {
                return re.is_match(path);
            }
        }

        // Exact match or substring match
        path == pattern || path.contains(pattern)
    }

    /// Adds an include pattern.
    pub fn add_include(&mut self, pattern: impl Into<String>) {
        self.include_patterns.push(pattern.into());
    }

    /// Adds an exclude pattern.
    pub fn add_exclude(&mut self, pattern: impl Into<String>) {
        self.exclude_patterns.push(pattern.into());
    }

    /// Adds an allowed extension.
    pub fn add_extension(&mut self, ext: impl Into<String>) {
        self.extensions.push(ext.into());
    }
}

/// Incremental indexer for processing file changes.
///
/// The `IncrementalIndexer` batches file system events and processes
/// them on flush, avoiding full re-indexing of the codebase.
///
/// # Examples
///
/// ```no_run
/// use forgekit_core::indexing::IncrementalIndexer;
/// use forgekit_core::watcher::WatchEvent;
/// use std::path::PathBuf;
///
/// # #[tokio::main]
/// # async fn main() -> anyhow::Result<()> {
/// # use forgekit_core::BackendKind;
/// # use std::sync::Arc;
/// # let store = Arc::new(forgekit_core::storage::UnifiedGraphStore::open(".", BackendKind::SQLite).await?);
/// let indexer = IncrementalIndexer::new(store);
///
/// // Queue some changes (only src/ and tests/ files will be indexed)
/// indexer.queue(WatchEvent::Modified(PathBuf::from("src/lib.rs")));
/// indexer.queue(WatchEvent::Created(PathBuf::from("tests/test.rs")));
/// indexer.queue(WatchEvent::Modified(PathBuf::from("target/debug/build.rs"))); // Ignored
///
/// // Process changes
/// indexer.flush().await?;
/// # Ok(())
/// # }
/// ```
#[derive(Clone, Debug)]
pub struct IncrementalIndexer {
    /// The graph store for writing index updates.
    store: Arc<UnifiedGraphStore>,
    /// Pending files to process.
    pending: Arc<tokio::sync::Mutex<HashSet<PathBuf>>>,
    /// Files to delete.
    deleted: Arc<tokio::sync::Mutex<HashSet<PathBuf>>>,
    /// Path filter for controlling which files get indexed.
    filter: PathFilter,
}

impl IncrementalIndexer {
    /// Creates a new incremental indexer with default path filtering.
    ///
    /// By default, only files in `src/` and `tests/` directories are indexed.
    ///
    /// # Arguments
    ///
    /// * `store` - The graph store for index updates
    pub fn new(store: Arc<UnifiedGraphStore>) -> Self {
        Self {
            store,
            pending: Arc::new(tokio::sync::Mutex::new(HashSet::new())),
            deleted: Arc::new(tokio::sync::Mutex::new(HashSet::new())),
            filter: PathFilter::default(),
        }
    }

    /// Creates a new incremental indexer with a custom path filter.
    ///
    /// # Arguments
    ///
    /// * `store` - The graph store for index updates
    /// * `filter` - Custom path filter
    pub fn with_filter(store: Arc<UnifiedGraphStore>, filter: PathFilter) -> Self {
        Self {
            store,
            pending: Arc::new(tokio::sync::Mutex::new(HashSet::new())),
            deleted: Arc::new(tokio::sync::Mutex::new(HashSet::new())),
            filter,
        }
    }

    /// Returns a reference to the path filter.
    pub fn filter(&self) -> &PathFilter {
        &self.filter
    }

    /// Sets a new path filter.
    pub fn set_filter(&mut self, filter: PathFilter) {
        self.filter = filter;
    }

    /// Queues a watch event for processing.
    ///
    /// Only files matching the path filter will be queued.
    ///
    /// # Arguments
    ///
    /// * `event` - The watch event to queue
    pub fn queue(&self, event: WatchEvent) {
        match event {
            WatchEvent::Created(path) | WatchEvent::Modified(path) => {
                // Apply path filter
                if !self.filter.should_index(&path) {
                    return;
                }

                let pending = self.pending.clone();
                tokio::spawn(async move {
                    pending.lock().await.insert(path);
                });
            }
            WatchEvent::Deleted(path) => {
                // Apply path filter for deletions too
                if !self.filter.should_index(&path) {
                    return;
                }

                let deleted = self.deleted.clone();
                tokio::spawn(async move {
                    deleted.lock().await.insert(path);
                });
            }
            WatchEvent::Error(_) => {
                // Log error but don't fail
            }
        }
    }

    /// Flushes pending changes to the graph store.
    ///
    /// This method processes all queued file changes and updates
    /// the index incrementally.
    ///
    /// # Returns
    ///
    /// `Ok(())` if flush succeeded, or an error.
    ///
    /// # Errors
    ///
    /// Returns an error if any file cannot be indexed.
    pub async fn flush(&self) -> anyhow::Result<FlushStats> {
        let mut pending = self.pending.lock().await;
        let mut deleted = self.deleted.lock().await;

        let mut stats = FlushStats::default();

        // Process deletions first
        for path in deleted.drain() {
            if let Err(e) = self.delete_file(&path).await {
                eprintln!("Error deleting {:?}: {}", path, e);
            } else {
                stats.deleted += 1;
            }
        }

        // Process additions/updates
        for path in pending.drain() {
            if let Err(e) = self.index_file(&path).await {
                eprintln!("Error indexing {:?}: {}", path, e);
            } else {
                stats.indexed += 1;
            }
        }

        Ok(stats)
    }

    /// Performs a full rescan of the codebase.
    ///
    /// This clears all pending changes and re-indexes from scratch,
    /// respecting the path filter.
    ///
    /// # Arguments
    ///
    /// * `root` - The root directory to scan
    ///
    /// # Returns
    ///
    /// `Ok(count)` with number of files indexed, or an error.
    pub async fn full_rescan(&self, root: &Path) -> anyhow::Result<usize> {
        // Clear pending
        self.pending.lock().await.clear();
        self.deleted.lock().await.clear();

        let mut count = 0;

        // Walk directory tree
        if root.is_dir() {
            self.scan_directory(root, &mut count).await?;
        }

        Ok(count)
    }

    /// Recursively scans a directory for files to index.
    async fn scan_directory(&self, dir: &Path, count: &mut usize) -> anyhow::Result<()> {
        let mut entries = tokio::fs::read_dir(dir).await?;

        while let Some(entry) = entries.next_entry().await? {
            let path = entry.path();

            if path.is_dir() {
                // Skip excluded directories early
                let path_str = path.to_string_lossy();
                if path_str.contains("/target/")
                    || path_str.contains("/node_modules/")
                    || path_str.contains("/.git/")
                    || path_str.contains("/.forge/")
                {
                    continue;
                }

                // Recurse into allowed directories
                Box::pin(self.scan_directory(&path, count)).await?;
            } else if path.is_file() && self.filter.should_index(&path) {
                self.pending.lock().await.insert(path);
                *count += 1;
            }
        }

        Ok(())
    }

    /// Returns the number of pending files to process.
    pub async fn pending_count(&self) -> usize {
        self.pending.lock().await.len() + self.deleted.lock().await.len()
    }

    /// Clears all pending changes without processing.
    pub async fn clear_pending(&self) {
        self.pending.lock().await.clear();
        self.deleted.lock().await.clear();
    }

    /// Indexes a single file using magellan.
    async fn index_file(&self, path: &Path) -> anyhow::Result<()> {
        if !path.exists() || !path.is_file() {
            return Ok(());
        }

        let db_path = self.store.db_path().join("graph.db");
        if !db_path.exists() {
            return Ok(());
        }

        {
            let mut graph = magellan::CodeGraph::open(&db_path)?;
            if let Some(parent) = path.parent() {
                graph.scan_directory(parent, None)?;
            }
        }

        Ok(())
    }

    /// Deletes a file from the index using magellan.
    async fn delete_file(&self, path: &Path) -> anyhow::Result<()> {
        let db_path = self.store.db_path().join("graph.db");
        if !db_path.exists() {
            return Ok(());
        }

        {
            let mut graph = magellan::CodeGraph::open(&db_path)?;
            let path_str = path.to_string_lossy();
            let _ = graph.delete_file(&path_str);
        }

        Ok(())
    }
}

/// Statistics from a flush operation.
#[derive(Debug, Default, Clone, PartialEq)]
pub struct FlushStats {
    /// Number of files indexed.
    pub indexed: usize,
    /// Number of files deleted.
    pub deleted: usize,
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::storage::{BackendKind, UnifiedGraphStore};

    #[tokio::test]
    async fn test_indexer_creation() {
        let store = Arc::new(UnifiedGraphStore::memory().await.unwrap());
        let indexer = IncrementalIndexer::new(store);

        assert_eq!(indexer.pending_count().await, 0);
    }

    #[tokio::test]
    async fn test_queue_events() {
        let store = Arc::new(UnifiedGraphStore::memory().await.unwrap());
        let indexer = IncrementalIndexer::new(store);

        indexer.queue(WatchEvent::Created(PathBuf::from("src/a.rs")));
        indexer.queue(WatchEvent::Modified(PathBuf::from("src/b.rs")));
        indexer.queue(WatchEvent::Deleted(PathBuf::from("src/c.rs")));

        tokio::time::sleep(std::time::Duration::from_millis(50)).await;

        assert_eq!(indexer.pending_count().await, 3);
    }

    #[tokio::test]
    async fn test_queue_filtered_events() {
        let store = Arc::new(UnifiedGraphStore::memory().await.unwrap());
        let indexer = IncrementalIndexer::new(store);

        // These should be indexed (src/ and tests/)
        indexer.queue(WatchEvent::Created(PathBuf::from("src/a.rs")));
        indexer.queue(WatchEvent::Modified(PathBuf::from("tests/b.rs")));

        // These should be filtered out
        indexer.queue(WatchEvent::Modified(PathBuf::from("target/debug/build.rs")));
        indexer.queue(WatchEvent::Modified(PathBuf::from(
            "node_modules/foo/index.js",
        )));
        indexer.queue(WatchEvent::Modified(PathBuf::from(".git/config")));
        indexer.queue(WatchEvent::Modified(PathBuf::from("Cargo.lock")));
        indexer.queue(WatchEvent::Modified(PathBuf::from("README.md"))); // Not in src/ or tests/

        tokio::time::sleep(std::time::Duration::from_millis(50)).await;

        // Only src/ and tests/ files should be queued
        assert_eq!(indexer.pending_count().await, 2);
    }

    #[test]
    fn test_path_filter_default() {
        let filter = PathFilter::default();

        // Should index src/ files
        assert!(filter.should_index(Path::new("src/lib.rs")));
        assert!(filter.should_index(Path::new("src/main.rs")));
        assert!(filter.should_index(Path::new("project/src/module.rs")));

        // Should index tests/ files
        assert!(filter.should_index(Path::new("tests/test.rs")));
        assert!(filter.should_index(Path::new("project/tests/integration.rs")));

        // Should NOT index target/
        assert!(!filter.should_index(Path::new("target/debug/build.rs")));
        assert!(!filter.should_index(Path::new("target/release/app")));

        // Should NOT index node_modules/
        assert!(!filter.should_index(Path::new("node_modules/foo/index.js")));

        // Should NOT index .git/
        assert!(!filter.should_index(Path::new(".git/config")));

        // Should NOT index Cargo.lock
        assert!(!filter.should_index(Path::new("Cargo.lock")));

        // Should NOT index files outside src/ or tests/
        assert!(!filter.should_index(Path::new("README.md")));
        assert!(!filter.should_index(Path::new("Cargo.toml")));
        assert!(!filter.should_index(Path::new("build.rs"))); // Not in src/
    }

    #[test]
    fn test_path_filter_extensions() {
        let filter = PathFilter::default();

        // Rust files
        assert!(filter.should_index(Path::new("src/lib.rs")));
        assert!(filter.should_index(Path::new("tests/test.rs")));

        // Python files
        assert!(filter.should_index(Path::new("src/main.py")));

        // JavaScript/TypeScript
        assert!(filter.should_index(Path::new("src/index.js")));
        assert!(filter.should_index(Path::new("src/index.ts")));
        assert!(filter.should_index(Path::new("src/App.jsx")));
        assert!(filter.should_index(Path::new("src/App.tsx")));

        // Binary files should be excluded
        assert!(!filter.should_index(Path::new("src/logo.png")));
        assert!(!filter.should_index(Path::new("src/data.bin")));
    }

    #[test]
    fn test_path_filter_custom() {
        let mut filter = PathFilter::new();
        filter.add_include("**/lib/**");
        filter.add_extension("go");

        assert!(filter.should_index(Path::new("lib/main.go")));
        assert!(!filter.should_index(Path::new("src/main.go"))); // Not in lib/
        assert!(!filter.should_index(Path::new("lib/main.rs"))); // Wrong extension
    }

    #[tokio::test]
    async fn test_flush_clears_pending() {
        let store = Arc::new(UnifiedGraphStore::memory().await.unwrap());
        let indexer = IncrementalIndexer::new(store);

        indexer.queue(WatchEvent::Modified(PathBuf::from("src/lib.rs")));
        tokio::time::sleep(std::time::Duration::from_millis(50)).await;

        let stats = indexer.flush().await.unwrap();
        assert_eq!(stats.indexed, 1);
        assert_eq!(indexer.pending_count().await, 0);
    }

    #[tokio::test]
    async fn test_flush_stats() {
        let store = Arc::new(UnifiedGraphStore::memory().await.unwrap());
        let indexer = IncrementalIndexer::new(store);

        indexer.queue(WatchEvent::Modified(PathBuf::from("src/a.rs")));
        indexer.queue(WatchEvent::Created(PathBuf::from("src/b.rs")));
        indexer.queue(WatchEvent::Deleted(PathBuf::from("src/c.rs")));

        tokio::time::sleep(std::time::Duration::from_millis(50)).await;

        let stats = indexer.flush().await.unwrap();

        assert_eq!(stats.indexed, 2);
        assert_eq!(stats.deleted, 1);
    }

    #[tokio::test]
    async fn test_clear_pending() {
        let store = Arc::new(UnifiedGraphStore::memory().await.unwrap());
        let indexer = IncrementalIndexer::new(store);

        indexer.queue(WatchEvent::Modified(PathBuf::from("src/a.rs")));
        tokio::time::sleep(std::time::Duration::from_millis(50)).await;

        assert_eq!(indexer.pending_count().await, 1);

        indexer.clear_pending().await;

        assert_eq!(indexer.pending_count().await, 0);
    }

    #[tokio::test]
    async fn test_full_rescan() {
        let temp = tempfile::tempdir().unwrap();
        let store = Arc::new(
            UnifiedGraphStore::open(temp.path(), BackendKind::default())
                .await
                .unwrap(),
        );
        let indexer = IncrementalIndexer::new(store);

        // Create a directory structure
        let src_dir = temp.path().join("src");
        let tests_dir = temp.path().join("tests");
        let target_dir = temp.path().join("target");
        tokio::fs::create_dir(&src_dir).await.unwrap();
        tokio::fs::create_dir(&tests_dir).await.unwrap();
        tokio::fs::create_dir(&target_dir).await.unwrap();

        // Create source files
        tokio::fs::write(src_dir.join("lib.rs"), "pub fn foo() {}")
            .await
            .unwrap();
        tokio::fs::write(src_dir.join("main.rs"), "fn main() {}")
            .await
            .unwrap();
        tokio::fs::write(tests_dir.join("test.rs"), "#[test] fn test() {}")
            .await
            .unwrap();
        tokio::fs::write(target_dir.join("build.rs"), "// build")
            .await
            .unwrap(); // Should be ignored
        tokio::fs::write(temp.path().join("README.md"), "# Project")
            .await
            .unwrap(); // Should be ignored

        // Perform rescan
        let count = indexer.full_rescan(temp.path()).await.unwrap();

        // Should only find src/ and tests/ files, not target/ or README.md
        assert_eq!(count, 3);

        // Verify pending queue has the files
        let pending = indexer.pending.lock().await;
        assert!(pending.contains(&src_dir.join("lib.rs")));
        assert!(pending.contains(&src_dir.join("main.rs")));
        assert!(pending.contains(&tests_dir.join("test.rs")));
        assert!(!pending.contains(&target_dir.join("build.rs")));
        assert!(!pending.contains(&temp.path().join("README.md")));
    }
}