From 0fff52c9980f7f34d640ec54382ddaa93f544d47 Mon Sep 17 00:00:00 2001 From: BryanFRD Date: Sat, 3 Oct 2026 11:56:12 +0200 Subject: [PATCH 1/2] fix(cli): reach /health and /ready above a named forge's prefix in doctor --- cli/src/client.rs | 19 ++++++++++++++++++- cli/src/client/tests.rs | 29 +++++++++++++++++++++++++++++ cli/src/doctor.rs | 4 ++-- 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 cli/src/client/tests.rs diff --git a/cli/src/client.rs b/cli/src/client.rs index f53184f8..cbeb4395 100644 --- a/cli/src/client.rs +++ b/cli/src/client.rs @@ -31,7 +31,14 @@ impl Server { } pub fn get(&self, path: &str) -> Result { - let url = format!("{}{path}", self.base); + self.fetch(format!("{}{path}", self.base)) + } + + pub fn get_from_root(&self, path: &str) -> Result { + self.fetch(format!("{}{path}", service_root(&self.base))) + } + + fn fetch(&self, url: String) -> Result { self.authenticated(self.client.get(&url)) .send() .with_context(|| format!("could not reach {url}")) @@ -57,6 +64,13 @@ impl Server { } } +pub fn service_root(base: &str) -> &str { + match base.rsplit_once("/-/") { + Some((root, forge)) if !forge.is_empty() && !forge.contains('/') => root, + _ => base, + } +} + pub fn resolve_token(explicit: Option) -> Option { explicit .or_else(|| std::env::var("LFSX_TOKEN").ok()) @@ -70,3 +84,6 @@ pub fn split_namespace(repository: &str) -> Result<(&str, &str)> { _ => bail!("expected a repository as org/repo, got {repository:?}"), } } + +#[cfg(test)] +mod tests; diff --git a/cli/src/client/tests.rs b/cli/src/client/tests.rs new file mode 100644 index 00000000..3da4c0b0 --- /dev/null +++ b/cli/src/client/tests.rs @@ -0,0 +1,29 @@ +use super::*; + +#[test] +fn the_health_routes_are_found_above_a_named_forge() { + assert_eq!( + service_root("https://lfs.example.com/-/work"), + "https://lfs.example.com" + ); + assert_eq!( + service_root("https://example.com/lfs/-/work"), + "https://example.com/lfs" + ); +} + +#[test] +fn a_base_without_a_forge_is_its_own_root() { + assert_eq!( + service_root("https://lfs.example.com"), + "https://lfs.example.com" + ); + assert_eq!( + service_root("https://example.com/lfs"), + "https://example.com/lfs" + ); + assert_eq!( + service_root("https://lfs.example.com/-/"), + "https://lfs.example.com/-/" + ); +} diff --git a/cli/src/doctor.rs b/cli/src/doctor.rs index 779fad58..4feaea85 100644 --- a/cli/src/doctor.rs +++ b/cli/src/doctor.rs @@ -34,13 +34,13 @@ impl Report { pub fn run(server: &Server, repository: Option<&str>) -> Result { let mut report = Report::new(); - match server.get("/health") { + match server.get_from_root("/health") { Ok(response) if response.status().is_success() => report.pass("the server is up"), Ok(response) => report.fail(format!("/health answered {}", response.status())), Err(error) => report.fail(format!("{error:#}")), } - match server.get("/ready") { + match server.get_from_root("/ready") { Ok(response) if response.status().is_success() => { report.pass("the storage root is writable") } From 266658382865ff70bd38bc4cec4268a1232d4c2b Mon Sep 17 00:00:00 2001 From: BryanFRD Date: Sat, 3 Oct 2026 11:59:51 +0200 Subject: [PATCH 2/2] fix(cli): drop the base-relative get doctor no longer uses --- cli/src/client.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cli/src/client.rs b/cli/src/client.rs index cbeb4395..14ec2f6e 100644 --- a/cli/src/client.rs +++ b/cli/src/client.rs @@ -30,10 +30,6 @@ impl Server { &self.base } - pub fn get(&self, path: &str) -> Result { - self.fetch(format!("{}{path}", self.base)) - } - pub fn get_from_root(&self, path: &str) -> Result { self.fetch(format!("{}{path}", service_root(&self.base))) }