Skip to content

feat(fix): add --package-managers flag#1292

Merged
Martin Torp (mtorp) merged 4 commits intov1.xfrom
mt/fix-package-managers-filter
Apr 30, 2026
Merged

feat(fix): add --package-managers flag#1292
Martin Torp (mtorp) merged 4 commits intov1.xfrom
mt/fix-package-managers-filter

Conversation

@mtorp
Copy link
Copy Markdown
Contributor

@mtorp Martin Torp (mtorp) commented Apr 30, 2026

Summary

Forward Coana's new --package-managers filter (coana-tech/coana-package-manager#2214) through socket fix so users can narrow fix computation to specific package managers within an ecosystem (e.g. only PNPM artifacts in a monorepo that mixes pnpm/yarn/npm).

Mirrors how --ecosystems (→ Coana --purl-types) is already plumbed through cmd-fix.mtshandle-fix.mtscoana-fix.mts.

Behavior

  • New flag: --package-managers <values...> on socket fix.
  • Accepts space- or comma-separated values; case-insensitive (normalized to uppercase before validation and before forwarding).
  • Validated against the same set as Coana's getFilterablePackageManagers(): CARGO, COMPOSER, GO, GRADLE, MAVEN, NPM, NUGET, PIPENV, PIP_REQUIREMENTS, PNPM, POETRY, RUBYGEMS, RUSH, SBT, YARN. Invalid values fail early with a friendly error listing valid values.
  • Forwarded to both Coana subcommands invoked by the fix flow:
    • find-vulnerabilities (GHSA discovery in discoverGhsaIds)
    • compute-fixes-and-upgrade-purls (both the local-mode call and the per-GHSA CI-loop call)
  • When combined with --ecosystems, Coana intersects the two filters per-artifact (an artifact must satisfy both).

Files changed

  • src/utils/package-manager.mts (new) — ALL_PACKAGE_MANAGERS constant + isValidPackageManager validator.
  • src/commands/fix/cmd-fix.mts — flag definition, validation, forwarding to handleFix.
  • src/commands/fix/types.mtspackageManagers: string[] on FixConfig.
  • src/commands/fix/handle-fix.mts — destructure + forward to coanaFix (and debug logging).
  • src/commands/fix/coana-fix.mts — pass --package-managers to all three Coana spawn sites.
  • src/commands/fix/cmd-fix.integration.test.mts — 5 new cmdit cases (single, lowercase comma-separated, multiple flags, invalid value, combined with --ecosystems); updated --help snapshot.

Out of scope

Mirrors the Coana PR's out-of-scope notes:

  • Not added to socket scan reach / the Coana run command. Its --purl-types operates at ecosystem-level pre-install and a per-PM filter there would require a larger refactor in Coana.
  • No bump of @coana-tech/cli here. The flag is forward-compatible — once a Coana release containing the linked PR is published, a separate version-bump PR will activate the feature for users.
  • Socket-side filtering: like --ecosystems today, the Socket CLI just forwards the flag; all matching logic lives in Coana.

Test plan

  • tsgo clean.

  • eslint clean on changed files (one pre-existing import-order warning in coana-fix.mts is unrelated).

  • pnpm test:unit src/commands/fix/cmd-fix.integration.test.mts passes for all --ecosystems, --package-managers, and --help snapshot tests (5 new tests + 4 existing ecosystem tests + help snapshot).

  • End-to-end smoke against a real multi-PM project (npm-app with axios@0.21.0 + real package-lock.json, pnpm-app with lodash@4.17.20 + real pnpm-lock.yaml, yarn-app with minimist@1.2.5 + real yarn.lock):

    Run axios (npm) lodash (pnpm) minimist (yarn)
    baseline
    --package-managers NPM ✓ kept ✗ excluded ⚠ included (PM-undetermined fallthrough)
    --package-managers PNPM ✗ excluded ✓ kept ⚠ included (PM-undetermined fallthrough)
    --package-managers YARN ✗ excluded ✗ excluded ✓ kept

    The axios (npm) and lodash (pnpm) cases are mutually-exclusive across the NPM/PNPM filters as expected. The minimist (yarn) case logs Coana's documented Could not determine package manager from manifest files [yarn-app/package.json] — including in --package-managers results fallthrough — Coana's per-artifact manifestFiles doesn't include the yarn.lock for that artifact, so its lockfile-based PM detection can't fire. That's a Coana-side detail (out of scope for this PR) — the Socket CLI is forwarding the flag correctly, as evidenced by the differentiated outputs across runs.

  • Validation: socket fix --package-managers FOO exits non-zero with Invalid package manager: "FOO". Valid values are: CARGO, COMPOSER, GO, GRADLE, MAVEN, NPM, NUGET, PIPENV, PIP_REQUIREMENTS, PNPM, POETRY, RUBYGEMS, RUSH, SBT, and YARN.

  • Case-insensitive: --package-managers npm,pnpm accepted (uppercased before forward).

Follow-ups

  • Bump @coana-tech/cli once a release containing the linked PR ships.
  • Investigate (in Coana) why a real yarn.lock isn't surfacing on the artifact's manifestFiles — would let YARN's filter exclude the yarn-app's vulns the same way NPM/PNPM do today.

Note

Medium Risk
Moderate risk: changes socket fix CLI surface area and alters which artifacts Coana processes by forwarding a new filter flag, which could change fix coverage in mixed-package-manager repos. Logic is straightforward (validation + argument plumbing) and covered by new integration/E2E tests.

Overview
Adds a new socket fix --package-managers filter to restrict fix computation to specific package managers (case-insensitive, comma/space-separated), with early validation and a clear error listing allowed values.

Plumbs the validated filter through the full fix flow (cmd-fixhandle-fixcoana-fix) and forwards --package-managers to both Coana invocations used for discovery and fix computation (local and CI/PR modes). Updates help text, adds integration + E2E coverage (including a new multi-PM fixture), and bumps @coana-tech/cli to 15.2.0 along with the release/version metadata (1.1.90).

Reviewed by Cursor Bugbot for commit 0d46020. Configure here.

Forward Coana's new --package-managers filter (coana-tech/coana-package-manager#2214) through socket fix so users can narrow fix computation to specific package managers within an ecosystem (e.g. only PNPM in a monorepo that mixes pnpm/yarn/npm).

The flag accepts comma- or space-separated values, is case-insensitive (normalized to uppercase before validation and forward), and is passed to both `find-vulnerabilities` and `compute-fixes-and-upgrade-purls`. When combined with --ecosystems, both filters must match (Coana intersects them per-artifact).

Valid values mirror Coana's getFilterablePackageManagers(): CARGO, COMPOSER, GO, GRADLE, MAVEN, NPM, NUGET, PIPENV, PIP_REQUIREMENTS, PNPM, POETRY, RUBYGEMS, RUSH, SBT, YARN.

Out of scope (matching the Coana PR): --package-managers is not added to socket scan reach / the coana run command — that command's --purl-types runs at ecosystem-level pre-install and a per-PM filter would require a larger refactor in Coana.
…-managers

- Bump @coana-tech/cli from 15.1.0 to 15.2.0 (release containing the upstream --package-managers filter).
- Bump CLI version 1.1.89 → 1.1.90 with a CHANGELOG entry covering both the new flag and the Coana version bump.
- Add a real-Coana e2e fixture under test/fixtures/commands/fix/e2e-test-multipm with npm-managed lodash and pnpm-managed axios subprojects (lockfiles generated with the actual npm/pnpm tools).
- Add three e2e cases:
  - `--package-managers NPM`: only the npm-managed lodash gets upgraded; pnpm-managed axios is left untouched.
  - `--package-managers PNPM`: only the pnpm-managed axios gets upgraded; npm-managed lodash is left untouched.
  - `--package-managers <invalid>`: fails fast with the same friendly error path as the unit tests.
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 30, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​@​coana-tech/​cli@​15.1.0 ⏵ 15.2.0961008098100

View full report

@socket-security-staging
Copy link
Copy Markdown

socket-security-staging Bot commented Apr 30, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​@​coana-tech/​cli@​15.1.0 ⏵ 15.2.0471008098100

View full report

The baseConfig in handle-fix-limit.test.mts is missing the new packageManagers field, which caused a TypeError ("Cannot read properties of undefined (reading 'length')") when coana-fix.mts evaluates packageManagers.length on the spread mock. Add packageManagers: [] alongside the existing array fields.
@socket-security-staging
Copy link
Copy Markdown

socket-security-staging Bot commented Apr 30, 2026

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm @coana-tech/cli is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: package.jsonnpm/@coana-tech/cli@15.2.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity-Staging ignore npm/@coana-tech/cli@15.2.0. You can also ignore all packages with @SocketSecurity-Staging ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm @coana-tech/cli is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: package.jsonnpm/@coana-tech/cli@15.2.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity-Staging ignore npm/@coana-tech/cli@15.2.0. You can also ignore all packages with @SocketSecurity-Staging ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm @coana-tech/cli is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: package.jsonnpm/@coana-tech/cli@15.2.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity-Staging ignore npm/@coana-tech/cli@15.2.0. You can also ignore all packages with @SocketSecurity-Staging ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm @coana-tech/cli is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: package.jsonnpm/@coana-tech/cli@15.2.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity-Staging ignore npm/@coana-tech/cli@15.2.0. You can also ignore all packages with @SocketSecurity-Staging ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm @coana-tech/cli is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: package.jsonnpm/@coana-tech/cli@15.2.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity-Staging ignore npm/@coana-tech/cli@15.2.0. You can also ignore all packages with @SocketSecurity-Staging ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm @coana-tech/cli is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: package.jsonnpm/@coana-tech/cli@15.2.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity-Staging ignore npm/@coana-tech/cli@15.2.0. You can also ignore all packages with @SocketSecurity-Staging ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 0d46020. Configure here.

Comment thread src/utils/package-manager.mts Outdated
Bugbot caught this: the helper was exported but never imported. cmd-fix.mts spreads ALL_PACKAGE_MANAGERS directly when building the validation error message, so the helper added no value.
@mtorp Martin Torp (mtorp) enabled auto-merge (squash) April 30, 2026 16:46
@mtorp Martin Torp (mtorp) merged commit 6c68f32 into v1.x Apr 30, 2026
12 checks passed
@mtorp Martin Torp (mtorp) deleted the mt/fix-package-managers-filter branch April 30, 2026 16:46
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.

2 participants