Skip to content

brun0ne/coderacer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Racer

An online type racer, but with code. Powered by Vite + React, Flask, and socketio.

How to run the app

$ docker compose up --build

Then go to http://localhost:8080.

Architecture overview

Overview

Showcase

Showcase

(the GIF may take a few seconds to load)

Tests overview

The project uses integration tests in tests/tests.py with pytest.

  • API coverage (requests): game creation, game fetch, and game list endpoints.
  • Worker/socket coverage (python-socketio): player join flow, progress updates, finish events, and end-game event.
  • Database checks (psycopg): verifies game records are created and deleted correctly.
  • Isolation: an autouse pytest fixture clears the games table after each test.

The tests run against real containers (api, worker, and postgres) through Docker Compose.

How to run tests locally

Run only the test stack (and required dependencies):

$ docker compose up --build --abort-on-container-exit --exit-code-from tests tests

What this does:

  1. Builds the tests image from tests/Dockerfile.
  2. Starts dependency services (api, worker, postgres) from compose.yaml.
  3. Waits briefly (DELAY_SECONDS) and executes pytest inside the tests container.
  4. Returns the test container exit code as the overall command exit code.

Optional cleanup after a run:

$ docker compose down -v --remove-orphans

CI pipeline (GitHub Actions)

GitHub Actions workflow: .github/workflows/tests.yml

  • Trigger: every push to main.
  • Purpose: execute tests

If tests fail, the workflow fails and the commit to main is marked as failed.

Environment variables (API)

The API service reads these variables:

  • USE_AI: enables/disables AI-generated race code.
    • Set to true to generate code with OpenAI.
    • Any other value (or unset) falls back to built-in sample snippets.
  • OPENAI_API_KEY: required only when USE_AI=true.
    • This is your OpenAI API key used by the API container to call the OpenAI API.

Example (.env):

USE_AI=true
OPENAI_API_KEY=your_openai_api_key_here

About

Code Racer game (Vite + React, Flask, socketio)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors