Skip to content

Fix/middleware startup - #267

Open
Saritahimthani wants to merge 4 commits into
YSTEM-LMS:mainfrom
Saritahimthani:fix/middleware-startup
Open

Saritahimthani wants to merge 4 commits into
YSTEM-LMS:mainfrom
Saritahimthani:fix/middleware-startup

Conversation

@Saritahimthani

Copy link
Copy Markdown
Collaborator

Summary

[Briefly describe what this PR does and why]

Type of Change

  • New feature
  • Bug fix
  • Refactor
  • Documentation update
  • Style/UI update
  • Performance improvement
  • Other (please specify):

Key Changes

[Describe the main areas of code affected and what was done, e.g., "Auth: Split signup into Parent/Mentor flows" or "Dashboard: Added parent dashboard and child progress view"]

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All tests pass

Bugs Fixed (if applicable)

  • [List any bugs fixed, with brief description]

TODO (Follow-up Work)

  • [List future tasks or known issues to address later]

Additional Notes

[Any extra context, dependencies, or deployment considerations]

Saritahimthani and others added 4 commits October 8, 2026 14:58
Challenge accept now saves a PvpGame (gameId, white, black, status),
and GET /challenge/game/:gameId lets the chess server verify a joining
player's identity against it instead of trusting the client.

Adds the service-key-gated POST /internal/gameResults, validated
against the saved PvpGame (unknown gameId -> 404, mismatched players
-> 400), idempotent on gameId. Removes the player-facing POST
/gameResults entirely - results can now only be written by the chess
server, authenticated with CHESS_SERVICE_KEY.

See "PvP game results: server-authoritative reporting" (v2), T1-T3.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ts own key

newpvpgame now calls GET /challenge/game/:gameId with the joining
player's own JWT and seats them under the username the middleware's
auth resolves (`you`), never the client-claimed username - a mismatch
is rejected with gameerror instead of silently corrected.
createOrJoinPvpGame takes white/black from that response only.

Deletes the Authentication header bug at the old EventHandlers.js:60
rather than renaming it - the whole player-token report path is gone.
reportGameResult now builds its request with the new pure
reporting/resultRequest.js and authenticates with CHESS_SERVICE_KEY
instead of relaying a player's token. Seats no longer store player
credentials for reporting.

Adds validateEnvironment.js (new - no such startup check existed) so
a production boot without CHESS_SERVICE_KEY/MIDDLEWARE_URL fails fast
instead of silently skipping every report, plus .env.example.

Adds the cross-service contract test (T4b): it imports resultRequest.js
by relative path and sends its exact output through the real
/internal/gameResults route (real service-key check, real models) so
the two services can't each pass their own tests while disagreeing -
which is how the header bug went unnoticed in v1.

Updates the design doc and feature guide to describe the new trust
model, replacing the known v1 limitation.

See "PvP game results: server-authoritative reporting" (v2), T4, T4b, T7.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Not run yet - needs the production count check and Devin's call on
whether legacy records should be excluded from chess score first.
Idempotent (only touches documents missing `source`), safe to run once
those are answered.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Rebasing the 3 PvP commits onto current upstream/main (now includes
Karthik's/Jimmy's merged currency-ledger work and a separate
signed-environment-separation effort) surfaced two real breaks,
beyond the straightforward conflicts in challenge.js/server.js and
the duplicate validateEnvironment.js/.env.example already resolved
in the rebase itself:

- gameResults.source was required: true, which broke the already-
  merged tests/backfillCurrencyLedger.test.js - its fixtures create
  GameResults documents with no source field. Changed to
  default: "legacy-unverified" instead of required: true: any write
  that doesn't explicitly claim source: "chessServer" (only
  internalGameResults.js does) now safely falls back to unverified
  rather than failing. Strictly more correct than required, and
  non-breaking for existing callers.

- challenge.pvpgame.test.js's acceptedGame() helper called POST
  /challenge and POST /challenge/:id/accept with no identity header.
  Both routes are now behind requireAuth with identity enforcement
  (added upstream, independently of this plan) - the caller must be
  fromUsername to create a challenge, and only toUsername may accept
  it. Updated the helper to authenticate as the right player on each
  call.

All 346 middleware + 40 chessServer tests pass on top of current main.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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