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(code): der gewaehlte Ordner wird nicht mehr still abgelehnt

David7f0133f6d276
diff --git a/src-tauri/src/commands/filesystem.rs b/src-tauri/src/commands/filesystem.rs
index c630d8ac..5ee25e8c 100644
--- a/src-tauri/src/commands/filesystem.rs
+++ b/src-tauri/src/commands/filesystem.rs
@@ -89,13 +89,7 @@ fn resolve_existing_prefix(p: &Path) -> PathBuf {
fn is_within(root: &Path, cand: &Path) -> bool {
#[cfg(windows)]
{
- // Windows paths are case-insensitive; compare lowercased. Both sides go
- // through the SAME key builder (which strips any `\\?\` verbatim prefix)
- // so an extended-length root and a plain candidate — or vice versa —
- // still compare equal.
- let r = win_compare_key(root);
- let c = win_compare_key(cand);
- c == r || c.starts_with(&format!("{}/", r))
+ win_is_within(root, cand)
}
#[cfg(not(windows))]
{
@@ -103,6 +97,26 @@ fn is_within(root: &Path, cand: &Path) -> bool {
}
}
+/// The Windows containment rule, on nothing but the two comparison keys.
+///
+/// Windows paths are case-insensitive; both sides go through the SAME key
+/// builder (which strips any `\\?\` verbatim prefix) so an extended-length root
+/// and a plain candidate, or vice versa, still compare equal.
+///
+/// Split out of `is_within` so the rule can be MEASURED on a host that is not
+/// Windows. `Path::components()` reads `D:\code` as a drive path only on
+/// Windows; everywhere else it is one ordinary file name, so a macOS run of
+/// `is_within` answers a different question than the shipped build does and
+/// proves nothing about it. `win_compare_key` is pure string work, so these two
+/// lines are the same two lines on every host, which is what bug D needed and
+/// did not have.
+#[cfg(any(windows, test))]
+fn win_is_within(root: &Path, cand: &Path) -> bool {
+ let r = win_compare_key(root);
+ let c = win_compare_key(cand);
+ c == r || c.starts_with(&format!("{}/", r))
+}
+
/// Jail `candidate` to `root`: return the normalized path when it stays inside
/// `root`, otherwise an error. Absolute paths are allowed ONLY when they fall
/// within `root`, so the desktop coding agent can still use absolute paths
@@ -157,7 +171,7 @@ pub(crate) fn contain_within(root: &Path, candidate: &Path) -> Result<PathBuf, S
/// MAX_PATH, but `workspace_root` stores the raw string — without normalizing
/// both sides identically here, a legitimately-picked folder fails containment
/// with "Path escapes the allowed workspace" (#79, DarkLordCmd / thecakeisnaoh).
-#[cfg(windows)]
+#[cfg(any(windows, test))]
fn win_compare_key(p: &Path) -> String {
let s = p.to_string_lossy().to_lowercase().replace('\\', "/");
let s = if let Some(rest) = s.strip_prefix("//?/unc/") {
@@ -409,21 +423,39 @@ fn may_be_a_picked_root(norm: &Path) -> Result<(), String> {
/// A renderer cannot open a native folder dialog and click in it, so the list of
/// folders a human picked there is a boundary it cannot cross at all.
///
-/// Two gates, in this order:
-/// 1. the allowlist — an app work dir, or a folder the user picked in the
-/// native dialog (this run or an earlier one; see `PICKED_ROOTS`);
-/// 2. `may_be_a_picked_root` — the handful of folders that are not a
-/// workspace even when a human clicked them.
+/// Two gates, and BOTH have to pass. `may_be_a_picked_root` runs first, for the
+/// sake of the message and nothing else. The set of roots this function
+/// accepts is the same either way, because a folder that gate refuses is also a
+/// folder `remember_picked_root` refuses to record, so it can never be in the
+/// allowlist.
+///
+/// 1. `may_be_a_picked_root`, the handful of folders that are not a
+/// workspace even when a human clicked them, each with its own reason;
+/// 2. the allowlist: an app work dir, or a folder the user picked in the
+/// native dialog (this run or an earlier one; see `PICKED_ROOTS`).
+///
+/// WHY THAT ORDER (bug D, aldrich_ironhart, Discord 2026-09-08). With the
+/// allowlist first, `$HOME`, `C:\Users` and everything under `AppData` were
+/// refused with "pick it again to allow it", an instruction that cannot work,
+/// because the dialog silently refuses to record exactly those folders. The
+/// user picks the folder, the picker hands the path back, the frontend puts it
+/// in the header as the working directory, and every file op answers with the
+/// same sentence for as long as the folder stays selected. Picking it again
+/// closes the loop instead of breaking it. The reason existed the whole time;
+/// only the order kept it from being said.
///
/// Upgrade note: a workspace picked by a build older than this one was never
/// recorded, so the first use after the update is refused until the user picks
/// the folder again. That is one dialog, once, per folder — the alternative is
-/// trusting a path the WebView sent us, which is the hole being closed.
+/// trusting a path the WebView sent us, which is the hole being closed. That
+/// sentence is only honest for a folder a pick CAN allow, which is what the
+/// order above guarantees.
fn check_workspace_root(root: &Path) -> Result<(), String> {
let norm = lexical_normalize(root);
if is_app_work_dir(&norm) {
return Ok(());
}
+ may_be_a_picked_root(&norm)?;
let picked = PICKED_ROOTS
.lock()
.map(|roots| roots.iter().any(|r| is_within(r, &norm)))
@@ -435,7 +467,7 @@ fn check_workspace_root(root: &Path) -> Result<(), String> {
root.display()
));
}
- may_be_a_picked_root(&norm)
+ Ok(())
}
/// `check_workspace_root` for callers outside this module (the Remote dispatch
@@ -1586,6 +1618,138 @@ mod workspace_allowlist_tests {
}
}
+/// Bug D, symptom 3. Discord ticket, aldrich_ironhart, 2026-09-08, Windows 11,
+/// LU 2.6.8, provider Ollama:
+///
+/// "Error: Not an allowed workspace folder (only a folder you chose in LU's
+/// folder picker can be a workspace, pick it again to allow it): D:\code"
+///
+/// for a folder he had picked. Two halves of that chain had no measurement.
+///
+/// THE DURABLE HALF. Every other test here allows its root through
+/// `allow_root_for_test`, which says in its own doc comment that it does not
+/// persist. So the path the shipped app actually walks, `system::pick_folder`
+/// to `remember_picked_root` to `workspace-roots.json` to the next start, was
+/// never walked end to end, and "a pick survives a restart" was measured on
+/// `save_roots_to`/`load_roots_from` alone, two functions the dialog never
+/// calls directly.
+///
+/// THE MESSAGE. `check_workspace_root` asked the ALLOWLIST first and the
+/// structural gate second, so a folder that no pick can ever allow ($HOME,
+/// `C:\Users`, anything under `AppData`) came back with "pick it again to
+/// allow it", an instruction that cannot work. Picking it again produced the
+/// same sentence, because `system::pick_folder` threw the reason away
+/// (`let _ = remember_picked_root(p)`). That is a closed loop, and it is the
+/// reporter's sentence "even though that same folder was picked".
+///
+/// THE WINDOWS SHAPES. The reporter's path is `D:\code`, and the spellings that
+/// reach these functions differ: the dialog can hand back an extended-length
+/// `\\?\D:\code`, the frontend persists whatever it was given, and Windows folds
+/// case. The rule that decides all of them is `win_is_within`, which is pure
+/// string work and therefore measurable here.
+#[cfg(test)]
+mod bug_d_the_picked_folder_tests {
+ use super::*;
+
+ use crate::os_paths::{TestDir, test_dir};
+
+ fn unique(tag: &str) -> TestDir {
+ test_dir(&format!("bugd-{tag}"))
+ }
+
+ /// The whole chain the shipped app walks, including the file.
+ #[test]
+ fn the_folder_from_the_dialog_is_still_a_workspace_after_a_restart() {
+ let dir = unique("restart");
+ let project = dir.join("code");
+ fs::create_dir_all(&project).unwrap();
+
+ // Before the dialog: refused, and the refusal is the English sentence.
+ let before = check_workspace_root(&project).expect_err("a folder nobody picked must be refused");
+ assert!(before.contains("Not an allowed workspace folder"), "got: {before}");
+
+ // The dialog records it. THIS is the call `system::pick_folder` makes,
+ // and its result is what the picker used to discard.
+ remember_picked_root(&project).expect("the dialog's own folder must be recordable");
+ assert!(check_workspace_root(&project).is_ok(), "the folder was refused right after the pick");
+
+ // RESTART: a fresh process knows nothing but the file on disk.
+ let after_restart = load_roots_from(&picked_roots_file());
+ let norm = lexical_normalize(&project);
+ assert!(
+ after_restart.iter().any(|r| is_within(r, &norm)),
+ "the pick did not reach the file, so the next start refuses the folder again: {after_restart:?}",
+ );
+ }
+
+ /// The counter-check that keeps the fix honest: a folder nobody picked is
+ /// still refused, in English, and the file API stays closed for it.
+ #[test]
+ fn a_folder_nobody_picked_still_gets_the_english_refusal() {
+ let dir = unique("foreign");
+ let foreign = dir.join("not-picked");
+ fs::create_dir_all(&foreign).unwrap();
+ let err = check_workspace_root(&foreign).expect_err("a foreign folder must stay refused");
+ assert!(err.contains("Not an allowed workspace folder"), "got: {err}");
+ assert!(err.contains("pick it again to allow it"), "got: {err}");
+ let s = foreign.to_string_lossy().to_string();
+ assert!(resolve_path("secrets.txt", Some("c"), Some(&s)).is_err());
+ }
+
+ /// The loop the reporter was in: a folder no pick can EVER allow was told
+ /// to be picked again.
+ #[test]
+ fn a_folder_no_pick_could_ever_allow_is_not_told_to_pick_it_again() {
+ let home = dirs::home_dir().unwrap_or_default();
+ let impossible: Vec<PathBuf> = vec![
+ home.clone(),
+ home.join(".ssh"),
+ home.join("AppData"),
+ PathBuf::from(if cfg!(windows) { "C:/" } else { "/" }),
+ ];
+ for bad in impossible {
+ // The dialog refuses to record it, that is the existing rule.
+ assert!(remember_picked_root(&bad).is_err(), "{bad:?} was recorded");
+ let err = check_workspace_root(&bad).expect_err("a forbidden root passed as a workspace");
+ assert!(
+ !err.contains("pick it again"),
+ "{bad:?} was refused with an instruction that cannot work: {err}",
+ );
+ assert!(err.contains("Not an allowed workspace folder"), "got: {err}");
+ }
+ }
+
+ /// `D:\code` in every spelling that reaches these functions on Windows.
+ /// Runs on any host: `win_is_within` is pure string work.
+ #[test]
+ fn every_windows_spelling_of_the_reported_folder_is_the_same_root() {
+ let picked = Path::new(r"D:\code");
+ for spelling in [
+ r"D:\code", // what the frontend persisted
+ r"D:/code", // forward slashes, as some callers hand it over
+ r"d:\CODE", // Windows folds case
+ "D:\\code\\", // a trailing separator
+ r"\\?\D:\code", // extended-length, as the dialog can return it
+ ] {
+ assert!(
+ win_is_within(picked, Path::new(spelling)),
+ "{spelling} was not recognised as the picked folder",
+ );
+ assert!(
+ win_is_within(Path::new(spelling), picked),
+ "the picked folder was not recognised as {spelling}",
+ );
+ }
+ // Inside the project is inside the workspace ...
+ assert!(win_is_within(picked, Path::new(r"D:\code\src\main.rs")));
+ // ... and the component boundary still holds.
+ assert!(!win_is_within(picked, Path::new(r"D:\code-backup\id_rsa")));
+ assert!(!win_is_within(picked, Path::new(r"C:\code")));
+ // A UNC share, verbatim or plain, is one path.
+ assert!(win_is_within(Path::new(r"\\srv\share\proj"), Path::new(r"\\?\UNC\srv\share\proj\src")));
+ }
+}
+
/// The two file tools that block for seconds run OFF the Tauri main thread.
#[cfg(test)]
mod off_main_thread_tests {
diff --git a/src-tauri/src/commands/system.rs b/src-tauri/src/commands/system.rs
index 1778d43e..7cadb9a0 100644
--- a/src-tauri/src/commands/system.rs
+++ b/src-tauri/src/commands/system.rs
@@ -246,13 +246,23 @@ fn capture_screen_to(_tmp: &std::path::Path) -> Result<(), String> {
/// `fs_read`. A renderer cannot open this dialog or click in it, so "folders a
/// human chose here" is a set it cannot extend.
///
-/// Recording is best-effort on purpose: this dialog also picks folders that are
-/// not workspaces at all (the GGUF download path, for instance). A folder that
-/// may not be a jail root — `$HOME`, `/`, a credential directory — is simply
-/// not recorded, and the picker still returns it for those other uses; only
-/// `check_workspace_root` cares, and it refuses with the reason.
+/// Recording is best-effort for the callers that are not choosing a workspace:
+/// this dialog also picks the GGUF download folder, and that one may perfectly
+/// well live somewhere `check_workspace_root` would never accept as a jail root.
+/// Such a folder is simply not recorded and still comes back for its own use.
+///
+/// `as_workspace` is for the callers that ARE choosing a workspace, and it turns
+/// the refusal into this command's error instead of dropping it (bug D,
+/// aldrich_ironhart, Discord 2026-09-08). Without it the picker answered
+/// `Ok(Some(path))` for a folder it had just refused to record: the Code tab put
+/// that path in its header as the working directory, and every file op after it
+/// answered "pick it again to allow it", which the user had just done. The
+/// reason was produced, discarded here, and never reached anybody.
#[tauri::command]
-pub async fn pick_folder(default_path: Option<String>) -> Result<Option<String>, String> {
+pub async fn pick_folder(
+ default_path: Option<String>,
+ as_workspace: Option<bool>,
+) -> Result<Option<String>, String> {
let mut dialog = rfd::AsyncFileDialog::new();
if let Some(ref p) = default_path {
dialog = dialog.set_directory(p);
@@ -260,7 +270,10 @@ pub async fn pick_folder(default_path: Option<String>) -> Result<Option<String>,
let result = dialog.pick_folder().await;
let picked = result.map(|f| f.path().to_path_buf());
if let Some(ref p) = picked {
- let _ = crate::commands::filesystem::remember_picked_root(p);
+ let recorded = crate::commands::filesystem::remember_picked_root(p);
+ if as_workspace.unwrap_or(false) {
+ recorded?;
+ }
}
Ok(picked.map(|p| p.to_string_lossy().to_string()))
}
diff --git a/src/components/chat/AgentWorkspaceDialog.tsx b/src/components/chat/AgentWorkspaceDialog.tsx
index 9f2f6eef..41a383d5 100644
--- a/src/components/chat/AgentWorkspaceDialog.tsx
+++ b/src/components/chat/AgentWorkspaceDialog.tsx
@@ -75,7 +75,12 @@ export function AgentWorkspaceDialog({
// pick_folder returns the chosen path as a STRING (or null on cancel) —
// NOT an object. Reading res.path here was the real bug: it was always
// undefined, so onChoose never fired and the dialog never closed.
- const res = await backendCall<string | null>('pick_folder', {})
+ //
+ // `asWorkspace: true` (Fehler D): eine Wurzel, die die Rust-Seite nicht
+ // annimmt, kommt jetzt als Fehler zurueck und landet im Kasten darunter,
+ // statt als Pfad ausgeliefert zu werden, den spaeter jede
+ // Dateioperation mit "pick it again to allow it" beantwortet.
+ const res = await backendCall<string | null>('pick_folder', { asWorkspace: true })
if (res) {
// Commit + close right after the folder is chosen. Picking IS the
// decision — the dialog must go away (David 2026-06-06). Multi-repo
@@ -97,7 +102,9 @@ export function AgentWorkspaceDialog({
setError(null)
try {
// pick_folder returns the path as a STRING (or null), not an object.
- const res = await backendCall<string | null>('pick_folder', {})
+ // Ein Zusatzpfad ist genauso eine Kaefigwurzel wie der Hauptordner, also
+ // dieselbe Meldung (Fehler D).
+ const res = await backendCall<string | null>('pick_folder', { asWorkspace: true })
if (!res) {
setPicking(false)
return
diff --git a/src/components/chat/ExplorerPanel.tsx b/src/components/chat/ExplorerPanel.tsx
index 650834e5..84c7c08b 100644
--- a/src/components/chat/ExplorerPanel.tsx
+++ b/src/components/chat/ExplorerPanel.tsx
@@ -67,6 +67,7 @@ import { FilePreview } from './FilePreview'
import { useChatStore } from '../../stores/chatStore'
import { useTodoStore } from '../../stores/todoStore'
import { HINWEIS_TEXT } from '../../lib/hinweis'
+import { workspacePickRefusedMessage } from '../../lib/workspace-rejected'
const fsList: FsList = (args) => backendCall('fs_list', args as unknown as Record<string, unknown>)
@@ -181,20 +182,41 @@ export function ExplorerPanel({ onApprovePlan }: Props) {
if (next.includes(node.path) && !listings[node.path]) load(node.path)
}
- // Native folder picker. Tauri uses the Rust dialog, dev mode a prompt.
+ // Der Ordner-Dialog der gepackten App (Fehler D, aldrich_ironhart,
+ // 08.09.2026).
+ //
+ // `asWorkspace: true` laesst die Rust-Seite einen Ordner, den sie nicht als
+ // Arbeitsordner annimmt, MELDEN statt den Pfad zurueckzugeben, als waere
+ // nichts gewesen. Vorher landete so ein Ordner in der Kopfzeile, und jede
+ // Dateioperation darunter antwortete mit "pick it again to allow it", also
+ // genau mit dem, was der Nutzer gerade getan hatte. Ein abgelehnter Ordner
+ // wird deshalb GAR NICHT gesetzt.
+ //
+ // Der getippte Pfad als RUECKFALL ist weg, und nur er. Auf die
+ // Erlaubnisliste der gepackten App kommt ein Ordner ausschliesslich ueber
+ // `system::pick_folder` (weiter zu `remember_picked_root`); ein in ein
+ // `window.prompt` getippter Pfad war dort also ein Arbeitsordner, der nie
+ // funktionieren konnte, und der Weg heraus aus dem Fehler war derselbe
+ // Prompt. Im Browser des Dev-Servers ist es umgekehrt: dort gibt es weder
+ // einen nativen Dialog noch ueberhaupt eine Erlaubnisliste (die Begruendung
+ // steht in lib/dev-fs-jail.ts), der getippte Pfad ist der vorgesehene Weg
+ // und er funktioniert. Deshalb steht er dort und nur dort.
const pickFolder = async () => {
- let picked: string | null = null
- if (isTauri()) {
- try {
- const invoke = (await import('@tauri-apps/api/core')).invoke
- picked = await invoke<string | null>('pick_folder', { defaultPath: root || undefined })
- } catch {
- picked = window.prompt('Enter folder path:', root || (isMacOS() ? '/Users/' : 'C:\\Users'))
- }
- } else {
- picked = window.prompt('Enter folder path:', root || (isMacOS() ? '/Users/' : 'C:\\Users'))
+ setError(null)
+ if (!isTauri()) {
+ const typed = window.prompt('Enter folder path:', root || (isMacOS() ? '/Users/' : 'C:\\Users'))
+ if (typed) setWorkingDirectory(typed)
+ return
+ }
+ try {
+ const picked = await backendCall<string | null>('pick_folder', {
+ defaultPath: root || undefined,
+ asWorkspace: true,
+ })
+ if (picked) setWorkingDirectory(picked)
+ } catch (e) {
+ setError(workspacePickRefusedMessage(e))
}
- if (picked) setWorkingDirectory(picked)
}
// Give the folder back (A8). Users reported no way out of a folder they had
diff --git a/src/components/chat/__tests__/the-picked-folder-is-not-swallowed.test.ts b/src/components/chat/__tests__/the-picked-folder-is-not-swallowed.test.ts
new file mode 100644
index 00000000..a4e0c85f
--- /dev/null
+++ b/src/components/chat/__tests__/the-picked-folder-is-not-swallowed.test.ts
@@ -0,0 +1,141 @@
+/**
+ * Bug D, symptom 3. Discord ticket, aldrich_ironhart, 2026-09-08, Windows 11,
+ * LU 2.6.8, provider Ollama, DESKTOP app, Code tab:
+ *
+ * "Error: Not an allowed workspace folder (only a folder you chose in LU's
+ * folder picker can be a workspace, pick it again to allow it): D:\code"
+ *
+ * for a folder he had picked. Three things in the Code tab's folder button made
+ * that a closed loop, and none of them was measured.
+ *
+ * 1. `system::pick_folder` recorded the folder with `let _ = …`, so a folder
+ * the allowlist refuses came back as `Ok(Some(path))` with the reason
+ * thrown away. The panel put it in the header as the working directory, and
+ * every file op under it answered with the sentence above.
+ * 2. The panel fell back to `window.prompt('Enter folder path:')` whenever the
+ * bridge call threw. A folder joins the allowlist through the NATIVE dialog
+ * and nowhere else, so a typed path was a workspace that could never work
+ * in the packaged app, and the way out of the error was the same prompt.
+ * (In the dev server's browser there is no allowlist at all, so the prompt
+ * is the intended mechanism there and stays.)
+ * 3. `check_workspace_root` asked the allowlist BEFORE the structural gate, so
+ * folders no pick can ever allow ($HOME, `C:\Users`, anything under
+ * `AppData`) were also told to "pick it again", which is the one action
+ * that cannot help.
+ *
+ * Source-level assertions, because `vitest.config.ts` runs environment 'node'
+ * and there is no renderer. The MESSAGE is checked for real, it is a pure
+ * function. Same split as
+ * src/components/layout/__tests__/der-abgelehnte-ordner-wird-nicht-verschluckt.test.ts,
+ * which pins the same repair on the Remote-dispatch picker.
+ *
+ * Run: npx vitest run src/components/chat/__tests__/the-picked-folder-is-not-swallowed.test.ts
+ */
+import { describe, it, expect } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+import { workspacePickRefusedMessage } from '../../../lib/workspace-rejected'
+
+const src = (...parts: string[]) => readFileSync(resolve(__dirname, '..', '..', '..', ...parts), 'utf8')
+
+/** The body of `pickFolder` in the explorer panel, braces counted. */
+function pickFolderBody(): string {
+ const raw = src('components', 'chat', 'ExplorerPanel.tsx')
+ const at = raw.indexOf('const pickFolder')
+ expect(at, 'the folder button lost its handler').toBeGreaterThan(0)
+ const open = raw.indexOf('{', raw.indexOf('=>', at))
+ let depth = 0
+ for (let i = open; i < raw.length; i++) {
+ if (raw[i] === '{') depth++
+ else if (raw[i] === '}') {
+ depth--
+ if (depth === 0) return raw.slice(open, i + 1)
+ }
+ }
+ return raw.slice(open)
+}
+
+describe('the Code tab folder button', () => {
+ it('asks for the folder AS A WORKSPACE, so a refusal comes back', () => {
+ const body = pickFolderBody()
+ expect(body, 'pick_folder is called without asWorkspace').toContain('asWorkspace: true')
+ })
+
+ it('never offers a typed path as a FALLBACK, because it can never be allowed', () => {
+ const body = pickFolderBody()
+ // The prompt itself may stay: `npm run dev` in a browser has no native
+ // dialog and no allowlist either (lib/dev-fs-jail.ts says why), so a typed
+ // path is the intended mechanism THERE. What must never come back is the
+ // prompt as the answer to a failed bridge call, where the typed path lands
+ // in the header and can then never be a workspace.
+ const prompts = body.match(/window\.prompt\(/g) ?? []
+ expect(prompts.length, 'more than the one dev-server prompt').toBeLessThanOrEqual(1)
+ const tryAt = body.indexOf('try {')
+ expect(tryAt, 'the bridge call is not guarded at all').toBeGreaterThan(0)
+ expect(body.slice(tryAt), 'the window.prompt fallback is back').not.toContain('window.prompt')
+ expect(body.indexOf('window.prompt'), 'the prompt is not in the no-bridge branch')
+ .toBeLessThan(tryAt === -1 ? Number.MAX_SAFE_INTEGER : tryAt)
+ })
+
+ it('a refused folder is reported and NOT set as the working directory', () => {
+ const body = pickFolderBody()
+ expect(body, 'the refusal never reaches the user').toContain('workspacePickRefusedMessage')
+ // The property that matters: nothing in the catch writes the folder. A
+ // `setWorkingDirectory` there would put the refused folder into the header
+ // anyway, and every file op under it would then answer with the sentence
+ // the user was just told to act on.
+ const catchAt = body.indexOf('} catch')
+ expect(catchAt, 'the refusal is not caught at all').toBeGreaterThan(0)
+ expect(body.slice(catchAt), 'the refused folder still lands in the header')
+ .not.toContain('setWorkingDirectory(')
+ })
+})
+
+describe('the native dialog reports what it refused to record', () => {
+ it('pick_folder no longer discards the recording result', () => {
+ const rust = readFileSync(
+ resolve(__dirname, '..', '..', '..', '..', 'src-tauri', 'src', 'commands', 'system.rs'),
+ 'utf8',
+ )
+ const at = rust.indexOf('pub async fn pick_folder')
+ expect(at, 'pick_folder is gone').toBeGreaterThan(0)
+ const body = rust.slice(at, at + 1200)
+ expect(body, 'the reason is discarded again').not.toMatch(/let _ = .*remember_picked_root/)
+ expect(body, 'as_workspace does not gate the refusal').toContain('as_workspace')
+ })
+
+ it('the structural gate decides the MESSAGE before the allowlist does', () => {
+ const rust = readFileSync(
+ resolve(__dirname, '..', '..', '..', '..', 'src-tauri', 'src', 'commands', 'filesystem.rs'),
+ 'utf8',
+ )
+ const at = rust.indexOf('fn check_workspace_root')
+ expect(at, 'check_workspace_root is gone').toBeGreaterThan(0)
+ const body = rust.slice(at, rust.indexOf('\n}', at))
+ const gate = body.indexOf('may_be_a_picked_root')
+ const list = body.indexOf('PICKED_ROOTS')
+ expect(gate, 'the structural gate is gone').toBeGreaterThan(0)
+ expect(list, 'the allowlist is gone').toBeGreaterThan(0)
+ expect(gate, 'a folder no pick can allow is still told to pick it again').toBeLessThan(list)
+ })
+})
+
+describe('the sentence the user reads', () => {
+ it('carries the real reason and says the folder was not taken', () => {
+ const satz = workspacePickRefusedMessage(new Error('a home or mount container is not a workspace'))
+ expect(satz).toContain('a home or mount container is not a workspace')
+ expect(satz).toContain('not taken')
+ })
+
+ it('survives a thrown plain string instead of an Error', () => {
+ expect(workspacePickRefusedMessage('system or credential directory')).toContain(
+ 'system or credential directory',
+ )
+ expect(workspacePickRefusedMessage('x')).not.toContain('undefined')
+ })
+
+ it('never tells the user to do the thing that cannot work', () => {
+ const satz = workspacePickRefusedMessage(new Error('system or credential directory'))
+ expect(satz.toLowerCase(), 'the closed loop is back').not.toContain('pick it again')
+ })
+})
diff --git a/src/lib/workspace-rejected.ts b/src/lib/workspace-rejected.ts
index f219025f..dbc6ec3b 100644
--- a/src/lib/workspace-rejected.ts
+++ b/src/lib/workspace-rejected.ts
@@ -15,16 +15,44 @@
* Wortlaut pruefbar ist. Ohne Renderer im Testlauf waere er sonst die einzige
* Stelle dieser Reparatur, die niemand messen kann.
*/
+/**
+ * Der Grund aus einem geworfenen Ding. `backendCall` wirft nicht immer ein
+ * Error. Ein roher String muss genauso durchkommen wie eine Message, sonst
+ * steht am Ende "undefined" im Satz.
+ */
+function grundText(fehler: unknown): string {
+ return fehler instanceof Error ? fehler.message
+ : typeof fehler === 'string' ? fehler
+ : String(fehler)
+}
+
export function workspaceRejectedMessage(pfad: string, fehler: unknown): string {
- // `backendCall` wirft nicht immer ein Error. Ein roher String muss genauso
- // durchkommen wie eine Message, sonst steht am Ende "undefined" im Satz.
- const grund =
- fehler instanceof Error ? fehler.message
- : typeof fehler === 'string' ? fehler
- : String(fehler)
return (
- `Cannot use "${pfad}" as the workspace: ${grund}. `
+ `Cannot use "${pfad}" as the workspace: ${grundText(fehler)}. `
+ `Nothing was started, and no folder is bound to the remote session. `
+ `Pick a project folder instead of a system or home directory.`
)
}
+
+/**
+ * Derselbe Fall eine Stufe frueher: der NATIVE DIALOG hat einen Ordner
+ * geliefert, den die Rust-Seite nicht als Arbeitsordner annimmt, und
+ * `pick_folder` meldet das seit Fehler D (aldrich_ironhart, 08.09.2026) mit
+ * `asWorkspace`, statt den Pfad auszuliefern, als waere nichts gewesen.
+ *
+ * Eigener Satz und nicht `workspaceRejectedMessage`: dort steht "no folder is
+ * bound to the remote session", und der Code-Reiter hat keine Fernsitzung. Der
+ * Pfad steht hier auch nicht drin: bei einem Fehler gibt der Dialog keinen
+ * zurueck, und ein erfundener waere schlimmer als keiner. Der Ordner bleibt in
+ * diesem Fall UNGESETZT, das ist die eigentliche Reparatur: ein abgelehnter
+ * Ordner in der Kopfzeile beantwortet jede spaetere Dateioperation mit
+ * "pick it again to allow it", also genau mit dem, was der Nutzer gerade getan
+ * hat.
+ */
+export function workspacePickRefusedMessage(fehler: unknown): string {
+ return (
+ `That folder cannot be the workspace: ${grundText(fehler)}. `
+ + `The folder was not taken. `
+ + `Pick a project folder, not a drive root, a home directory or a system folder.`
+ )
+}