Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(models): die kleinen Punkte aus dem Review, jeder mit Gegenkontrolle

purpleaea28435d1bd
diff --git a/src-tauri/src/commands/custom_models.rs b/src-tauri/src/commands/custom_models.rs
index d7e660f0..c80ada56 100644
--- a/src-tauri/src/commands/custom_models.rs
+++ b/src-tauri/src/commands/custom_models.rs
@@ -21,11 +21,23 @@
use std::path::{Path, PathBuf};
/// The `folder_paths` keys ComfyUI accepts in an extra-model-paths file, which
-/// are also the folder names it uses on disk. Kept in step with
-/// `subfolderForSource` in `src/api/comfyui.ts` (a test holds the two lists
-/// against each other).
+/// are also the folder names it uses on disk.
+///
+/// Two directions to keep straight, and a test for each. Every folder LU's own
+/// inventory reads has to be in here, or a file the app can see would be one
+/// LU never hands over (`subfolderForSource` in `src/api/comfyui.ts`). And
+/// every entry here has to be a key ComfyUI really has, or the config file
+/// carries a line ComfyUI ignores at best.
+///
+/// `clip` and `unet` are ComfyUI's older names for `text_encoders` and
+/// `diffusion_models`; both are still live keys and a folder filed under the
+/// old name is common. `audio_encoders` is the newer audio lane. None of the
+/// three appears in `subfolderForSource`, which is why the first test can only
+/// check one direction.
pub(crate) const COMFY_MODEL_FOLDERS: &[&str] = &[
+ "audio_encoders",
"checkpoints",
+ "clip",
"clip_vision",
"controlnet",
"diffusion_models",
@@ -33,6 +45,7 @@ pub(crate) const COMFY_MODEL_FOLDERS: &[&str] = &[
"loras",
"style_models",
"text_encoders",
+ "unet",
"upscale_models",
"vae",
];
@@ -363,6 +376,35 @@ mod tests {
assert_eq!(block["vae"].as_str().unwrap(), root.join("vae").to_string_lossy());
}
+ /// The other direction of the drift test in
+ /// `src/lib/__tests__/custom-model-dir-comfy.test.ts`, which can only prove
+ /// that everything LU lists is mapped. This one pins the list against
+ /// ComfyUI's own `folder_paths` keys, so a typo or an invented folder name
+ /// cannot ride along into a config file ComfyUI then ignores.
+ #[test]
+ fn every_mapped_folder_is_a_key_comfyui_actually_has() {
+ // ComfyUI folder_paths keys, as its own extra_model_paths.yaml.example
+ // lists them. A copy on purpose: it is the thing being checked.
+ const COMFYUI_KEYS: &[&str] = &[
+ "audio_encoders", "checkpoints", "clip", "clip_vision", "configs",
+ "controlnet", "diffusion_models", "embeddings", "gligen", "hypernetworks",
+ "loras", "photomaker", "style_models", "text_encoders", "unet",
+ "upscale_models", "vae", "vae_approx",
+ ];
+ for key in COMFY_MODEL_FOLDERS {
+ assert!(COMFYUI_KEYS.contains(key), "{key} is not a ComfyUI folder_paths key");
+ }
+ // Negative control: the list is sorted and free of duplicates, so a
+ // second entry for the same folder cannot write two lines for it.
+ let mut sorted = COMFY_MODEL_FOLDERS.to_vec();
+ sorted.sort_unstable();
+ sorted.dedup();
+ assert_eq!(sorted.as_slice(), COMFY_MODEL_FOLDERS);
+ // And a folder that is not a model folder is not in here.
+ assert!(!COMFY_MODEL_FOLDERS.contains(&"custom_nodes"));
+ assert!(!COMFY_MODEL_FOLDERS.contains(&"output"));
+ }
+
// ── The folder the user typed, before any stat ────────────────────────
#[test]
diff --git a/src-tauri/src/commands/engine.rs b/src-tauri/src/commands/engine.rs
index 5620abbc..8d32b88e 100644
--- a/src-tauri/src/commands/engine.rs
+++ b/src-tauri/src/commands/engine.rs
@@ -1242,11 +1242,20 @@ pub(crate) fn bundled_scan_dirs(app_dir: &Path, extra: &[String]) -> Vec<PathBuf
// Windows paths arrive with a drive letter and backslashes and are
// compared case-insensitively; `G:\AI\Models` and `g:/ai/models\` are one
// folder. PathBuf does not know that, so the key is normalised by hand.
+ //
+ // The case fold is NOT applied on Linux. `/mnt/Models` and `/mnt/models`
+ // are two different folders on ext4, and folding them would silently drop
+ // one of the two from the scan. Windows and a default macOS volume are
+ // case-insensitive, so there the fold is what stops one folder from being
+ // walked twice under two spellings.
+ let fold_case = !cfg!(target_os = "linux");
let key = |p: &Path| {
- p.to_string_lossy()
+ let normalised = p
+ .to_string_lossy()
.replace('\\', "/")
.trim_end_matches('/')
- .to_lowercase()
+ .to_string();
+ if fold_case { normalised.to_lowercase() } else { normalised }
};
let mut seen: std::collections::HashSet<String> = std::collections::HashSet::new();
seen.insert(key(app_dir));
@@ -2341,8 +2350,9 @@ mod tests {
&[
" ".to_string(),
"G:\\AI\\Models".to_string(),
- // The same folder written the other way round: one entry.
- "g:/ai/models/".to_string(),
+ // The same folder with a trailing slash and the other
+ // separator: one entry, on every platform.
+ "G:/AI/Models/".to_string(),
"/data/Locally Uncensored/models".to_string(),
"/mnt/second".to_string(),
],
@@ -2357,6 +2367,27 @@ mod tests {
);
}
+ /// Case folding follows the file system, not the developer's machine.
+ ///
+ /// Windows and a default macOS volume are case-insensitive, so `g:/ai` and
+ /// `G:/AI` are one folder and folding them is what stops a double walk. On
+ /// Linux they are two folders, and folding would silently drop one of them.
+ #[test]
+ fn two_spellings_are_one_folder_only_where_the_file_system_says_so() {
+ let app = Path::new("/data/models");
+ let dirs = bundled_scan_dirs(
+ app,
+ &["/mnt/Models".to_string(), "/mnt/models".to_string()],
+ );
+ if cfg!(target_os = "linux") {
+ assert_eq!(dirs.len(), 3, "ext4 keeps both: {dirs:?}");
+ } else {
+ assert_eq!(dirs.len(), 2, "one folder under two spellings: {dirs:?}");
+ }
+ // Either way the first entry given wins, so the app dir stays root 0.
+ assert_eq!(dirs[0], PathBuf::from("/data/models"));
+ }
+
// ── The scan has to come back (S1, S6) ────────────────────────────────
#[test]
diff --git a/src/App.tsx b/src/App.tsx
index 87efb5b9..2f4842e9 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -29,6 +29,16 @@ function App() {
import('./stores/workflowStore').then(({ hydrateCivitaiApiKey }) => {
hydrateCivitaiApiKey().catch(() => {})
})
+
+ // Hand the user's own model folder to ComfyUI at boot. It used to happen
+ // only while the AI Backends settings tab was mounted, so a user who set
+ // the folder in an older build and never opened that tab again would have
+ // started ComfyUI without it forever.
+ void (async () => {
+ const { syncCustomModelDir } = await import('./lib/custom-model-dir')
+ const { useSettingsStore: store } = await import('./stores/settingsStore')
+ await syncCustomModelDir(store.getState().settings.hfDownloadPathOverride)
+ })()
}
// Probe local Whisper (STT) once at boot and push the result into the voice
diff --git a/src/lib/__tests__/custom-model-dir-comfy.test.ts b/src/lib/__tests__/custom-model-dir-comfy.test.ts
index d1dd0ae4..7d5b8ccb 100644
--- a/src/lib/__tests__/custom-model-dir-comfy.test.ts
+++ b/src/lib/__tests__/custom-model-dir-comfy.test.ts
@@ -112,6 +112,27 @@ describe('the Model Storage copy tells the truth', () => {
})
})
+describe('the handover does not depend on a settings tab being open', () => {
+ const app = readFileSync(join(process.cwd(), 'src/App.tsx'), 'utf8')
+
+ it('runs at boot from the persisted setting', () => {
+ // It used to run only inside the AI Backends panel's effect, so a folder
+ // set in an older build and never revisited never reached ComfyUI.
+ expect(app).toMatch(/syncCustomModelDir/)
+ expect(app).toMatch(/settings\.hfDownloadPathOverride/)
+ })
+
+ // Negative control: the settings panel still syncs on change, or a folder the
+ // user picks would only take effect after the next restart.
+ it('and still on every change in the panel', () => {
+ const panel = readFileSync(
+ join(process.cwd(), 'src/components/settings/SettingsPage.tsx'),
+ 'utf8',
+ )
+ expect(panel).toMatch(/syncCustomModelDir\(override\)/)
+ })
+})
+
describe('the folder names Rust looks for are the folders ComfyUI uses', () => {
it('matches subfolderForSource, so the two lists cannot drift apart', () => {
const rust = readFileSync(