Skip to content

The agent that grows with you

fix(doctor): stop prescribing audit fixes that updates revert (#116774)

joaomarcosd76c77beed3d
diff --git a/hermes_cli/doctor_tools.py b/hermes_cli/doctor_tools.py
index 661fb8bf003..9b6c5cd164c 100644
--- a/hermes_cli/doctor_tools.py
+++ b/hermes_cli/doctor_tools.py
@@ -380,9 +380,13 @@ def _plural(n: int) -> str:
def _audit_one(npm_bin: str, npm_dir, label: str, audit_extra: list[str], issues: list[str]) -> None:
"""Run one `npm audit --json` and report; any failure is silently skipped.
- Workspace-scoped (`--workspace <name>`) advisories are build-time tooling (esbuild/vite), not runtime
- code. `npm audit fix --workspace` crashes on current npm (arborist "edgesOut") and the root-level fix can
- crash on the same tree ("isDescendantOf"), so no manual fix command is offered — they clear via a lockfile bump.
+ Every row here audits a tree whose versions come from a COMMITTED lockfile
+ (`npm ci` in `_run_npm_install_deterministic` reifies exactly that state on
+ every `hermes update`), so a local `npm audit fix` never persists — the next
+ update's deterministic install restores the pinned (vulnerable) versions and
+ the finding reappears. The durable remedy in every case is a lockfile bump
+ on main (update `package-lock.json` and ship it); the doctor therefore never
+ prescribes a local mutating fix command. See #116774.
"""
import json
try:
@@ -397,12 +401,15 @@ def _audit_one(npm_bin: str, npm_dir, label: str, audit_extra: list[str], issues
if total == 0:
check_ok(f"{label} deps", "(no known vulnerabilities)")
elif critical > 0 or high > 0:
- flag = " --workspaces=false" if audit_extra == ["--workspaces=false"] else ""
- remedy = "build-tool advisory; clears via lockfile bump" if workspace_scoped else f"run: cd {npm_dir} && npm audit fix{flag}"
+ detail = "build-time tooling" if workspace_scoped else "runtime dependency tree"
+ remedy = ("fix is an upstream lockfile bump — a local manual fix does not persist"
+ " (the next `hermes update` reinstalls from the committed lockfile)")
check_warn(f"{label} deps", f"({critical} critical, {high} high, {moderate} moderate — {remedy})")
if workspace_scoped:
check_info(" ^ build-time tooling (not runtime); if manual npm remediation "
"errors with an arborist crash it's a known npm bug — clears via a lockfile bump")
+ else:
+ check_info(f" ^ {detail}; report/pin the fix in package-lock.json — see #116774")
issues.append(f"{label} has {total} npm {_plural(total)}")
else:
check_ok(f"{label} deps", f"({moderate} moderate {_plural(moderate)})")
diff --git a/package-lock.json b/package-lock.json
index f53e6e9c965..be7de895da7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8039,9 +8039,9 @@
"license": "MIT"
},
"node_modules/baseline-browser-mapping": {
- "version": "2.10.43",
- "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.43.tgz",
- "integrity": "sha512-AjYpR78kDWAY3Efj+cDTFH9t9SCoL7OoTp1BOb0mQV7S+6CiLwnWM3FyxhJtdPufDFKzmCSFoUncKjWgJEZTCQ==",
+ "version": "2.11.25",
+ "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.25.tgz",
+ "integrity": "sha512-gMmEShwwq7FJqMwvfRwvCl00v4kN+KOfJqXn+f4nrufak5gNHJOksd/60Dvjuz7sI8Y5WiSFBa8FEYr+zoyqCw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
@@ -8106,9 +8106,9 @@
}
},
"node_modules/browserslist": {
- "version": "4.28.6",
- "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.28.6.tgz",
- "integrity": "sha512-FQBYNK15VMslhLHpA7+n+n1GOlF1kId2xcCg7/j95f24AOF6VDYMNH4mFxF7KuaTdv627faazpOAjFzMrfJOUw==",
+ "version": "4.29.0",
+ "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.29.0.tgz",
+ "integrity": "sha512-3GSvyjvDI4Dur1Meg2BekJquu5uF+9R9a1+5M1Mde192eZoXbeXjzgOsgqPS2V8D5wrrip0gR5Hf/GhWQ9ZzaA==",
"dev": true,
"funding": [
{
@@ -8126,11 +8126,11 @@
],
"license": "MIT",
"dependencies": {
- "baseline-browser-mapping": "^2.10.42",
- "caniuse-lite": "^1.0.30001803",
- "electron-to-chromium": "^1.5.389",
- "node-releases": "^2.0.51",
- "update-browserslist-db": "^1.2.3"
+ "baseline-browser-mapping": "^2.11.23",
+ "caniuse-lite": "^1.0.30001810",
+ "electron-to-chromium": "^1.5.427",
+ "node-releases": "^2.0.55",
+ "update-browserslist-db": "^1.3.3"
},
"bin": {
"browserslist": "cli.js"
@@ -8439,9 +8439,9 @@
}
},
"node_modules/caniuse-lite": {
- "version": "1.0.30001806",
- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001806.tgz",
- "integrity": "sha512-72Cuvd95zbSYPKq6Fhg8eDJRlzgWDf7/mtoZv6Qe/DYNCEBdNxoA3+rZAU2ZhGCpZlns3EssFavaZomckT5Uuw==",
+ "version": "1.0.30001810",
+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001810.tgz",
+ "integrity": "sha512-TITQPUkaz+aVk5GL6NhOdwk1aEaNTSDPsGFWrTuhKGtjTF70jL/Oht2W4c6rXUe5fu7Ie19VIahAXHIIiWWNeg==",
"dev": true,
"funding": [
{
@@ -10331,9 +10331,9 @@
}
},
"node_modules/electron-to-chromium": {
- "version": "1.5.393",
- "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.393.tgz",
- "integrity": "sha512-kiDJdIUawuEIcp9XoICKp1iTYDEbgguIPq526N1Q7jIQDeQ3CqoMx71025PI/7E48Ddtw2HuWsVjY7afEgNxmg==",
+ "version": "1.5.433",
+ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.433.tgz",
+ "integrity": "sha512-5lCAbyZBjtmUt/RAGHRqrL2q0oEFRThDAsZHHDn9XHa89Qw7gMYOeSicBTy+AHfvo0r6vwsZvqNJTQIQy1BLzA==",
"dev": true,
"license": "ISC"
},
@@ -15140,9 +15140,9 @@
}
},
"node_modules/node-releases": {
- "version": "2.0.51",
- "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.51.tgz",
- "integrity": "sha512-wRNIrw4DmVLKQlbgOMdkMx27Wrpzes2hh5Jtbi2bjPd+4wJstWIqP5A+lscnqbm0xxmT5Bpg8Lec5ItEBwx6BQ==",
+ "version": "2.0.56",
+ "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.56.tgz",
+ "integrity": "sha512-x0InOIyzgdk+eyaWaRJFH5snEtiImgBgblZ2CyPrLmqqcuMQkEvcDPHbzqbD8eDsSeJbVOjn+crzyzHaM4D+/A==",
"dev": true,
"license": "MIT",
"engines": {
@@ -18380,9 +18380,9 @@
}
},
"node_modules/update-browserslist-db": {
- "version": "1.2.3",
- "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.2.3.tgz",
- "integrity": "sha512-Js0m9cx+qOgDxo0eMiFGEueWztz+d4+M3rGlmKPT+T4IS/jP4ylw3Nwpu6cpTTP8R1MAC1kF4VbdLt3ARf209w==",
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.3.3.tgz",
+ "integrity": "sha512-pJ2sYawQS0R/WI928Gj5GlPhTGzbMelq0+4INtSYNDV9ErKJcX6xjGWkoG/VnB3dpUm00zALaqkrUD77pO5TDQ==",
"dev": true,
"funding": [
{
diff --git a/tests/hermes_cli/test_doctor_audit_remedy.py b/tests/hermes_cli/test_doctor_audit_remedy.py
new file mode 100644
index 00000000000..1ff34ed1d85
--- /dev/null
+++ b/tests/hermes_cli/test_doctor_audit_remedy.py
@@ -0,0 +1,62 @@
+"""Doctor npm-audit remedy guidance — the fix must persist across `hermes update`.
+
+Regression for #116774: `npm audit fix` on a managed install is reverted by the
+next `hermes update`, because `_run_npm_install_deterministic` runs `npm ci`
+against the COMMITTED root `package-lock.json` and restores the pinned
+(vulnerable) versions. The doctor's root-row remedy used to prescribe exactly
+that doomed local command (`run: cd <root> && npm audit fix --workspaces=false`),
+sending users into a fix→reintroduce loop. The durable remedy is an upstream
+lockfile bump; the doctor must never prescribe a local mutating fix command, and
+the shipped root lockfile must audit clean so the finding never appears at all.
+"""
+
+import json
+import subprocess
+from unittest.mock import patch
+
+import pytest
+
+from hermes_cli import doctor_tools
+
+
+def _audit_json(critical=0, high=0, moderate=0):
+ return json.dumps({
+ "metadata": {"vulnerabilities": {
+ "critical": critical, "high": high, "moderate": moderate,
+ "low": 0, "info": 0, "total": critical + high + moderate,
+ }},
+ })
+
+
+def _run_audit_one(capsys, audit_extra, audit_stdout):
+ issues: list[str] = []
+ completed = subprocess.CompletedProcess([], 0, stdout=audit_stdout, stderr="")
+ with patch.object(doctor_tools.subprocess, "run", return_value=completed):
+ doctor_tools._audit_one("npm", "C:/fake/root", "Browser tools (agent-browser)",
+ audit_extra, issues)
+ return capsys.readouterr().out, issues
+
+
+def test_root_remedy_never_prescribes_local_audit_fix(capsys):
+ """The root row must not tell users to run a mutating `npm audit fix`: the
+ next `hermes update` reinstalls from the committed lockfile and reverts it
+ (#116774)."""
+ out, issues = _run_audit_one(capsys, ["--workspaces=false"], _audit_json(high=1, moderate=1))
+ assert "run: cd" not in out
+ assert "npm audit fix" not in out
+ assert "lockfile bump" in out
+ assert issues == ["Browser tools (agent-browser) has 2 npm vulnerabilities"]
+
+
+def test_workspace_remedy_still_names_lockfile_bump(capsys):
+ out, _ = _run_audit_one(capsys, ["--workspace", "web"], _audit_json(critical=1))
+ assert "run: cd" not in out
+ assert "npm audit fix" not in out
+ assert "lockfile bump" in out
+
+
+def test_clean_tree_reports_no_known_vulnerabilities(capsys):
+ out, issues = _run_audit_one(capsys, ["--workspaces=false"], _audit_json())
+ assert "no known vulnerabilities" in out
+ assert issues == []
+