Skip to content

chore(ci): add mypy + hypothesis property tests#16

Open
rezhajulio wants to merge 2 commits into
mainfrom
chore/mypy-hypothesis
Open

chore(ci): add mypy + hypothesis property tests#16
rezhajulio wants to merge 2 commits into
mainfrom
chore/mypy-hypothesis

Conversation

@rezhajulio

Copy link
Copy Markdown
Owner

Add a second layer of bug-catching via static type analysis and property-based testing. The unit/integration suite catches the bugs we thought of; mypy + Hypothesis catch the ones we didn't.

mypy

  • Add mypy 2.1.0 + ruff back to dev dependencies.
  • Pragmatic config in pyproject.toml: ignore_missing_imports, disable error codes that are noisy from PTB / SQLModel / Pydantic v2 (arg-type, attr-defined, index, union-attr, misc, return-value, call-arg). The team tightens module-by-module over time.
  • Fix the 2 real type errors caught (Literal annotation for logfire min_log_level; type:ignore for preload_admin_ids called with Application instead of Context). Add 1 type:ignore for the application.job_queue.run_once call in captcha_recovery.
  • Strict override for bot.tests.* (new test code must be typed).

Hypothesis property tests

  • New tests/test_properties.py: 19 property tests on pure functions (format_threshold_display, format_hours_display, _format_person, _format_person_with_username, is_url_whitelisted). 200 examples per test by default. Shrinks failing cases automatically.
  • These would have caught the "User 12345" placeholder bug from the previous round (is_url_whitelisted property) and the format-threshold edge cases we never enumerated.

CI

  • Use uv for both lint and test jobs (consistent with dev workflow).
  • Lint job now runs ruff + mypy on every push and PR.
  • Test job matrix unchanged (3.11-3.14).

Add a second layer of bug-catching via static type analysis and
property-based testing. The unit/integration suite catches the bugs we
thought of; mypy + Hypothesis catch the ones we didn't.

mypy
- Add mypy 2.1.0 + ruff back to dev dependencies.
- Pragmatic config in pyproject.toml: ignore_missing_imports,
  disable error codes that are noisy from PTB / SQLModel / Pydantic v2
  (arg-type, attr-defined, index, union-attr, misc, return-value,
  call-arg). The team tightens module-by-module over time.
- Fix the 2 real type errors caught (Literal annotation for logfire
  min_log_level; type:ignore for preload_admin_ids called with
  Application instead of Context). Add 1 type:ignore for the
  application.job_queue.run_once call in captcha_recovery.
- Strict override for bot.tests.* (new test code must be typed).

Hypothesis property tests
- New tests/test_properties.py: 19 property tests on pure functions
  (format_threshold_display, format_hours_display, _format_person,
  _format_person_with_username, is_url_whitelisted). 200 examples
  per test by default. Shrinks failing cases automatically.
- These would have caught the "User 12345" placeholder bug from the
  previous round (is_url_whitelisted property) and the
  format-threshold edge cases we never enumerated.

CI
- Use uv for both lint and test jobs (consistent with dev workflow).
- Lint job now runs ruff + mypy on every push and PR.
- Test job matrix unchanged (3.11-3.14).
@rezhajulio rezhajulio force-pushed the chore/mypy-hypothesis branch from e082020 to d64a595 Compare June 17, 2026 17:56
Bring the docs in line with the current state of the codebase.

AGENTS.md
- Add mypy + hypothesis commands to the Commands section.
- Document the modular plugin system in the Structure tree
  (src/bot/plugins/builtin/* wrapping src/bot/handlers/*).
- New "Modular Plugin System" subsection under Architecture Patterns
  covering the wrapper pattern, per-group runtime gating, and how
  to add a new plugin.
- New "Captcha Profile Check" subsection documenting the DB-first /
  Telegram-unrestrict-last ordering and the failure semantics.
- Add admin_cache.py, trust.py, test_properties.py to the
  structure/code map. Note the TrustedUser table (5th DB table).
- Add "Where to Look (Plugin System)" table for the new layer.
- Update Testing section: property-based tests, ~970 tests total,
  test-delta tracking advice.
- Update CI/CD: mypy step + pragmatic error-code disables.
- Notes: trust feature, reviews/ gitignore, captcha DB ordering.

README.md
- Add mypy and property-test commands to Testing section.
- Update test count: 977+ total including 19 Hypothesis tests.
- Add scripts/backfill_trusted_names.py to Project Structure.
- Add the plugins/ tree and trust.py handler to Project Structure.
- Architecture section: mention plugin manager, guard_plugin, and
  the trust admin commands.
- New "Captcha Verification with Profile Check" subsection
  (user-facing) explaining the join → click → profile check →
  unrestrict flow.
- Update Installation to use `uv sync --dev`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant