feat: preflight - prerequisites checked and tool paths recorded before wikitool runs; launcher refuses without it (#151, POSIX half)
Files changed: - .claude/settings.json - .gitea/workflows/ci.yml - .gitea/workflows/nightly.yml - .gitea/workflows/release.yml - .gitea/workflows/tracker-live.yml - .github/hooks/wiki-trace.json - .gitignore - .vibe/hooks.toml - AGENTS.md - CHANGES.md - EVALS.md - INSTALL.md - README.md - VERSION - instructions/bootstrap.md - instructions/preflight.md - instructions/setup-instance.md - instructions/upgrade-instance.md - tools/CONTRACT.md - tools/README.md - tools/chemenu/cli.py - tools/chemenu/commands/dist_cmd.py - tools/chemenu/commands/docs_verify.py - tools/chemenu/commands/doctor.py - tools/chemenu/commands/git_publish.py - tools/chemenu/commands/migrate_cmd.py - tools/chemenu/config.py - tools/chemenu/corpus_cache.py - tools/chemenu/prerequisites.py - tools/chemenu/search/ripgrep.py - tools/chemenu/tests/conftest.py - tools/chemenu/tests/test_dist_upgrade.py - tools/chemenu/tests/test_doctor.py - tools/chemenu/tests/test_preflight.py - tools/chemenu/toolpaths.py - tools/preflight.sh - tools/prerequisites.txt - tools/run_wikitool.py - tools/trace-hook - tools/wikitool
This commit is contained in:
1 parent
5a731729f6
commit
e4b2b6d9b1
40 files changed
+1849
-125
No files matched your search
@@ -4,12 +4,14 @@ is missing."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from chemenu import config, conventions
|
||||
from chemenu import config, conventions, prerequisites, toolpaths
|
||||
from chemenu.commands import doctor, instructions_cmd
|
||||
|
||||
|
||||
@@ -17,6 +19,18 @@ def _git(root: Path, *args: str) -> None:
|
||||
subprocess.run(["git", *args], cwd=root, check=True, capture_output=True)
|
||||
|
||||
|
||||
def _write_tools_file(path: Path, tools: dict, complete: bool = True) -> Path:
|
||||
path.write_text(
|
||||
json.dumps({"schema": 1, "complete": complete, "tools": tools}, indent=2) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
return path
|
||||
|
||||
|
||||
def _real_tools() -> dict:
|
||||
return {"python": sys.executable, "git": shutil.which("git"), "rg": shutil.which("rg")}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def instance(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
||||
"""A minimal, fully-configured wiki instance: a git repo with identity,
|
||||
@@ -72,6 +86,11 @@ def instance(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
||||
_git(root, "config", "user.name", "Fixture Author")
|
||||
_git(root, "config", "user.email", "fixture@example.com")
|
||||
|
||||
# What the preflight would have written: every tool this platform needs,
|
||||
# at the path it really has on this machine.
|
||||
tools_file = _write_tools_file(root / toolpaths.FILE_NAME, _real_tools())
|
||||
monkeypatch.setattr(toolpaths, "tools_file", lambda: tools_file)
|
||||
|
||||
instructions_cmd.sync(force=False)
|
||||
return root
|
||||
|
||||
@@ -558,3 +577,66 @@ def test_tasks_provider_names_an_active_override(instance, monkeypatch):
|
||||
checks = doctor.run_doctor()
|
||||
assert _status(checks, "tasks-provider") == "OK"
|
||||
assert "WIKITOOL_TASKS_CONFIG" in _detail(checks, "tasks-provider")
|
||||
|
||||
|
||||
# --- tool paths and the install folder (Gitea #151) --------------------------
|
||||
|
||||
|
||||
def test_tool_paths_missing_file_is_a_fail_naming_the_preflight(instance):
|
||||
(instance / toolpaths.FILE_NAME).unlink()
|
||||
checks = doctor.run_doctor()
|
||||
assert _status(checks, "tool-paths") == "FAIL"
|
||||
fix = next(c.fix for c in checks if c.name == "tool-paths")
|
||||
assert "tools/preflight.sh" in fix
|
||||
|
||||
|
||||
def test_tool_paths_incomplete_run_is_a_fail(instance):
|
||||
_write_tools_file(instance / toolpaths.FILE_NAME, _real_tools(), complete=False)
|
||||
assert _status(doctor.run_doctor(), "tool-paths") == "FAIL"
|
||||
|
||||
|
||||
def test_tool_paths_vanished_path_is_a_fail(instance):
|
||||
tools = {**_real_tools(), "rg": str(instance / "gone" / "rg")}
|
||||
_write_tools_file(instance / toolpaths.FILE_NAME, tools)
|
||||
checks = doctor.run_doctor()
|
||||
assert _status(checks, "tool-paths") == "FAIL"
|
||||
assert "no longer there: rg" in _detail(checks, "tool-paths")
|
||||
# The same broken path makes the ripgrep check fail instead of finding rg on PATH.
|
||||
assert _status(checks, "ripgrep") == "FAIL"
|
||||
|
||||
|
||||
def test_tool_paths_unrecorded_tool_is_a_fail(instance):
|
||||
tools = _real_tools()
|
||||
del tools["git"]
|
||||
_write_tools_file(instance / toolpaths.FILE_NAME, tools)
|
||||
checks = doctor.run_doctor()
|
||||
assert _status(checks, "tool-paths") == "FAIL"
|
||||
assert "not recorded: git" in _detail(checks, "tool-paths")
|
||||
|
||||
|
||||
def test_tool_paths_complete_file_is_ok(instance):
|
||||
assert _status(doctor.run_doctor(), "tool-paths") == "OK"
|
||||
|
||||
|
||||
def _folder_of(length: int) -> str:
|
||||
return "C:\\" + "x" * (length - 3)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("length, longpaths, expected", [
|
||||
(95, "0", "OK"),
|
||||
(96, "0", "FAIL"),
|
||||
(96, "1", "OK"),
|
||||
])
|
||||
def test_install_dir_limit_at_the_boundary(instance, monkeypatch, length, longpaths, expected):
|
||||
monkeypatch.setenv(prerequisites.ENV_PLATFORM, "windows")
|
||||
monkeypatch.setenv(prerequisites.ENV_LONGPATHS, longpaths)
|
||||
folder = _folder_of(length)
|
||||
assert len(folder) == length
|
||||
monkeypatch.setattr(prerequisites, "install_dir", lambda: folder)
|
||||
assert _status(doctor.run_doctor(), "install-dir") == expected
|
||||
|
||||
|
||||
def test_install_dir_is_not_limited_off_windows(instance, monkeypatch):
|
||||
monkeypatch.setenv(prerequisites.ENV_PLATFORM, "linux")
|
||||
monkeypatch.setattr(prerequisites, "install_dir", lambda: "/" + "x" * 300)
|
||||
assert _status(doctor.run_doctor(), "install-dir") == "OK"
|
||||
Reference in new issue
Block a user