Skip to content

Fix/issue 461#464

Merged
sonukapoor merged 1 commit into
OWASP:mainfrom
MohammadYusif:fix/issue-461
May 31, 2026
Merged

Fix/issue 461#464
sonukapoor merged 1 commit into
OWASP:mainfrom
MohammadYusif:fix/issue-461

Conversation

@MohammadYusif

@MohammadYusif MohammadYusif commented May 27, 2026

Copy link
Copy Markdown
Contributor

Closes #461

Summary

Adds tests/validate.test.ts with 13 unit tests covering every validation branch in src/cli/validate.ts. The file had no dedicated tests before this PR.

Why this change

src/cli/validate.ts was recently extracted from src/index.ts to centralize CLI flag compatibility checks. Despite containing several distinct error branches, it had 0% test coverage. Any regression in flag validation would go undetected.

What changed

  • Created tests/validate.test.ts with one test per incompatible flag combination
  • Covers: --offline/--offline-db + --osv-url, --no-cache + --offline/--offline-db, invalid --osv-url format, --fix + --json, --report + --json
  • Also covers valid option combinations that must not throw

Validation

  • npm test — 348/348 tests pass (up from 335)
  • All 13 new tests pass in isolation
  • No production code was changed

User-facing impact

  • affect scanning behavior
  • affect output formatting
  • affect JSON output
  • affect docs only

No behavior change. Tests only.

Notes

Each it block asserts the exact error message string so future wording changes are caught immediately. A small opts() helper at the top of the file fills required fields (failOn, batchSize) so individual tests only declare the flags they care about.

@sonukapoor

Copy link
Copy Markdown
Collaborator

Hey Mohammad, great work on the test coverage - exactly the kind of thing this file needed.

Two quick things before we can merge:

The branch has fallen behind main and has merge conflicts - could you rebase against origin/main? A few of the source file changes (formatters, printers, etc.) look like they overlap with the pluralize PR that landed after you opened this, so they should drop out cleanly once you rebase.

Also, could you add Closes #461 to the PR body? GitHub uses that to auto-close the issue on merge, which keeps the issue tracker tidy and avoids someone else picking it up thinking it's still open.

@MohammadYusif

Copy link
Copy Markdown
Contributor Author

Done — rebased onto main and added Closes #461 to the PR body. Thanks for the quick review!

@sonukapoor

Copy link
Copy Markdown
Collaborator

Sorry for the continued back-and-forth — we've merged several PRs since you last rebased and conflicts have crept back in. Could you run git fetch upstream && git rebase upstream/main one more time and push the result? Appreciate your patience with this.

Adds tests/validate.test.ts covering all five validation branches
in validateOptions(): offline+osv-url conflict, no-cache+offline conflict,
invalid osv-url format, fix+json conflict, and report+json conflict.
Also covers valid option combinations that must not throw.

Brings coverage for src/cli/validate.ts from 0% to 100%.

Closes OWASP#461
@MohammadYusif

Copy link
Copy Markdown
Contributor Author

No issue, your request is done.

Always ready to help.

@sonukapoor
sonukapoor merged commit 6b43f59 into OWASP:main May 31, 2026
6 checks passed
coder-Yash886 pushed a commit to coder-Yash886/cve-lite-cli that referenced this pull request Jun 10, 2026
Adds tests/validate.test.ts covering all five validation branches
in validateOptions(): offline+osv-url conflict, no-cache+offline conflict,
invalid osv-url format, fix+json conflict, and report+json conflict.
Also covers valid option combinations that must not throw.

Brings coverage for src/cli/validate.ts from 0% to 100%.

Closes OWASP#461

Co-authored-by: MohammadYusif <MohammadYusif@users.noreply.github.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.

chore: add unit tests for src/cli/validate.ts

2 participants