## Change description > Whole-repo lint + pre-commit convention, CONFIG ONLY (no source reformat in this PR). Python (ruff) and TypeScript (eslint + prettier) share a 120-col margin via the committed pre-commit gate. This upgrades main's existing basic ruff setup and adds the TS lint stack (none existed on main). > > What this PR adds: > - ruff: line-length 120; security rules S101/S105/S106/S107/S506/S605/S607; policy per-file-ignores (tests + accepted CLI deferred-imports + product asserts + N818, each commented); ruff pinned <0.16. > - eslint/prettier: shared base (`eslint.base.mjs` + `prettier.config.mjs`); ui-tui extends it with React rules, bridge with a Node-only config; hermes-ink vendor and generated RPC types excluded. > - pre-commit: keeps main's hooks (conventional-commit, detect-private-key, etc.), adds a top-level exclude and 4 local eslint/prettier hooks; bumps the pre-commit dev dep. > - 2 lint-surfaced fixes: PlannerContext import (F821) in the sentinel runner; lower-cased file-local cron-heartbeat constants (N806). (raven/config/raven.py's F821 was already fixed on main.) > > Sequencing: config only. `ruff check` is intentionally red on ~307 auto-fixables (I001/F401/F541/E701/E702); a SEPARATE reformat branch runs `ruff --fix` + `ruff format` + eslint/prettier --fix to clear them (100% auto-resolvable, zero manual). Enforcement (pre-commit install / CI) turns on only after the reformat lands, so do not expect a green tree from this PR alone. > > CLI-owned files (the reformat and several per-file-ignores touch `raven/cli/*`) are under review by the CLI team. Judgment items (TS no-explicit-any, no-unused-expressions, S101 convert-vs-keep, N818 rename, C90, mypy) are deferred to v2. ## Type of change - [ ] Bug fix - [x] New feature - [ ] Document - [x] Others ## Related issues (if there is) > none ## Checklists ### Development - [ ] Lint rules pass locally - [ ] Application changes have been tested thoroughly - [ ] Automated tests covering modified code pass > config-only: `ruff check` is red on auto-fixables by design (the reformat branch clears them); eslint/prettier configs load in both ui-tui and bridge. ### Security - [x] Security impact of change has been considered - [ ] Code follows company security practices and guidelines > Only dependency change is the dev-only pre-commit tool plus the ruff pin; the detect-private-key hook from main is retained. ### Code review - [x] Pull request has a descriptive title and context useful to a reviewer - [ ] Pull request linked to JIRA ticket when applicable --------- Co-authored-by: Sheng Zhao <sheng.zhao@evermind.ai> Co-authored-by: Claude (claude-opus-4-8) <noreply@anthropic.com>
117 lines
4.1 KiB
Python
117 lines
4.1 KiB
Python
"""Tests for the skill body ref-path resolver.
|
|
|
|
Used by both the active-skills render path and the router-hits post-gate
|
|
hydrate step — same helper, so a single test set covers both."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from raven.memory_engine.skill_forge.refs import resolve_refs
|
|
|
|
|
|
def _make_skill_dir(tmp_path: Path) -> Path:
|
|
"""Build a SKILL directory with all four bundled subdirs populated."""
|
|
skill = tmp_path / "skill"
|
|
(skill / "references").mkdir(parents=True)
|
|
(skill / "scripts").mkdir()
|
|
(skill / "assets").mkdir()
|
|
(skill / "examples").mkdir()
|
|
(skill / "references" / "CONFIG.md").write_text("config body")
|
|
(skill / "scripts" / "run.sh").write_text("#!/bin/bash")
|
|
(skill / "assets" / "logo.png").write_bytes(b"\x89PNG")
|
|
return skill
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
# {baseDir}/x substitution
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
def test_resolve_basedir_existing_ref(tmp_path: Path) -> None:
|
|
skill = _make_skill_dir(tmp_path)
|
|
body = "Read {baseDir}/references/CONFIG.md for details."
|
|
out, ok = resolve_refs(body, skill)
|
|
assert str(skill) + "/references/CONFIG.md" in out
|
|
assert "{baseDir}" not in out
|
|
assert ok is True
|
|
|
|
|
|
def test_resolve_basedir_missing_ref_left_literal(tmp_path: Path) -> None:
|
|
skill = _make_skill_dir(tmp_path)
|
|
body = "Run {baseDir}/scripts/nope.sh"
|
|
out, ok = resolve_refs(body, skill)
|
|
# Missing target → literal placeholder preserved so the agent doesn't
|
|
# waste a turn on a confident 404.
|
|
assert "{baseDir}/scripts/nope.sh" in out
|
|
assert ok is False
|
|
|
|
|
|
def test_resolve_bare_basedir_substitutes_dir(tmp_path: Path) -> None:
|
|
skill = _make_skill_dir(tmp_path)
|
|
body = "cd {baseDir} then run scripts."
|
|
out, ok = resolve_refs(body, skill)
|
|
assert f"cd {skill}" in out
|
|
assert ok is True
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
# Markdown link substitution
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
def test_resolve_markdown_link_to_bundled(tmp_path: Path) -> None:
|
|
skill = _make_skill_dir(tmp_path)
|
|
body = "See [Config](./references/CONFIG.md) for setup."
|
|
out, ok = resolve_refs(body, skill)
|
|
assert f"[Config]({skill}/references/CONFIG.md)" in out
|
|
assert ok is True
|
|
|
|
|
|
def test_resolve_markdown_link_keeps_fragment(tmp_path: Path) -> None:
|
|
skill = _make_skill_dir(tmp_path)
|
|
body = "See [Config](references/CONFIG.md#section-a) for setup."
|
|
out, _ok = resolve_refs(body, skill)
|
|
assert f"[Config]({skill}/references/CONFIG.md#section-a)" in out
|
|
|
|
|
|
def test_resolve_markdown_link_missing_target_untouched(tmp_path: Path) -> None:
|
|
skill = _make_skill_dir(tmp_path)
|
|
body = "See [Missing](references/nope.md)."
|
|
out, ok = resolve_refs(body, skill)
|
|
assert "[Missing](references/nope.md)" in out
|
|
assert ok is False
|
|
|
|
|
|
def test_resolve_skips_code_fence(tmp_path: Path) -> None:
|
|
skill = _make_skill_dir(tmp_path)
|
|
body = "Use this snippet:\n```\n[Config](references/CONFIG.md)\n```\nReal ref: [Config](references/CONFIG.md)"
|
|
out, ok = resolve_refs(body, skill)
|
|
# Inside the fence: untouched.
|
|
assert "```\n[Config](references/CONFIG.md)\n```" in out
|
|
# Outside the fence: rewritten.
|
|
assert f"Real ref: [Config]({skill}/references/CONFIG.md)" in out
|
|
assert ok is True
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
# No skill_dir (sqlite-only / db-imported skills)
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
def test_no_skill_dir_strips_basedir_prefix() -> None:
|
|
body = "Read {baseDir}/references/x.md and run {baseDir}/scripts/y.sh."
|
|
out, ok = resolve_refs(body, None)
|
|
# Strip the literal `{baseDir}/` so refs read as bare relatives —
|
|
# better than handing the agent a placeholder it can't expand.
|
|
assert "{baseDir}" not in out
|
|
assert "references/x.md" in out
|
|
assert "scripts/y.sh" in out
|
|
assert ok is False
|
|
|
|
|
|
def test_empty_body_safe() -> None:
|
|
out, ok = resolve_refs("", None)
|
|
assert out == ""
|
|
assert ok is False
|