mantimon-tcg/CONTRIBUTING.md
Cal Corum 0d416028c0
Fix prize zone rendering in Mantimon TCG mode (#2)
* Fix hand card rotation direction

Cards now fan outward correctly instead of curling inward

* Update StateRenderer to require MatchScene type for type safety

- Change constructor parameter from Phaser.Scene to MatchScene
- Update scene property type to MatchScene
- Add import for MatchScene type
- Update JSDoc example to reflect type-safe constructor

* Defer Board creation to StateRenderer for correct rules config

- Make board property nullable (Board | null instead of Board?)
- Remove Board and createBoard imports (now handled by StateRenderer)
- Update setupBoard() to skip Board creation
- Add setBoard() method for StateRenderer to call
- Update clearBoard() to use null instead of undefined
- Add JSDoc explaining why Board creation is deferred

* Create Board in StateRenderer with correct layout options

- Add Board and createBoard imports
- Add board property to StateRenderer
- Create Board in render() on first call with correct rules_config
- Add debug logging for Board creation and zone creation
- Update clear() to destroy Board when clearing
- Board now created after we have rules_config from first state

* Add fatal error handling with toast notification and auto-redirect

- Add 'fatal-error' event to GameBridgeEvents type
- Import and initialize useToast in GamePage
- Listen for 'fatal-error' event from Phaser
- Show error toast that persists until redirect
- Show full-screen fatal error overlay with countdown
- Auto-redirect to /play after 3 seconds
- Update StateRenderer to emit 'fatal-error' when Board creation fails

* Gate debug logging with DEV flag

- Add DEBUG_RENDERER constant gated by import.meta.env.DEV
- Update all console.log statements in StateRenderer to only log in development
- Keep console.error and console.warn as they are (always show errors)
- Debug logs now only appear during development, not in production

* Fix code audit issues - add missing imports and improve error UX

Critical fixes:
- Add missing gameBridge import to StateRenderer (fixes runtime error in fatal error handler)
- Add missing Board type import to MatchScene (fixes TypeScript compilation error)

UX improvements:
- Replace fatal error auto-redirect with manual 'Return to Menu' button
- Add toast notification when resignation fails
- Give users unlimited time to read fatal errors before returning

Addresses issues found in frontend code audit:
- errors.missing-import (StateRenderer.ts:166)
- errors.missing-type-import (MatchScene.ts:84)
- errors.catch-only-console (GamePage.vue:145)
- architecture.missing-fatal-error-handling (GamePage.vue:261)

* Add CONTRIBUTING policy and fix pre-existing lint/test errors

- Add CONTRIBUTING.md with strict policy: never use --no-verify without approval
- Add comprehensive testing documentation (TESTING.md, VISUAL-TEST-GUIDE.md)
- Add test-prize-fix.md quick test checklist and verify-fix.sh script

Lint fixes (enables pre-commit hooks):
- Remove unused imports in 9 files
- Fix unused variables (underscore convention)
- Replace 'as any' type assertions with proper VisibleGameState types
- Add missing CARD_WIDTH_MEDIUM import in layout.spec.ts
- All ESLint errors now resolved (only acceptable warnings remain)

Test fixes (all 1000 tests now passing):
- Fix layout.spec.ts: Add missing CARD_WIDTH_MEDIUM import
- Fix PlayPage.spec.ts: Update test to use actual hardcoded UUIDs
- Fix useAuth.spec.ts: Mock API profile fetch in initialization tests
- Fix PhaserGame.spec.ts: Add scenes export to mock and update createGame call expectations

This ensures pre-commit hooks work properly going forward and prevents
bypassing TypeScript/lint checks that catch errors early.

* Add comprehensive test coverage improvement plan

- Create PROJECT_PLAN_TEST_COVERAGE.json with 25 structured tasks
- Create TEST_COVERAGE_PLAN.md with executive summary and roadmap
- Plan addresses critical gaps: game engine (0%), WebSocket (27%)
- 6-week roadmap to reach 85% coverage from current 63%
- Target: Phase 1 (weeks 1-3) - critical game engine and network tests
- Includes quick wins, production blockers, and success metrics

Based on coverage analysis showing:
- Strong: Composables (84%), Components (90%), Stores (88%)
- Critical gaps: Phaser game engine (~5,500 untested lines)
- High priority: WebSocket/multiplayer reliability

See TEST_COVERAGE_PLAN.md for overview and week-by-week breakdown.

* Add coverage tooling and ignore coverage directory

- Add @vitest/coverage-v8 package for coverage analysis
- Add coverage/ directory to .gitignore
- Used during test coverage analysis for PROJECT_PLAN_TEST_COVERAGE.json
2026-02-02 15:30:27 -06:00

3.5 KiB

Contributing to Mantimon TCG

Git Commit Guidelines

Pre-Commit Hooks

CRITICAL RULE: Never use --no-verify without explicit approval.

This project has pre-commit hooks that run:

  • ESLint (catches undefined variables, unused imports, syntax errors)
  • TypeScript type checking (catches missing imports, type errors)
  • Tests (ensures nothing breaks)

These hooks are required to catch bugs before they enter the codebase.

When Hooks Fail

If the pre-commit hook fails:

DO:

  1. Read the error message carefully
  2. Fix the errors in your code
  3. Commit normally (hooks will pass)

DO NOT:

  1. Use --no-verify to bypass the hooks
  2. Ignore lint/type errors
  3. Assume "it will be fine"

Exception Process

If you believe you must bypass hooks (extremely rare):

  1. Ask for approval first: "I need to use --no-verify because [reason]"
  2. Wait for explicit approval
  3. Document why in the commit message
  4. Fix the issues in a follow-up commit immediately

Why This Matters

Real Example: In PR #X, commits were made with --no-verify to bypass pre-existing lint errors. This caused:

  • Missing imports that weren't caught until code audit
  • Runtime errors that would have been caught by TypeScript
  • Hours of debugging that could have been prevented

The pre-commit hook would have caught these issues in 5 seconds.

Common Scenarios

"But there are pre-existing lint errors!"

Solution: Fix them first in a separate commit:

# Fix pre-existing errors
npm run lint -- --fix
git add .
git commit -m "Fix pre-existing lint errors"

# Now do your work with hooks enabled
git add my-feature.ts
git commit -m "Add new feature"  # Hooks will pass

"The hook is taking too long!"

The hooks are optimized to only check changed files. If they're slow:

  • Check if you have too many staged files
  • Consider committing in smaller chunks
  • Don't bypass - the time saved now will cost hours later

"I'm just fixing a typo!"

Even typo fixes should pass hooks. If hooks fail on a typo fix, something is wrong with the surrounding code that needs addressing.


Code Quality Standards

TypeScript

  • All code must pass npm run typecheck
  • No any types without justification
  • Explicit return types on functions
  • Proper imports (no missing or unused)

ESLint

  • All code must pass npm run lint
  • No unused variables or imports
  • Follow project style guide
  • Use eslint-disable sparingly with comments explaining why

Testing

  • All code must pass npm run test
  • New features require tests
  • Bug fixes require regression tests

Pre-Commit Hook Details

Located at: .git/hooks/pre-commit

Backend checks:

  • Black formatting (black --check app tests)
  • Ruff linting (ruff check app tests)
  • Pytest (pytest --tb=short -q)

Frontend checks:

  • ESLint (npm run lint)
  • TypeScript (npm run typecheck)
  • Vitest (npm run test)

All checks must pass before commit is allowed.


Emergency Bypass Procedure

Only with explicit approval:

# 1. Get approval first
# 2. Document in commit message:
git commit --no-verify -m "Emergency fix: [issue]

This commit bypasses pre-commit hooks because [specific reason].
Pre-commit errors will be fixed in next commit.

Approved by: [name]"

# 3. Fix immediately:
git commit -m "Fix issues from previous emergency commit"

Never leave bypassed commits unfixed.


Questions?

If you're unsure whether to bypass hooks, ask first. It's better to ask than to introduce bugs into the codebase.