Skip to content

Make the exploration, encounter, and battle handler tables private - #140

Merged
mmacy merged 2 commits into
mainfrom
chunk/handler-privacy
Sep 15, 2026
Merged

mmacy merged 2 commits into
mainfrom
chunk/handler-privacy

Conversation

@mmacy

@mmacy mmacy commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • osrlib.crawl.exploration.HANDLERS, osrlib.crawl.encounter.HANDLERS, and osrlib.crawl.battle.HANDLERS are renamed to _HANDLERS, dropped from each module's __all__, and no longer documented as a public extension point.
  • GameSession no longer merges the three tables into a module-level _HANDLERS_CACHE in crawl/session.py. Each session now assembles its own merged table lazily, on its first call to execute, and caches it on the instance (self._handlers), so two sessions never share a table object and replacing a handler after a session's first command reaches that session as intended.
  • GameSession.execute is unchanged in behavior: the same handler runs for every command class, session.command.wrong_mode and the "no handler for command type" ValueError behave as before, and no golden file moved.
  • Docstrings in the three procedure modules that described HANDLERS as public are rewritten to describe the private table and GameSession.execute as the only documented way in; the runnable example in exploration.py's HANDLERS docstring, which imported the public name, is removed.
  • CHANGELOG.md gets one bullet under ## [Unreleased] / ### Removed.

Closes #107

Test plan

  • uv run pytest --runxfail tests/test_handler_dispatch.py — 3 passed (the two chunk-marked tests now pass under --runxfail, and the control test still passes; the @pytest.mark.xfail markers are left in place per the packet).
  • uv run ruff format --check — 160 files already formatted.
  • uv run ruff check — all checks passed.
  • uv run pyright — 0 errors, 0 warnings.
  • uv run pytest — 2928 passed, 146 skipped, 4 xfailed, 2 xpassed (the two handler-dispatch tests, not marked strict so they don't fail the suite).
  • uv run mkdocs build --strict — builds clean.

https://claude.ai/code/session_01NmCezTw8hKKujkaEZ3YGAs

)

Each module's HANDLERS map was public and documented as an extension
point, but GameSession merged the three into a module-level cache on
its first dispatch, so replacing an entry afterward reached no
session. The tables are now private (_HANDLERS), and each session
builds its own merged table lazily on its first dispatch and keeps it
on the instance, so two sessions never share one and
GameSession.execute is the only documented way to run a command.

Claude-Session: https://claude.ai/code/session_01NmCezTw8hKKujkaEZ3YGAs
@mmacy
mmacy merged commit 2f1a997 into main Sep 15, 2026
4 checks passed
@mmacy
mmacy deleted the chunk/handler-privacy branch September 15, 2026 04:44
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.

Make handler registration a real API or make HANDLERS private

1 participant