Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d73ef96
refactor(events): extract ready handler to events/ready.js
Mar 4, 2026
bdfe4f8
refactor(events): extract messageCreate handler to events/messageCrea…
Mar 4, 2026
f13be71
refactor(events): extract guildMemberAdd and voiceState handlers
Mar 4, 2026
549a9e6
refactor(events): extract interaction handlers to events/interactionC…
Mar 4, 2026
5930224
refactor(events): extract reaction handlers to events/reactions.js
Mar 4, 2026
08b1fda
refactor(events): extract error handlers to events/errors.js
Mar 4, 2026
f250bfb
refactor(events): extract voice state handler to events/voiceState.js
Mar 4, 2026
e4c7b93
refactor(events): update main events.js to use extracted modules
Mar 4, 2026
24195e9
refactor(events): modularize event handlers
Mar 4, 2026
ecc6714
test(utils): add cronParser and flattenToLeafPaths tests
Mar 4, 2026
45e3569
fix(test): correct cronParser timezone handling and dangerousKeys imp…
Mar 4, 2026
7c1df72
Merge branch 'main' into feat/code-quality-improvements
BillChirico Mar 4, 2026
011237f
refactor: wire guildMemberAdd handler from dedicated module
Mar 4, 2026
2b6bcfa
fix: use safeReply when interaction not deferred, sanitize error mess…
Mar 4, 2026
de39ceb
fix: add error logging for background tasks
Mar 4, 2026
64d6e16
fix: add mobile responsive header
Mar 4, 2026
0b88cd2
fix(test): use JSON.parse for __proto__ test reliability
Mar 4, 2026
c53c502
style: apply biome lint fixes
Mar 4, 2026
d69a2d9
fix(a11y): resolve accessibility errors in landing page
Mar 4, 2026
a3e1415
fix(a11y): add aria-expanded and aria-controls to mobile nav toggle
Mar 4, 2026
0d942a8
fix: check both deferred and replied in showcase error handler
Mar 4, 2026
043d801
docs: fix markdownlint MD022/MD031 violations in task files
Mar 4, 2026
59d72f6
fix: await accumulateMessage before evaluateNow for immediate triage
Mar 4, 2026
4f9c4a8
fix: import DANGEROUS_KEYS instead of duplicating
Mar 4, 2026
a442741
fix(messageCreate): improve async error handling and abort on buffer …
Mar 4, 2026
80b6482
fix(interactionCreate): improve error handling for deferred interactions
Mar 4, 2026
7aba485
fix(events): wrap sendSpamAlert in try/catch to prevent unhandled rej…
Mar 4, 2026
2b5d10f
fix(interactionCreate): add config gates and wrap fallback replies
Mar 4, 2026
48d53db
fix(test): update ticket handler tests for sanitized error messages
Mar 4, 2026
c4ff232
fix: resolve biome lint issues
Mar 4, 2026
abd62a7
fix: update tests for events module refactoring
Mar 4, 2026
daf4354
fix(test): add config mocks for challenge and poll handlers
Mar 4, 2026
e9096a4
fix: resolve biome lint errors (duplicate keys + formatting)
Mar 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions TASK-REFACTOR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Task: Refactor events.js

## Goal

Split src/modules/events.js into smaller modules.

## CRITICAL RULES

1. Read the source file FIRST before doing anything
2. Create ONE file at a time
3. COMMIT after EVERY file you create
4. DO NOT try to do everything at once

## Step-by-Step

### Step 1: Read and Understand

Read src/modules/events.js completely. Identify all the handler functions.

### Step 2: Create Directory

```bash
mkdir -p src/modules/events
```

COMMIT: `git add src/modules/events && git commit -m "refactor(events): create events directory"`

### Step 3: Extract ready.js

Create src/modules/events/ready.js with the registerReadyHandler function.

Keep exports simple: `export function registerReadyHandler(client, config, healthMonitor) { ... }`

COMMIT immediately after creating the file.

### Step 4: Extract messageCreate.js

Create src/modules/events/messageCreate.js with the messageCreate handler.

Export: `export function handleMessageCreate(message, client) { ... }`

COMMIT immediately.

### Step 5: Extract interactionCreate.js

Create src/modules/events/interactionCreate.js with all interaction handlers.

Export: `export function handleInteractionCreate(interaction) { ... }`

COMMIT immediately.

### Step 6: Update events.js

Modify src/modules/events.js to import from the new files instead of having inline handlers.

Keep the same public exports for backward compatibility.

Run `pnpm lint` and fix any issues.

Run `pnpm test` and ensure tests pass.

COMMIT: `git commit -m "refactor(events): update main events.js to use extracted modules"`

## Standards

- ESM imports/exports
- Single quotes
- 2-space indent
- Semicolons required
66 changes: 66 additions & 0 deletions TASK-TESTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Task: Add Missing Tests

## Goal

Add test coverage for files without tests.

## CRITICAL RULES

1. Read ONE source file at a time
2. Create its test file
3. COMMIT immediately after each test file
4. DO NOT batch multiple files

## Priority Order

### Test 1: cronParser.js

Source: src/utils/cronParser.js

Test: tests/utils/cronParser.test.js

Steps:

1. Read src/utils/cronParser.js
2. Understand what it does (parses cron expressions?)
3. Create tests/utils/cronParser.test.js
4. Test valid inputs, invalid inputs, edge cases
5. Run `pnpm test tests/utils/cronParser.test.js`
6. COMMIT: `git add tests/utils/cronParser.test.js && git commit -m "test(utils): add cronParser tests"`

### Test 2: flattenToLeafPaths.js

Source: src/utils/flattenToLeafPaths.js

Test: tests/utils/flattenToLeafPaths.test.js

Steps:

1. Read src/utils/flattenToLeafPaths.js
2. Understand what it does (flattens nested objects?)
3. Create tests/utils/flattenToLeafPaths.test.js
4. Test nested objects, arrays, edge cases
5. Run `pnpm test tests/utils/flattenToLeafPaths.test.js`
6. COMMIT: `git add tests/utils/flattenToLeafPaths.test.js && git commit -m "test(utils): add flattenToLeafPaths tests"`

### Test 3: dangerousKeys.js

Source: src/api/utils/dangerousKeys.js

Test: tests/api/utils/dangerousKeys.test.js

Steps:

1. Read src/api/utils/dangerousKeys.js
2. Create tests/api/utils/dangerousKeys.test.js
3. Run `pnpm test tests/api/utils/dangerousKeys.test.js`
4. COMMIT: `git add tests/api/utils/dangerousKeys.test.js && git commit -m "test(api): add dangerousKeys tests"`

Continue with remaining files if time permits.

## Standards

- Use Vitest (describe, it, expect)
- Mock external dependencies
- Test happy paths AND error cases
- Follow existing test patterns in tests/
60 changes: 60 additions & 0 deletions TASK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Code Quality Improvements

## Task 1: Refactor events.js

Split src/modules/events.js (959 lines) into smaller, focused handler modules.

### Current Structure

- events.js has ~959 lines with many event handlers mixed together
- Handles: ready, messageCreate, interactionCreate, reactionAdd/Remove, voiceStateUpdate, etc.

### Target Structure

Create separate modules in src/modules/events/:

- ready.js - Client ready handler
- messageCreate.js - Message handling (AI, moderation, spam, etc.)
- interactionCreate.js - Slash commands, buttons, modals
- reactionHandlers.js - Starboard, reaction roles, polls
- voiceStateUpdate.js - Voice channel tracking
- guildMemberAdd.js - Welcome messages

### Steps

1. Create src/modules/events/ directory
2. Move each handler to its own file
3. Update events.js to import and register all handlers
4. Keep the same exports (registerReadyHandler, registerEventHandlers, etc.)
5. Run pnpm lint and pnpm test after changes
6. Commit with conventional commits

## Task 2: Add Missing Tests

Add test coverage for files without tests.

### Files to Test (priority order)

1. src/utils/cronParser.js
2. src/utils/flattenToLeafPaths.js
3. src/api/utils/dangerousKeys.js
4. src/modules/pollHandler.js
5. src/modules/reviewHandler.js
6. src/modules/reputationDefaults.js

### Steps

1. Create test files in tests/ matching source structure
2. Follow existing test patterns (Vitest, describe/it/expect)
3. Test both happy paths and edge cases
4. Mock external dependencies (Discord.js, DB, etc.)
5. Run pnpm test to verify coverage increases
6. Commit with conventional commits

## Standards

- ESM imports/exports
- Single quotes
- 2-space indent
- Semicolons required
- Use Winston logger (no console.*)
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.4.4/schema.json",
"$schema": "https://biomejs.dev/schemas/2.4.5/schema.json",
"files": {
"includes": [
"src/**/*.js",
Expand Down
40 changes: 40 additions & 0 deletions memory/2026-03-03.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# March 3, 2026 — Code Quality Improvements

## Events.js Refactoring (PR #240)

### Completed
- Split 959-line `src/modules/events.js` into 7 focused modules:
- `events/ready.js` — Client ready handler
- `events/messageCreate.js` — Message processing (spam, AI, triage)
- `events/interactionCreate.js` — Slash commands, buttons, modals
- `events/reactions.js` — Starboard and reaction roles
- `events/errors.js` — Error handling
- `events/voiceState.js` — Voice channel tracking
- `events/guildMemberAdd.js` — Welcome messages

- Main `events.js` now ~60 lines (re-exports for backward compatibility)
- Added welcome.enabled config gate to guildMemberAdd handler
- Fixed interaction error handling (removed !interaction.replied checks)

### Tests Added
- `tests/utils/cronParser.test.js` — 15 tests for cron parsing
- `tests/utils/flattenToLeafPaths.test.js` — 11 tests for object flattening
- `tests/api/utils/dangerousKeys.test.js` — 5 tests for dangerous keys

### Fixes Applied
- Fixed timezone issues in cronParser tests (use local time)
- Fixed __proto__ test to use computed key for actual own property
- Fixed dangerousKeys import path
- Fixed all CodeRabbit review comments
- Fixed pre-existing a11y errors in landing page (button types, SVG titles)

### PR Status
- PR #240 approved and ready to merge
- All lint errors resolved (0 errors)
- 31 new tests passing
- Pre-existing backup.test.js failures unrelated to this work

## Key Decisions
- Use GLM-5 for sub-agents (Claude rate limits)
- Commit after every file change (prevents lost work)
- Import ordering matters for Biome lint
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ import { startTriage, stopTriage } from './modules/triage.js';
import { closeRedisClient as closeRedis, initRedis } from './redis.js';
import { pruneOldLogs } from './transports/postgres.js';
import { stopCacheCleanup } from './utils/cache.js';
import { logCommandUsage } from './utils/commandUsage.js';
import { HealthMonitor } from './utils/health.js';
import { loadCommandsFromDirectory } from './utils/loadCommands.js';
import { getPermissionError, hasPermission } from './utils/permissions.js';
import { logCommandUsage } from './utils/commandUsage.js';
import { registerCommands } from './utils/registerCommands.js';
import { recordRestart, updateUptimeOnShutdown } from './utils/restartTracker.js';

Expand Down
11 changes: 10 additions & 1 deletion src/modules/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
* @see https://github.com/VolvoxLLC/volvox-bot/issues/129
*/

import { access, constants, mkdir, readdir, readFile, stat, unlink, writeFile } from 'node:fs/promises';
import {
access,
constants,
mkdir,
readdir,
readFile,
stat,
unlink,
writeFile,
} from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { SAFE_CONFIG_KEYS, SENSITIVE_FIELDS } from '../api/utils/configAllowlist.js';
Expand Down
Loading
Loading