npm / npm/cli

[BUG] @npmcli/arborist Report metadata count not correct

Open
#5,524 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

when use @npmcli/arborist to refiy a package and use json formate report it will return result:

    nodes:
      - node_modules/update-notifier
    fixAvailable:
      name:          @cloud/sfe-updater
      version:       1.0.23
      isSemVerMajor: true
metadata:
  vulnerabilities:
    info:     0
    low:      0  //not count out number
    moderate: 0  //not count out number
    high:     0  //not count out number
    critical: 0.   //not count out number
    total:    13
    null:     NaN
  dependencies:
    prod:         392
    dev:          0
    optional:     2
    peer:         0
    peerOptional: 0
    total:        393
Expected Behavior

it should be count right number of vulnbilities

Steps To Reproduce

code samples:

// fetch  advisories
const advisories = await got(this.vulnAPI, {
            method: 'post',
            headers: { 'Content-Type': 'application/json' },
            responseType: 'json',
            json: {
                versions: payload,
                ecosystem: 'npm',
            },
            https: { rejectUnauthorized: false },
        }).json();

// do check
const apt = new AuditReport(virtualTree, options);
const init = Object.getOwnPropertySymbols(AuditReport.prototype).find((sym) => sym.toString() == 'Symbol(init)');
apt.report = advisories;
await apt[init]();

return apt.toJSON();
Environment

"@npmcli/arborist": "^5.6.2"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied example with @npmcli/arborist 5.6.2 and inspect AuditReport initialization and toJSON(). Compare the vulnerability metadata counts with the advisories assigned to apt.report. Done means the JSON report counts each severity correctly and no longer returns zero, NaN, or an incorrect total.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.