Skip to content

fix: comprehensive codebase review — bugs, dead code, and hardening - #36

Merged
m9tzin merged 2 commits into
devfrom
fix/codebase-review-fixes
Apr 27, 2026
Merged

fix: comprehensive codebase review — bugs, dead code, and hardening#36
m9tzin merged 2 commits into
devfrom
fix/codebase-review-fixes

Conversation

@m9tzin

@m9tzin m9tzin commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix critical bugs: hasCS2Data now handles ELO 0 correctly, processMatchStreak skips unknown teams instead of marking as Loss, winrate denominator only counts participated matches
  • Structured error handling: Replaced fragile message.includes() substring matching with typed error classes (MissingNicknameError, CS2DataNotFoundError, FaceitApiError, PlayerNotFoundError)
  • !stats without player: All routes now detect Nightbot placeholders (null, undefined, $(1), $(2)) — /stats returns "Indique o nickname FACEIT (ex.: !stats s1mple)" when no player is provided
  • Hardening: Defensive optional chaining on FACEIT API payloads, MatchStatsCache eviction (max 500), proper graceful shutdown with server.close(), express.json size limit
  • Dead code cleanup: Removed getMatchDetails, getExtendedMatchStats, mapExternalMatchStatsToLocal, getPlayerStats, SessionEloCache, unused cacheMiddleware module, unused currentElo param, unused totalHeadshotKills
  • DevOps: CI workflows now trigger on dev (was develop), engines updated to >=18 (Express 5 requirement), npm test no longer fails

Files changed (11)

File Changes
src/services/faceitService.js Bug fixes, dead code removal, defensive checks, findPlayerTeam helper
src/middlewares/errorHandler.js New error classes, instanceof-based handler
src/middlewares/cache.js Deleted (dead code, never imported)
src/routes/stats.js Uses MissingNicknameError for missing player
src/routes/elo.js Nightbot placeholder detection, CS2DataNotFoundError
src/routes/streak.js Nightbot placeholder detection, hasCS2Data check, CS2DataNotFoundError
src/utils/cache.js Removed SessionEloCache, added eviction to MatchStatsCache
src/index.js Graceful shutdown with server.close(), json size limit
package.json engines >=18, npm test exit 0
.github/workflows/ci.yml Branch developdev
.github/workflows/code-quality.yml Branch developdev

Test plan

  • GET /stats sem player → deve retornar "Indique o nickname FACEIT (ex.: !stats s1mple)"
  • GET /stats?player=null → mesma mensagem de erro
  • GET /stats?player=s1mple → stats normais
  • GET /elo → ELO do player default
  • GET /elo?player=null → ELO do player default (fallback)
  • GET /streak → streak do player default
  • GET /streak?player=null → streak do player default (fallback)
  • GET /health → OK
  • Verificar que jogador com ELO 0 não é rejeitado
  • Verificar graceful shutdown com SIGTERM

Made with Cursor

- Fix hasCS2Data treating faceit_elo === 0 as "no data" (use != null)
- Fix processMatchStreak marking unknown teams as Loss (now skips them)
- Fix winrate denominator using total matches instead of participated ones
- Fix Promise.any collapsing all failures into "player not found" — now
  distinguishes API errors from genuine 404s via FaceitApiError class
- Fix error handler using fragile substring matching — replaced with
  structured error classes (MissingNicknameError, CS2DataNotFoundError,
  FaceitApiError)
- Add Nightbot placeholder detection (null, undefined, $(1), $(2)) to
  /elo and /streak routes (was only on /stats)
- Add hasCS2Data check to /streak route (was missing)
- Add defensive optional chaining on FACEIT API payloads (teams, results)
- Add MatchStatsCache eviction (max 500 entries) to prevent unbounded growth
- Add proper graceful shutdown (server.close + drain timeout)
- Add express.json size limit (16kb)
- Fix CI workflows triggering on "develop" instead of actual "dev" branch
- Fix engines field from >=14 to >=18 (required by Express 5 / Promise.any)
- Fix npm test placeholder (exit 1 → exit 0)
- Rename misleading totalHeadshots to totalHsPercent
- Remove unused currentElo param from calculateTodayStats
- Remove unused totalHeadshotKills accumulator
- Remove dead code: getMatchDetails, getExtendedMatchStats,
  mapExternalMatchStatsToLocal, getPlayerStats, SessionEloCache,
  cacheMiddleware module
- Remove hardcoded initial cache keys (Cache now uses plain object)

Made-with: Cursor
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 845f5d67-7e2c-46dd-a32d-1c4b9dcaf3b2

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/codebase-review-fixes

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.

Integrate dev improvements (LRU cache with Map, FaceitApiError with
status codes, parseHeadshotPercentField, mapPool, tests) with our
codebase review fixes (MissingNicknameError, NoCS2DataError,
defensive optional chaining, Nightbot placeholder detection,
processMatchStreak skipping unknown teams, winrate denominator fix).

- Keep dev's LRU Cache implementation (Map-based with evictLruIfNeeded)
- Keep dev's FaceitApiError(status, message) signature with per-status
  handling in errorHandler (429, 401/403, 5xx)
- Keep dev's parseHeadshotPercentField and mapPool concurrency helper
- Keep dev's test runner (node --test) and test files
- Add MissingNicknameError for !stats without player nickname
- Add config.cache.maxEntries for LRU eviction threshold
- Update streak test: unknown teams are now skipped (not marked as ?)
- Delete src/middlewares/cache.js (dead code, never imported)

Made-with: Cursor
@m9tzin
m9tzin merged commit d6e0aaa into dev Apr 27, 2026
7 checks passed
@m9tzin
m9tzin deleted the fix/codebase-review-fixes branch April 27, 2026 01:18
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