unit-tests.md 5.0 KB


type: testing title: Unit tests description: Overview of the in-module unit test suites in src/*.rs (including the web panel), what each one covers and how to run them. tags: [testing, cargo, unit-tests] sources:

  • id: openwiki-source-651d1fb6c9 resource: repo://Cargo.toml
  • id: openwiki-source-1b05507d70 resource: repo://src/ai.rs
  • id: openwiki-source-9fec9d1af4 resource: repo://src/app.rs
  • id: openwiki-source-043e6252ba resource: repo://src/autoreply.rs
  • id: openwiki-source-2a737474d8 resource: repo://src/config.rs
  • id: openwiki-source-ce0c4ea8cd resource: repo://src/history.rs
  • id: openwiki-source-6bddea306b resource: repo://src/ui.rs
  • id: openwiki-source-7b75006986 resource: repo://src/web.rs
  • id: openwiki-source-7ea5eac45e resource: repo://src/whatsapp.rs generated: { by: "claude-code", at: "2026-10-20T20:27:06.515Z" } verified:
  • by: openwiki/0.7.2 at: 2026-10-20T20:27:06.515Z ---

Unit tests

All tests are plain Rust unit tests in #[cfg(test)] mod tests blocks at the bottom of each source file. There are no integration tests, no [dev-dependencies] (Cargo.toml only has [dependencies]) and no test touches the network, binds a port or uses a real WhatsApp session.

Running

cargo test                      # whole suite
cargo test autoreply::          # one module
cargo test should_reply_false   # by name filter

Suites

Module Tests Location Covers
autoreply 77 src/autoreply.rs:528+ private/group/self-chat detection, supports_autoreply (groups yes, broadcasts and newsletters no), every ReplyGate::should_reply rule (disabled, own messages, backlog, blank/placeholder text, per-chat cooldown, group cooldown vs. addressed messages via is_addressed), deferral_due / take_pending / record_reply pending logic, catch_up_due rules, custom and zero cooldowns, context_start, build_turns roles, role notes, group sender prefixes, context truncation, voice-note and image instructions
config 32 src/config.rs:323+ defaults, trimming, multiline prompt, base URL normalisation, Debug masking, DB and AI log paths, ai_log, cooldown, catch-up and ai_retries defaults/custom values/negative rejection, web_port (unset, valid, 0 and out of range rejected), BOM/CRLF, non-leaking parse errors, missing/invalid/unreadable files
whatsapp 27 src/whatsapp.rs:1005+ fatal-only app state sync reporting, addressed_jids (mentions, quoted participant, media context info), message rendering and placeholders, captions, image references, silent messages, JID device suffix, push-name filtering
ai 25 src/ai.rs:526+ request and vision body shapes, image validation limits, Debug redaction, reply parsing, endpoint construction, AI log records (no key, images redacted), logging only when enabled, append-only log writes, retry policy (is_retryable, StatusError message, linear retry_delay), truncation
history 16 src/history.rs:481+ dedupe by message id, ordering and limits, messages_since (boundary, limit keeps most recent, ascending order), chat name fallbacks, per-chat and global autoreply flags, delete_chat, contacts, on-disk open
ui 14 src/ui.rs:558+ footer key help (F4 highlight), sender labels, clock time, QR text, wrapping, visible lines, input tail, messages title, list title (global marker, filter), selection clamp
app 14 src/app.rs:1167+ autoreply enable rules (private, self-chat LID, groups; broadcasts, newsletters and missing AI refused), web_chats filtering and order, vision applicability, error combining, list filter matching, selection and toggle helpers, AltGr handling, fixed function-key codes
web 9 src/web.rs:366+ query stripping, route resolution, X-Wh-Request header check (any case, missing/wrong value), which routes require it, request body trimming, empty/invalid UTF-8 rejection and the 1024-byte limit

Total: 214 #[test] functions.

Test isolation

  • History tests use History::open_in_memory() (only compiled for tests, src/history.rs:76-86); the on-disk test writes under std::env::temp_dir() in a per-process directory (src/history.rs:749-763).
  • AI tests check request bodies, parsing, log records and the retry policy without sending requests; the append test writes a per-process file under std::env::temp_dir() and removes it (src/ai.rs:802-813).
  • Web tests exercise the pure routing and parsing helpers; the HTTP server itself is never started.

Pages with module details: AI autoreply, Configuration, AI client, WhatsApp client, Web control panel, History store, Terminal UI, Application state.