mirror of
https://github.com/tiennm99/vngeoguessr.git
synced 2026-10-11 03:13:56 +00:00
Scoring, the Upstash key adapter, sessions and the leaderboards had no coverage, and they carry the anti-cheat model: server-held coordinates, session TTLs, rank arithmetic. One suite runs against two backing stores. By default @upstash/redis is mocked with an in-memory fake, so `npm test` needs no service and finishes well under a second. With TEST_REDIS=real the mock steps aside and the same files run against a real Redis behind SRH, the proxy Upstash recommends for local work, since the SDK speaks HTTP REST rather than RESP and a plain Redis container cannot serve it alone. Running both is what keeps the fake honest: a semantic it gets wrong shows up as a green unit run and a red integration run. Two tests skip against real Redis, one asserting a response shape only an older SDK produces and one fast-forwarding half an hour to watch a session expire. The suite was checked by mutation rather than by passing alone. Breaking a score band, the key prefix and the session TTL each failed a test; reversing the global trim window did not, because only the city leaderboard was asserted, so that test now covers both scopes. The compose stack doubles as a local Redis for `npm run dev`, which had no credentials to reach one before. package.json also loses the eight unused runtime dependencies removed in the cleanup that follows; they cannot be split from the same file.
37 lines
1.2 KiB
YAML
37 lines
1.2 KiB
YAML
# Local stand-in for Upstash Redis.
|
|
#
|
|
# Upstash itself is cloud-only, but @upstash/redis talks HTTP REST rather than
|
|
# RESP, so any server exposing that REST surface is indistinguishable to the
|
|
# app. SRH is the proxy Upstash's own docs recommend for this: it accepts the
|
|
# Upstash REST API and forwards to a real Redis.
|
|
#
|
|
# npm run redis:up start it
|
|
# npm run redis:down stop it and discard the data
|
|
#
|
|
# Used by `npm run test:integration`, and usable for `npm run dev` by pointing
|
|
# UPSTASH_REDIS_REST_URL at http://localhost:8079 with the token below.
|
|
|
|
services:
|
|
redis:
|
|
image: redis:7-alpine
|
|
# No volume: this data is disposable by design, and tests flush it anyway.
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 15
|
|
|
|
srh:
|
|
image: hiett/serverless-redis-http:latest
|
|
ports:
|
|
- "8079:80"
|
|
environment:
|
|
SRH_MODE: env
|
|
# Local-only credential. SRH accepts any token it is configured with, and
|
|
# this one never reaches a real Upstash database.
|
|
SRH_TOKEN: vngeoguessr-local-token
|
|
SRH_CONNECTION_STRING: "redis://redis:6379"
|
|
depends_on:
|
|
redis:
|
|
condition: service_healthy
|