Skip to content

fix: setup robust unit testing foundation - #937

Open
rohitkumarnaidu wants to merge 4 commits into
RohanExploit:mainfrom
rohitkumarnaidu:fix/issue-925
Open

fix: setup robust unit testing foundation#937
rohitkumarnaidu wants to merge 4 commits into
RohanExploit:mainfrom
rohitkumarnaidu:fix/issue-925

Conversation

@rohitkumarnaidu

@rohitkumarnaidu rohitkumarnaidu commented Jul 24, 2026

Copy link
Copy Markdown

Resolves #925

Changes

  • Fixed SQLite database file lock issue (EBUSY) on Windows in dailyRefinement.test.ts by ensuring database connection is closed properly after tests.
  • Modified trendAnalyzer.ts to properly handle asynchronous close.
  • Ensured npm test runs successfully without hanging or file locking issues.

Summary by cubic

Fixes the Windows SQLite file lock (EBUSY) in daily refinement tests and adds core unit tests for PriorityEngine, IntelligenceIndex, and AdaptiveWeights with equality-boundary checks for duplicate thresholds. TrendAnalyzer.close now accepts a callback and tests ensure proper cleanup and error propagation so npm test exits cleanly (addresses #925).

  • Bug Fixes
    • Update TrendAnalyzer.close(callback?) to pass the callback to the DB’s close.
    • In dailyRefinement.test.ts, close the DB after stmt.finalize, pass any finalize/close error to done, and await analyzer.close via a Promise in a try/finally.

Written for commit 389ae46. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved database shutdown handling to support reliable async cleanup via an optional completion callback.
    • Updated test teardown so statement finalization and analyzer shutdown complete before assertions run.
  • Tests

    • Added/expanded coverage for adaptive weight optimization, including weights file creation, persistence, and category boosting behavior.
    • Added coverage for intelligence index calculation across issue-count scenarios and history persistence.
    • Added coverage for priority engine duplicate-threshold tuning across issue-count ranges.

Copilot AI review requested due to automatic review settings July 24, 2026 10:16
@netlify

netlify Bot commented Jul 24, 2026

Copy link
Copy Markdown

👷 Deploy request for fixmybharat pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 389ae46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

🙏 Thank you for your contribution, @rohitkumarnaidu!

PR Details:

Quality Checklist:
Please ensure your PR meets the following criteria:

  • Code follows the project's style guidelines
  • Self-review of code completed
  • Code is commented where necessary
  • Documentation updated (if applicable)
  • No new warnings generated
  • Tests added/updated (if applicable)
  • All tests passing locally
  • No breaking changes to existing functionality

Review Process:

  1. Automated checks will run on your code
  2. A maintainer will review your changes
  3. Address any requested changes promptly
  4. Once approved, your PR will be merged! 🎉

Note: The maintainers will monitor code quality and ensure the overall project flow isn't broken.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

TrendAnalyzer.close now supports asynchronous callbacks. New Jest suites cover adaptive weights, intelligence index calculations and persistence, and priority threshold behavior.

Changes

Core validation and shutdown

Layer / File(s) Summary
Async shutdown contract and test cleanup
services/trendAnalyzer.ts, tests/dailyRefinement.test.ts
TrendAnalyzer.close forwards an optional SQLite callback; tests explicitly finalize statements and await analyzer cleanup.
Adaptive weights validation
tests/adaptiveWeights.test.ts
Tests cover default weight creation, volume-based boosting, persisted weights, and test-directory cleanup.
Index and priority validation
tests/intelligenceIndex.test.ts, tests/priorityEngine.test.ts
Tests cover index calculations, metadata fallbacks, history persistence, and duplicate-threshold ranges.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR adds core unit tests and fixes test cleanup, but the summary does not show a new local test command being added. Confirm the test script/command is present and the Jest setup is fully wired for local execution.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The changes are focused on test infrastructure, cleanup, and core logic tests, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: establishing a robust unit testing foundation.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/dailyRefinement.test.ts`:
- Line 47: Update the analyzer shutdown around analyzer.close in the test setup
so the Promise rejects when SQLite reports a close error instead of always
resolving. Move the shutdown into a finally block or shared teardown that runs
after both successful and failed test execution, ensuring the database is always
closed and existing test behavior is preserved.
- Line 28: Update the stmt.finalize callback in the test fixture setup to retain
its finalization error, close the database, and pass either the finalization
error or the database close error to done. Ensure setup cannot report success
when statement finalization or database closing fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 631261b4-3822-4bc5-9a4e-27a02a49621f

📥 Commits

Reviewing files that changed from the base of the PR and between ba88d8d and 467ff17.

📒 Files selected for processing (2)
  • services/trendAnalyzer.ts
  • tests/dailyRefinement.test.ts

Comment thread tests/dailyRefinement.test.ts Outdated
Comment thread tests/dailyRefinement.test.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread tests/dailyRefinement.test.ts Outdated
Comment thread tests/dailyRefinement.test.ts Outdated
@github-actions github-actions Bot added size/m and removed size/xs labels Jul 25, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/adaptiveWeights.test.ts (1)

28-34: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add equality-boundary assertions to the threshold tests.

Both suites exercise values on either side of strict comparisons but skip equality itself.

  • tests/adaptiveWeights.test.ts#L28-L34: test exactly 10% and assert that the category is not boosted.
  • tests/intelligenceIndex.test.ts#L32-L48: test exactly 50 and 200 issues with no score adjustment.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/adaptiveWeights.test.ts` around lines 28 - 34, The threshold tests omit
equality-boundary coverage. In tests/adaptiveWeights.test.ts lines 28-34, extend
the AdaptiveWeights.optimizeWeights tests to use exactly 10% volume and assert
the category is not boosted; in tests/intelligenceIndex.test.ts lines 32-48, add
cases for exactly 50 and exactly 200 issues and assert that neither boundary
changes the score.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/adaptiveWeights.test.ts`:
- Around line 28-34: The threshold tests omit equality-boundary coverage. In
tests/adaptiveWeights.test.ts lines 28-34, extend the
AdaptiveWeights.optimizeWeights tests to use exactly 10% volume and assert the
category is not boosted; in tests/intelligenceIndex.test.ts lines 32-48, add
cases for exactly 50 and exactly 200 issues and assert that neither boundary
changes the score.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e16eb500-9e4a-44e7-973d-0b4ed7cdd95a

📥 Commits

Reviewing files that changed from the base of the PR and between 467ff17 and b109524.

📒 Files selected for processing (3)
  • tests/adaptiveWeights.test.ts
  • tests/intelligenceIndex.test.ts
  • tests/priorityEngine.test.ts

@github-actions

Copy link
Copy Markdown

🔍 Quality Reminder

Thanks for the updates! Please ensure:
- Your changes don't break existing functionality
- All tests still pass
- Code quality standards are maintained

*The maintainers will verify that the overall project flow remains intact.*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add unit tests for core functionality

2 participants