Skip to content

Conversation

@jdalton
Copy link
Contributor

@jdalton jdalton commented Nov 20, 2025

Fixes bug where socket fix --limit N processed all vulnerabilities instead of limiting to N.

  • Added discoverGhsaIds helper to DRY it out
  • Added unit and integration tests
    (Renamed test files to match naming convention)

Note

Enforces --limit in local/PR modes by discovering/applying a capped set of GHSA IDs and adds thorough unit/integration tests for --limit and --id flags.

  • Fix command (coana-fix.mts):
    • Add discoverGhsaIds to fetch GHSA IDs via Coana without applying fixes.
    • Apply --limit correctly in local and PR modes, including isAll flows; early-exit on limit < 1 or no IDs.
    • Use computed ids for --apply-fixes-to; reuse discovery for PR flow; minor cleanup of temp-file unlink catch.
  • Tests:
    • Add src/commands/fix/handle-fix-limit.test.mts covering local vs PR mode, discovery, PR-count-based limit adjustment, and --id filtering with limits.
    • Expand integration tests to validate --limit, --id, and their combinations (dry-run and non-dry-run).

Written by Cursor Bugbot for commit 5ae586c. Configure here.

- Fixed bug where --limit flag was ignored in local mode (line 159)
  - Was passing full ghsas array instead of limited ids array
  - Now correctly passes only the first N GHSAs as specified by --limit
- Add discoverGhsaIds helper to DRY vulnerability discovery logic
  - Consolidates duplicate code between local and PR modes
  - Accepts orgSlug, tarHash, fixConfig, and optional options
  - Supports optional cwd (defaults to process.cwd()), limit, and spinner
- Add comprehensive unit tests for --limit and --id behavior
  - 9 unit tests with mocks/spies verify actual business logic
  - Tests verify correct number of GHSAs passed to coana CLI
  - Tests cover local mode, PR mode, limit adjustment, and edge cases
- Add CLI parsing tests for --limit and --id flags
  - 18 CLI tests verify flag acceptance and combinations
  - Tests verify --limit 0, --limit 1, --limit 100, defaults
  - Tests verify --id with GHSA, CVE, and PURL formats
  - Tests verify --limit and --id work together with other flags

Fixes issue reported by users where 'socket fix --limit 1' would
process all vulnerabilities instead of limiting to 1.
- Rename cmd-fix.test.mts → cmd-fix.integration.test.mts
  - File contains integration tests that spawn CLI process
- Rename cmd-fix-e2e.test.mts → cmd-fix.e2e.test.mts
  - Use dot notation for consistency with .integration pattern
- Update vitest.e2e.config.mts include pattern to match *.e2e.test.mts
- Update vitest.config.mts exclude pattern to match *.e2e.test.mts
@jdalton jdalton force-pushed the jdalton/test-fix-limit-id branch from 16122e1 to 0af9e17 Compare November 20, 2025 03:23
@jdalton jdalton merged commit 62196d1 into v1.x Nov 20, 2025
7 checks passed
@jdalton jdalton deleted the jdalton/test-fix-limit-id branch November 20, 2025 14:28
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.

3 participants