From 4dfb607c9e8ef53ae9341438d21e900e1e94bf8a Mon Sep 17 00:00:00 2001 From: Jonathan Little Date: Tue, 28 Oct 2025 21:50:34 -0700 Subject: [PATCH] fix: expand ~ in prompt file:// URIs --- crates/chat-cli/src/util/file_uri.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/chat-cli/src/util/file_uri.rs b/crates/chat-cli/src/util/file_uri.rs index 37b402cd57..ecb987af0d 100644 --- a/crates/chat-cli/src/util/file_uri.rs +++ b/crates/chat-cli/src/util/file_uri.rs @@ -40,6 +40,9 @@ pub fn resolve_file_uri(uri: &str, base_path: &Path) -> Result Result<(), Box> { + // Test that tilde gets expanded by verifying the path is absolute after expansion + // We can't easily mock HOME and don't want to write test files there, but we can verify + // the expansion behavior using error messages + let uri = "file://~/test.txt"; + let base = Path::new("/some/other/path"); + + // This will fail to find the file (expected), but the error should show + // an expanded absolute path, not a path with literal ~ + let result = resolve_file_uri(uri, base); + + match result { + Err(FileUriError::FileNotFound { path }) => { + // Verify the path was expanded (should start with / not ~) + assert!(path.starts_with("/"), "Path should be absolute after tilde expansion, got: {:?}", path); + assert!(!path.to_string_lossy().contains("~"), "Path should not contain literal tilde, got: {:?}", path); + }, + _ => panic!("Expected FileNotFound error"), + } + + Ok(()) + } }