Skip to content

test(channels): add injectable test transport to TelegramChannel#2128

Merged
bug-ops merged 3 commits intomainfrom
feat-issue-2121-test-channels-injectable
Mar 22, 2026
Merged

test(channels): add injectable test transport to TelegramChannel#2128
bug-ops merged 3 commits intomainfrom
feat-issue-2121-test-channels-injectable

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Mar 22, 2026

Summary

  • Adds new_test() constructor under #[cfg(test)] that returns (TelegramChannel, mpsc::Sender<IncomingMessage>), enabling unit tests without a real bot token or live Telegram API
  • Adds make_mocked_channel() test helper using wiremock to intercept bot API calls for paths that call send() (the /start welcome message and flush_chunks() with message_id)
  • Adds 12 new behavioural tests covering all scenarios from the issue spec

Test coverage added

Scenario Approach
recv() returns message on inject new_test()
/reset and /skills routed correctly new_test()
Unknown command passed through new_test()
Channel close returns None new_test()
send_chunk() accumulates without API new_test() + set last_edit
flush_chunks() clears state (no message_id) new_test()
/start consumed internally wiremock
flush_chunks() with message_id wiremock
confirm() timeout logic rx-timeout isolation (Discord pattern)
confirm() channel-close logic rx-timeout isolation
confirm() accepts "yes" rx-timeout isolation
confirm() rejects non-"yes" rx-timeout isolation

Test plan

  • cargo nextest run -p zeph-channels — 99 tests passed, 0 skipped
  • cargo +nightly fmt --check — clean
  • cargo clippy --workspace --features full -- -D warnings — clean
  • Full workspace: 6384 tests passed

Closes #2121

bug-ops added 2 commits March 22, 2026 14:59
Add new_test() constructor under #[cfg(test)] that injects the mpsc::Sender<IncomingMessage>
directly, enabling unit tests without a real Telegram bot token or live API access.

Add 12 behavioural tests covering:
- recv() message delivery, /reset and /skills routing, unknown-command passthrough,
  channel-close returning None
- send_chunk() text accumulation (throttle prevents API call)
- flush_chunks() state clearing with and without message_id (wiremock for edit path)
- /start consumed internally via wiremock
- confirm() timeout, channel-close, yes, and non-yes logic at the rx-timeout level

Add wiremock and tokio test-util to zeph-channels dev-dependencies.
No production code paths were changed.

Closes #2121
@github-actions github-actions bot added documentation Improvements or additions to documentation channels zeph-channels crate (Telegram) rust Rust code changes dependencies Dependency updates tests Test-related changes size/L Large PR (201-500 lines) labels Mar 22, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 22, 2026 14:04
@github-actions github-actions bot removed the tests Test-related changes label Mar 22, 2026
@bug-ops bug-ops merged commit 3413e29 into main Mar 22, 2026
25 checks passed
@bug-ops bug-ops deleted the feat-issue-2121-test-channels-injectable branch March 22, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channels zeph-channels crate (Telegram) dependencies Dependency updates documentation Improvements or additions to documentation rust Rust code changes size/L Large PR (201-500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(channels): add injectable test transport to TelegramChannel for unit testing without Telegram API

1 participant