Skip to content
Open
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
5 changes: 2 additions & 3 deletions hindsight-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2199,11 +2199,10 @@ fn handle_configure(

// Validate the URL
if !new_api_url.starts_with("http://") && !new_api_url.starts_with("https://") {
ui::print_error(&format!(
anyhow::bail!(
"Invalid API URL: {}. Must start with http:// or https://",
new_api_url
));
return Ok(());
);
}

// Use provided api_key, or keep existing one if not provided
Expand Down
37 changes: 37 additions & 0 deletions hindsight-cli/tests/cli_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,40 @@ fn hindsight_profile_env_var_is_honored() {
+ &String::from_utf8_lossy(&out.stdout);
assert!(err.contains("from-env"), "expected profile URL in output:\n{}", err);
}

#[test]
fn configure_rejects_invalid_url_with_nonzero_exit() {
let home = unique_tempdir("bad-url");
let out = run_with_home(
&home,
&[
"configure",
"--api-url",
"not-a-valid-url",
"--api-key",
"test-key",
],
);

assert!(
!out.status.success(),
"configure with invalid URL should exit non-zero, got success"
);
assert!(
stderr(&out).contains("Invalid API URL"),
"expected error message on stderr, got:\n{}",
stderr(&out)
);
}

#[test]
fn configure_accepts_valid_http_and_https_urls() {
for url in ["http://localhost:8080", "https://api.example.com"] {
let home = unique_tempdir("valid-url");
let out = run_with_home(
&home,
&["configure", "--api-url", url, "--api-key", "test-key"],
);
assert_success(&out);
}
}