Merge branch 'feature/code-graph-by-default' into unify/skills-20261114
# Conflicts: # docs/requirements/009-code-graph-by-default.md # tests/test_install.py
This commit is contained in:
commit
2f25443a9f
12 files changed
+1799
-48
No files matched your search
+110
-2
@@ -10,8 +10,10 @@ import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
INSTALL = Path(__file__).resolve().parents[1] / "scripts" / "install.sh"
|
||||
ORGANIZE = Path(__file__).resolve().parents[1] / "skills" / "kvb-org-organize"
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
INSTALL = REPO_ROOT / "scripts" / "install.sh"
|
||||
ORGANIZE = REPO_ROOT / "skills" / "kvb-org-organize"
|
||||
UNIT = REPO_ROOT / "skills" / "kvb-agent-optimize" / "systemd" / "kvb-code-graph.service"
|
||||
NPX = "#!/bin/sh\nmkdir -p .agents/skills/locked\necho locked > .agents/skills/locked/SKILL.md\n"
|
||||
BYTECODE = ("__pycache__/radio.cpython-312.pyc", "json.pyc", "legacy.pyo")
|
||||
LIVE_MEMORY = {
|
||||
@@ -21,6 +23,23 @@ LIVE_MEMORY = {
|
||||
SHIPPED = ORGANIZE / "config.default.json"
|
||||
DEFAULT = json.loads(SHIPPED.read_text(encoding="utf-8"))
|
||||
ROW_MEMORY = DEFAULT["memory_limits"]
|
||||
HOME_TOOLS = ("bash", "cp", "dirname", "find", "install", "ln", "mkdir", "rm")
|
||||
CGROUP_KILL = """
|
||||
case "$*" in *try-restart*kvb-code-graph*)
|
||||
unit=$(while IFS= read -r line; do echo "$line"; done < "$HOME/.config/systemd/user/kvb-code-graph.service")
|
||||
case "$unit" in *KillMode=process*) ;; *) echo "cgroup killed the daemon" >> "{daemon}" ;; esac
|
||||
esac"""
|
||||
HOME_UNITS = (
|
||||
"kvb-dream/systemd/kvb-dream-notify.service",
|
||||
"kvb-dream/systemd/kvb-dream-notify.timer",
|
||||
"kvb-org-queue-cleanup/systemd/kvb-org-queue-cleanup.service",
|
||||
"kvb-org-queue-cleanup/systemd/kvb-org-queue-cleanup.timer",
|
||||
"kvb-org-queue-cleanup/systemd/kvb-org-queue-cleanup.path",
|
||||
)
|
||||
|
||||
|
||||
def read_lines(path: Path) -> list[str]:
|
||||
return path.read_text(encoding="utf-8").splitlines() if path.is_file() else []
|
||||
|
||||
|
||||
class TestInstall(unittest.TestCase):
|
||||
@@ -94,6 +113,95 @@ class TestInstall(unittest.TestCase):
|
||||
self.assertEqual(json.loads(config.read_text(encoding="utf-8")), {"mine": True})
|
||||
self.assertIn(str(config), done.stderr)
|
||||
|
||||
def home_install(self, root: Path, binary: bool, config: bool = True, fail_now: bool = False) -> tuple[subprocess.CompletedProcess, list[str], list[str]]:
|
||||
repo, stubs, home = root / "repo", root / "bin", root / "home"
|
||||
(repo / "scripts").mkdir(parents=True)
|
||||
shutil.copy(INSTALL, repo / "scripts" / "install.sh")
|
||||
for unit in HOME_UNITS:
|
||||
(repo / "skills" / unit).parent.mkdir(parents=True, exist_ok=True)
|
||||
(repo / "skills" / unit).write_text("[Unit]\n", encoding="utf-8")
|
||||
(repo / "skills" / UNIT.relative_to(REPO_ROOT / "skills")).parent.mkdir(parents=True)
|
||||
shutil.copy(UNIT, repo / "skills" / UNIT.relative_to(REPO_ROOT / "skills"))
|
||||
stubs.mkdir()
|
||||
for tool in HOME_TOOLS:
|
||||
(stubs / tool).symlink_to(shutil.which(tool))
|
||||
log, cbm = root / "systemctl.log", root / "cbm.log"
|
||||
now = '\ncase "$*" in *--now*kvb-code-graph*) exit 1 ;; esac' if fail_now else ""
|
||||
for name, body in (
|
||||
("npx", NPX),
|
||||
("systemctl", f'#!/bin/sh\necho "$*" >> "{log}"{now}{CGROUP_KILL.format(daemon=root / "daemon.log")}\nexit 0\n'),
|
||||
("curl", "#!/bin/sh\nexit 22\n"),
|
||||
("codebase-memory-mcp", f'#!/bin/sh\necho "$*" >> "{cbm}"\nexit 0\n'),
|
||||
):
|
||||
(stubs / name).write_text(body, encoding="utf-8")
|
||||
(stubs / name).chmod(0o755)
|
||||
home.mkdir()
|
||||
if binary:
|
||||
(home / ".local" / "bin").mkdir(parents=True)
|
||||
shutil.copy(stubs / "codebase-memory-mcp", home / ".local" / "bin" / "codebase-memory-mcp")
|
||||
if config:
|
||||
(home / ".config" / "kvb-code-graph").mkdir(parents=True)
|
||||
(home / ".config" / "kvb-code-graph" / "config.json").write_text(
|
||||
'{"queue_file_threshold": 2000, "queue_task": "work/code-graph-index"}\n', encoding="utf-8"
|
||||
)
|
||||
env = {"PATH": str(stubs), "TARGET": str(home), "HOME": str(home)}
|
||||
done = subprocess.run(["/bin/bash", str(repo / "scripts" / "install.sh")], env=env, capture_output=True, text=True, check=False)
|
||||
return done, read_lines(log), read_lines(cbm)
|
||||
|
||||
def test_the_home_install_enables_the_code_graph_service(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
done, calls, _ = self.home_install(root, binary=True)
|
||||
self.assertEqual(done.returncode, 0, done.stderr)
|
||||
self.assertIn("--user enable --now kvb-code-graph.service", calls)
|
||||
installed = root / "home" / ".config" / "systemd" / "user" / "kvb-code-graph.service"
|
||||
self.assertEqual(installed.read_text(encoding="utf-8"), UNIT.read_text(encoding="utf-8"))
|
||||
self.assertNotIn("kvb-code-graph: no config", done.stderr)
|
||||
|
||||
def test_the_home_install_turns_the_daemon_auto_index_off(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
done, _, cbm = self.home_install(Path(tmp), binary=True)
|
||||
self.assertEqual(done.returncode, 0, done.stderr)
|
||||
self.assertIn("config set auto_index false", cbm)
|
||||
self.assertNotIn("config set auto_index true", cbm)
|
||||
|
||||
def test_the_home_install_without_config_says_so_once(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
done, _, _ = self.home_install(Path(tmp), binary=True, config=False)
|
||||
self.assertEqual(done.returncode, 0, done.stderr)
|
||||
notes = [line for line in done.stderr.splitlines() if line.startswith("skills: kvb-code-graph: no config")]
|
||||
self.assertEqual(len(notes), 1, done.stderr)
|
||||
self.assertIn("queue_file_threshold", notes[0])
|
||||
self.assertIn("queue_task", notes[0])
|
||||
|
||||
def test_a_reinstall_restarts_a_running_supervisor_on_the_new_unit(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
done, calls, _ = self.home_install(Path(tmp), binary=True)
|
||||
self.assertEqual(done.returncode, 0, done.stderr)
|
||||
reload = max(number for number, call in enumerate(calls) if call == "--user daemon-reload")
|
||||
self.assertIn("--user try-restart kvb-code-graph.service", calls[reload:])
|
||||
|
||||
def test_a_restart_of_the_supervisor_leaves_its_daemon_running(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
done, _, _ = self.home_install(Path(tmp), binary=True)
|
||||
self.assertEqual(done.returncode, 0, done.stderr)
|
||||
self.assertEqual(read_lines(Path(tmp) / "daemon.log"), [])
|
||||
self.assertIn("KillMode=process", UNIT.read_text(encoding="utf-8").splitlines())
|
||||
|
||||
def test_a_unit_that_cannot_start_now_takes_effect_at_next_login(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
done, calls, _ = self.home_install(Path(tmp), binary=True, fail_now=True)
|
||||
self.assertEqual(done.returncode, 0, done.stderr)
|
||||
self.assertIn("--user enable kvb-code-graph.service", calls)
|
||||
self.assertIn("takes effect at next login", done.stdout + done.stderr)
|
||||
|
||||
def test_the_home_install_skips_the_service_without_the_binary(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
done, calls, _ = self.home_install(Path(tmp), binary=False)
|
||||
self.assertEqual(done.returncode, 0, done.stderr)
|
||||
self.assertFalse([call for call in calls if "kvb-code-graph" in call])
|
||||
self.assertIn("graphs keep their watch only while a session runs", done.stderr)
|
||||
|
||||
def test_reinstall_empties_the_skill_directories_in_place(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
|
||||
Reference in new issue
Block a user