unit-tests.md 4.2 KB


type: testing title: Unit tests description: Overview of the in-module unit test suites in src/*.rs, 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-7ea5eac45e resource: repo://src/whatsapp.rs generated: { by: "claude-code", at: "2026-10-19T19:53:56.480Z" } verified:
  • by: openwiki/0.7.2 at: 2026-10-19T19:53:56.480Z ---

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 or 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 26 src/config.rs:288+ defaults, trimming, multiline prompt, base URL normalisation, Debug masking, DB and AI log paths, ai_log, cooldown and catch-up defaults/custom values/negative rejection, BOM/CRLF, non-leaking parse errors, missing/invalid/unreadable files
ai 21 src/ai.rs:452+ 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, truncation
whatsapp 26 src/whatsapp.rs:990+ addressed_jids (mentions, quoted participant, media context info), message rendering and placeholders, captions, image references, silent messages, JID device suffix, push-name filtering
history 14 src/history.rs:418+ dedupe by message id, ordering and limits, messages_since (boundary, limit keeps most recent, ascending order), chat name fallbacks, autoreply flags, contacts, on-disk open
ui 11 src/ui.rs:508+ sender labels, clock time, QR text, wrapping, visible lines, input tail, title, selection clamp
app 11 src/app.rs:909+ autoreply enable rules (private, self-chat LID, groups; broadcasts, newsletters and missing AI refused), vision applicability, error combining, selection and toggle helpers, AltGr handling

Total: 186 #[test] functions.

Test isolation

  • History tests use History::open_in_memory() (only compiled for tests, src/history.rs:74-80); the on-disk test writes under std::env::temp_dir() in a per-process directory (src/history.rs:648-662).
  • AI tests check request bodies, parsing and log records without sending requests; the append test writes a per-process file under std::env::temp_dir() and removes it (src/ai.rs:720-731).

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