refactor: implement trait-based DI for TdClient and fix stack overflow
Implement complete trait-based dependency injection pattern for TdClient to enable testing with FakeTdClient mock. Fix critical stack overflow bugs caused by infinite recursion in trait implementations. Breaking Changes: - App is now generic: App<T: TdClientTrait = TdClient> - All UI and input handlers are generic over TdClientTrait - TdClient methods now accessed through trait interface New Files: - src/tdlib/trait.rs: TdClientTrait definition with 40+ methods - src/tdlib/client_impl.rs: TdClientTrait impl for TdClient - tests/helpers/fake_tdclient_impl.rs: TdClientTrait impl for FakeTdClient Critical Fixes: - Fix stack overflow in send_message, edit_message, delete_messages - Fix stack overflow in forward_messages, current_chat_messages - Fix stack overflow in current_pinned_message - All methods now call message_manager directly to avoid recursion Testing: - FakeTdClient supports configurable auth_state for auth screen tests - Added pinned message support in FakeTdClient - All 196+ tests passing (188 tests + 8 benchmarks) Dependencies: - Added async-trait = "0.1" Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,7 +46,7 @@ fn snapshot_footer_network_waiting() {
|
||||
let mut app = TestAppBuilder::new().with_chat(chat).build();
|
||||
|
||||
// Set network state to WaitingForNetwork
|
||||
app.td_client.network_state = NetworkState::WaitingForNetwork;
|
||||
*app.td_client.network_state.lock().unwrap() = NetworkState::WaitingForNetwork;
|
||||
|
||||
let buffer = render_to_buffer(80, 24, |f| {
|
||||
tele_tui::ui::footer::render(f, f.area(), &app);
|
||||
@@ -63,7 +63,7 @@ fn snapshot_footer_network_connecting_proxy() {
|
||||
let mut app = TestAppBuilder::new().with_chat(chat).build();
|
||||
|
||||
// Set network state to ConnectingToProxy
|
||||
app.td_client.network_state = NetworkState::ConnectingToProxy;
|
||||
*app.td_client.network_state.lock().unwrap() = NetworkState::ConnectingToProxy;
|
||||
|
||||
let buffer = render_to_buffer(80, 24, |f| {
|
||||
tele_tui::ui::footer::render(f, f.area(), &app);
|
||||
@@ -80,7 +80,7 @@ fn snapshot_footer_network_connecting() {
|
||||
let mut app = TestAppBuilder::new().with_chat(chat).build();
|
||||
|
||||
// Set network state to Connecting
|
||||
app.td_client.network_state = NetworkState::Connecting;
|
||||
*app.td_client.network_state.lock().unwrap() = NetworkState::Connecting;
|
||||
|
||||
let buffer = render_to_buffer(80, 24, |f| {
|
||||
tele_tui::ui::footer::render(f, f.area(), &app);
|
||||
|
||||
Reference in New Issue
Block a user