fix(cli): make skill-version warning direction-aware (#1568)
_check_skill_version advised "Run 'graphify install' to update" on ANY version mismatch. But `install` writes the package's OWN bundled skill and re-stamps .graphify_version, so when the skill on disk is NEWER than the running package, following that advice silently DOWNGRADES the skill to silence the warning. The docstring even said "warn if the skill is from an OLDER version" but the code never checked direction. Compare versions numerically (new _version_tuple, so 0.10 > 0.9 and a malformed stamp degrades instead of raising). When the skill is newer than the package, recommend upgrading the package (uv tool upgrade / pip install -U) instead of install; the older-skill case is unchanged. Hit in practice by a stale `uv tool` CLI and by contributors whose dev checkout stamped a newer skill. Reported by @TPAteeq. 4 tests (numeric ordering, both mismatch directions, silent-when-equal). Full suite 2730 passed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
6dc1cb0dd7
commit
47033c8b75
@@ -4,6 +4,7 @@ Full release notes with details on each version: [GitHub Releases](https://githu
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Fix: the skill-version mismatch warning is now direction-aware (#1568, thanks @TPAteeq). It used to advise `Run 'graphify install' to update` on ANY version difference, but `install` writes the package's own bundled skill and re-stamps the version — so when the skill on disk was NEWER than the package (a stale `uv tool` CLI, or a contributor's dev checkout), following that advice silently DOWNGRADED the skill to make the warning go away. Now when the skill is newer, the warning recommends upgrading the package (`uv tool upgrade graphifyy` / `pip install -U graphifyy`) instead; the older-skill case still recommends `install`. Versions compare numerically (so `0.10` > `0.9`).
|
||||
- Feat: extend `indirect_call` capture to JS/TS (#1566). The same model now applies to JavaScript and TypeScript: a callback passed by name (`arr.map(fn)`, `setTimeout(fn)`, Express-style `app.get("/", handler)`, event wiring `emitter.on("e", handler)`) and functions listed in object/array dispatch tables (`const ROUTES = { create: handler }`, `const HOOKS = [onStart, onStop]`). Arrow-const functions (`const cb = () => {}`) count as callable targets; object shorthand (`{ handler }`) is a reference; inline arrows/function expressions are direct definitions and are not captured; object KEYS and non-callable values are excluded. Same guards as Python: callable-target-only, not shadowed by a param/local/module reassignment, single-definition god-node guard cross-file. Cross-file resolution is import-aware — a `import { onEvent }` edge to the symbol no longer suppresses the `indirect_call` to it. Module-level call-argument registration (idiomatic in JS) is captured in addition to the function-scoped capture Python has.
|
||||
- Feat: extend `indirect_call` to dispatch tables (#1566). A function listed as a VALUE in a dict/list/set/tuple literal — a route/handler registry like `ROUTES = {"create": create_user, "delete": delete_user}` or `HOOKS = [on_start, on_stop]` — now emits an `indirect_call` edge so `affected` reaches those handlers too. Works at module level (attributed to the file) and inside a function (attributed to the function), same-file and cross-file. Same guards as the call-argument case: callable-target-only, not shadowed by a param/local/module-level reassignment, dict KEYS excluded (only values are references).
|
||||
- Feat: capture indirect dispatch as `indirect_call` edges so `graphify affected` (blast radius) catches callers that pass a function by name as a call argument — `executor.submit(fn)`, `Thread(target=fn)`, `map(fn, xs)`, callbacks (#1565, thanks @sheik-hiiobd). Kept as a distinct INFERRED relation separate from `calls` (strict call-graph queries stay precise) and added to the affected relation set. Hardened against false edges: the argument name must resolve to a callable definition and must NOT be shadowed by a parameter or local binding in the enclosing function — so the idiomatic `def via(pool, handler): pool.submit(handler)` (handler is the param) and a data variable sharing a function's name produce no edge. Now also resolves cross-file: a callback imported from another module (`from .handlers import on_event; pool.submit(on_event)`) routes through the same cross-file resolver as direct calls — single-definition god-node guard, callable-target-only, staying INFERRED — closing the gap where #1565 saw only same-file callbacks (the common real-world shape is cross-module). Python only for now.
|
||||
|
||||
+35
-1
@@ -148,7 +148,41 @@ def _check_skill_version(skill_dst: Path) -> None:
|
||||
except OSError:
|
||||
return
|
||||
if installed != __version__:
|
||||
print(f" warning: skill is from graphify {installed}, package is {__version__}. Run 'graphify install' to update.", file=sys.stderr)
|
||||
if _version_tuple(installed) > _version_tuple(__version__):
|
||||
# The skill on disk is NEWER than the running package. `graphify install`
|
||||
# writes the package's OWN (older) bundled skill and re-stamps the version,
|
||||
# so following the old "run install" advice would silently DOWNGRADE the
|
||||
# skill. The real fix is to upgrade the package (#1568). Common for a stale
|
||||
# `uv tool` CLI, or a contributor whose dev checkout stamped a newer skill.
|
||||
print(
|
||||
f" warning: skill is from graphify {installed}, but the package is "
|
||||
f"{__version__} (older). Upgrade the package "
|
||||
f"(e.g. 'uv tool upgrade graphifyy' or 'pip install -U graphifyy'); "
|
||||
f"running 'graphify install' would downgrade the skill.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
else:
|
||||
print(f" warning: skill is from graphify {installed}, package is {__version__}. Run 'graphify install' to update.", file=sys.stderr)
|
||||
|
||||
|
||||
def _version_tuple(version: str) -> tuple[int, ...]:
|
||||
"""Parse a version string into a comparable integer tuple (``0.9.2`` -> ``(0, 9, 2)``).
|
||||
|
||||
Reads the leading digits of each dot-segment, so pre/post-release suffixes
|
||||
(``1.0.0rc1``) compare by their numeric core. A non-numeric or empty segment
|
||||
becomes 0, so a malformed stamp degrades to a conservative comparison rather
|
||||
than raising.
|
||||
"""
|
||||
parts: list[int] = []
|
||||
for segment in str(version).split("."):
|
||||
digits = ""
|
||||
for ch in segment:
|
||||
if ch.isdigit():
|
||||
digits += ch
|
||||
else:
|
||||
break
|
||||
parts.append(int(digits) if digits else 0)
|
||||
return tuple(parts)
|
||||
|
||||
|
||||
def _refresh_all_version_stamps() -> None:
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
"""Direction-aware skill-version mismatch warning (#1568).
|
||||
|
||||
`_check_skill_version` used to advise `graphify install` on ANY version
|
||||
mismatch. But `install` writes the package's OWN bundled skill and re-stamps
|
||||
the version, so when the skill on disk is NEWER than the package, following
|
||||
that advice silently DOWNGRADES the skill. These tests pin that the warning is
|
||||
now direction-aware: skill-older -> recommend install; skill-newer -> recommend
|
||||
upgrading the package instead.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import graphify.__main__ as mainmod
|
||||
|
||||
|
||||
def _make_skill(tmp_path: Path, stamped: str) -> Path:
|
||||
skill_dst = tmp_path / "skills" / "graphify" / "SKILL.md"
|
||||
skill_dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
skill_dst.write_text("# graphify skill\n", encoding="utf-8")
|
||||
(skill_dst.parent / ".graphify_version").write_text(stamped, encoding="utf-8")
|
||||
return skill_dst
|
||||
|
||||
|
||||
def test_version_tuple_orders_numerically():
|
||||
vt = mainmod._version_tuple
|
||||
assert vt("0.9.2") > vt("0.8.27") # 9 > 8, not string-compared
|
||||
assert vt("0.10.0") > vt("0.9.0") # 10 > 9
|
||||
assert vt("0.9.3") == vt("0.9.3")
|
||||
assert vt("1.0.0rc1") == vt("1.0.0") # pre-release suffix compares by core
|
||||
assert vt("") == (0,) # malformed stamp degrades, no raise
|
||||
|
||||
|
||||
def test_skill_older_than_package_recommends_install(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.setattr(mainmod, "__version__", "0.9.3")
|
||||
skill_dst = _make_skill(tmp_path, "0.8.27")
|
||||
mainmod._check_skill_version(skill_dst)
|
||||
err = capsys.readouterr().err
|
||||
assert "Run 'graphify install' to update" in err
|
||||
assert "downgrade" not in err
|
||||
|
||||
|
||||
def test_skill_newer_than_package_recommends_upgrade_not_install(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.setattr(mainmod, "__version__", "0.8.27")
|
||||
skill_dst = _make_skill(tmp_path, "0.9.2")
|
||||
mainmod._check_skill_version(skill_dst)
|
||||
err = capsys.readouterr().err
|
||||
# must NOT tell the user to run install (that would downgrade the skill)
|
||||
assert "Run 'graphify install' to update" not in err
|
||||
assert "downgrade" in err
|
||||
assert "upgrade" in err.lower()
|
||||
|
||||
|
||||
def test_matching_version_is_silent(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.setattr(mainmod, "__version__", "0.9.3")
|
||||
skill_dst = _make_skill(tmp_path, "0.9.3")
|
||||
mainmod._check_skill_version(skill_dst)
|
||||
assert capsys.readouterr().err == ""
|
||||
Reference in New Issue
Block a user