Skip to content

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

refactor(core): consolidate progressive-edit tests into backend error mapping

Steven Enamakel62e58597122b
diff --git a/crates/openhuman-core/src/channels/bus.rs b/crates/openhuman-core/src/channels/bus.rs
index c1739a96cb..2a02e1c0b5 100644
--- a/crates/openhuman-core/src/channels/bus.rs
+++ b/crates/openhuman-core/src/channels/bus.rs
@@ -5,23 +5,11 @@
//! channel provider and sends the reply back through the REST API.
mod delivery;
-mod draft;
-mod filler;
-mod progressive_ui;
-mod streaming_state;
mod subscriber;
-mod thinking;
mod thread_id;
pub use subscriber::ChannelInboundSubscriber;
-// Re-exported at module scope (rather than left as private `pub(super)`
-// items reached only through their owning submodule) so the `#[path]`
-// test modules below — which share this module's scope via `super::*` —
-// can see them exactly as they could when this was one unsplit file.
-use draft::extract_message_id;
-use streaming_state::StreamingState;
-use thinking::latest_thinking_snippet;
pub(crate) use thread_id::derive_inbound_thread_id;
#[cfg(test)]
diff --git a/crates/openhuman-core/src/channels/bus_inbound_thread_id_tests_tests.rs b/crates/openhuman-core/src/channels/bus_inbound_thread_id_tests_tests.rs
index 2c5a288e2a..ffc555651d 100644
--- a/crates/openhuman-core/src/channels/bus_inbound_thread_id_tests_tests.rs
+++ b/crates/openhuman-core/src/channels/bus_inbound_thread_id_tests_tests.rs
@@ -1,24 +1,7 @@
use super::delivery::channel_message_body_with_idempotency;
-use super::progressive_ui::channel_supports_progressive_ui;
use super::thread_id::{derive_inbound_client_id, derive_inbound_thread_id};
use serde_json::json;
-#[test]
-fn progressive_ui_is_an_allowlist_failing_safe_for_unknown_channels() {
- // Only edit+delete-capable providers opt in. Telegram supports both;
- // everything else (Discord's stub delete / 404 edits, and any new or
- // unknown adapter) is suppressed so the "💭" spam can't reappear.
- assert!(channel_supports_progressive_ui("telegram"));
- assert!(channel_supports_progressive_ui("tg"));
- // Inbound channels arrive provider-prefixed — the prefix must still match.
- assert!(channel_supports_progressive_ui("tg:12345"));
- assert!(!channel_supports_progressive_ui("discord"));
- assert!(!channel_supports_progressive_ui("discord:guild-1"));
- // Unknown/new adapters fail safe (allowlist, not denylist).
- assert!(!channel_supports_progressive_ui("slack"));
- assert!(!channel_supports_progressive_ui("whatsapp:123"));
-}
-
#[test]
fn channel_message_body_adds_deterministic_idempotency_key() {
let left = channel_message_body_with_idempotency(
diff --git a/crates/openhuman-core/src/channels/bus_test_support_tests.rs b/crates/openhuman-core/src/channels/bus_test_support_tests.rs
index 708dd11714..40e84e94a4 100644
--- a/crates/openhuman-core/src/channels/bus_test_support_tests.rs
+++ b/crates/openhuman-core/src/channels/bus_test_support_tests.rs
@@ -1,6 +1,9 @@
//! Debug-build seams for raw integration coverage of channel inbound helpers.
use super::*;
+use tinychannels::delivery::progressive::{
+ extract_message_id, latest_thinking_snippet, StreamingState,
+};
pub fn extract_message_id_for_test(resp: &serde_json::Value) -> Option<String> {
extract_message_id(resp)
diff --git a/crates/openhuman-core/src/channels/bus_tests.rs b/crates/openhuman-core/src/channels/bus_tests.rs
index bcaaa8af62..948a39d410 100644
--- a/crates/openhuman-core/src/channels/bus_tests.rs
+++ b/crates/openhuman-core/src/channels/bus_tests.rs
@@ -3,11 +3,8 @@ use crate::backend::BackendApiError;
use crate::core::events::DomainEvent;
use tinybus::EventHandler;
-use crate::channels::bus::progressive_ui::channel_edits_unsupported;
-use crate::channels::bus::progressive_ui::classify_edit_failure;
-use crate::channels::bus::progressive_ui::edit_capability_key;
-use crate::channels::bus::progressive_ui::mark_channel_edits_unsupported;
-use crate::channels::bus::progressive_ui::EditFailure;
+use crate::channels::bus::delivery::map_backend_error;
+use tinychannels::delivery::progressive::ProgressiveSendError;
#[test]
fn subscriber_metadata_is_stable() {
let subscriber = ChannelInboundSubscriber::new();
@@ -24,154 +21,45 @@ async fn unrelated_events_are_ignored() {
.await;
}
-// ── Channel-message edit failures (#5230) ──────────────────────────────────
+// ── Backend error mapping (#5230) ───────────────────────────────────────────
//
-// The backend implements no `PATCH /channels/:channel/messages/:messageId`, so
-// every edit 404s. That 404 used to be classified as `MessageNotFound` ("the
-// user deleted this message"), and the recovery for *that* condition is to
-// forget the message id — which orphaned the streaming draft and left the
-// ephemeral "💭 Thinking:" bubble in the chat permanently, because finalization
-// then had no id left to delete.
+// Route absence and message absence need different recoveries in the
+// progressive driver; conflating them once left a permanent "💭 Thinking:"
+// bubble in the chat. The mapping is by type, never by message text.
#[test]
-fn edit_failure_classification_separates_route_absence_from_message_absence() {
+fn backend_errors_map_to_distinct_progressive_recoveries() {
let route_absent = anyhow::Error::new(BackendApiError::ChannelEditUnsupported {
provider: "telegram".into(),
message_id: "1103".into(),
});
- assert_eq!(
- classify_edit_failure(&route_absent),
- EditFailure::RouteUnsupported
- );
+ assert!(matches!(
+ map_backend_error(route_absent),
+ ProgressiveSendError::EditUnsupported
+ ));
let message_absent = anyhow::Error::new(BackendApiError::MessageNotFound {
provider: "telegram".into(),
message_id: "1103".into(),
});
- assert_eq!(
- classify_edit_failure(&message_absent),
- EditFailure::MessageGone
- );
+ assert!(matches!(
+ map_backend_error(message_absent),
+ ProgressiveSendError::MessageGone
+ ));
// Anything untyped (5xx, transport, rate limit) keeps the retry budget.
- let transient = anyhow::anyhow!("502 Bad Gateway");
- assert_eq!(classify_edit_failure(&transient), EditFailure::Transient);
+ assert!(matches!(
+ map_backend_error(anyhow::anyhow!("502 Bad Gateway")),
+ ProgressiveSendError::Other(_)
+ ));
// A different typed variant must not be mistaken for either edit case.
let unauthorized = anyhow::Error::new(BackendApiError::Unauthorized {
method: "PATCH".into(),
path: "/channels/telegram/messages/1103".into(),
});
- assert_eq!(classify_edit_failure(&unauthorized), EditFailure::Transient);
-}
-
-#[test]
-fn route_absence_keeps_the_draft_id_so_finalize_can_clean_it_up() {
- let mut state = StreamingState {
- message_id: Some("1103".into()),
- draft_sent: true,
- ..Default::default()
- };
-
- state.latch_draft_edits_unsupported();
-
- assert!(state.edit_disabled, "edits must stop being attempted");
- assert_eq!(
- state.message_id.as_deref(),
- Some("1103"),
- "the draft is still on screen and still ours — finalize needs its id to \
- delete it before posting the canonical reply (#5230)"
- );
-}
-
-#[test]
-fn message_absence_forgets_the_draft_id() {
- let mut state = StreamingState {
- message_id: Some("1103".into()),
- draft_sent: true,
- ..Default::default()
- };
-
- state.forget_draft();
-
- assert!(state.edit_disabled);
- assert_eq!(
- state.message_id, None,
- "a message that is genuinely gone leaves nothing to edit or delete"
- );
-}
-
-#[test]
-fn route_absence_keeps_the_thinking_bubble_id_so_it_still_gets_deleted() {
- let mut state = StreamingState {
- thinking_message_id: Some("2201".into()),
- thinking_sent: true,
- ..Default::default()
- };
-
- state.latch_thinking_edits_unsupported();
-
- assert!(state.thinking_edit_disabled);
- assert_eq!(
- state.thinking_message_id.as_deref(),
- Some("2201"),
- "finalization deletes the ephemeral bubble by id — dropping it here is \
- why '💭 Thinking:' stayed in the chat forever (#5230)"
- );
-}
-
-#[test]
-fn message_absence_forgets_the_thinking_bubble_id() {
- let mut state = StreamingState {
- thinking_message_id: Some("2201".into()),
- thinking_sent: true,
- ..Default::default()
- };
-
- state.forget_thinking();
-
- assert!(state.thinking_edit_disabled);
- assert_eq!(state.thinking_message_id, None);
-}
-
-#[test]
-fn edit_capability_latches_per_provider_not_per_chat() {
- // Provider names unique to this test: the latch is process-wide by design,
- // so sharing `telegram` with another test would couple them.
- assert!(!channel_edits_unsupported("noedit-a:chat-1"));
-
- mark_channel_edits_unsupported("noedit-a:chat-1");
-
- assert!(
- channel_edits_unsupported("noedit-a:chat-1"),
- "the channel that taught us must be latched"
- );
- assert!(
- channel_edits_unsupported("noedit-a:chat-2"),
- "route existence is a per-provider backend fact, so a different chat on \
- the same provider must not re-probe it"
- );
- assert!(
- channel_edits_unsupported("noedit-a"),
- "un-prefixed channel ids resolve to the same provider key"
- );
- assert!(
- !channel_edits_unsupported("noedit-b:chat-1"),
- "an unrelated provider must be unaffected"
- );
-}
-
-#[test]
-fn marking_edit_capability_twice_is_idempotent() {
- mark_channel_edits_unsupported("noedit-c:chat-1");
- mark_channel_edits_unsupported("noedit-c:chat-1");
- assert!(channel_edits_unsupported("noedit-c:chat-1"));
-}
-
-#[test]
-fn edit_capability_key_strips_the_chat_suffix() {
- assert_eq!(edit_capability_key("telegram:12345"), "telegram");
- assert_eq!(edit_capability_key("discord:guild:chan"), "discord");
- assert_eq!(edit_capability_key("telegram"), "telegram");
- assert_eq!(edit_capability_key(""), "");
+ assert!(matches!(
+ map_backend_error(unauthorized),
+ ProgressiveSendError::Other(_)
+ ));
}