Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(update): make the release endpoint injectable for tests, without making it configurable\n\n`check_available()` built `https://api.github.com/...` inline, so the HTTP and\nJSON-parse path could only ever run against the live endpoint. No test could\ntell "failed to fetch latest release" from a genuine "no update", and the call\nis subject to GitHub's unauthenticated 60/h/IP limit, so the same test could\ntake either branch on different runs. `scheduler_tests.rs` says exactly this,\nand skips testing `tick()` for that reason, naming\n`check_available_with_url(base_url)` as the refactor it wanted.\n\n`check_available()` is now a two-line wrapper over a private\n`check_available_with_base_url(base_url)`. Only the URL construction changed —\nthe transport-failure classifier, the observability branches, the non-2xx\nhandling and asset selection are untouched.\n\nPrivate, and not an env var, on purpose. #6089 asks whether an operator-supplied\nupdate endpoint should be allowed to bypass `ops::validate_download_url`'s\nGitHub host allowlist; this avoids answering that rather than answering it\nwrongly. A runtime-overridable release endpoint would be a self-update\nredirection primitive on the highest-trust path in the product. The seam is\nreachable only from the unit suite, which points it at a wiremock server.\n\nFive tests: platform asset selection against a decoy for another triple, the\nno-update branch, a 403 rate-limit response, a malformed body, and a pin that\nthe URL a shipped binary builds is byte-identical to the previous literal —\nthat last one is what breaks if someone later makes the origin configurable.\n\nCloses #6089\n\nClaude-Session: https://claude.ai/code/session_01Rx5Fzc5keoeUQB3MwMFqMM\n

M3gA-Mind75671bdd5981
diff --git a/src/openhuman/platform/update/core.rs b/src/openhuman/platform/update/core.rs
index fb9e152371..5944d6c931 100644
--- a/src/openhuman/platform/update/core.rs
+++ b/src/openhuman/platform/update/core.rs
@@ -17,6 +17,10 @@ use crate::openhuman::util::utf8_safe_prefix_at_byte_boundary;
const GITHUB_OWNER: &str = "tinyhumansai";
const GITHUB_REPO: &str = "openhuman";
+/// Origin of the release-metadata API. Not configurable at runtime — see
+/// `check_available_with_base_url`.
+const GITHUB_API_BASE: &str = "https://api.github.com";
+
/// Current binary version (set at compile time from Cargo.toml).
pub fn current_version() -> &'static str {
env!("CARGO_PKG_VERSION")
@@ -87,13 +91,25 @@ fn is_newer(latest: &str, current: &str) -> bool {
/// Check GitHub Releases for a newer version of openhuman-core.
pub async fn check_available() -> Result<UpdateInfo, String> {
+ check_available_with_base_url(GITHUB_API_BASE).await
+}
+
+/// `check_available`, with the API origin injected.
+///
+/// Deliberately **private**, and deliberately not an env var. `ops::validate_download_url`
+/// pins asset downloads to the GitHub host allowlist on purpose; a runtime-overridable
+/// release endpoint would be a self-update redirection primitive on the highest-trust
+/// path in the product. The only caller besides `check_available` is the unit suite,
+/// which points it at a local mock — which is what the note in `scheduler_tests.rs`
+/// asked for.
+async fn check_available_with_base_url(base_url: &str) -> Result<UpdateInfo, String> {
let current = current_version();
log::info!(
"[update] checking for updates — current version: {}",
current
);
- let url = format!("https://api.github.com/repos/{GITHUB_OWNER}/{GITHUB_REPO}/releases/latest");
+ let url = format!("{base_url}/repos/{GITHUB_OWNER}/{GITHUB_REPO}/releases/latest");
let client = reqwest::Client::builder()
.user_agent("openhuman-core-updater")
diff --git a/src/openhuman/platform/update/core_tests.rs b/src/openhuman/platform/update/core_tests.rs
index e5d9b879c9..6628cc0a78 100644
--- a/src/openhuman/platform/update/core_tests.rs
+++ b/src/openhuman/platform/update/core_tests.rs
@@ -37,3 +37,131 @@ async fn transport_failure_classifier_catches_unreachable_host() {
"unreachable-host reqwest error must classify as transport: {err}"
);
}
+
+// ---------------------------------------------------------------------------
+// #6089: `check_available` used to build `https://api.github.com/...` inline, so
+// the HTTP + JSON-parse path could only be exercised against the live endpoint —
+// which `scheduler_tests.rs` calls out as the reason `tick()` is untested. These
+// drive the private `check_available_with_base_url` seam against a local mock.
+// ---------------------------------------------------------------------------
+
+/// The release JSON GitHub actually returns, trimmed to the fields we parse.
+/// `decoy` is an asset for another platform: it must never be selected.
+fn release_body(tag: &str) -> String {
+ let triple = platform_triple();
+ format!(
+ r#"{{
+ "tag_name": "{tag}",
+ "body": "release notes for {tag}",
+ "published_at": "2026-09-08T00:00:00Z",
+ "assets": [
+ {{"name": "openhuman-core-some-other-triple", "browser_download_url": "https://example.invalid/decoy", "size": 1}},
+ {{"name": "openhuman-core-{triple}", "browser_download_url": "https://example.invalid/{triple}", "size": 2}}
+ ]
+ }}"#
+ )
+}
+
+async fn releases_mock(status: u16, body: &str) -> wiremock::MockServer {
+ use wiremock::matchers::{method, path};
+ use wiremock::{Mock, MockServer, ResponseTemplate};
+
+ let server = MockServer::start().await;
+ Mock::given(method("GET"))
+ .and(path("/repos/tinyhumansai/openhuman/releases/latest"))
+ .respond_with(ResponseTemplate::new(status).set_body_string(body))
+ .mount(&server)
+ .await;
+ server
+}
+
+#[tokio::test]
+async fn check_available_parses_a_release_and_picks_this_platforms_asset() {
+ let server = releases_mock(200, &release_body("v99.0.0")).await;
+
+ let info = check_available_with_base_url(&server.uri())
+ .await
+ .expect("mocked release must parse");
+
+ assert_eq!(info.latest_version, "99.0.0", "the leading v is stripped");
+ assert_eq!(info.current_version, current_version());
+ assert!(
+ info.update_available,
+ "99.0.0 is newer than {}",
+ current_version()
+ );
+ assert_eq!(
+ info.asset_name.as_deref(),
+ Some(format!("openhuman-core-{}", platform_triple()).as_str()),
+ "the decoy asset for another triple must not be selected"
+ );
+ assert_eq!(
+ info.download_url.as_deref(),
+ Some(format!("https://example.invalid/{}", platform_triple()).as_str())
+ );
+ assert_eq!(
+ info.release_notes.as_deref(),
+ Some("release notes for v99.0.0")
+ );
+ assert_eq!(info.published_at.as_deref(), Some("2026-09-08T00:00:00Z"));
+}
+
+#[tokio::test]
+async fn check_available_reports_no_update_for_an_older_tag() {
+ let server = releases_mock(200, &release_body("v0.0.1")).await;
+
+ let info = check_available_with_base_url(&server.uri())
+ .await
+ .expect("mocked release must parse");
+
+ assert_eq!(info.latest_version, "0.0.1");
+ assert!(
+ !info.update_available,
+ "0.0.1 must not be newer than {}",
+ current_version()
+ );
+}
+
+#[tokio::test]
+async fn check_available_surfaces_a_non_2xx_as_a_github_api_error() {
+ // 403 is what the unauthenticated rate limit returns — the case the issue
+ // says a caller currently cannot tell apart from "no update".
+ let server = releases_mock(403, r#"{"message":"API rate limit exceeded"}"#).await;
+
+ let err = check_available_with_base_url(&server.uri())
+ .await
+ .expect_err("a 403 must not be reported as a successful check");
+
+ assert!(
+ err.contains("GitHub API error: 403"),
+ "error must name the status, got: {err}"
+ );
+}
+
+#[tokio::test]
+async fn check_available_surfaces_a_malformed_body_as_a_parse_error() {
+ let server = releases_mock(200, "{ not json").await;
+
+ let err = check_available_with_base_url(&server.uri())
+ .await
+ .expect_err("a malformed body must not be reported as a successful check");
+
+ assert!(
+ err.contains("failed to parse release JSON"),
+ "error must distinguish parse from transport, got: {err}"
+ );
+}
+
+/// The seam exists for tests only: the shipped binary must still resolve the
+/// pinned GitHub origin. Guards the extraction itself — if someone later makes
+/// the base URL configurable at runtime, this is what breaks, and
+/// `ops::validate_download_url`'s host allowlist is why that matters.
+#[test]
+fn the_default_origin_is_still_the_pinned_github_api() {
+ assert_eq!(GITHUB_API_BASE, "https://api.github.com");
+ assert_eq!(
+ format!("{GITHUB_API_BASE}/repos/{GITHUB_OWNER}/{GITHUB_REPO}/releases/latest"),
+ "https://api.github.com/repos/tinyhumansai/openhuman/releases/latest",
+ "the URL check_available() builds must be byte-identical to the pre-refactor literal"
+ );
+}
diff --git a/src/openhuman/platform/update/scheduler_tests.rs b/src/openhuman/platform/update/scheduler_tests.rs
index 65dba4e2ea..521d81dce9 100644
--- a/src/openhuman/platform/update/scheduler_tests.rs
+++ b/src/openhuman/platform/update/scheduler_tests.rs
@@ -28,9 +28,8 @@ async fn run_returns_immediately_when_disabled() {
// `update_core::check_available()` which performs a real HTTPS request
// to api.github.com — running that from the unit suite makes the test
// flaky (offline CI runners, rate limits, DNS hiccups). Coverage of
-// the HTTP + JSON-parse path is better handled via an integration test
-// that uses an HTTP mock (e.g. `httpmock`) around a refactored
-// `check_available_with_url(base_url)`. For now the surrounding
-// properties are locked down by:
+// the HTTP + JSON-parse path now lives in `core_tests.rs`, which drives
+// `check_available_with_base_url(base_url)` against a wiremock server
+// (#6089). The surrounding scheduler properties are locked down here by:
// - `min_interval_is_at_least_ten_minutes` (rate-limit floor)
// - `run_returns_immediately_when_disabled` (disabled short-circuit)