Web: list script subfolders in the browser settings store

WebConfig had only the empty list_dirs default, so a script stored as Scripts/Tools/Hello.jsx
could be run by name but was not listed in File > Scripts or file.scripts.list. Review feedback
from CodeRabbit on #2289.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
onlykshitij
2026-10-27 11:08:06 +05:30
co-authored by Claude Opus 5.5
parent c9d823483f
commit d9ccf6a2df
+31
View File
@@ -366,6 +366,21 @@ impl ConfigStore for WebConfig {
v.sort();
v
}
/// The first name part of the keys under `dir/`.
fn list_dirs(&self, dir: &str) -> Vec<String> {
let pre = format!("{CONFIG}{}/", dir.trim_end_matches('/'));
let mut v: Vec<String> = self
.store
.lock()
.list(&pre)
.into_iter()
.filter_map(|(k, ..)| k.strip_prefix(&pre)?.split_once('/').map(|(d, _)| d.to_string()))
.filter(|d| !d.is_empty())
.collect();
v.sort();
v.dedup();
v
}
fn dir(&self) -> Option<PathBuf> {
Some(PathBuf::from("/"))
}
@@ -533,6 +548,22 @@ mod tests {
assert_eq!(s.file("/clip.mp4").as_deref(), Some(&b"abc"[..]));
}
/// Scripts in a subfolder of the Scripts folder (`Tools/Hello.jsx`) are listed, as on the desktop.
#[test]
fn config_store_lists_folders() {
let c = WebConfig::new(store());
for name in ["Scripts/Top.jsx", "Scripts/Tools/Hello.jsx", "Scripts/Tools/More.jsx", "Scripts/ScriptUI Panels/Kit/A.jsx"] {
c.write(name, "x").unwrap();
}
assert_eq!(c.list("Scripts"), ["Top.jsx"]);
assert_eq!(c.list_dirs("Scripts"), ["ScriptUI Panels", "Tools"]);
assert_eq!(c.list_dirs("Scripts/ScriptUI Panels"), ["Kit"]);
let mut s = effectcraft_engine::Session { config: Some(Arc::new(c)), ..Default::default() };
let list = s.execute("file.scripts.list", serde_json::json!({})).unwrap();
let installed: Vec<&str> = list.as_array().unwrap().iter().filter(|e| e["source"] == "installed").filter_map(|e| e["name"].as_str()).collect();
assert_eq!(installed, ["Tools/Hello.jsx", "Tools/More.jsx", "Top.jsx", "Kit/A.jsx"]);
}
#[test]
fn config_store_and_file_ops() {
let s = store();