Skip to content

test: add validateOptions function parameter validation tests (#461)#469

Closed
anzjj wants to merge 1 commit into
OWASP:mainfrom
anzjj:issue-461-add-validate-tests
Closed

test: add validateOptions function parameter validation tests (#461)#469
anzjj wants to merge 1 commit into
OWASP:mainfrom
anzjj:issue-461-add-validate-tests

Conversation

@anzjj

@anzjj anzjj commented May 27, 2026

Copy link
Copy Markdown

Description

Closes #461 - Add parameter validation tests for the validateOptions function

Changes

  1. Added 17 test cases to cover all parameter validation rules
  2. Tested conflicting flag combinations, including --offline with --osv-url, --no-cache with --offline, etc.
  3. Verified valid parameter combinations
  4. Fixed type definition issues in defaultOptions
  5. Corrected the invalid combination in the non-conflicting flags test case

Test Results

  • All tests passed: 1 test suite passed, 17 tests passed
  • All validation logic is fully covered, including error throwing and normal execution scenarios

Notes

No breaking changes. Only test code is added, and it will not affect existing features.

@sonukapoor sonukapoor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Welcome, and thanks for picking this up - test coverage for validateOptions is exactly what was needed, and the scenarios you've chosen map cleanly to every validation rule in the function. A few things to fix before this is ready:

  • Comments throughout the file are in Chinese - please translate them to English to be consistent with the rest of the codebase.
  • The file is missing a newline at the end.
  • The branch is behind main - please rebase against origin/main before we merge.

Comment thread tests/validate.test.ts
@@ -0,0 +1,120 @@
// @ts-nocheck // 临时忽略tsconfig的rootDir报错(可选)
import { describe, it, expect } from '@jest/globals';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please remove @ts-nocheck - it disables type checking for the entire file. The root cause is that defaultOptions is missing two required fields from ParsedOptions: failOn and batchSize. Add those to the object (e.g. failOn: 'critical', batchSize: '100') and the TypeScript error should resolve without needing to suppress it.

@sonukapoor

Copy link
Copy Markdown
Collaborator

Hey @anzjj, thanks for the contribution! It turns out PR #464 covers the same ground and was already open when this was submitted — it also adds validateOptions tests and handles the failOn/batchSize required fields cleanly via a small helper. Closing this one in favour of that PR to avoid duplicate work. Feel free to pick up another open issue — happy to have you contribute!

@sonukapoor sonukapoor closed this May 27, 2026
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