Scripts: a startup listing over the script limit keeps the first names in order

The listing sorts the eligible names before it applies the limit, so the same scripts run on every launch.
This commit is contained in:
dotCooCoo committed 2026-11-26 00:30:17 -08:00
1 parent 844980f135
commit d1eb8c9503
2 files changed
+17 -4

No files matched your search

+4 -4
View File
@@ -80,13 +80,13 @@ pub fn list_with(root: &Path, limits: &folder::Limits, elapsed: &mut dyn FnMut()
if !kind.is_file() || kind.is_symlink() || entry.metadata().is_ok_and(|m| folder::hidden_meta(&m)) {
continue;
}
if names.len() >= limits.scripts {
listing.truncated = true;
continue;
}
names.push(name);
}
names.sort_by(|a, b| (a.to_lowercase(), a).cmp(&(b.to_lowercase(), b)));
if names.len() > limits.scripts {
listing.truncated = true;
names.truncate(limits.scripts);
}
listing.scripts = names.into_iter().map(|n| root.join(n)).collect();
listing
}
+13
View File
@@ -389,3 +389,16 @@ fn the_automation_read_root_keeps_an_agent_out_of_the_scripts_folder() {
});
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn a_startup_listing_over_the_script_limit_keeps_the_first_names_in_order() {
let dir = vectorcraft_testkit::TempDir::new("startup-limit");
for name in ["d.jsx", "b.jsx", "e.jsx", "a.jsx", "c.jsx"] {
touch(&dir, name);
}
let limits = Limits { scripts: 3, ..Limits::default() };
let listing = crate::script::startup::list_with(&dir, &limits, &mut || Duration::ZERO);
let names: Vec<_> = listing.scripts.iter().map(|p| p.file_name().unwrap().to_string_lossy().into_owned()).collect();
assert_eq!(names, ["a.jsx", "b.jsx", "c.jsx"]);
assert!(listing.truncated);
}