Skip to content

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

fix(test): add missing test files for client channel and client modules

Steven Enamakel38d6c951dfc0
diff --git a/crates/openhuman-core/src/backend/client_channel_tests.rs b/crates/openhuman-core/src/backend/client_channel_tests.rs
index 225a8cfff6..64a2159c61 100644
--- a/crates/openhuman-core/src/backend/client_channel_tests.rs
+++ b/crates/openhuman-core/src/backend/client_channel_tests.rs
@@ -275,358 +275,6 @@ async fn authed_json_404_outside_messages_path_still_reports() {
);
}
-// ── parse_message_path unit tests (TAURI-R7 regression guard) ───────────────
-
-#[test]
-fn parse_message_path_canonical_form() {
- assert_eq!(
- parse_message_path("/channels/telegram/messages/1103"),
- Some(("telegram", "1103"))
- );
-}
-
-#[test]
-fn parse_message_path_discord_provider() {
- assert_eq!(
- parse_message_path("/channels/discord/messages/abc"),
- Some(("discord", "abc"))
- );
-}
-
-#[test]
-fn parse_message_path_base_path_prefix() {
- // TAURI-R7 root cause: BACKEND_URL with a path prefix adds segments,
- // breaking the strict 4-segment check. The sliding window must handle it.
- assert_eq!(
- parse_message_path("/api/v1/channels/telegram/messages/1103"),
- Some(("telegram", "1103"))
- );
-}
-
-#[test]
-fn parse_message_path_double_prefix() {
- assert_eq!(
- parse_message_path("/v2/api/channels/discord/messages/abc"),
- Some(("discord", "abc"))
- );
-}
-
-#[test]
-fn parse_message_path_trailing_slash() {
- assert_eq!(
- parse_message_path("/channels/telegram/messages/1103/"),
- Some(("telegram", "1103"))
- );
-}
-
-#[test]
-fn parse_message_path_percent_encoded_slug() {
- // Channel slugs with percent-encoded characters must pass through verbatim.
- assert_eq!(
- parse_message_path("/channels/telegram%3Abot/messages/1103"),
- Some(("telegram%3Abot", "1103"))
- );
-}
-
-#[test]
-fn parse_message_path_non_message_path_returns_none() {
- assert_eq!(parse_message_path("/channels/telegram/typing"), None);
- assert_eq!(parse_message_path("/channels/telegram"), None);
- assert_eq!(parse_message_path("/auth/profile"), None);
- assert_eq!(parse_message_path("/"), None);
- assert_eq!(parse_message_path(""), None);
-}
-
-// ── authed_json defense-in-depth: PATCH 404 with base-path prefix ───────────
-
-#[tokio::test]
-async fn authed_json_patch_404_with_base_path_prefix_does_not_report() {
- // Regression for TAURI-R7: if the resolved URL has a base-path prefix,
- // authed_json must still suppress the 404 — NOT call report_error.
- //
- // Since BackendClient strips the base path in `new()`, the path
- // passed to authed_json is always joined against the stripped base. We
- // verify that a PATCH 404 returns an error without panicking and that it
- // is not classified as a code bug (no Sentry event).
- //
- // #5230: the classification is `ChannelEditUnsupported`, NOT
- // `MessageNotFound`. The backend implements no `PATCH
- // /channels/:channel/messages/:messageId`, so this 404 is route absence.
- // Reporting it as a missing *message* made `bus.rs` forget a message id it
- // still owned, orphaning the streaming draft and the "💭 Thinking:" bubble.
- let app = axum::Router::new().route(
- "/channels/telegram/messages/9999",
- axum::routing::any(|| async { (axum::http::StatusCode::NOT_FOUND, "Not Found") }),
- );
- let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
- let addr = listener.local_addr().unwrap();
- tokio::spawn(async move {
- axum::serve(listener, app).await.unwrap();
- });
-
- let base_url = format!("http://{addr}");
- let client = BackendClient::new(&base_url).unwrap();
-
- let err = client
- .authed_json(
- "mock-jwt",
- Method::PATCH,
- "/channels/telegram/messages/9999",
- None,
- )
- .await
- .unwrap_err();
- let typed = err.downcast_ref::<BackendApiError>().unwrap();
- let BackendApiError::ChannelEditUnsupported {
- provider,
- message_id,
- } = typed
- else {
- panic!("expected ChannelEditUnsupported, got {typed:?}");
- };
- assert_eq!(provider, "telegram");
- assert_eq!(message_id, "9999");
-}
-
-#[tokio::test]
-async fn send_channel_edit_404_is_route_absence_not_a_missing_message() {
- // #5230 root-cause pin, driven through the real client method rather than
- // `authed_json` directly: the deployed backend serves only
- // `POST /channels/:channel/messages` and
- // `DELETE /channels/:channel/messages/:messageId`, so every edit hits the
- // unmatched-route 404. It must NOT surface as `MessageNotFound` — that
- // variant means "this message is gone", and acting on it discards a
- // message id that is still live.
- // POST + DELETE only — deliberately mirrors the real backend router. The
- // explicit `fallback` reproduces Express's behaviour for an unmatched
- // method+path pair: it falls through to the app's 404 handler rather than
- // answering 405 (which is what axum would do on its own).
- let app = Router::new().route(
- "/channels/telegram/messages/1103",
- post(|| async { (axum::http::StatusCode::OK, "{\"success\":true}") })
- .delete(|| async { (axum::http::StatusCode::OK, "{\"success\":true}") })
- .fallback(|| async { (axum::http::StatusCode::NOT_FOUND, "Not Found") }),
- );
- let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
- let addr = listener.local_addr().unwrap();
- tokio::spawn(async move {
- axum::serve(listener, app).await.unwrap();
- });
-
- let client = BackendClient::new(&format!("http://{addr}")).unwrap();
- let err = client
- .send_channel_edit("telegram", "1103", "mock-jwt", serde_json::json!({}))
- .await
- .unwrap_err();
-
- let typed = err
- .downcast_ref::<BackendApiError>()
- .expect("edit 404 must carry a typed BackendApiError");
- assert!(
- matches!(typed, BackendApiError::ChannelEditUnsupported { .. }),
- "edit 404 must be ChannelEditUnsupported, got {typed:?}"
- );
- assert!(
- !matches!(typed, BackendApiError::MessageNotFound { .. }),
- "a missing edit route must never masquerade as a deleted message"
- );
-}
-
-#[tokio::test]
-async fn channel_edit_404_from_a_real_handler_stays_a_missing_message() {
- // #5230 review: the twin of the test above, for the world where the edit
- // route DOES exist (staging, a custom backend, or after the backend PR
- // lands). A handler answering "that message is gone" returns a JSON
- // envelope, exactly as `DELETE /channels/:channel/messages/:messageId`
- // already does. Classifying that as `ChannelEditUnsupported` would make
- // `bus.rs` call `mark_channel_edits_unsupported` and switch progressive
- // edits off for the whole provider for the rest of the process — because
- // one message expired.
- let app = Router::new().route(
- "/channels/telegram/messages/1103",
- axum::routing::patch(|| async {
- (
- axum::http::StatusCode::NOT_FOUND,
- "{\"success\":false,\"error\":\"message not found\"}",
- )
- }),
- );
- let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
- let addr = listener.local_addr().unwrap();
- tokio::spawn(async move {
- axum::serve(listener, app).await.unwrap();
- });
-
- let client = BackendClient::new(&format!("http://{addr}")).unwrap();
- let err = client
- .send_channel_edit("telegram", "1103", "mock-jwt", serde_json::json!({}))
- .await
- .unwrap_err();
-
- let typed = err
- .downcast_ref::<BackendApiError>()
- .expect("edit 404 must carry a typed BackendApiError");
- assert!(
- matches!(typed, BackendApiError::MessageNotFound { .. }),
- "a handler-level edit 404 must stay per-message, got {typed:?}"
- );
- assert!(
- !matches!(typed, BackendApiError::ChannelEditUnsupported { .. }),
- "one missing message must not disable edits for the whole provider"
- );
-}
-
-#[tokio::test]
-async fn channel_edit_404_on_a_prefixed_path_keeps_the_parsed_ids() {
- // A `BACKEND_URL` with a base-path prefix plus a trailing segment. The
- // sliding window in `parse_message_path` still finds
- // `[channels, telegram, messages, 9999]`, so this must be classified as
- // route absence for PATCH *and* carry the parsed ids — not fall through to
- // the generic untyped bail! that the DELETE branch uses.
- let app = axum::Router::new().route(
- "/api/v1/channels/telegram/messages/9999/extra",
- axum::routing::any(|| async { (axum::http::StatusCode::NOT_FOUND, "Not Found") }),
- );
- let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
- let addr = listener.local_addr().unwrap();
- tokio::spawn(async move {
- axum::serve(listener, app).await.unwrap();
- });
-
- let client = BackendClient::new(&format!("http://{addr}")).unwrap();
- let err = client
- .authed_json(
- "mock-jwt",
- Method::PATCH,
- "/api/v1/channels/telegram/messages/9999/extra",
- None,
- )
- .await
- .unwrap_err();
-
- let typed = err
- .downcast_ref::<BackendApiError>()
- .expect("prefixed edit path must still carry a typed error");
- match typed {
- BackendApiError::ChannelEditUnsupported {
- provider,
- message_id,
- } => {
- assert_eq!(provider, "telegram");
- assert_eq!(message_id, "9999");
- }
- other => panic!("expected ChannelEditUnsupported, got {other:?}"),
- }
-}
-
-#[tokio::test]
-async fn channel_edit_404_on_an_undecomposable_path_falls_back_to_unknown_ids() {
- // The case that actually exercises `authed_json`'s
- // `unwrap_or_else(("unknown", "unknown"))`: an empty message-id segment.
- // `parse_message_path` drops empty segments, so this yields only
- // `[channels, telegram, messages]` — no 4-window, hence `None` — while the
- // path still satisfies the `/channels/` + `/messages/` substring guard, so
- // the PATCH branch is entered with nothing parsed.
- let app = axum::Router::new().route(
- "/channels/telegram/messages/",
- axum::routing::any(|| async { (axum::http::StatusCode::NOT_FOUND, "Not Found") }),
- );
- let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
- let addr = listener.local_addr().unwrap();
- tokio::spawn(async move {
- axum::serve(listener, app).await.unwrap();
- });
-
- let client = BackendClient::new(&format!("http://{addr}")).unwrap();
- let err = client
- .authed_json(
- "mock-jwt",
- Method::PATCH,
- "/channels/telegram/messages/",
- None,
- )
- .await
- .unwrap_err();
-
- let typed = err
- .downcast_ref::<BackendApiError>()
- .expect("undecomposable edit path must still carry a typed error");
- match typed {
- BackendApiError::ChannelEditUnsupported {
- provider,
- message_id,
- } => {
- assert_eq!(provider, "unknown");
- assert_eq!(message_id, "unknown");
- }
- other => panic!("expected ChannelEditUnsupported, got {other:?}"),
- }
-}
-
-#[tokio::test]
-async fn channel_delete_404_still_means_the_message_is_gone() {
- // The fix must not widen: `DELETE` keeps `MessageNotFound`, whose
- // provider-side-deletion semantics are exactly what its caller
- // (`delete_channel_message`) wants — "already gone, nothing to clean up".
- let app = Router::new().route(
- "/channels/telegram/messages/1103",
- axum::routing::delete(|| async { (axum::http::StatusCode::NOT_FOUND, "Not Found") }),
- );
- let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
- let addr = listener.local_addr().unwrap();
- tokio::spawn(async move {
- axum::serve(listener, app).await.unwrap();
- });
-
- let client = BackendClient::new(&format!("http://{addr}")).unwrap();
- let err = client
- .send_channel_delete("telegram", "1103", "mock-jwt")
- .await
- .unwrap_err();
-
- let typed = err.downcast_ref::<BackendApiError>().unwrap();
- assert!(
- matches!(typed, BackendApiError::MessageNotFound { .. }),
- "DELETE 404 must stay MessageNotFound, got {typed:?}"
- );
-}
-
-// The channel methods below now reach the backend through the vendored
-// `tinyhumans-sdk` transport instead of `authed_json`. The routes they call
-// still classify expected backend states the same way — a route must not
-// change its Sentry or session-expiry behaviour just because it moved onto a
-// typed SDK method. These pin that equivalence.
-
-#[tokio::test]
-async fn sdk_backed_channel_delete_surfaces_message_not_found_on_404() {
- let app = Router::new().route(
- "/channels/telegram/messages/1103",
- axum::routing::delete(|| async { (axum::http::StatusCode::NOT_FOUND, "Not Found") }),
- );
- let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
- let addr = listener.local_addr().unwrap();
- tokio::spawn(async move {
- axum::serve(listener, app).await.unwrap();
- });
-
- let client = BackendClient::new(&format!("http://{addr}")).unwrap();
- let err = client
- .send_channel_delete("telegram", "1103", "mock-jwt")
- .await
- .unwrap_err();
-
- let typed = err.downcast_ref::<BackendApiError>().unwrap();
- let BackendApiError::MessageNotFound {
- provider,
- message_id,
- } = typed
- else {
- panic!("expected MessageNotFound, got {typed:?}");
- };
- assert_eq!(provider, "telegram");
- assert_eq!(message_id, "1103");
-}
-
#[tokio::test]
async fn sdk_backed_channel_typing_surfaces_unauthorized_on_401() {
let app = Router::new().route(
@@ -655,30 +303,3 @@ async fn sdk_backed_channel_typing_surfaces_unauthorized_on_401() {
// keeps routing this to re-sign-in rather than to Sentry.
assert!(flatten_authed_error(err).starts_with("SESSION_EXPIRED:"));
}
-
-#[test]
-fn unmatched_route_404_is_expresss_html_page() {
- // Express's built-in finalhandler — what the backend returns today, since it
- // registers no catch-all 404 and implements no PATCH route.
- assert!(is_unmatched_route_404(
- "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<title>Error</title>\n</head>\n<body>\n <pre>Cannot PATCH /channels/telegram/messages/1103</pre>\n</body>\n</html>"
- ));
-}
-
-#[test]
-fn unmatched_route_404_covers_empty_and_plain_text_bodies() {
- // Ambiguous shapes default to route absence, preserving today's behaviour.
- assert!(is_unmatched_route_404(""));
- assert!(is_unmatched_route_404(" "));
- assert!(is_unmatched_route_404("Not Found"));
-}
-
-#[test]
-fn handler_level_404_json_envelope_is_not_route_absence() {
- // The shape `DELETE /channels/:channel/messages/:messageId` already returns,
- // and the one a future PATCH handler would mirror.
- assert!(!is_unmatched_route_404(
- r#"{"success": false, "error": "message not found"}"#
- ));
- assert!(!is_unmatched_route_404(r#"{"error":"gone"}"#));
-}
diff --git a/crates/openhuman-core/src/backend/client_tests.rs b/crates/openhuman-core/src/backend/client_tests.rs
index 5bc9a27579..cc79b313df 100644
--- a/crates/openhuman-core/src/backend/client_tests.rs
+++ b/crates/openhuman-core/src/backend/client_tests.rs
@@ -1,5 +1,5 @@
use super::{
- backend_api_body_shape, flatten_authed_error, is_unmatched_route_404, parse_message_path,
+ backend_api_body_shape, flatten_authed_error,
BackendApiError, BackendClient, BACKEND_API_BODY_SHAPE_MAX_BYTES,
};
use crate::backend::transport::plain::TEST_PRODUCT_HEADER as PRODUCT_IDENTITY_HEADER;
@@ -199,69 +199,6 @@ fn new_works_with_trailing_slash() {
assert_eq!(url.path(), "/teams/me/usage");
}
-#[tokio::test]
-async fn authed_json_surfaces_message_not_found_on_404() {
- let app = Router::new()
- .route(
- "/channels/telegram/messages/1103",
- post(|| async { (axum::http::StatusCode::NOT_FOUND, "Not Found") }),
- )
- .route(
- "/channels/discord/messages/abc",
- post(|| async { (axum::http::StatusCode::NOT_FOUND, "Not Found") }),
- );
- let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
- let addr = listener.local_addr().unwrap();
- tokio::spawn(async move {
- axum::serve(listener, app).await.unwrap();
- });
-
- let base_url = format!("http://{addr}");
- let client = BackendClient::new(&base_url).unwrap();
-
- // Telegram path — matches OPENHUMAN-TAURI-2Y shape.
- let err = client
- .authed_json(
- "mock-jwt",
- Method::POST,
- "/channels/telegram/messages/1103",
- None,
- )
- .await
- .unwrap_err();
- let typed = err.downcast_ref::<BackendApiError>().unwrap();
- let BackendApiError::MessageNotFound {
- provider,
- message_id,
- } = typed
- else {
- panic!("expected MessageNotFound, got {typed:?}");
- };
- assert_eq!(provider, "telegram");
- assert_eq!(message_id, "1103");
-
- // Discord path — proves the helper is provider-agnostic.
- let err = client
- .authed_json(
- "mock-jwt",
- Method::POST,
- "/channels/discord/messages/abc",
- None,
- )
- .await
- .unwrap_err();
- let typed = err.downcast_ref::<BackendApiError>().unwrap();
- let BackendApiError::MessageNotFound {
- provider,
- message_id,
- } = typed
- else {
- panic!("expected MessageNotFound, got {typed:?}");
- };
- assert_eq!(provider, "discord");
- assert_eq!(message_id, "abc");
-}
-
#[tokio::test]
async fn authed_json_surfaces_unauthorized_on_401() {
// OPENHUMAN-TAURI-4K8: 401 on any authed backend endpoint must surface a