Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build-config/buildspec-linux-minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ phases:
# Install cargo
- curl --retry 5 --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- . "$HOME/.cargo/env"
- rustup toolchain install `cat rust-toolchain.toml | grep channel | cut -d '=' -f2 | tr -d ' "'`
# Install cross only if the musl env var is set and not null
- if [ ! -z "${AMAZON_Q_BUILD_MUSL:+x}" ]; then cargo install cross --git https://github.com/cross-rs/cross; fi
# Install python/node via mise (https://mise.jdx.dev/continuous-integration.html)
Expand Down
1 change: 1 addition & 0 deletions build-config/buildspec-linux-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ phases:
# Install cargo
- curl --retry 5 --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- . "$HOME/.cargo/env"
- rustup toolchain install `cat rust-toolchain.toml | grep channel | cut -d '=' -f2 | tr -d ' "'`
# Install tauri-cli, required for building and bundling the desktop app
- cargo install --version 1.6.2 tauri-cli
# Install cross only if the musl env var is set and not null
Expand Down
32 changes: 32 additions & 0 deletions crates/q_cli/src/cli/chat/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ fn absolute_to_relative(cwd: impl AsRef<Path>, path: impl AsRef<Path>) -> Result
if a == b {
cwd_parts.next();
path_parts.next();
} else {
break;
}
}

Expand All @@ -250,6 +252,14 @@ fn absolute_to_relative(cwd: impl AsRef<Path>, path: impl AsRef<Path>) -> Result
fn format_path(cwd: impl AsRef<Path>, path: impl AsRef<Path>) -> String {
absolute_to_relative(cwd, path.as_ref())
.map(|p| p.to_string_lossy().to_string())
// If we have three consecutive ".." then it should probably just stay as an absolute path.
.map(|p| {
if p.starts_with("../../..") {
path.as_ref().to_string_lossy().to_string()
} else {
p
}
})
.unwrap_or(path.as_ref().to_string_lossy().to_string())
}

Expand Down Expand Up @@ -407,4 +417,26 @@ mod tests {
"tilde should not expand when not the first component"
);
}

#[tokio::test]
async fn test_format_path() {
async fn assert_paths(cwd: &str, path: &str, expected: &str) {
let ctx = Context::builder().with_test_home().await.unwrap().build_fake();
let fs = ctx.fs();
let cwd = sanitize_path_tool_arg(&ctx, cwd);
let path = sanitize_path_tool_arg(&ctx, path);
fs.create_dir_all(&cwd).await.unwrap();
fs.create_dir_all(&path).await.unwrap();
// Using `contains` since the chroot test directory will prefix the formatted path with a tmpdir
// path.
assert!(format_path(cwd, path).contains(expected));
}
assert_paths("/Users/testuser/src", "/Users/testuser/Downloads", "../Downloads").await;
assert_paths(
"/Users/testuser/projects/MyProject/src",
"/Volumes/projects/MyProject/src",
"/Volumes/projects/MyProject/src",
)
.await;
}
}
1 change: 1 addition & 0 deletions typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ zvariant = "zvariant"
ser = "ser"
sur = "sur"
ratatui = "ratatui"
typ = "typ"

[type.rust.extend-identifiers]
# typos really wanted to correct 2ND -> 2AND
Expand Down
Loading