-
Notifications
You must be signed in to change notification settings - Fork 436
fix(fff-mcp): apply --max-cached-files as a cap, not a repo size (#847) #848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||||||||
| //! Regression test for https://github.com/dmtrKovalenko/fff/issues/847 | ||||||||||
| //! | ||||||||||
| //! An explicit `--max-cached-files` cap must reach the picker verbatim and | ||||||||||
| //! survive the initial scan, which otherwise auto-sizes the budget. | ||||||||||
|
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Remove the top-file module comment. The As per coding guidelines: no module comments, no top-file comments, and no comment longer than two lines. Proposed fix-//! Regression test for https://github.com/dmtrKovalenko/fff/issues/847
-//!
-//! An explicit `--max-cached-files` cap must reach the picker verbatim and
-//! survive the initial scan, which otherwise auto-sizes the budget.📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||
|
|
||||||||||
| use std::fs; | ||||||||||
|
|
||||||||||
| use fff_search::file_picker::FilePicker; | ||||||||||
| use fff_search::{ContentCacheBudget, FilePickerOptions}; | ||||||||||
| use tempfile::TempDir; | ||||||||||
|
|
||||||||||
| #[test] | ||||||||||
| fn explicit_cap_reaches_the_picker_and_survives_the_scan() { | ||||||||||
| let dir = TempDir::new().unwrap(); | ||||||||||
| for i in 0..8 { | ||||||||||
| fs::write(dir.path().join(format!("f{i}.txt")), "x".repeat(32 * 1024)).unwrap(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| let mut picker = FilePicker::new(FilePickerOptions { | ||||||||||
| base_path: dir.path().to_string_lossy().to_string(), | ||||||||||
| watch: false, | ||||||||||
| cache_budget: Some(ContentCacheBudget::with_max_files(2)), | ||||||||||
| ..Default::default() | ||||||||||
| }) | ||||||||||
| .expect("failed to create FilePicker"); | ||||||||||
|
|
||||||||||
| assert!(picker.has_explicit_cache_budget()); | ||||||||||
| assert_eq!(picker.cache_budget().max_files, 2); | ||||||||||
|
|
||||||||||
| picker.collect_files().expect("failed to collect files"); | ||||||||||
|
|
||||||||||
| // 8 files would otherwise bucket into the 30_000 heuristic | ||||||||||
| assert_eq!(picker.cache_budget().max_files, 2); | ||||||||||
| assert_eq!( | ||||||||||
| picker.cache_budget().max_file_size, | ||||||||||
| ContentCacheBudget::default().max_file_size | ||||||||||
| ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[test] | ||||||||||
| fn zero_cap_keeps_the_budget_exhausted_after_the_scan() { | ||||||||||
| let dir = TempDir::new().unwrap(); | ||||||||||
| fs::write(dir.path().join("a.txt"), "x".repeat(32 * 1024)).unwrap(); | ||||||||||
|
|
||||||||||
| let mut picker = FilePicker::new(FilePickerOptions { | ||||||||||
| base_path: dir.path().to_string_lossy().to_string(), | ||||||||||
| watch: false, | ||||||||||
| cache_budget: Some(ContentCacheBudget::with_max_files(0)), | ||||||||||
| ..Default::default() | ||||||||||
| }) | ||||||||||
| .expect("failed to create FilePicker"); | ||||||||||
| picker.collect_files().expect("failed to collect files"); | ||||||||||
|
|
||||||||||
| assert_eq!(picker.cache_budget().max_files, 0); | ||||||||||
| assert!(picker.cache_budget().is_exhausted()); | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,7 +154,8 @@ pub(crate) struct Args { | |
|
|
||
| /// Maximum number of files whose content is kept persistently in memory. | ||
| /// Files beyond this limit are still searchable via temporary mmaps that | ||
| /// are released after each grep. Defaults to 30 000. | ||
| /// are released after each grep. `0` disables persistent caching entirely. | ||
| /// Unset: auto-sized from the scanned file count. | ||
|
Comment on lines
+157
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Shorten this CLI help comment. The field documentation is five lines. Keep it to two lines while preserving the As per coding guidelines: comments must be concise and no longer than two lines. Proposed fix- /// Maximum number of files whose content is kept persistently in memory.
- /// Files beyond this limit are still searchable via temporary mmaps that
- /// are released after each grep. `0` disables persistent caching entirely.
- /// Unset: auto-sized from the scanned file count.
+ /// Persistent content-cache file cap; `0` disables persistent caching.
+ /// Unset auto-sizes from the scanned file count; grep uses temporary mmaps.🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| /// Also settable via the FFF_MAX_CACHED_FILES environment variable. | ||
| #[arg(long = "max-cached-files", env = "FFF_MAX_CACHED_FILES")] | ||
| max_cached_files: Option<usize>, | ||
|
|
@@ -347,7 +348,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| mode: FFFMode::Ai, | ||
| cache_budget: args | ||
| .max_cached_files | ||
| .map(fff::ContentCacheBudget::new_for_repo), | ||
| .map(fff::ContentCacheBudget::with_max_files), | ||
| follow_symlinks: args.follow_symlinks, | ||
| enable_home_dir_scanning: args.enable_home_scan, | ||
| enable_fs_root_scanning: args.enable_root_scan, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Shorten this doc comment.
This public API comment is three lines. Keep the
0behavior, but state it in two lines.As per coding guidelines: comments must be concise and no longer than two lines.
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines