Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

Environments: an npm dist-tag resolves to its version in the package check (#496)

Abhishek Jhacd89d05da835
diff --git a/runner/environments.py b/runner/environments.py
index 1d419c75..e6f5d4f2 100644
--- a/runner/environments.py
+++ b/runner/environments.py
@@ -649,6 +649,7 @@ def check_package(manager: str, spec: str) -> dict:
raise HTTPException(400, "that is not a package spec")
name, pin = spec_parts(spec, manager)
out = {"manager": manager, "name": name, "spec": spec, "exists": None, "latest": "", "version": "", "error": ""}
+ dist_tags: dict = {} # npm only: PyPI and apt have no dist-tag concept
try:
if manager == "pip":
st, j = _http_json(f"https://pypi.org/pypi/{urllib.parse.quote(name)}/json")
@@ -667,7 +668,8 @@ def check_package(manager: str, spec: str) -> dict:
return out
if st != 200:
raise RuntimeError(f"the npm registry answered {st}")
- out.update(exists=True, latest=str((j.get("dist-tags") or {}).get("latest") or ""))
+ dist_tags = j.get("dist-tags") or {}
+ out.update(exists=True, latest=str(dist_tags.get("latest") or ""))
versions = set((j.get("versions") or {}).keys())
else:
_apt_lists()
@@ -681,7 +683,12 @@ def check_package(manager: str, spec: str) -> dict:
m = subprocess.run(["apt-cache", "madison", name], capture_output=True, text=True, timeout=60, env=env)
versions = {ln.split("|")[1].strip() for ln in m.stdout.splitlines() if ln.count("|") >= 2}
if pin:
- if pin in versions:
+ # A dist-tag is a name for a version, not a version: resolve it before checking
+ # the published versions, so `lodash@latest` stops reading as "not published".
+ # An unknown tag keeps the error below; only an exact version is looked up.
+ if pin in dist_tags:
+ out["version"] = str(dist_tags[pin])
+ elif pin in versions:
out["version"] = pin
else:
out["error"] = f"{name} {pin} is not published; the latest is {out['latest']}"
diff --git a/runner/tests/test_environments.py b/runner/tests/test_environments.py
index aa3f4eb4..5822a99a 100644
--- a/runner/tests/test_environments.py
+++ b/runner/tests/test_environments.py
@@ -722,3 +722,25 @@ def test_an_npm_range_is_a_name_with_no_pin(monkeypatch):
ranged = E.check_package("npm", "lodash@^4.17.0")
assert ranged["exists"] is True and ranged["error"] == "" and ranged["version"] == ""
assert "not published" in E.check_package("npm", "[email protected]")["error"]
+
+
+def test_an_npm_dist_tag_resolves_to_its_version(monkeypatch):
+ """#494: `lodash@latest` names a dist-tag, not a version — the check resolves the tag
+ instead of reporting it "not published". An unknown tag keeps the error."""
+ answers = {
+ "https://registry.npmjs.org/lodash": (200, {
+ "dist-tags": {"latest": "4.17.21", "next": "4.17.22-beta.0"},
+ "versions": {"4.17.21": {}, "4.17.20": {}},
+ }),
+ }
+ monkeypatch.setattr(E, "_http_json", lambda url: answers.get(url, (503, {})))
+ tagged = E.check_package("npm", "lodash@latest")
+ assert tagged["exists"] is True and tagged["version"] == "4.17.21" and not tagged["error"]
+ other_tag = E.check_package("npm", "lodash@next")
+ assert other_tag["version"] == "4.17.22-beta.0" and not other_tag["error"]
+ unknown = E.check_package("npm", "lodash@no-such-tag")
+ assert unknown["version"] == "" and "no-such-tag is not published" in unknown["error"]
+ exact = E.check_package("npm", "[email protected]")
+ assert exact["version"] == "" and "9.9.9 is not published" in exact["error"]
+ pinned = E.check_package("npm", "[email protected]")
+ assert pinned["version"] == "4.17.20" and not pinned["error"]