Skip to content

Commit 1f4c0b7

Browse files
committed
refactor: remove legacy bot thread navigation
1 parent 9b36fa7 commit 1f4c0b7

11 files changed

Lines changed: 164 additions & 1341 deletions

File tree

garyx-channels/src/telegram/tests.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -793,36 +793,6 @@ mod dispatch_tests {
793793
}
794794
}
795795

796-
#[tokio::test]
797-
async fn test_command_session_navigation() {
798-
let router = make_router();
799-
800-
// Set up thread history
801-
{
802-
let mut r = router.lock().await;
803-
let user_key = MessageRouter::build_binding_context_key("telegram", "bot1", "42");
804-
r.switch_to_thread(&user_key, "session_a");
805-
r.switch_to_thread(&user_key, "session_b");
806-
r.switch_to_thread(&user_key, "session_c");
807-
}
808-
809-
// Navigate backwards (/threadprev)
810-
{
811-
let mut r = router.lock().await;
812-
let user_key = MessageRouter::build_binding_context_key("telegram", "bot1", "42");
813-
let prev = r.navigate_thread(&user_key, -1);
814-
assert_eq!(prev.as_deref(), Some("session_b"));
815-
}
816-
817-
// Navigate forwards (/threadnext)
818-
{
819-
let mut r = router.lock().await;
820-
let user_key = MessageRouter::build_binding_context_key("telegram", "bot1", "42");
821-
let next = r.navigate_thread(&user_key, 1);
822-
assert_eq!(next.as_deref(), Some("session_c"));
823-
}
824-
}
825-
826796
#[tokio::test]
827797
async fn test_bridge_dispatch() {
828798
let router = make_router();

garyx-gateway/src/routes/tests.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5919,18 +5919,6 @@ async fn delete_thread_clears_in_memory_last_delivery() {
59195919
async fn delete_thread_clears_switched_thread_references() {
59205920
let (state, _logger, _dir) = test_state().await;
59215921
let thread_id = "thread::switch-delete";
5922-
state
5923-
.threads
5924-
.thread_store
5925-
.set(
5926-
"thread::older",
5927-
serde_json::json!({
5928-
"thread_id": "thread::older",
5929-
"thread_id": "thread::older",
5930-
"label": "Older"
5931-
}),
5932-
)
5933-
.await;
59345922
state
59355923
.threads
59365924
.thread_store
@@ -5946,7 +5934,6 @@ async fn delete_thread_clears_switched_thread_references() {
59465934
{
59475935
let mut router = state.threads.router.lock().await;
59485936
let user_key = MessageRouter::build_account_user_key("telegram", "main", "u1", false, None);
5949-
router.switch_to_thread(&user_key, "thread::older");
59505937
router.switch_to_thread(&user_key, thread_id);
59515938
assert_eq!(
59525939
router.get_current_thread_id_for_account("telegram", "main", "u1", false, None),
@@ -5966,7 +5953,7 @@ async fn delete_thread_clears_switched_thread_references() {
59665953
let router = state.threads.router.lock().await;
59675954
assert_eq!(
59685955
router.get_current_thread_id_for_account("telegram", "main", "u1", false, None),
5969-
Some("thread::older")
5956+
None
59705957
);
59715958
}
59725959

garyx-router/src/lib.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub mod inbound {
2121
pub mod routing {
2222
pub use crate::router::{
2323
AgentDispatcher, InboundRequest, InboundResult, InboundSink, MessageRouter, ThreadCreator,
24-
ThreadListEntry, ThreadMessageRequest,
24+
ThreadMessageRequest,
2525
};
2626
}
2727

@@ -48,16 +48,15 @@ pub mod threading {
4848
pub use crate::threads::{
4949
ChannelBinding, KNOWN_CHANNEL_ENDPOINTS_KEY, KnownChannelEndpoint, ThreadEnsureOptions,
5050
ThreadIndexStats,
51-
agent_id_from_value, bind_endpoint_to_thread, bindings_from_value, create_thread_record,
51+
agent_id_from_value, bindings_from_value, create_thread_record,
5252
default_agent_for_channel_account, default_workspace_for_channel_account,
5353
default_workspace_mode_for_channel_account, delete_thread_record,
54-
detach_endpoint_from_thread, endpoint_key, is_default_thread_list_hidden,
55-
is_hidden_thread_value, is_thread_key, label_from_value, list_known_channel_endpoints,
56-
list_registry_channel_endpoints, new_thread_key, normalize_workspace_dir,
57-
remove_binding, thread_kind_from_value, thread_metadata_from_value, update_thread_record,
58-
upsert_binding, upsert_known_channel_endpoint, upsert_thread_fields,
59-
validate_thread_accepts_bot_binding, workspace_dir_from_value,
60-
worktree_base_dir_for_config,
54+
endpoint_key, is_default_thread_list_hidden, is_hidden_thread_value, is_thread_key,
55+
label_from_value, list_known_channel_endpoints, list_registry_channel_endpoints,
56+
new_thread_key, normalize_workspace_dir, remove_binding, thread_kind_from_value,
57+
thread_metadata_from_value, update_thread_record, upsert_binding,
58+
upsert_known_channel_endpoint, upsert_thread_fields, validate_thread_accepts_bot_binding,
59+
workspace_dir_from_value, worktree_base_dir_for_config,
6160
};
6261
}
6362

@@ -94,15 +93,14 @@ pub use thread_history::{
9493
pub use threads::{
9594
ChannelBinding, KNOWN_CHANNEL_ENDPOINTS_KEY, KnownChannelEndpoint, ThreadEnsureOptions,
9695
ThreadIndexStats,
97-
agent_id_from_value, bind_endpoint_to_thread, bindings_from_value, create_thread_record,
96+
agent_id_from_value, bindings_from_value, create_thread_record,
9897
default_agent_for_channel_account, default_workspace_for_channel_account,
99-
default_workspace_mode_for_channel_account, delete_thread_record, detach_endpoint_from_thread,
100-
endpoint_key, is_default_thread_list_hidden, is_hidden_thread_value, is_thread_key,
101-
label_from_value, list_known_channel_endpoints, list_registry_channel_endpoints,
102-
new_thread_key, normalize_workspace_dir, remove_binding, thread_kind_from_value,
103-
thread_metadata_from_value, update_thread_record, upsert_binding,
104-
upsert_known_channel_endpoint, upsert_thread_fields, validate_thread_accepts_bot_binding,
105-
workspace_dir_from_value, worktree_base_dir_for_config,
98+
default_workspace_mode_for_channel_account, delete_thread_record, endpoint_key,
99+
is_default_thread_list_hidden, is_hidden_thread_value, is_thread_key, label_from_value,
100+
list_known_channel_endpoints, list_registry_channel_endpoints, new_thread_key,
101+
normalize_workspace_dir, remove_binding, thread_kind_from_value, thread_metadata_from_value,
102+
update_thread_record, upsert_binding, upsert_known_channel_endpoint, upsert_thread_fields,
103+
validate_thread_accepts_bot_binding, workspace_dir_from_value, worktree_base_dir_for_config,
106104
};
107105
pub use worktree::{
108106
PreparedWorktree, WorkspaceGitStatus, WorkspaceMode, prepare_thread_worktree,

garyx-router/src/router/contracts.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ pub struct InboundResult {
6767
pub dispatch_outcome: Option<AgentDispatchOutcome>,
6868
}
6969

70-
#[derive(Debug, Clone, PartialEq, Eq)]
71-
pub struct ThreadListEntry {
72-
pub thread_id: String,
73-
pub label: Option<String>,
74-
pub updated_at: Option<String>,
75-
}
76-
7770
#[derive(Clone, Copy)]
7871
pub(crate) struct RouteContext<'a> {
7972
pub(crate) channel: &'a str,

garyx-router/src/router/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ mod threading;
2424
pub use command_catalog::{command_catalog_for_config, reserved_command_names};
2525
pub use contracts::ThreadCreator;
2626
pub use contracts::{
27-
AgentDispatcher, InboundRequest, InboundResult, InboundSink, ThreadListEntry,
28-
ThreadMessageRequest,
27+
AgentDispatcher, InboundRequest, InboundResult, InboundSink, ThreadMessageRequest,
2928
};
3029
pub(crate) use contracts::{DispatchMetadataContext, NavigationContext, RouteContext};
3130
pub use inbound::is_native_command_text;
3231

3332
#[cfg(test)]
3433
mod tests;
3534

36-
/// Maximum number of threads kept in per-user navigation history.
37-
const MAX_HISTORY: usize = 20;
3835
/// Maximum number of outbound message records persisted per thread.
3936
const MAX_OUTBOUND_MESSAGE_IDS: usize = 100;
4037
pub const NATIVE_COMMAND_TEXT_METADATA_KEY: &str = "native_command_text";

garyx-router/src/router/tests/dispatch/route_and_dispatch.rs

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::*;
22
use crate::threads::is_thread_key;
33
use crate::{
44
ChannelBinding, ThreadCreator, ThreadEnsureOptions, ThreadStore, WorkspaceMode,
5-
bind_endpoint_to_thread, bindings_from_value, create_thread_record,
5+
bindings_from_value, create_thread_record,
66
};
77

88
struct FallbackOnlyThreadCreator;
@@ -2020,25 +2020,30 @@ async fn test_route_and_dispatch_reply_routing_falls_back_to_rebound_thread_when
20202020
)
20212021
.await
20222022
.expect("thread should be created");
2023-
bind_endpoint_to_thread(
2024-
&store_dyn,
2025-
&new_thread,
2026-
ChannelBinding {
2027-
channel: "telegram".to_owned(),
2028-
account_id: "bot1".to_owned(),
2029-
binding_key: "user42".to_owned(),
2030-
chat_id: "user42".to_owned(),
2031-
delivery_target_type: "chat_id".to_owned(),
2032-
delivery_target_id: "user42".to_owned(),
2033-
display_label: "user42".to_owned(),
2034-
last_inbound_at: None,
2035-
last_delivery_at: None,
2036-
},
2037-
)
2038-
.await
2039-
.expect("bind should succeed");
2023+
let (mut router, mutator) = test_router(store.clone(), GaryxConfig::default());
2024+
let old_binding = bindings_from_value(&store.get("thread::old").await.unwrap())
2025+
.into_iter()
2026+
.next()
2027+
.unwrap();
2028+
mutator.seed_owner("thread::old", old_binding).await;
2029+
router
2030+
.bind_endpoint_runtime(
2031+
&new_thread,
2032+
ChannelBinding {
2033+
channel: "telegram".to_owned(),
2034+
account_id: "bot1".to_owned(),
2035+
binding_key: "user42".to_owned(),
2036+
chat_id: "user42".to_owned(),
2037+
delivery_target_type: "chat_id".to_owned(),
2038+
delivery_target_id: "user42".to_owned(),
2039+
display_label: "user42".to_owned(),
2040+
last_inbound_at: None,
2041+
last_delivery_at: None,
2042+
},
2043+
)
2044+
.await
2045+
.expect("bind should succeed");
20402046

2041-
let mut router = MessageRouter::new(store.clone(), GaryxConfig::default());
20422047
router.record_outbound_message_for_chat(
20432048
"thread::old",
20442049
"telegram",
@@ -2086,7 +2091,7 @@ async fn test_route_and_dispatch_reply_routing_falls_back_to_rebound_thread_when
20862091
async fn test_route_and_dispatch_reply_routing_falls_back_after_real_initial_dispatch_and_delete() {
20872092
let store = Arc::new(InMemoryThreadStore::new());
20882093
let store_dyn: Arc<dyn crate::ThreadStore> = store.clone();
2089-
let mut router = MessageRouter::new(store.clone(), GaryxConfig::default());
2094+
let (mut router, _) = test_router(store.clone(), GaryxConfig::default());
20902095
let dispatcher = MockDispatcher::new();
20912096

20922097
let initial = InboundRequest {
@@ -2125,23 +2130,23 @@ async fn test_route_and_dispatch_reply_routing_falls_back_after_real_initial_dis
21252130
)
21262131
.await
21272132
.expect("thread should be created");
2128-
bind_endpoint_to_thread(
2129-
&store_dyn,
2130-
&new_thread,
2131-
ChannelBinding {
2132-
channel: "telegram".to_owned(),
2133-
account_id: "bot1".to_owned(),
2134-
binding_key: "user42".to_owned(),
2135-
chat_id: "user42".to_owned(),
2136-
delivery_target_type: "chat_id".to_owned(),
2137-
delivery_target_id: "user42".to_owned(),
2138-
display_label: "user42".to_owned(),
2139-
last_inbound_at: None,
2140-
last_delivery_at: None,
2141-
},
2142-
)
2143-
.await
2144-
.expect("bind should succeed");
2133+
router
2134+
.bind_endpoint_runtime(
2135+
&new_thread,
2136+
ChannelBinding {
2137+
channel: "telegram".to_owned(),
2138+
account_id: "bot1".to_owned(),
2139+
binding_key: "user42".to_owned(),
2140+
chat_id: "user42".to_owned(),
2141+
delivery_target_type: "chat_id".to_owned(),
2142+
delivery_target_id: "user42".to_owned(),
2143+
display_label: "user42".to_owned(),
2144+
last_inbound_at: None,
2145+
last_delivery_at: None,
2146+
},
2147+
)
2148+
.await
2149+
.expect("bind should succeed");
21452150

21462151
assert!(store.delete(&initial_result.thread_id).await);
21472152
router.rebuild_thread_indexes().await;

0 commit comments

Comments
 (0)