Skip to content

feat: add robust validation and 100% branch coverage for _derive_grade#63

Merged
jpdevhub merged 4 commits into
jpdevhub:mainfrom
BHOGALA-SRIKA:feat/test-grade-derivation
Jun 3, 2026
Merged

feat: add robust validation and 100% branch coverage for _derive_grade#63
jpdevhub merged 4 commits into
jpdevhub:mainfrom
BHOGALA-SRIKA:feat/test-grade-derivation

Conversation

@BHOGALA-SRIKA

Copy link
Copy Markdown
Contributor

Closes #10

Description

This PR resolves the issue tracking critical business logic testing for the backend grading utility. It introduces comprehensive validation checking and branch coverage for _derive_grade in main.py to prevent regression bugs.

Changes Made

  • Type Validation: Added explicit type checks using isinstance to catch and gracefully reject non-numeric inputs (str, NoneType, list, bool), raising a clean ValueError instead of unhandled runtime crashes.
  • Scale Boundaries: Implemented strict value limits ensuring inputs reside safely between 0 and 100 inclusive.
  • Test Isolation Mocks: Configured sys.modules interception in tests/test_ci.py to isolate tests from heavy third-party framework layers (torch binary paths and supabase network connections), dropping local CI suite test execution to < 2 seconds.

Checklist

  • npm run lint passes with no errors
  • npm run build compiles without TypeScript errors
  • python -m pytest passes (including new tests I added)
  • No .env files, API keys, secrets, model weights, or __pycache__ in this diff
  • Branch is rebased on main, not merged

@vercel

vercel Bot commented Jun 2, 2026

Copy link
Copy Markdown

@BHOGALA-SRIKA is attempting to deploy a commit to the karan3431's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

🎉 Thank you for your Pull Request! We're thrilled to have your contribution to FreshScan AI.

Before we review, please make sure you have:

  • Followed the CONTRIBUTING.md guidelines.
  • Ensured all automated CI checks (linting, tests) are passing.
  • Checked that your commit messages follow the Conventional Commits format.

A maintainer will review your code as soon as possible!

@jpdevhub jpdevhub left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Excellent work on this PR! The strict type validation for the grading boundaries is a great addition, and the way you isolated the heavy ML modules using sys.modules interception in the tests is fantastic. I confirmed it drops the test suite execution time to less than a second.
Once that duplicate block at the bottom of the test file is removed, this is good to go!

Comment thread backend/tests/test_ci.py Outdated
Comment on lines +185 to +191
mock_inference = MagicMock()
# Provide dummy mock functions so main.py can unpack them during import
mock_inference.load_models = MagicMock()
mock_inference.predict_stream_a = MagicMock()
mock_inference.predict_stream_b = MagicMock()
sys.modules['inference'] = mock_inference

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This code is dublicated since you already correctly placed this mock interception at the very top of the file (lines 14-27) where it belongs, the block at the bottom is redundant and should be deleted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review. I caught that duplicate block, cleaned it up, and just pushed the final refactored file structure. It should be 100% clean and ready now.

@vercel

vercel Bot commented Jun 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fresh-scan-ai Ready Ready Preview, Comment Jun 3, 2026 6:41pm

@jpdevhub jpdevhub left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for contributing.

@jpdevhub jpdevhub merged commit 064001c into jpdevhub:main Jun 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QA-01: Unit Test Coverage for Grade Derivation Logic

2 participants