Skip to content

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

test(skills): cover registry paging, detail and outages over JSON-RPC

oxoxDev7e07a8ed486d
diff --git a/tests/in_process/skill_registry_e2e.rs b/tests/in_process/skill_registry_e2e.rs
index fc5f4a053d..159906782c 100644
--- a/tests/in_process/skill_registry_e2e.rs
+++ b/tests/in_process/skill_registry_e2e.rs
@@ -1,7 +1,8 @@
-//! Skill registry E2E: exercises browse, search, sources, and install
-//! JSON-RPC endpoints against a real core router.
+//! Skill registry E2E: exercises browse, search, sources, detail, install
+//! and uninstall JSON-RPC endpoints against a real core router backed by the
+//! tinyskills `SkillRegistry`.
//!
-//! Run: `cargo test -p openhuman-cli --test in_process_all`
+//! Run: `cargo test -p openhuman-cli --test in_process_all skill_registry`
//!
//! The test uses a local fixture catalog and local SKILL.md download URL so CI
//! does not depend on the live Hermes API.
@@ -11,9 +12,15 @@ use crate::env_guard::EnvVarGuard;
use crate::rpc_auth::{ensure_rpc_auth, rpc_token};
use openhuman_core::core::auth::CORE_TOKEN_ENV_VAR;
use std::net::SocketAddr;
+use std::path::Path;
+use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
+use std::sync::Arc;
use std::time::Duration;
+use axum::extract::State;
use axum::http::header::AUTHORIZATION;
+use axum::http::StatusCode;
+use axum::response::{IntoResponse, Response};
use axum::routing::get;
use axum::Router;
use serde_json::{json, Value};
@@ -21,13 +28,7 @@ use tempfile::tempdir;
use openhuman_rpc::server::build_core_http_router;
-// ── Constants ──────────────────────────────────────────────────────────────
-
-// ── One-time auth init ─────────────────────────────────────────────────────
-
-// ── Env lock (process-global env vars must not race) ──────────────────────
-
-// ── EnvVarGuard ───────────────────────────────────────────────────────────
+const FILLER_ENTRIES: usize = 28;
// ── Server helpers ─────────────────────────────────────────────────────────
@@ -46,43 +47,67 @@ async fn serve_on_ephemeral(
(addr, handle)
}
-async fn serve_fixture_catalog() -> (
- SocketAddr,
- tokio::task::JoinHandle<Result<(), std::io::Error>>,
-) {
- async fn catalog() -> axum::Json<Value> {
- axum::Json(json!([
- {
- "name": "git-helper",
- "description": "Automate git status and branch triage.",
- "overview": "Fixture skill for registry tests.",
- "category": "software-development",
- "categoryLabel": "Software Development",
- "source": "fixture",
- "tags": ["git", "workflow"],
- "platforms": ["linux", "macos"],
- "author": "OpenHuman Test",
- "version": "1.0.0",
- "license": "MIT",
- "envVars": [],
- "commands": ["git"],
- "docsPath": "fixture/software-development/software-development-git-helper"
- },
- {
- "name": "notes-helper",
- "description": "Summarize notes.",
- "category": "productivity",
- "source": "fixture",
- "tags": ["notes"],
- "platforms": ["linux", "macos"],
- "envVars": [],
- "commands": []
- }
- ]))
+#[derive(Clone, Default)]
+struct FixtureState {
+ catalog_hits: Arc<AtomicUsize>,
+ offline: Arc<AtomicBool>,
+}
+
+fn fixture_catalog() -> Value {
+ let mut items = vec![
+ json!({
+ "name": "git-helper",
+ "description": "Automate git status and branch triage.",
+ "overview": "Fixture skill for registry tests.",
+ "category": "software-development",
+ "categoryLabel": "Software Development",
+ "source": "fixture",
+ "tags": ["git", "workflow"],
+ "platforms": ["linux", "macos"],
+ "author": "OpenHuman Test",
+ "version": "1.0.0",
+ "license": "MIT",
+ "envVars": [],
+ "commands": ["git"],
+ "docsPath": "fixture/software-development/software-development-git-helper"
+ }),
+ json!({
+ "name": "notes-helper",
+ "description": "Summarize notes.",
+ "category": "productivity",
+ "source": "fixture",
+ "tags": ["notes"],
+ "platforms": ["linux", "macos"],
+ "envVars": [],
+ "commands": []
+ }),
+ ];
+ items.extend((0..FILLER_ENTRIES).map(|i| {
+ json!({
+ "name": format!("filler-{i:02}"),
+ "description": "Padding so the catalog spans more than one page.",
+ "category": "productivity",
+ "source": "fixture-extra",
+ "tags": [],
+ "platforms": [],
+ "envVars": [],
+ "commands": []
+ })
+ }));
+ Value::Array(items)
+}
+
+async fn catalog(State(state): State<FixtureState>) -> Response {
+ state.catalog_hits.fetch_add(1, Ordering::SeqCst);
+ if state.offline.load(Ordering::SeqCst) {
+ return StatusCode::SERVICE_UNAVAILABLE.into_response();
}
+ tokio::time::sleep(Duration::from_millis(50)).await;
+ axum::Json(fixture_catalog()).into_response()
+}
- async fn skill_md() -> &'static str {
- r#"---
+async fn skill_md() -> &'static str {
+ r#"---
name: git-helper
description: Automate git status and branch triage.
version: 1.0.0
@@ -102,12 +127,20 @@ Use when git state needs summarizing.
## Procedure
Run `git status --short` and report the result.
"#
- }
+}
+async fn serve_fixture_catalog() -> (
+ SocketAddr,
+ FixtureState,
+ tokio::task::JoinHandle<Result<(), std::io::Error>>,
+) {
+ let state = FixtureState::default();
let app = Router::new()
.route("/skills.json", get(catalog))
- .route("/skills/git-helper/SKILL.md", get(skill_md));
- serve_on_ephemeral(app).await
+ .route("/skills/git-helper/SKILL.md", get(skill_md))
+ .with_state(state.clone());
+ let (addr, join) = serve_on_ephemeral(app).await;
+ (addr, state, join)
}
// ── JSON-RPC helpers ───────────────────────────────────────────────────────
@@ -149,345 +182,378 @@ fn assert_no_jsonrpc_error<'a>(v: &'a Value, context: &str) -> &'a Value {
.unwrap_or_else(|| panic!("{context}: missing `result` field: {v}"))
}
-// ── Test ───────────────────────────────────────────────────────────────────
-
-/// End-to-end coverage for the `openhuman.skill_registry_*` endpoints.
-///
-/// Steps:
-/// 1. `sources` — lists the distinct upstream sources from the Hermes catalog.
-/// 2. `browse` — fetches the live catalog (force_refresh = true).
-/// 3. `search` — queries for "git" and expects at least one match.
-/// 4. `schemas` — exposes CLI/RPC schemas for prod smoke scripts.
-/// 5. `install` — happy-path install of a skill.
-/// 6. `install` — duplicate install returns idempotent success with no new skills.
-/// 7. `uninstall` — removes the installed skill.
-#[tokio::test]
-async fn skill_registry_e2e_sources_browse_search_install() {
- let _env_lock = env_lock_async().await;
-
- let tmp = tempdir().expect("create tempdir");
- let home = tmp.path();
- let openhuman_home = home.join(".openhuman");
+fn jsonrpc_error_message(v: &Value, context: &str) -> String {
+ let error = v
+ .get("error")
+ .unwrap_or_else(|| panic!("{context}: expected a JSON-RPC error, got {v}"));
+ error
+ .get("message")
+ .and_then(Value::as_str)
+ .unwrap_or_default()
+ .to_owned()
+}
- let _home_guard = EnvVarGuard::set_to_path("HOME", home);
- let _workspace_guard = EnvVarGuard::unset("OPENHUMAN_WORKSPACE");
- let _token_guard = EnvVarGuard::set(CORE_TOKEN_ENV_VAR, rpc_token());
- let _keyring_guard = EnvVarGuard::set("OPENHUMAN_KEYRING_BACKEND", "file");
+fn entry_names(result: &Value) -> Vec<String> {
+ result
+ .get("entries")
+ .and_then(Value::as_array)
+ .expect("result must contain an `entries` array")
+ .iter()
+ .filter_map(|e| e.get("name").and_then(Value::as_str).map(str::to_owned))
+ .collect()
+}
- let cfg_dir = openhuman_home.clone();
- std::fs::create_dir_all(&cfg_dir).expect("create .openhuman dir");
- std::fs::write(
- cfg_dir.join("config.toml"),
- r#"api_url = "http://127.0.0.1:9"
+fn write_core_config(home: &Path) {
+ let openhuman_home = home.join(".openhuman");
+ let config = r#"api_url = "http://127.0.0.1:9"
default_model = "skill-e2e-model"
[secrets]
encrypt = false
-"#,
- )
- .expect("write config.toml");
-
+"#;
+ std::fs::create_dir_all(&openhuman_home).expect("create .openhuman dir");
+ std::fs::write(openhuman_home.join("config.toml"), config).expect("write config.toml");
let user_cfg_dir = openhuman_home.join("users").join("local");
std::fs::create_dir_all(&user_cfg_dir).expect("create users/local dir");
- std::fs::write(
- user_cfg_dir.join("config.toml"),
- r#"api_url = "http://127.0.0.1:9"
-default_model = "skill-e2e-model"
+ std::fs::write(user_cfg_dir.join("config.toml"), config)
+ .expect("write users/local/config.toml");
+}
-[secrets]
-encrypt = false
-"#,
- )
- .expect("write users/local/config.toml");
+struct Stack {
+ rpc_base: String,
+ fixture_base: String,
+ fixture: FixtureState,
+ _guards: Vec<EnvVarGuard>,
+ joins: Vec<tokio::task::JoinHandle<Result<(), std::io::Error>>>,
+}
- let (fixture_addr, fixture_join) = serve_fixture_catalog().await;
- let fixture_base = format!("http://{fixture_addr}");
- let _catalog_guard = EnvVarGuard::set(
- "OPENHUMAN_SKILL_REGISTRY_CATALOG_URL",
- format!("{fixture_base}/skills.json"),
- );
- let _download_guard = EnvVarGuard::set(
- "OPENHUMAN_SKILL_REGISTRY_DOWNLOAD_BASE_URL",
- format!("{fixture_base}/skills"),
- );
- let _local_http_guard = EnvVarGuard::set("OPENHUMAN_SKILL_INSTALL_ALLOW_LOCAL_HTTP", "1");
+impl Drop for Stack {
+ fn drop(&mut self) {
+ for join in &self.joins {
+ join.abort();
+ }
+ }
+}
+async fn boot(home: &Path) -> Stack {
+ write_core_config(home);
+ let (fixture_addr, fixture, fixture_join) = serve_fixture_catalog().await;
+ let fixture_base = format!("http://{fixture_addr}");
+ let guards = vec![
+ EnvVarGuard::set_to_path("HOME", home),
+ EnvVarGuard::unset("OPENHUMAN_WORKSPACE"),
+ EnvVarGuard::set(CORE_TOKEN_ENV_VAR, rpc_token()),
+ EnvVarGuard::set("OPENHUMAN_KEYRING_BACKEND", "file"),
+ EnvVarGuard::unset("OPENHUMAN_SKILL_REGISTRY_CACHE_DIR"),
+ EnvVarGuard::set(
+ "OPENHUMAN_SKILL_REGISTRY_CATALOG_URL",
+ format!("{fixture_base}/skills.json"),
+ ),
+ EnvVarGuard::set(
+ "OPENHUMAN_SKILL_REGISTRY_DOWNLOAD_BASE_URL",
+ format!("{fixture_base}/skills"),
+ ),
+ EnvVarGuard::set("OPENHUMAN_SKILL_INSTALL_ALLOW_LOCAL_HTTP", "1"),
+ ];
let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;
- let rpc_base = format!("http://{rpc_addr}");
+ Stack {
+ rpc_base: format!("http://{rpc_addr}"),
+ fixture_base,
+ fixture,
+ _guards: guards,
+ joins: vec![rpc_join, fixture_join],
+ }
+}
- // ── Step 1: sources ────────────────────────────────────────────────────
+// ── Tests ──────────────────────────────────────────────────────────────────
+
+/// End-to-end coverage for the `openhuman.skill_registry_*` endpoints:
+/// concurrent cold reads share one upstream fetch, paging, multi-source
+/// filtering, search, detail, schemas, install (happy, duplicate, unknown id)
+/// and uninstall.
+#[tokio::test]
+async fn skill_registry_e2e_sources_browse_search_install() {
+ let _env_lock = env_lock_async().await;
+ let tmp = tempdir().expect("create tempdir");
+ let home = tmp.path();
+ let stack = boot(home).await;
+ let rpc_base = stack.rpc_base.as_str();
+
+ // ── Concurrent cold browses: one upstream fetch ──────────────────────
+ let mut reads = Vec::new();
+ for id in 0..5 {
+ let rpc_base = rpc_base.to_owned();
+ reads.push(tokio::spawn(async move {
+ post_json_rpc(
+ &rpc_base,
+ 9100 + id,
+ "openhuman.skill_registry_browse",
+ json!({ "page": 1, "page_size": 25 }),
+ )
+ .await
+ }));
+ }
+ for read in reads {
+ let response = read.await.expect("browse task");
+ let result = assert_no_jsonrpc_error(&response, "concurrent browse");
+ assert_eq!(result["total"], 2 + FILLER_ENTRIES as u64);
+ }
+ assert_eq!(
+ stack.fixture.catalog_hits.load(Ordering::SeqCst),
+ 1,
+ "concurrent cold reads must share one catalog fetch"
+ );
+ // ── sources ──────────────────────────────────────────────────────────
let sources_resp = post_json_rpc(
- &rpc_base,
+ rpc_base,
9001,
"openhuman.skill_registry_sources",
json!({}),
)
.await;
let sources_result = assert_no_jsonrpc_error(&sources_resp, "skill_registry_sources");
+ let sources: Vec<&str> = sources_result["sources"]
+ .as_array()
+ .expect("sources array")
+ .iter()
+ .filter_map(Value::as_str)
+ .collect();
+ assert_eq!(sources, ["fixture-extra", "fixture"], "most entries first");
- let sources = sources_result
- .get("sources")
- .and_then(Value::as_array)
- .expect("sources result must contain a `sources` array");
-
- assert!(
- !sources.is_empty(),
- "expected at least one source from the Hermes catalog"
- );
-
- // Sources should be string values (e.g. "built-in", "ClawHub", "skills.sh").
- for source in sources {
- assert!(
- source.is_string(),
- "each source must be a string, got: {source}"
- );
- }
-
- // ── Step 2: browse (force_refresh = true) ─────────────────────────────
-
- let browse_resp = post_json_rpc(
- &rpc_base,
+ // ── browse: pages 1 and 2 ────────────────────────────────────────────
+ let page_one = post_json_rpc(
+ rpc_base,
9002,
"openhuman.skill_registry_browse",
- json!({ "force_refresh": true }),
+ json!({ "page": 1, "page_size": 25 }),
)
.await;
- let browse_result = assert_no_jsonrpc_error(&browse_resp, "skill_registry_browse");
-
- let entries = browse_result
- .get("entries")
- .and_then(Value::as_array)
- .expect("browse result must contain an `entries` array");
-
- assert!(
- !entries.is_empty(),
- "browse catalog must return at least one entry after force_refresh"
- );
-
- // Every entry must carry the required fields.
- let required_entry_fields = [
- "id",
- "name",
- "description",
- "download_url",
- "source",
- "category",
- ];
- for entry in entries.iter().take(10) {
- for field in &required_entry_fields {
- assert!(
- entry.get(field).is_some(),
- "catalog entry missing field '{field}': {entry}"
- );
+ let page_one = assert_no_jsonrpc_error(&page_one, "browse page 1");
+ assert_eq!(page_one["page"], 1);
+ assert_eq!(page_one["total_pages"], 2);
+ assert_eq!(page_one["freshness"], "live");
+ assert!(page_one["last_error"].is_null());
+ assert_eq!(entry_names(page_one).len(), 25);
+ for entry in page_one["entries"].as_array().unwrap() {
+ for field in [
+ "id",
+ "name",
+ "description",
+ "download_url",
+ "source_url",
+ "source",
+ "category",
+ "registry",
+ "installable",
+ ] {
+ assert!(entry.get(field).is_some(), "entry missing '{field}': {entry}");
}
}
- // ── Step 3: search ────────────────────────────────────────────────────
-
- let search_resp = post_json_rpc(
- &rpc_base,
+ let page_two = post_json_rpc(
+ rpc_base,
9003,
- "openhuman.skill_registry_search",
- json!({ "query": "git" }),
+ "openhuman.skill_registry_browse",
+ json!({ "page": 2, "page_size": 25 }),
)
.await;
- let search_result = assert_no_jsonrpc_error(&search_resp, "skill_registry_search (git)");
+ let page_two = assert_no_jsonrpc_error(&page_two, "browse page 2");
+ assert_eq!(page_two["page"], 2);
+ assert_eq!(entry_names(page_two).len(), 2 + FILLER_ENTRIES - 25);
- let search_entries = search_result
- .get("entries")
- .and_then(Value::as_array)
- .expect("search result must contain an `entries` array");
+ // ── browse: unpaged legacy read returns everything ───────────────────
+ let unpaged = post_json_rpc(
+ rpc_base,
+ 9004,
+ "openhuman.skill_registry_browse",
+ json!({ "force_refresh": true }),
+ )
+ .await;
+ let unpaged = assert_no_jsonrpc_error(&unpaged, "browse unpaged");
+ assert_eq!(entry_names(unpaged).len(), 2 + FILLER_ENTRIES);
- assert!(
- !search_entries.is_empty(),
- "search for 'git' must return at least one match"
- );
+ // ── search with sources[] ────────────────────────────────────────────
+ let filtered = post_json_rpc(
+ rpc_base,
+ 9005,
+ "openhuman.skill_registry_search",
+ json!({ "query": "", "sources": ["fixture"], "page": 1 }),
+ )
+ .await;
+ let filtered = assert_no_jsonrpc_error(&filtered, "search sources[]");
+ let mut names = entry_names(filtered);
+ names.sort();
+ assert_eq!(names, ["git-helper", "notes-helper"]);
- for entry in search_entries.iter().take(5) {
- let name = entry
- .get("name")
- .and_then(Value::as_str)
- .unwrap_or("")
- .to_lowercase();
- let desc = entry
- .get("description")
- .and_then(Value::as_str)
- .unwrap_or("")
- .to_lowercase();
- let tags: Vec<String> = entry
- .get("tags")
- .and_then(Value::as_array)
- .map(|arr| {
- arr.iter()
- .filter_map(|t| t.as_str())
- .map(str::to_lowercase)
- .collect()
- })
- .unwrap_or_default();
- let category = entry
- .get("category")
- .and_then(Value::as_str)
- .unwrap_or("")
- .to_lowercase();
- let author = entry
- .get("author")
- .and_then(Value::as_str)
- .unwrap_or("")
- .to_lowercase();
-
- let matches = name.contains("git")
- || desc.contains("git")
- || tags.iter().any(|t| t.contains("git"))
- || category.contains("git")
- || author.contains("git");
- assert!(
- matches,
- "search result entry does not match query 'git': {entry}"
- );
- }
+ let search = post_json_rpc(
+ rpc_base,
+ 9006,
+ "openhuman.skill_registry_search",
+ json!({ "query": "git", "page": 1 }),
+ )
+ .await;
+ let search = assert_no_jsonrpc_error(&search, "search git");
+ assert_eq!(entry_names(search), ["git-helper"]);
+ let git_helper = &search["entries"][0];
+ assert_eq!(
+ git_helper["download_url"],
+ format!("{}/skills/git-helper/SKILL.md", stack.fixture_base)
+ );
+ let entry_id = git_helper["id"].as_str().expect("entry id").to_owned();
- // ── Step 4: schemas ───────────────────────────────────────────────────
+ // ── detail ───────────────────────────────────────────────────────────
+ let detail = post_json_rpc(
+ rpc_base,
+ 9007,
+ "openhuman.skill_registry_detail",
+ json!({ "entry_id": entry_id }),
+ )
+ .await;
+ let detail = assert_no_jsonrpc_error(&detail, "detail");
+ assert_eq!(detail["overview"], "Fixture skill for registry tests.");
+ assert_eq!(detail["license"], "MIT");
+ // ── schemas ──────────────────────────────────────────────────────────
let schemas_resp = post_json_rpc(
- &rpc_base,
- 9004,
+ rpc_base,
+ 9008,
"openhuman.skill_registry_schemas",
json!({}),
)
.await;
let schemas_result = assert_no_jsonrpc_error(&schemas_resp, "skill_registry_schemas");
- let schemas = schemas_result
- .get("schemas")
- .and_then(Value::as_array)
- .expect("schemas result must contain a `schemas` array");
- assert!(
- schemas.iter().any(|schema| {
- schema.get("function").and_then(Value::as_str) == Some("install")
- && schema.get("namespace").and_then(Value::as_str) == Some("skill_registry")
- }),
- "schemas must include skill_registry install schema: {schemas:?}"
- );
-
- // ── Step 5: install (happy path) ──────────────────────────────────────
-
- // Find the fixture entry with a local download_url.
- let install_target = entries
+ let functions: Vec<&str> = schemas_result["schemas"]
+ .as_array()
+ .expect("schemas array")
.iter()
- .find(|e| {
- e.get("download_url")
- .and_then(Value::as_str)
- .map(|u| u == format!("{fixture_base}/skills/git-helper/SKILL.md"))
- .unwrap_or(false)
- })
- .expect("expected the fixture git-helper download_url");
-
- let entry_id = install_target
- .get("id")
- .and_then(Value::as_str)
- .expect("install_target id");
+ .filter_map(|schema| schema.get("function").and_then(Value::as_str))
+ .collect();
+ for function in ["browse", "search", "detail", "install", "uninstall"] {
+ assert!(functions.contains(&function), "{function}: {functions:?}");
+ }
+ // ── install (happy path) ─────────────────────────────────────────────
let install_resp = post_json_rpc(
- &rpc_base,
- 9005,
+ rpc_base,
+ 9009,
"openhuman.skill_registry_install",
json!({ "entry_id": entry_id }),
)
.await;
- let install_result = assert_no_jsonrpc_error(&install_resp, "skill_registry_install (happy)");
-
- let install_url = install_result
- .get("url")
- .and_then(Value::as_str)
- .expect("install result must contain `url`");
+ let install_result = assert_no_jsonrpc_error(&install_resp, "install (happy)");
assert!(
- !install_url.is_empty(),
+ !install_result["url"].as_str().unwrap_or_default().is_empty(),
"install result `url` must not be empty"
);
-
- let install_stdout = install_result
- .get("stdout")
- .and_then(Value::as_str)
- .expect("install result must contain `stdout`");
+ let install_stdout = install_result["stdout"].as_str().unwrap_or_default();
assert!(
install_stdout.contains("Installed to"),
"install stdout should mention 'Installed to', got: {install_stdout}"
);
-
- let _install_stderr = install_result
- .get("stderr")
- .expect("install result must contain `stderr`");
-
- let new_skills = install_result
- .get("new_skills")
- .and_then(Value::as_array)
- .expect("install result must contain `new_skills` array");
+ assert!(install_result.get("stderr").is_some());
+ let new_skills = install_result["new_skills"]
+ .as_array()
+ .expect("new_skills array");
assert!(
- new_skills.iter().any(|s| s.as_str() == Some(entry_id)),
+ new_skills.iter().any(|s| s.as_str() == Some(entry_id.as_str())),
"new_skills must contain '{entry_id}', got: {new_skills:?}"
);
-
- // Verify the SKILL.md file actually landed on disk.
let skill_file = home
.join(".openhuman")
.join("skills")
- .join(entry_id)
+ .join(&entry_id)
.join("SKILL.md");
- assert!(
- skill_file.exists(),
- "SKILL.md should exist on disk at {}, but was not found",
- skill_file.display()
- );
-
- // ── Step 6: install (duplicate no-op success) ────────────────────────
+ assert!(skill_file.exists(), "SKILL.md missing at {}", skill_file.display());
+ // ── install (duplicate no-op success) ────────────────────────────────
let dup_resp = post_json_rpc(
- &rpc_base,
- 9006,
+ rpc_base,
+ 9010,
"openhuman.skill_registry_install",
json!({ "entry_id": entry_id }),
)
.await;
- let dup_result = assert_no_jsonrpc_error(&dup_resp, "skill_registry_install (duplicate)");
- let dup_stdout = dup_result
- .get("stdout")
- .and_then(Value::as_str)
- .expect("duplicate install result must contain `stdout`");
- assert!(
- dup_stdout.contains("already installed"),
- "duplicate install stdout should mention 'already installed', got: {dup_stdout}"
- );
- let dup_new_skills = dup_result
- .get("new_skills")
- .and_then(Value::as_array)
- .expect("duplicate install result must contain `new_skills` array");
+ let dup_result = assert_no_jsonrpc_error(&dup_resp, "install (duplicate)");
+ assert!(dup_result["stdout"]
+ .as_str()
+ .unwrap_or_default()
+ .contains("already installed"));
+ assert_eq!(dup_result["new_skills"], json!([]));
+
+ // ── install (unknown id) ─────────────────────────────────────────────
+ let missing = post_json_rpc(
+ rpc_base,
+ 9011,
+ "openhuman.skill_registry_install",
+ json!({ "entry_id": "git-helpr" }),
+ )
+ .await;
+ let message = jsonrpc_error_message(&missing, "install (unknown id)");
assert!(
- dup_new_skills.is_empty(),
- "duplicate install should report no new skills, got: {dup_new_skills:?}"
+ message.contains("SKILL_REGISTRY_NOT_FOUND: "),
+ "an unknown id is a typed not-found: {message}"
);
+ assert!(message.contains("git-helper"), "suggests real ids: {message}");
- // ── Step 7: uninstall ─────────────────────────────────────────────────
-
+ // ── uninstall ────────────────────────────────────────────────────────
let uninstall_resp = post_json_rpc(
- &rpc_base,
- 9007,
+ rpc_base,
+ 9012,
"openhuman.skill_registry_uninstall",
json!({ "name": entry_id }),
)
.await;
let uninstall_result = assert_no_jsonrpc_error(&uninstall_resp, "skill_registry_uninstall");
- assert_eq!(
- uninstall_result.get("name").and_then(Value::as_str),
- Some(entry_id)
- );
- assert!(
- !skill_file.exists(),
- "SKILL.md should be removed after uninstall at {}",
- skill_file.display()
- );
+ assert_eq!(uninstall_result["name"], json!(entry_id));
+ assert!(!skill_file.exists(), "SKILL.md should be removed after uninstall");
+}
- // ── Cleanup ───────────────────────────────────────────────────────────
+/// A registry that has fetched once keeps serving its catalog when the
+/// upstream goes down, flagging the failure; one that never fetched returns
+/// the typed error.
+#[tokio::test]
+async fn skill_registry_e2e_serves_the_held_catalog_when_the_upstream_fails() {
+ let _env_lock = env_lock_async().await;
+ let tmp = tempdir().expect("create tempdir");
+ let stack = boot(tmp.path()).await;
+ let rpc_base = stack.rpc_base.as_str();
+
+ let live = post_json_rpc(
+ rpc_base,
+ 9201,
+ "openhuman.skill_registry_browse",
+ json!({ "page": 1 }),
+ )
+ .await;
+ let live = assert_no_jsonrpc_error(&live, "browse live");
+ assert_eq!(live["freshness"], "live");
- rpc_join.abort();
- fixture_join.abort();
+ stack.fixture.offline.store(true, Ordering::SeqCst);
+ let held = post_json_rpc(
+ rpc_base,
+ 9202,
+ "openhuman.skill_registry_browse",
+ json!({ "page": 1, "force_refresh": true }),
+ )
+ .await;
+ let held = assert_no_jsonrpc_error(&held, "browse after the upstream failed");
+ assert_eq!(held["total"], 2 + FILLER_ENTRIES as u64);
+ assert_eq!(held["last_error"]["kind"], "unavailable");
+
+ let cold_tmp = tempdir().expect("create tempdir");
+ let cold = boot(cold_tmp.path()).await;
+ cold.fixture.offline.store(true, Ordering::SeqCst);
+ let failed = post_json_rpc(
+ &cold.rpc_base,
+ 9203,
+ "openhuman.skill_registry_browse",
+ json!({ "page": 1 }),
+ )
+ .await;
+ let message = jsonrpc_error_message(&failed, "browse with nothing held");
+ assert!(
+ message.contains("SKILL_REGISTRY_UNAVAILABLE: "),
+ "a cold registry with an unreachable upstream is a typed error: {message}"
+ );
}