Skip to content

fix: code review fixes, Perplexity API enhancements, and test improvements - #15

Open
powerfulqa wants to merge 3 commits into
mainfrom
code-review-fixes
Open

fix: code review fixes, Perplexity API enhancements, and test improvements#15
powerfulqa wants to merge 3 commits into
mainfrom
code-review-fixes

Conversation

@powerfulqa

Copy link
Copy Markdown
Owner

Summary

  • Security: Fix SQL injection in getPerformanceMetrics() — parameterized query instead of string interpolation
  • Architecture: Remove 625 lines of duplicate inline socket handlers from web-dashboard.js by wiring up extracted handler modules, replace all sync file I/O with async
  • Perplexity API: Auto-upgrade to sonar-pro for multi-turn conversations, enable citations with compact domain footer, add search recency filter for time-sensitive queries, log token usage
  • Bug fixes: Fix getTimeAgo() calendar math (DST/month boundary flakiness), fix conversation cleanup using wrong threshold, fix metrics broadcast overlap
  • Tests: 32 new tests for Perplexity features, all 1845 tests passing (0 failures)

Changes by file

File Change
src/services/database.js SQL injection fix
src/services/web-dashboard.js -625 lines: remove duplicate handlers, async I/O, logging
src/services/web-dashboard/handlers/configHandlers.js Async file I/O
src/services/web-dashboard/metrics-broadcaster.js Self-scheduling to prevent overlap
src/utils/conversation.js Fix cleanup threshold, cap userStats Map
src/services/api-client.js Model selection, search options, token logging
src/services/perplexity-secure.js Citation footer, recency filter detection
src/config/config.js New Perplexity API config fields
src/utils/time-ago.js Calendar-aware month/year math
src/commands/index.js Template literal for help command
__tests__/unit/services/api-client-search-features.test.js 20 new tests
__tests__/unit/services/perplexity-secure-search-features.test.js 12 new tests

Test plan

  • All 1845 tests pass (182 suites, 0 failures)
  • ESLint clean on all changed files
  • Pull to Pi, npm install, restart service, verify bot responds with citation footers
  • Check logs for API Usage: and model="sonar-pro" entries

🤖 Generated with Claude Code

powerfulqa and others added 3 commits April 8, 2026 14:34
…ments

Security:
- Fix SQL injection in database.js getPerformanceMetrics() - pass hours as
  parameterized query instead of string interpolation

Error handling & resilience:
- Fix conversation cleanup using wrong threshold (24h cache interval instead
  of 15min inactivity timeout)
- Replace setInterval with self-scheduling setTimeout in metrics broadcaster
  to prevent overlapping broadcasts
- Add debug logging to empty catch blocks in web-dashboard
- Replace all synchronous file I/O (readFileSync, writeFileSync, execSync)
  with async equivalents in web-dashboard and configHandlers

Architecture:
- Remove 625 lines of duplicate inline socket handlers from web-dashboard.js
  (3233 -> 2608 lines) by wiring up the already-extracted handler modules
- Remove unused imports (fs, getBootEnabledStatus, buildServiceObject, etc.)
- Cap userStats Map loading to DEFAULT_MAX_ENTRIES to prevent unbounded growth

Perplexity API enhancements:
- Auto-upgrade to sonar-pro model for multi-turn conversations (>2 messages)
- Enable return_citations and append compact domain-only source footer
- Add configurable search_domain_filter for gaming-specific sources
- Auto-detect time-sensitive queries and apply search_recency_filter
- Log token usage (prompt/completion/total) from every API response
- Extract _selectModel() and _buildSearchOptions() helpers for testability

Bug fixes:
- Fix getTimeAgo() month/year calculation using calendar-aware math instead
  of dividing days by 30 (fixes flaky tests near month boundaries and DST)
- Convert help command from string concatenation to template literal

Tests:
- Add 32 new tests for Perplexity API features (api-client-search-features,
  perplexity-secure-search-features)
- All 1845 tests passing across 182 suites (0 failures)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Bump package.json version to 2.0.0
- Create docs/RELEASE-NOTES-v2.0.0.md with full release notes
- Update CHANGELOG.md with v2.0.0 entry
- Update README.md: version, test count, features (citations, sonar-pro),
  future enhancements checklist
- Update wiki/Home.md and wiki/_Sidebar.md to v2.0.0
- Update docs/README.md to mark v2.0.0 as LATEST

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Remove tracked test artifacts (test-output.txt, test-results.json)
  from git — these were committed before .gitignore rules were added
- Move QLTY-FIXES-SUMMARY.md and QUALITY-IMPROVEMENTS-FINAL.md from
  root to docs/qlty/ where they belong
- Archive 17 v1.x release notes to docs/release-notes/ subdirectory,
  keeping only v2.0.0 at docs/ top level
- Update all internal links across README.md, docs/README.md,
  docs/CACHE-SERVICE-ARCHITECTURE.md, docs/DASHBOARD-API-REFERENCE-v1.9.0.md,
  wiki/Dashboard-Features-Complete.md, wiki/V1.9.0-Dashboard-Implementation.md

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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