Skip to content

Pyproject rework - #198

Open
OmniTroid wants to merge 26 commits into
masterfrom
pyproject-rework
Open

Pyproject rework#198
OmniTroid wants to merge 26 commits into
masterfrom
pyproject-rework

Conversation

@OmniTroid

Copy link
Copy Markdown
Collaborator

No description provided.

OmniTroid and others added 26 commits May 27, 2026 12:14
Dependencies move into [project] with a [dependency-groups].dev for
pytest/black/tox; Dockerfile, Travis, tox.ini, start scripts and README
are updated to install/run via uv. uv.lock is committed for reproducible
installs.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
tox 4 reads native TOML config from [tool.tox], so the standalone
tox.ini is redundant. tox-uv is pinned alongside tox in the dev group
so `uv run tox` works straight out of `uv sync`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Brings over the real-server pytest fixture and AO-protocol MockClient
so tests can drive a live TsuServer3 over WebSocket on an ephemeral
port. Adds handshake/select/IC and /login coverage; drops the old
AOProtocol-direct mocks.

- server.tsuserver: extract `serve_websocket(host, port)` so the
  fixture can bind without running the full `start()` loop
- server.constants: add `decode_ao_packet` (inverse of the existing
  encode_ao_packet) — needed by MockClient
- tests.conftest: neutralize TsuServer3's mid-init
  `sys.setrecursionlimit(50)` for the fixture only (it breaks PyYAML
  and pytest-asyncio's stack)
- MockClient MS defaults: send "0" instead of "" for frames_* /
  effect to satisfy KFO's stricter STR (vs STR_OR_EMPTY) validation
- test_exception_does_not_disconnect is xfail-strict:
  aoprotocol.data_received intentionally KKs + disconnects on
  unhandled exceptions, unlike czar

Skipped czar tests with no KFO counterpart: test_timer.py (Timer is
a nested class on Area/AreaManager here, not server.timer) and
test_ms_parser.py (MS is parsed inline in net_cmd_ms).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds ruff config for intentional patterns (scripts/ ad-hoc utilities;
star imports + post-decorator imports in server/commands/__init__.py)
and fixes the remaining 37 lint findings in-code:

- E711/E712: replace `== None` / `== True/False` with `is`/truthy checks
- E722: replace bare `except:` with `except Exception:` (15 sites)
- E741: rename ambiguous `l` to `p` in a pos comprehension
- F841: remove dead locals (commented-out y-offset parsing, unused
  fighter_name, unused cid in send_discord_chat, unused timer flag)

Notable behavior change (F811):
- client_manager.py: the `latest_area` setter was mistakenly decorated
  `@inventory.setter`, binding it to the wrong property — writes to
  `client.latest_area` previously silently no-op'd. Now correctly
  `@latest_area.setter`, so kick_to_latest_area / latest-area tracking
  actually persist.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Removes black and its transitive deps from the dev group, moves
line-length/target-version onto [tool.ruff] so both `ruff check` and
`ruff format` honor them, and updates the README to point at
`uv run ruff format .`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replaces the old flake8/requirements.txt/Python-3.12 workflow with a
uv-based pipeline that runs `ruff check`, `ruff format --check`, and
`pytest` on push to master and on PRs. Uses astral-sh/setup-uv with
caching and cancels stale runs on the same branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- tests/__init__.py: docstring pointed at the deleted tests.mock.mocks
- start_server.py: drop check_deps() import-shim and version check
  (uv + requires-python enforce both); update banner KFO-Server
- docker-compose.yml: drop deprecated version: "3.3" key; rename
  service/image from tsuserver to kfo-server

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Class renamed to match the project name; module file renamed via
git mv so history follows. Updates the two import sites
(start_server.py, tests/conftest.py), test docstrings, and a stale
TODO in client_manager.py that pointed at the old filename.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- /help welcome banner: "Welcome to tsuserver3!" -> "Welcome to KFO-Server!"
- Default Discord webhook username: "tsuserver webhook" -> "KFO-Server webhook"

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Retarget the project to Python 3.13 (tox, ruff, requires-python) and bump
every dependency to its latest version. This removes the stdlib `audioop`
deprecation warning at the source: on 3.13 discord.py 2.7.1 uses the
`audioop-lts` backport instead of the removed stdlib module. Upgrading
python-dateutil to 2.9.0.post0 clears a second deprecation 3.13 surfaced.

Fix two websockets 12->17 API breaks in the client handler: the connection
handler no longer receives `path`, and `request_headers` is now
`request.headers`. Without these, all client connections failed.

Pin ruff's lint selection to the historical default (E4/E7/E9/F) so the
0.16 upgrade doesn't silently broaden lint scope.
Previously an unhandled exception in net-command dispatch sent the client a
KK error, disconnected them, and re-raised — so a bug handling one packet
dropped the whole connection. Log and notify, but keep processing the rest
of the buffer instead. Removes the now-passing xfail marker (and its orphaned
pytest import) on test_exception_does_not_disconnect.
KK is a kick packet; sending it on an internal error dropped the client.
Just log the exception (with traceback via exc_info) and keep the connection.
data_received documented packet_size as bytes (config) but the code comment
said bits and multiplied by 8 (bytes->bits, the wrong direction), so the real
limit was 8192 bytes while every config said 1024. Compare len(buf) directly
against packet_size in bytes and set the default/sample to 8192, preserving
the effective limit the server has always enforced.
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