The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(skills): cover scan-gate retry, refusal, acknowledgement and cooldown for catalog installs (#7082)
oxoxDevec0c2690bbfa
diff --git a/crates/openhuman-core/src/skills/catalog/ops_install_tests.rs b/crates/openhuman-core/src/skills/catalog/ops_install_tests.rsindex 2c3ba5248f..b756eb63d9 100644--- a/crates/openhuman-core/src/skills/catalog/ops_install_tests.rs+++ b/crates/openhuman-core/src/skills/catalog/ops_install_tests.rs@@ -143,4 +143,148 @@ async fn a_throttled_document_host_reports_rate_limiting() {"{message}");assert!(message.contains("42s"), "{message}");+ assert_eq!(+ fixture.document_hits.load(Ordering::SeqCst),+ 1,+ "a throttled host is not hit again at once"+ );+}++fn installed_skill(home: &std::path::Path, slug: &str) -> std::path::PathBuf {+ home.join(".openhuman/skills").join(slug).join("SKILL.md")+}++#[tokio::test]+async fn a_scan_block_is_retried_once_and_a_clean_retry_installs() {+ let fixture = Fixture::start(vec![hermes_item("flaky-scan", "built-in")]).await;+ fixture.blocked_documents.store(1, Ordering::SeqCst);+ let home = tempfile::tempdir().unwrap();++ let outcome = install_from_catalog_in(+ &fixture.registry(),+ home.path(),+ Some(home.path()),+ "flaky-scan",+ ScanAcknowledgement::Absent,+ )+ .await+ .expect("install");++ assert_eq!(outcome.status(), "installed");+ assert_eq!(fixture.document_hits.load(Ordering::SeqCst), 2);+ let written = std::fs::read_to_string(installed_skill(home.path(), "flaky-scan")).unwrap();+ assert!(+ !written.contains('\u{200b}'),+ "the clean retry is what lands"+ );+}++#[tokio::test]+async fn a_document_that_still_blocks_is_not_installed() {+ let fixture = Fixture::start(vec![hermes_item("poisoned", "built-in")]).await;+ fixture+ .blocked_documents+ .store(usize::MAX, Ordering::SeqCst);+ let home = tempfile::tempdir().unwrap();++ let outcome = install_from_catalog_in(+ &fixture.registry(),+ home.path(),+ Some(home.path()),+ "poisoned",+ ScanAcknowledgement::Absent,+ )+ .await+ .expect("a scan block is an outcome, not an error");++ let SkillInstallOutcome::ScanBlocked(blocked) = outcome else {+ panic!("expected scan_blocked, got {outcome:?}");+ };+ assert_eq!(fixture.document_hits.load(Ordering::SeqCst), 2, "one retry");+ assert_eq!(blocked.target, "poisoned");+ assert_eq!(blocked.slug, "poisoned");+ assert!(blocked.findings.iter().any(|finding| finding.check+ == tinyskills::ScanCheck::InvisibleCodePoints+ && finding.verdict == tinyskills::Verdict::Block));+ assert!(+ blocked.message.contains("not installed"),+ "{}",+ blocked.message+ );+ assert!(!installed_skill(home.path(), "poisoned").exists());+}++#[tokio::test]+async fn an_acknowledged_install_writes_the_blocked_document() {+ let fixture = Fixture::start(vec![hermes_item("acknowledged", "built-in")]).await;+ fixture+ .blocked_documents+ .store(usize::MAX, Ordering::SeqCst);+ let home = tempfile::tempdir().unwrap();++ let outcome = install_from_catalog_in(+ &fixture.registry(),+ home.path(),+ Some(home.path()),+ "acknowledged",+ ScanAcknowledgement::ByUser,+ )+ .await+ .expect("install")+ .installed()+ .expect("the user acknowledged the findings");++ assert_eq!(outcome.new_skills, ["acknowledged"]);+ assert_eq!(+ fixture.document_hits.load(Ordering::SeqCst),+ 1,+ "an acknowledged install does not refetch"+ );+ let written = std::fs::read_to_string(installed_skill(home.path(), "acknowledged")).unwrap();+ assert!(written.contains('\u{200b}'));+}++#[tokio::test]+async fn a_failed_document_fetch_is_retried_once() {+ let fixture = Fixture::start(vec![hermes_item("down", "built-in")]).await;+ fixture.document_status.store(503, Ordering::SeqCst);+ let home = tempfile::tempdir().unwrap();++ let error = install_from_catalog_in(+ &fixture.registry(),+ home.path(),+ Some(home.path()),+ "down",+ ScanAcknowledgement::Absent,+ )+ .await+ .expect_err("the host stays down");++ assert_eq!(error.kind(), Some(RegistryErrorKind::Unavailable));+ assert_eq!(fixture.document_hits.load(Ordering::SeqCst), 2);+}++#[tokio::test]+async fn the_install_retry_does_not_refetch_a_catalog_in_cooldown() {+ let fixture = Fixture::start(vec![hermes_item("cold", "built-in")]).await;+ fixture.catalog_status.store(503, Ordering::SeqCst);+ let home = tempfile::tempdir().unwrap();++ let error = install_from_catalog_in(+ &fixture.registry(),+ home.path(),+ Some(home.path()),+ "cold",+ ScanAcknowledgement::Absent,+ )+ .await+ .expect_err("no catalog to locate the entry in");++ assert_eq!(error.kind(), Some(RegistryErrorKind::Unavailable));+ assert_eq!(+ fixture.catalog_hits.load(Ordering::SeqCst),+ 1,+ "the retry answers from the cooldown instead of refetching"+ );+ assert_eq!(fixture.document_hits.load(Ordering::SeqCst), 0);}diff --git a/crates/openhuman-core/src/skills/catalog/test_fixtures.rs b/crates/openhuman-core/src/skills/catalog/test_fixtures.rsindex 7778b9b5e4..993e3f0491 100644--- a/crates/openhuman-core/src/skills/catalog/test_fixtures.rs+++ b/crates/openhuman-core/src/skills/catalog/test_fixtures.rs@@ -21,6 +21,10 @@ pub(crate) struct Fixture {pub(crate) catalog_hits: Arc<AtomicUsize>,pub(crate) catalog_status: Arc<AtomicU16>,pub(crate) document_status: Arc<AtomicU16>,+ pub(crate) document_hits: Arc<AtomicUsize>,+ /// How many of the next `SKILL.md` responses carry content the+ /// supply-chain scan blocks.+ pub(crate) blocked_documents: Arc<AtomicUsize>,}#[derive(Clone)]@@ -29,8 +33,13 @@ struct FixtureState {catalog_hits: Arc<AtomicUsize>,catalog_status: Arc<AtomicU16>,document_status: Arc<AtomicU16>,+ document_hits: Arc<AtomicUsize>,+ blocked_documents: Arc<AtomicUsize>,}+/// A zero-width space: an invisible code point the scan blocks on.+pub(crate) const SCAN_BLOCKING_TEXT: &str = "Run the steps\u{200b} in order.";+async fn catalog_route(State(state): State<FixtureState>) -> Response {state.catalog_hits.fetch_add(1, Ordering::SeqCst);tokio::time::sleep(Duration::from_millis(30)).await;@@ -45,6 +54,7 @@ async fn document_route(State(state): State<FixtureState>,AxumPath(name): AxumPath<String>,) -> Response {+ state.document_hits.fetch_add(1, Ordering::SeqCst);let status = state.document_status.load(Ordering::SeqCst);if status != 200 {let mut response = StatusCode::from_u16(status).unwrap().into_response();@@ -55,7 +65,14 @@ async fn document_route(}return response;}- format!("---\nname: {name}\ndescription: Fixture skill {name}.\n---\n\n# {name}\n")+ let blocked = state+ .blocked_documents+ .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |left| {+ left.checked_sub(1)+ })+ .is_ok();+ let body = if blocked { SCAN_BLOCKING_TEXT } else { "" };+ format!("---\nname: {name}\ndescription: Fixture skill {name}.\n---\n\n# {name}\n{body}\n").into_response()}@@ -77,6 +94,8 @@ impl Fixture {catalog_hits: Arc::new(AtomicUsize::new(0)),catalog_status: Arc::new(AtomicU16::new(200)),document_status: Arc::new(AtomicU16::new(200)),+ document_hits: Arc::new(AtomicUsize::new(0)),+ blocked_documents: Arc::new(AtomicUsize::new(0)),};let app = Router::new().route("/skills.json", get(catalog_route))@@ -92,6 +111,8 @@ impl Fixture {catalog_hits: state.catalog_hits,catalog_status: state.catalog_status,document_status: state.document_status,+ document_hits: state.document_hits,+ blocked_documents: state.blocked_documents,}}@@ -119,6 +140,7 @@ impl Fixture {SkillRegistry::builder(ReqwestTransport::new()).source(source).policy(policy)+ .timeouts(RegistryConfig::timeouts()).limits(RegistryConfig::limits()).clock(clock).build()