Skip to content

Refactor/phase 5 tests - #5

Merged
Nitrocosm merged 4 commits into
masterfrom
refactor/phase-5-tests
May 19, 2026
Merged

Nitrocosm merged 4 commits into
masterfrom
refactor/phase-5-tests

Conversation

@Nitrocosm

Copy link
Copy Markdown
Owner

No description provided.

Nitrocosm added 4 commits May 19, 2026 04:39
…t,badges,config}


Adds 84 unit tests across 5 new test modules. All target pure / near-pure
helpers - no Discord connection or async needed.

  tests/test_points.py         (24 tests)
    parse_challenge_role: valid official/custom/star/ultimate variants
      + invalid forms (missing tier emoji, missing /+N/, malformed)
    calculate_points: no-challenge path; sums + sorts roles descending
    get_leaderboard: excludes bots + zero-point members
    get_ranked_leaderboard: ties group at the same rank
    get_member_rank: ranked + unranked
    has_all_challenges: empty / all owned / missing one / 💠 excluded

  tests/test_moderation.py     (20 tests)
    get_timeout_duration: all suffixes (s/m/h/d/w/max); zero / invalid /
      >28d all raise; 4w (==28d) is the boundary that passes
    format_timedelta: singular vs plural unit nouns; mixed durations

  tests/test_role_management.py (6 tests)
    _parse_relations_from_text: single / multiple parents, blank lines
    don't reset context, non-bullet comments DO reset, parent with no
    children stays in the dict

  tests/test_badges.py          (29 tests)
    points_to_difficulty: every bucket boundary including the negative
    edge; DIFFICULTY_PLACEHOLDERS has the right length and every index
    points_to_difficulty can produce has a placeholder

  tests/test_config.py          (5 tests)
    check_guild target/other; full public surface present after the
    Phase 1 package split; Phase 1.3 dropped duplicate keys stay dropped

Total: 90/90 passing (84 new + 6 from test_cogs_load.py).
Adds 43 tests for the pure helpers in modules/verification.py:

  _get_youtube_video_id / _get_youtube_url
    8 valid URL forms (youtube.com/watch, youtu.be, m.youtube.com,
    youtube.com/shorts, with query params, http, schemeless) + 5
    invalid (empty, non-YT, channel URLs, too-short id).

  _verifiers_for_points
    Boundary check at 14: 13 pts -> 2 verifiers, 14 pts -> 3.

  _verifier_tag
    Maps 3/2/1 to the right TAG_*_NEEDED snowflakes; unknown counts
    fall back to TAG_3_NEEDED.

  _next_5min_interval
    Strictly future even at an exact boundary (1500 -> 1800, not 1500).

  _build_challenge_message - the state-machine renderer that produces
  the user-facing message for every verification state. Tests cover
  each branch: rejected / reported / manual / video_ready (+ optional
  last_verifier) / video uploading (with next_check_at) / no_footage /
  default no-video / awaiting_video hint / url-line conditional /
  role-name resolution when the guild's get_role returns a parseable
  challenge role.

All 133 tests pass (43 new + 90 from prior commits).
6 tests pinning the Phase 4 fixes so they don't regress silently:

  - general.send raises RuntimeError when bot.get_channel returns None
    (previously: returned the input str typed as Message)
  - general.update_status() with no args passes status=None to
    change_presence (previously: callers passed Bot as status)
  - general.update_status(status=Status.online) forwards correctly
  - general.update_status is a no-op when get_guild returns None
  - RoleSession.commit serialises edits per member (same member ->
    strict start/end/start/end ordering, never interleaved)
  - RoleSession.commit does NOT serialise across members (different
    members -> start/start/end/end, fully concurrent)

The two concurrency tests exercise the per-member asyncio.Lock end to
end: stubbed `member.edit` records start/end events; the test asserts
overlap or strict ordering depending on whether the member ids match.

139 / 139 tests passing.
Adds .github/workflows/ci.yml running on every push and pull-request to
any branch. Two gates:

  - ruff check .   (hard fail)
  - pytest tests/  (hard fail)

To get there from 99 remaining ruff issues:

  1) Auto-fix (ruff --fix) removed 15 trivially-safe issues across 10
     files (trailing-blank-line, unused asyncio import, f-strings with
     no placeholders).

  2) Hand-fixed:
       - 7 F841 unused-variable warnings: dropped the dead `msg = ` in
         CoreCog.update; dropped user_id / username / request_id from
         _on_join_request_create (only ever used by commented-out code);
         dropped request_id from _on_join_request_delete; dropped
         unused `guild` in build_activity_cache; dropped unused
         `reason` in _check_youtube_video
       - 1 E402: moved `import functools` from mid-file to the top of
         modules/general.py

  3) Globally ignored three style categories in pyproject.toml:
       E501 - long lines (Discord message templates are intentionally
              long and don't decompose cleanly)
       E701 - `if x: y` one-liners (intentional throughout)
       E702 - semicolon-chained statements (ditto)
     Stricter rules can be turned back on in a future cleanup if wanted.

Result: ruff reports "All checks passed!"; 139 / 139 tests pass.
@Nitrocosm
Nitrocosm merged commit 4e610a1 into master May 19, 2026
3 checks passed
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