Skip to content

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

test(channels): cover stale model cache and sign-out cancellation

Steven Enamakelbe7275c04c32
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index 226113e21d..c49a53fd66 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -284,19 +284,17 @@ fn route_selection_round_trip() {
#[cfg(feature = "modules")]
#[tokio::test]
-async fn cached_models_and_help_responses_render_expected_text() {
+async fn module_route_help_ignores_stale_model_cache_and_projects_providers() {
let tempdir = tempfile::tempdir().unwrap();
let state_dir = tempdir.path().join("state");
std::fs::create_dir_all(&state_dir).unwrap();
std::fs::write(
state_dir.join("models_cache.json"),
serde_json::json!({
- "entries": [
- {
- "provider": "openai",
- "models": ["gpt-5", "gpt-5-mini", "gpt-4.1"]
- }
- ]
+ "entries": [{
+ "provider": "openai",
+ "models": ["stale-model"]
+ }]
})
.to_string(),
)
@@ -304,8 +302,13 @@ async fn cached_models_and_help_responses_render_expected_text() {
let models = module_route_help_response(tempdir.path(), "/model", Vec::new()).await;
assert!(models.contains("Current provider: `openai`"));
- assert!(models.contains("Cached model IDs"));
- assert!(models.contains("- `gpt-5-mini`"));
+ // The module no longer reads `models_cache.json` (tinychannels 0.1.38):
+ // a catalog-less channel points the user at the web UI instead of listing
+ // a possibly stale workspace file.
+ assert!(models.contains("Model catalog is unavailable in this channel"));
+ assert!(!models.contains("stale-model"));
+ assert!(!models.contains("gpt-5-mini"));
+ assert!(!models.contains("Cached model IDs"));
let providers = module_route_help_response(
tempdir.path(),
@@ -399,21 +402,51 @@ async fn sign_out_cancels_remote_invalidation_while_it_waits_for_the_session_tab
#[cfg(feature = "modules")]
#[tokio::test]
-async fn load_cached_model_preview_returns_empty_when_cache_json_is_invalid() {
- let tempdir = tempfile::tempdir().unwrap();
- let state_dir = tempdir.path().join("state");
- std::fs::create_dir_all(&state_dir).unwrap();
- std::fs::write(
- state_dir.join("models_cache.json"),
- "{ definitely invalid json",
- )
- .unwrap();
+async fn sign_out_cancels_remote_invalidation_while_it_waits_for_the_session_table() {
+ let core_context =
+ crate::core::runtime::CoreContext::for_test(crate::core::runtime::DomainSet::full(), None);
+ let expected_core_context = Arc::clone(&core_context);
+ crate::core::runtime::CoreContext::scope(core_context, async {
+ let guard = crate::web_chat::lock_thread_sessions_for_test(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ )
+ .await;
+ let cancellation = tokio_util::sync::CancellationToken::new();
+ let callback = RouteCallbacks::new(
+ runtime_context(PathBuf::from("/tmp/channel-callback")),
+ cancellation.clone(),
+ );
+ assert!(Arc::ptr_eq(
+ callback.core_context.as_ref().unwrap(),
+ &expected_core_context
+ ));
+ assert_eq!(callback.tenant, crate::core::runtime::Tenant::default());
- let response = module_route_help_response(tempdir.path(), "/model", Vec::new()).await;
- assert!(
- response.contains("No cached model list found for `openai`"),
- "{response}"
- );
+ let request = tinychannels_bus::ChannelBackendRequest::RemoteControl(
+ tinychannels_bus::module_remote::RemoteHostRequest::InvalidateThread {
+ thread_id: "sign-out-in-flight".into(),
+ },
+ );
+ let mut operation = Box::pin(callback.dispatch_controller_backend(request));
+ let waker = Waker::noop().clone();
+ let mut task_context = Context::from_waker(&waker);
+
+ assert!(
+ matches!(operation.as_mut().poll(&mut task_context), Poll::Pending),
+ "the callback should be waiting on the locked session table"
+ );
+ cancellation.cancel();
+ assert!(
+ matches!(
+ operation.as_mut().poll(&mut task_context),
+ Poll::Ready(Err(_))
+ ),
+ "sign-out must cancel the callback before it can mutate session state"
+ );
+
+ drop(guard);
+ })
+ .await;
}
#[tokio::test]