Skip to content

Conversation

@PythonFZ
Copy link
Member

@PythonFZ PythonFZ commented Jan 8, 2026

  • Add tests/server_provider.py with ServerProvider class for managing
    server lifecycle in tests (start/stop/restart/fresh_restart)
  • Add flush_redis() and fresh_restart() for complete server resets
  • Add server_provider fixture to conftest.py
  • Add config singleton reset to _create_server_process for test isolation
  • Refactor test_zndraw_admin.py to use conftest fixtures (removes 116
    lines of duplicate code)
  • Add tests for ServerProvider (12 tests) and extension persistence (2 tests)

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

TODO

  • ensure tests for extension registration are correct
  • remove or cleanup tests that do more than they should

PythonFZ and others added 15 commits January 7, 2026 19:29
BREAKING CHANGES:
- Room creation is now separate from joining:
  - POST /api/rooms creates a new room (returns 201)
  - POST /api/rooms/{id}/join joins existing rooms only (returns 404 if not exists)
- Password hashing upgraded from SHA-256 to Argon2id (existing passwords invalidated)
- JWT tokens now have 7-day expiration

Key changes:
- Add ensure_user_exists() to UserService for idempotent user creation
- Users are created on socket connect from JWT claims, not during login
- JWT is now the single source of truth for identity
- Simplified login endpoint - guests get JWT without Redis entry until socket connect
- Added argon2-cffi dependency for secure password hashing
- Frontend: Removed redundant role state, use getRoleFromToken() only
- Updated all tests to use create-then-join pattern

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This refactoring enforces strict single responsibility per endpoint:
- /api/user/register: ONLY place for user creation (guest or registered)
- /api/login: ONLY authenticates users (never creates)
- Socket connect and room join validate user exists

Key changes:
- Add password validation (minimum 8 characters)
- Add get_authoritative_role() for Redis-based role checks
- Add is_admin_username() to AdminService for proper error messages
- Replace deprecated datetime.utcnow() with time utilities
- Remove redundant USERNAME_KEY from frontend localStorage
- Update Python client to use register-then-login flow

All users must now register before login. Guest flow:
1. POST /api/user/register (creates user)
2. POST /api/login (authenticates, returns JWT)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Security fixes:
- Unify all auth error messages to "Authentication failed" to prevent
  username enumeration attacks
- Add username validation (1-64 chars, alphanumeric + underscore/hyphen)
  to prevent path injection, XSS, and DoS attacks

Bug fixes:
- Fix 409 handling in frontend auth.ts - now properly handles case where
  registerData.userName is undefined on conflict response

Code cleanup:
- Remove unused get_authoritative_role() function (YAGNI)
- Update get_current_user_role() docstring to reference AdminService

Test updates:
- Update tests to expect generic "Authentication failed" message
- Fix test usernames to comply with new validation (John Doe → john-doe)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Upgrade argon2-cffi from >=23.1.0 to >=25.1.0 (current stable)
- Use datetime.timezone.utc instead of datetime.UTC for Python 3.11.x compatibility
- Replace deprecated datetime.utcnow() with utc_now() utility in tests
- Add clarifying comment for username regex pattern (1 + 0-63 = 1-64 chars)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Sanitize worker_id to valid username by replacing ':' with '-'
  (celery:{uuid} format violates username pattern)
- Remove unused 'public' parameter from _get_extension_class (YAGNI)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Move PasswordValidationError import to module level
- Remove redundant exception object from log.exception calls
- Add specific error message for 409 Conflict in room creation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Change PID file from single `~/.zndraw/server.pid` to port-specific
  `~/.zndraw/server-{port}.pid` files
- Remove `--force-new-server` flag (no longer needed with port-based detection)
- Add `find_running_server(port)` function for auto-discovery:
  - If port specified, only checks that port
  - If port is None, checks default port (5000) first, then smallest port
- Update all dependent code to use new API:
  - cli.py: Use find_running_server for server detection
  - zndraw.py: Use find_running_server for auto-discovery
  - zndraw-mcp: Use find_running_server for status checks
  - tests: Remove --force-new-server, pass port to remove_server_info

This enables running multiple ZnDraw servers simultaneously on different
ports, each with their own PID file for proper lifecycle management.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix redundant exception handling: remove ConnectionError (subclass of
  RequestException)
- Skip default port in find_running_server loop to avoid double-checking
- Update docstring for get_current_state with proper return type docs
- Improve error messages with actionable guidance

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add unit tests for server_manager.py (22 tests):
  - PID file path generation (port-specific paths)
  - Read/write/remove server info operations
  - list_all_pid_files discovery
  - find_running_server auto-discovery logic
  - get_server_status with stale file cleanup

- Add CLI tests for --status and --shutdown flags (14 tests):
  - Mock-based tests for CLI behavior
  - Port-specific vs auto-discovery behavior
  - Integration tests with real server fixture

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add tests/server_provider.py with ServerProvider class for managing
  server lifecycle in tests (start/stop/restart/fresh_restart)
- Add flush_redis() and fresh_restart() for complete server resets
- Add server_provider fixture to conftest.py
- Add config singleton reset to _create_server_process for test isolation
- Refactor test_zndraw_admin.py to use conftest fixtures (removes 116
  lines of duplicate code)
- Add tests for ServerProvider (12 tests) and extension persistence (2 tests)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link

codecov-commenter commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 93.89671% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.52%. Comparing base (3f80b07) to head (d47f43b).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tests/server_provider.py 86.07% 11 Missing ⚠️
tests/test_extension_persistence.py 94.73% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #833      +/-   ##
==========================================
+ Coverage   79.33%   79.52%   +0.19%     
==========================================
  Files         156      159       +3     
  Lines       19075    19221     +146     
==========================================
+ Hits        15133    15286     +153     
+ Misses       3942     3935       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Base automatically changed from feat/port-based-server-isolation to main January 8, 2026 16:00
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.

3 participants