Skip to main content
ollim-bot has a pytest-based test suite covering data structures, storage I/O, scheduling, permissions, forks, and more. Tests run against real files in temp directories rather than mocking internal behavior.

Running tests

To run with coverage reporting:
To run a single test file:
No extra configuration is needed. The conftest.py sets default environment variables (OLLIM_USER_NAME=TestUser, OLLIM_BOT_NAME=test-bot) so tests run without a .env file.

Test philosophy

Tests verify real behavior against real data. The guiding principle: mock only what you cannot control. What gets tested with real instances:
  • Dataclass construction and field defaults (Routine, Reminder, BudgetState)
  • File I/O — JSONL reading/writing, markdown parsing, roundtrip serialization
  • State transitions — ping budget refill, session compaction, permission approval
  • Configuration loading and validation
What gets mocked:
  • Discord API calls (channel.send(), message objects) — these require an active gateway connection
  • Agent/Client creation in fork execution — these start real Claude API calls
This is not “no mocks.” It is no gratuitous mocks. If the code under test can run with real objects and temp files, it does.

Test structure

Dependencies

All three are in the dev dependency group and installed by uv sync.

The data_dir fixture

Every test that touches the filesystem uses the data_dir fixture from conftest.py. It redirects all module-level path constants to a tmp_path directory:
This means tests never touch ~/.ollim-bot/. Each test gets an isolated temp directory that is cleaned up automatically.

File organization

All tests live in tests/ as module-level functions — no test classes. Each file maps to a source module:

ADHD behavior evals

The eval system tests whether the bot responds appropriately to simulated ADHD users. It runs multi-turn conversations between a Haiku-powered user-proxy (playing a simulated ADHD user) and the real bot agent, then scores the transcript with a Sonnet-powered LLM judge.

What it tests

Each scenario defines a persona (personality, goal, opening message, max turns) and criteria the judge scores on a 1-5 scale. Criteria are ADHD-specific behavioral anchors — things like whether the bot gives exactly one next step instead of an option dump, uses warm tone instead of productivity-coach language, and avoids adding cognitive load. There are 6 scenarios in src/ollim_bot/evals/cases/: Scenarios with goal_type: file_created pass when the bot creates a routine or reminder file. Scenarios with goal_type: qualitative always run to max_turns and rely entirely on the judge’s scoring.

Running evals

See CLI reference for the full list of subcommands and flags.
Evals require Claude authentication and make real API calls — they are not part of the fast pytest suite. Run them separately when you want to validate ADHD behavior quality.

ADHD behavior regression tests

Three test modules (33 tests, 441 lines) protect ADHD-specific behavior without requiring API calls:
  • test_behavior_prompts.py — verifies prompt content includes required ADHD-specific instructions
  • test_behavior_scenarios.py — tests multi-step interaction flows and scenario data model integrity
  • test_behavior_context.py — tests context assembly for eval environments
These run as part of the regular pytest suite and catch regressions in prompt content and scenario definitions.

Counterfactual trajectory testing

The counterfactual command answers a different question from ADHD behavior evals: “what would the agent have done here if I changed X?” It replays a real production transcript up to a chosen point, applies an intervention, and prints the new response next to the original so you can see exactly what changed. Use it when you want to validate a prompt edit, tool restriction, or model swap against a session that already happened — without waiting for similar behavior to recur in production.
counterfactual is a separate top-level command installed alongside ollim-bot by uv tool install --editable .. It is not an ollim-bot subcommand.

How it works

counterfactual truncates the session’s JSONL transcript at the rewind point, then uses the Claude Agent SDK’s fork feature to resume from the truncated state with modified ClaudeAgentOptions. It can run two forks in parallel — a baseline (same settings as the original) and a variant (with the intervention) — so you can distinguish sampling noise from the intervention’s effect. The truncated file and both fork sessions are cleaned up after the run. Source: src/ollim_bot/eval/counterfactual.py and src/ollim_bot/eval/counterfactual_cli.py.

Running a test

The session argument accepts UUID prefixes, prev, prev-N, or slug names — matching claude-history conventions. The rewind_uuid must be a user message UUID (assistant and tool-result UUIDs are rejected), and it cannot be the first record in the session. See the counterfactual CLI reference for every flag and default.

Bundled Claude Code skill

The source repo ships a counterfactual-test Claude Code skill at .claude/skills/counterfactual-test/SKILL.md. It walks Claude Code through picking a session and rewind point, choosing an intervention, and interpreting the output. The skill sets disable-model-invocation: true, so it runs only when you type /counterfactual-test in a Claude Code session inside the source repo — the model will not trigger it automatically. This is a Claude Code dev-harness skill, separate from ollim-bot runtime skills loaded by the bot at startup.

Cost and gotchas

  • Default caps are $0.50 per run and 5 turns; --with-baseline doubles cost by running two forks.
  • Discord MCP tools are not connected — pick rewind points where the original response did not depend on ping_user, discord_embed, or other Discord-side tools, or the comparison is invalid.
  • Variant runs use bypassPermissions — tools denied in production can succeed on replay, which may change tool selection behavior.
  • Profile drift — the variant uses the current IDENTITY.md and USER.md. If these changed since the original session, differences may reflect profile edits rather than the intervention.
  • Interrupted runs may leave orphaned JSONL files under ~/.claude/projects/. Delete them manually if cleanup did not run.

Writing tests

Basic pattern

Tests follow a three-part structure: set up state, call the function, assert the result.
Use data_dir as a fixture parameter whenever the test involves file I/O. For tests that only need a temp directory without path redirection, use pytest’s built-in tmp_path.

Async tests

Most async tests use a sync _run() helper that drives coroutines through the event loop — no @pytest.mark.asyncio needed:

Assertions

Use direct assertions rather than assertion helpers:

Next steps

Development guide

Dev setup, project structure, and code conventions.

CLI reference

All ollim-bot subcommands and flags.

Architecture overview

Module map and data flow through the system.

Troubleshooting

Common issues and debugging techniques.