Merge origin/main into task/14: CLAUDE.md became the AGENTS.md pointer
Rename-vs-edit conflict: task 13 (landed) moved the workflow brief to AGENTS.md leaving CLAUDE.md as a pointer, while this branch had edited the brief's work-launch section in place. Resolution: CLAUDE.md keeps main's pointer form; this branch's documentation of the branch-from-origin behaviour moved verbatim into AGENTS.md where that text now lives. agents.py and the rest auto-merged; 103 tests green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,239 @@
|
||||
"""Choosing agent models per launch intent (task 12): the BOARD_AGENT_MODEL
|
||||
settings resolve intent → model in config, travel to the adapter as
|
||||
AGENT_MODEL (absent when empty — never an empty flag value), and each
|
||||
adapter renders the opaque name natively. With nothing set, launches are
|
||||
byte-identical to the inherit-everything behaviour.
|
||||
|
||||
The `run` scripts are exercised end-to-end against stub binaries
|
||||
(BOARD_CLAUDE_BIN / BOARD_OPENCODE_BIN), the same seam a live board uses.
|
||||
Run with: python3 -m unittest discover -s tests
|
||||
"""
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
REPO = Path(__file__).resolve().parents[1]
|
||||
CORE = REPO / "manager" / "core"
|
||||
CLAUDE = CORE / "adapters" / "claude"
|
||||
OPENCODE = CORE / "adapters" / "opencode"
|
||||
|
||||
sys.path.insert(0, str(CORE))
|
||||
|
||||
import agents # noqa: E402
|
||||
import config # noqa: E402
|
||||
|
||||
|
||||
def _load(name, path):
|
||||
spec = importlib.util.spec_from_file_location(name, path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
permission_config = _load("permission_config", OPENCODE / "permission_config.py")
|
||||
|
||||
# Neutralize any local/.env or shell leakage: process env beats .env, and
|
||||
# an empty value is exactly "nothing configured".
|
||||
UNSET = {"BOARD_AGENT_MODEL": "", "BOARD_AGENT_MODEL_WORK": "",
|
||||
"BOARD_AGENT_MODEL_ACT_PR": "", "BOARD_AGENT_MODEL_REVIEW": ""}
|
||||
|
||||
|
||||
def _resolve(settings: dict) -> dict:
|
||||
"""config.agent_model per intent, in a fresh interpreter so the given
|
||||
settings are what config reads at import."""
|
||||
env = dict(os.environ)
|
||||
env.update(UNSET)
|
||||
env.update(settings)
|
||||
out = subprocess.check_output(
|
||||
[sys.executable, "-c",
|
||||
"import sys; sys.path.insert(0, sys.argv[1]); import config, json; "
|
||||
"print(json.dumps({m: config.agent_model(m) "
|
||||
"for m in ('work', 'act-pr', 'review')}))",
|
||||
str(CORE)],
|
||||
env=env, text=True)
|
||||
return json.loads(out)
|
||||
|
||||
|
||||
class ModelResolution(unittest.TestCase):
|
||||
def test_nothing_set_means_inherit_for_every_intent(self):
|
||||
self.assertEqual(_resolve({}),
|
||||
{"work": "", "act-pr": "", "review": ""})
|
||||
|
||||
def test_the_general_setting_covers_all_intents(self):
|
||||
self.assertEqual(_resolve({"BOARD_AGENT_MODEL": "vendor-x"}),
|
||||
{"work": "vendor-x", "act-pr": "vendor-x",
|
||||
"review": "vendor-x"})
|
||||
|
||||
def test_a_per_intent_setting_beats_the_general_one_for_that_intent_only(self):
|
||||
resolved = _resolve({"BOARD_AGENT_MODEL": "big",
|
||||
"BOARD_AGENT_MODEL_REVIEW": "cheap"})
|
||||
self.assertEqual(resolved,
|
||||
{"work": "big", "act-pr": "big", "review": "cheap"})
|
||||
|
||||
def test_per_intent_alone_leaves_the_others_inheriting(self):
|
||||
resolved = _resolve({"BOARD_AGENT_MODEL_ACT_PR": "pusher"})
|
||||
self.assertEqual(resolved,
|
||||
{"work": "", "act-pr": "pusher", "review": ""})
|
||||
|
||||
|
||||
class LaunchEnv(unittest.TestCase):
|
||||
"""_launch's half of the contract: AGENT_MODEL set iff a model is
|
||||
configured — absent means absent, even against a leaky environment."""
|
||||
|
||||
def setUp(self):
|
||||
self._tmp = tempfile.TemporaryDirectory()
|
||||
tmp = Path(self._tmp.name)
|
||||
self.capture = tmp / "env.json"
|
||||
adapter = tmp / "stub-adapter"
|
||||
adapter.mkdir()
|
||||
run = adapter / "run"
|
||||
run.write_text("#!/usr/bin/env python3\n"
|
||||
"import json, os\n"
|
||||
f"open({str(self.capture)!r}, 'w').write(json.dumps(dict(os.environ)))\n")
|
||||
run.chmod(run.stat().st_mode | stat.S_IXUSR)
|
||||
self._saved = (config.AGENT_MODEL, config.AGENT_MODELS,
|
||||
config.adapter_dir, config.child_env)
|
||||
config.adapter_dir = lambda: adapter
|
||||
# A stray AGENT_MODEL inherited by the board process must not leak.
|
||||
config.child_env = lambda: {"PATH": os.environ.get("PATH", ""),
|
||||
"AGENT_MODEL": "stray-from-the-shell"}
|
||||
|
||||
def tearDown(self):
|
||||
(config.AGENT_MODEL, config.AGENT_MODELS,
|
||||
config.adapter_dir, config.child_env) = self._saved
|
||||
self._tmp.cleanup()
|
||||
|
||||
def _launch_env(self, mode: str) -> tuple[dict, str]:
|
||||
log = Path(self._tmp.name) / "job.log"
|
||||
proc, log_file, model = agents._launch(
|
||||
mode, "do the task", Path(self._tmp.name), "id-1", "t.md", log)
|
||||
proc.wait()
|
||||
log_file.close()
|
||||
return json.loads(self.capture.read_text()), model
|
||||
|
||||
def test_no_model_configured_means_no_variable_at_all(self):
|
||||
config.AGENT_MODEL = ""
|
||||
config.AGENT_MODELS = {"work": "", "act-pr": "", "review": ""}
|
||||
env, model = self._launch_env("work")
|
||||
self.assertNotIn("AGENT_MODEL", env)
|
||||
self.assertEqual(model, "")
|
||||
|
||||
def test_the_resolved_model_arrives_as_agent_model(self):
|
||||
config.AGENT_MODEL = "big"
|
||||
config.AGENT_MODELS = {"work": "", "act-pr": "", "review": "cheap"}
|
||||
env, model = self._launch_env("review")
|
||||
self.assertEqual(env["AGENT_MODEL"], "cheap")
|
||||
self.assertEqual(model, "cheap")
|
||||
env, model = self._launch_env("work")
|
||||
self.assertEqual(env["AGENT_MODEL"], "big")
|
||||
self.assertEqual(model, "big")
|
||||
|
||||
|
||||
class AgentRecord(unittest.TestCase):
|
||||
def test_public_record_carries_the_model_none_means_inherited(self):
|
||||
base = {"id": "a", "task": "t.md", "branch": None, "worktree": None,
|
||||
"status": "running", "rc": None, "started": 0.0,
|
||||
"session": None, "mode": "review", "name": "Wren"}
|
||||
self.assertIsNone(agents._agent_public(base)["model"])
|
||||
self.assertEqual(
|
||||
agents._agent_public({**base, "model": "cheap"})["model"], "cheap")
|
||||
|
||||
|
||||
def _write_stub(directory: Path, name: str, script: str) -> Path:
|
||||
stub = directory / name
|
||||
stub.write_text(script, encoding="utf-8")
|
||||
stub.chmod(stub.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
||||
return stub
|
||||
|
||||
|
||||
class ClaudeRunModel(unittest.TestCase):
|
||||
"""AGENT_MODEL reaches the claude launch as --model; absent (or empty,
|
||||
which must never happen but costs nothing to survive) = no flag."""
|
||||
|
||||
def _run(self, model: str | None) -> list[str]:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
capture = Path(tmp) / "args.json"
|
||||
stub = _write_stub(Path(tmp), "claude-stub",
|
||||
"#!/usr/bin/env python3\n"
|
||||
"import json, sys\n"
|
||||
f"open({str(capture)!r}, 'w').write(json.dumps(sys.argv[1:]))\n")
|
||||
wrapper = _write_stub(Path(tmp), "bin",
|
||||
f"#!/usr/bin/env bash\nexec python3 {stub} \"$@\"\n")
|
||||
env = dict(os.environ)
|
||||
env.pop("AGENT_MODEL", None)
|
||||
env.update({"BOARD_CLAUDE_BIN": str(wrapper),
|
||||
"AGENT_PROMPT": "do the task", "AGENT_MODE": "work",
|
||||
"AGENT_COMMANDS": "python3 -m unittest"})
|
||||
if model is not None:
|
||||
env["AGENT_MODEL"] = model
|
||||
result = subprocess.run(["bash", str(CLAUDE / "run")], env=env,
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
return json.loads(capture.read_text())
|
||||
|
||||
def test_unset_launches_byte_identical_to_today(self):
|
||||
args = self._run(None)
|
||||
self.assertNotIn("--model", args)
|
||||
self.assertEqual(args, self._run("")) # empty behaves like absent
|
||||
|
||||
def test_set_appends_model_and_changes_nothing_else(self):
|
||||
args = self._run("claude-model-x")
|
||||
i = args.index("--model")
|
||||
self.assertEqual(args[i + 1], "claude-model-x")
|
||||
self.assertEqual(args[:i] + args[i + 2:], self._run(None))
|
||||
|
||||
|
||||
class OpencodeRunModel(unittest.TestCase):
|
||||
"""AGENT_MODEL reaches the opencode launch as the generated config's
|
||||
model key; absent = no key, config byte-identical to today."""
|
||||
|
||||
def _run(self, model: str | None) -> dict:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
capture = Path(tmp) / "capture.json"
|
||||
stub = _write_stub(Path(tmp), "opencode-stub",
|
||||
"#!/usr/bin/env python3\n"
|
||||
"import json, os\n"
|
||||
f"open({str(capture)!r}, 'w').write("
|
||||
"json.dumps(json.load(open(os.environ['OPENCODE_CONFIG']))))\n")
|
||||
wrapper = _write_stub(Path(tmp), "bin",
|
||||
f"#!/usr/bin/env bash\nexec python3 {stub} \"$@\"\n")
|
||||
env = dict(os.environ)
|
||||
env.pop("AGENT_MODEL", None)
|
||||
env.update({"BOARD_OPENCODE_BIN": str(wrapper),
|
||||
"AGENT_PROMPT": "do the task", "AGENT_MODE": "review",
|
||||
"AGENT_COMMANDS": "python3 -m unittest"})
|
||||
if model is not None:
|
||||
env["AGENT_MODEL"] = model
|
||||
result = subprocess.run(["bash", str(OPENCODE / "run")], env=env,
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
return json.loads(capture.read_text())
|
||||
|
||||
def test_unset_launches_byte_identical_to_today(self):
|
||||
cfg = self._run(None)
|
||||
self.assertNotIn("model", cfg)
|
||||
self.assertEqual(cfg, permission_config.build_config(
|
||||
"review", ["python3 -m unittest"]))
|
||||
|
||||
def test_set_lands_as_the_config_model_key_untranslated(self):
|
||||
cfg = self._run("anthropic/model-x")
|
||||
self.assertEqual(cfg["model"], "anthropic/model-x")
|
||||
del cfg["model"]
|
||||
self.assertEqual(cfg, self._run(None))
|
||||
|
||||
def test_build_config_only_grows_the_key_when_given_a_model(self):
|
||||
commands = ["python3 -m unittest"]
|
||||
self.assertNotIn("model", permission_config.build_config("work", commands))
|
||||
self.assertEqual(
|
||||
permission_config.build_config("work", commands, "p/m")["model"], "p/m")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,263 @@
|
||||
"""Project-owned definition-of-done checks (task 03).
|
||||
|
||||
What counts as a check is project knowledge: core ships a default
|
||||
definition (core/checks), a same-named file in local/ replaces it
|
||||
wholesale, the claude adapter classifies agent commands against the
|
||||
resolved file, and the Focus panel renders one row per entry from the
|
||||
same definition served over /api/state. These tests pin the resolution
|
||||
order, the two parsers' agreement, the generic pass/fail judgment that
|
||||
replaced per-tool output parsing, and the absence of the origin
|
||||
project's stack anywhere else in core.
|
||||
|
||||
python3 -m unittest discover -s tests -v
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
REPO = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(REPO / "manager" / "core"))
|
||||
sys.path.insert(0, str(REPO / "manager" / "core" / "adapters" / "claude"))
|
||||
|
||||
import config # noqa: E402
|
||||
import emit # noqa: E402
|
||||
|
||||
CORE = REPO / "manager" / "core"
|
||||
|
||||
|
||||
class ShippedDefault(unittest.TestCase):
|
||||
"""A project defining nothing sees today's rows — as the default."""
|
||||
|
||||
def test_default_rows_and_patterns(self):
|
||||
original = config.LOCAL
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
config.LOCAL = Path(tmp) # no local/checks
|
||||
checks = config.checks()
|
||||
finally:
|
||||
config.LOCAL = original
|
||||
self.assertEqual([c["label"] for c in checks],
|
||||
["pytest", "lint-imports", "frontend"])
|
||||
by_label = {c["label"]: c["pattern"] for c in checks}
|
||||
self.assertTrue(re.search(by_label["pytest"], "python3 -m pytest -q"))
|
||||
self.assertTrue(re.search(by_label["lint-imports"], "lint-imports"))
|
||||
for cmd in ("npm run test", "vue-tsc --noEmit", "npx vitest run"):
|
||||
self.assertTrue(re.search(by_label["frontend"], cmd), cmd)
|
||||
self.assertFalse(re.search(by_label["pytest"], "python3 -m unittest"))
|
||||
|
||||
|
||||
class LocalOverride(unittest.TestCase):
|
||||
"""local/checks beats core/checks wholesale, like prompts."""
|
||||
|
||||
def _with_local(self, text):
|
||||
original = config.LOCAL
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
config.LOCAL = Path(tmp)
|
||||
(Path(tmp) / "checks").write_text(text, encoding="utf-8")
|
||||
return config.checks()
|
||||
finally:
|
||||
config.LOCAL = original
|
||||
|
||||
def test_local_definition_wins(self):
|
||||
checks = self._with_local("# ours\nsmoke: \\bmake smoke\\b\n"
|
||||
"types: \\bmypy\\b\n")
|
||||
self.assertEqual([c["label"] for c in checks], ["smoke", "types"])
|
||||
|
||||
def test_replacement_is_wholesale_even_when_empty(self):
|
||||
self.assertEqual(self._with_local("# nothing to check\n"), [])
|
||||
|
||||
def test_malformed_lines_are_skipped(self):
|
||||
checks = self._with_local("no separator here\n"
|
||||
": pattern without label\n"
|
||||
"label without pattern:\n"
|
||||
"bad-regex: [unclosed\n"
|
||||
"good: \\bok\\b\n")
|
||||
self.assertEqual([c["label"] for c in checks], ["good"])
|
||||
|
||||
def test_bench_defines_its_own(self):
|
||||
"""Bench's real local/checks: the stdlib suite, so the self-hosted
|
||||
Focus view shows a check that can actually run here."""
|
||||
checks = config.checks()
|
||||
self.assertEqual([c["label"] for c in checks], ["unittest"])
|
||||
self.assertTrue(re.search(checks[0]["pattern"], "python3 -m unittest"))
|
||||
|
||||
|
||||
class AdapterReadsTheSameFile(unittest.TestCase):
|
||||
"""emit.py resolves and parses the identical definition, so a label
|
||||
edit flows to classification and rendering alike."""
|
||||
|
||||
def test_parsers_agree_on_the_shipped_default(self):
|
||||
original = emit.MANAGER
|
||||
try:
|
||||
emit.MANAGER = Path(tempfile.mkdtemp()) # no local, no core
|
||||
(emit.MANAGER / "core").mkdir()
|
||||
(emit.MANAGER / "core" / "checks").write_text(
|
||||
(CORE / "checks").read_text(encoding="utf-8"), encoding="utf-8")
|
||||
adapter_view = [(label, pattern.pattern)
|
||||
for label, pattern in emit.check_defs()]
|
||||
finally:
|
||||
emit.MANAGER = original
|
||||
core_original = config.LOCAL
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
config.LOCAL = Path(tmp)
|
||||
board_view = [(c["label"], c["pattern"]) for c in config.checks()]
|
||||
finally:
|
||||
config.LOCAL = core_original
|
||||
self.assertEqual(adapter_view, board_view)
|
||||
|
||||
def test_local_wins_in_the_adapter_too(self):
|
||||
original = emit.MANAGER
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
emit.MANAGER = Path(tmp)
|
||||
(Path(tmp) / "core").mkdir()
|
||||
(Path(tmp) / "core" / "checks").write_text(
|
||||
"core-only: \\bx\\b\n", encoding="utf-8")
|
||||
(Path(tmp) / "local").mkdir()
|
||||
(Path(tmp) / "local" / "checks").write_text(
|
||||
"ours: \\bmake check\\b\n", encoding="utf-8")
|
||||
defs = emit.check_defs()
|
||||
finally:
|
||||
emit.MANAGER = original
|
||||
self.assertEqual([label for label, _ in defs], ["ours"])
|
||||
|
||||
def test_missing_files_mean_no_checks_not_a_crash(self):
|
||||
original = emit.MANAGER
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
emit.MANAGER = Path(tmp)
|
||||
self.assertEqual(emit.check_defs(), [])
|
||||
finally:
|
||||
emit.MANAGER = original
|
||||
|
||||
|
||||
class Classification(unittest.TestCase):
|
||||
"""Bash commands classify against the resolved definitions; the label
|
||||
carries into the summary; judgment is generic, not per-tool."""
|
||||
|
||||
def setUp(self):
|
||||
self._original = emit.MANAGER
|
||||
self._tmp = tempfile.TemporaryDirectory()
|
||||
emit.MANAGER = Path(self._tmp.name)
|
||||
(emit.MANAGER / "core").mkdir()
|
||||
(emit.MANAGER / "core" / "checks").write_text(
|
||||
"suite: \\bunittest\\b\nlint: \\bmake lint\\b\n", encoding="utf-8")
|
||||
|
||||
def tearDown(self):
|
||||
emit.MANAGER = self._original
|
||||
self._tmp.cleanup()
|
||||
|
||||
def _bash(self, cmd, out="", hook="PostToolUse"):
|
||||
return emit.classify(hook, "Bash", {"command": cmd},
|
||||
{"stdout": out, "stderr": ""})
|
||||
|
||||
def test_matching_command_becomes_a_check_with_its_label(self):
|
||||
ev = self._bash("python3 -m unittest discover -s tests",
|
||||
"Ran 7 tests in 0.1s\n\nOK")
|
||||
self.assertEqual(ev["kind"], "check")
|
||||
self.assertTrue(ev["ok"])
|
||||
self.assertTrue(ev["summary"].startswith("suite — "))
|
||||
|
||||
def test_label_edits_flow_to_the_event(self):
|
||||
(emit.MANAGER / "core" / "checks").write_text(
|
||||
"renamed: \\bunittest\\b\n", encoding="utf-8")
|
||||
ev = self._bash("python3 -m unittest", "OK")
|
||||
self.assertTrue(ev["summary"].startswith("renamed — "))
|
||||
|
||||
def test_counted_failures_fail(self):
|
||||
ev = self._bash("python3 -m unittest", "2 failed, 5 passed in 1.2s")
|
||||
self.assertEqual(ev["kind"], "check")
|
||||
self.assertFalse(ev["ok"])
|
||||
self.assertIn("2 failed", ev["summary"])
|
||||
self.assertIn("5 passed", ev["summary"])
|
||||
|
||||
def test_unjudgeable_output_stays_neutral(self):
|
||||
ev = self._bash("make lint", "some chatter")
|
||||
self.assertEqual(ev["kind"], "check")
|
||||
self.assertIsNone(ev["ok"])
|
||||
|
||||
def test_unmatched_commands_stay_commands(self):
|
||||
self.assertEqual(self._bash("ls -la")["kind"], "command")
|
||||
|
||||
def test_git_classification_survives(self):
|
||||
ev = self._bash('git commit -m "a message"')
|
||||
self.assertEqual(ev["kind"], "git")
|
||||
|
||||
def test_running_events_keep_the_check_kind(self):
|
||||
ev = self._bash("python3 -m unittest", hook="PreToolUse")
|
||||
self.assertEqual(ev["kind"], "check")
|
||||
self.assertTrue(ev["running"])
|
||||
|
||||
|
||||
class GenericJudgment(unittest.TestCase):
|
||||
"""No tool names: counts, broken totals and OK/FAILED verdict lines."""
|
||||
|
||||
def test_ladder(self):
|
||||
cases = [
|
||||
("3 passed in 0.5s", True),
|
||||
("1 failed, 2 passed", False),
|
||||
("2 errors", False),
|
||||
("Ran 7 tests in 0.1s\n\nOK", True),
|
||||
("Ran 7 tests in 0.1s\n\nFAILED (failures=1)", False),
|
||||
("0 broken contracts", True),
|
||||
("4 broken contracts", False),
|
||||
("nothing recognizable", None),
|
||||
("", None),
|
||||
]
|
||||
for out, expected in cases:
|
||||
ok, _ = emit.judge(out)
|
||||
self.assertEqual(ok, expected, f"judge({out!r})")
|
||||
|
||||
|
||||
class ServedToTheBrowser(unittest.TestCase):
|
||||
"""The state API carries the definition; Focus renders from it with
|
||||
no fixed rows and no duplicated patterns."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.html = (CORE / "board.html").read_text(encoding="utf-8")
|
||||
|
||||
def test_state_payload_includes_checks(self):
|
||||
import httpd
|
||||
payload = httpd.state_payload()
|
||||
self.assertIn("checks", payload)
|
||||
self.assertEqual(payload["checks"], config.checks())
|
||||
|
||||
def test_focus_renders_from_served_definition(self):
|
||||
self.assertIn("S.state?.checks", self.html)
|
||||
self.assertIn("new RegExp(c.pattern)", self.html)
|
||||
self.assertIn("no checks defined", self.html)
|
||||
|
||||
def test_no_fixed_rows_or_duplicated_patterns(self):
|
||||
for fossil in ("lint-imports", "vitest", "vue-tsc", "pytest"):
|
||||
self.assertNotIn(fossil, self.html, f"board.html still hardcodes {fossil}")
|
||||
|
||||
|
||||
class NoFossilsInCore(unittest.TestCase):
|
||||
"""Nothing in manager/core/ names the origin project's stack outside
|
||||
the shipped default checks definition."""
|
||||
|
||||
def test_core_is_clean(self):
|
||||
allowed = CORE / "checks"
|
||||
pattern = re.compile(r"pytest|lint-imports|vue-tsc|vitest")
|
||||
for path in sorted(CORE.rglob("*")):
|
||||
if not path.is_file() or path == allowed:
|
||||
continue
|
||||
try:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
except UnicodeDecodeError:
|
||||
continue
|
||||
self.assertIsNone(pattern.search(text),
|
||||
f"{path.relative_to(REPO)} names a stack "
|
||||
"that belongs in the checks definition")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,82 @@
|
||||
"""The kanban's columns yield on small laptops (task 09).
|
||||
|
||||
board.html is a single file with inline JS and no frontend test runner, so
|
||||
these are source-level invariants: the ones that, if broken, would bring
|
||||
back the rigid 296px columns that clipped the Done column on a 13" MacBook,
|
||||
or let the floor drift above what a 1280px viewport can hold.
|
||||
|
||||
python3 -m unittest discover -s tests -v
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
BOARD = Path(__file__).resolve().parents[1] / "manager" / "core" / "board.html"
|
||||
|
||||
COLUMNS = 5 # backlog → to-do → in-progress → review → done
|
||||
|
||||
|
||||
class ColumnFlexTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.html = BOARD.read_text(encoding="utf-8")
|
||||
m = re.search(r"\.kcol\{([^}]*)\}", cls.html)
|
||||
assert m, "board.html lost its .kcol rule"
|
||||
cls.kcol = m.group(1)
|
||||
|
||||
def token(self, name: str) -> int:
|
||||
m = re.search(rf"{name}:\s*(\d+)px", self.html)
|
||||
self.assertIsNotNone(m, f"{name} must be a px token at the top of board.html")
|
||||
return int(m.group(1))
|
||||
|
||||
def test_floor_is_a_design_token(self):
|
||||
"""The floor lives beside --col with the other layout tokens, not as
|
||||
a magic number buried in the rule."""
|
||||
self.token("--col-min")
|
||||
self.assertIn("min-width:var(--col-min)", self.kcol.replace(" ", ""),
|
||||
".kcol must take its floor from the --col-min token")
|
||||
|
||||
def test_columns_yield_between_floor_and_cap(self):
|
||||
"""flex:1 1 0 with max-width:var(--col): wide screens cap at today's
|
||||
296px (pixel-identical), narrower viewports shrink all five evenly."""
|
||||
flat = self.kcol.replace(" ", "")
|
||||
self.assertIn("flex:110", flat,
|
||||
".kcol must grow and shrink from a zero basis")
|
||||
self.assertIn("max-width:var(--col)", flat,
|
||||
"wide screens must still cap columns at --col")
|
||||
self.assertNotIn("width:var(--col);", flat.replace("max-width", ""),
|
||||
"a fixed width would undo the flex")
|
||||
self.assertEqual(self.token("--col"), 296,
|
||||
"the cap is today's column width; changing it is a "
|
||||
"redesign, not this fix")
|
||||
|
||||
def test_five_columns_fit_a_1280px_viewport(self):
|
||||
"""At the floor, 5 columns + 4 gaps + the board's own padding must
|
||||
not exceed 1280 CSS px — the smallest laptop this board honours."""
|
||||
floor = self.token("--col-min")
|
||||
gap = self.token("--gap")
|
||||
board = re.search(r"#board\{([^}]*)\}", self.html).group(1)
|
||||
pad = re.search(r"padding:\s*\d+px\s+(\d+)px", board)
|
||||
self.assertIsNotNone(pad, "#board lost its horizontal padding")
|
||||
footprint = COLUMNS * floor + (COLUMNS - 1) * gap + 2 * int(pad.group(1))
|
||||
self.assertLessEqual(footprint, 1280,
|
||||
f"five columns at the floor need {footprint}px; "
|
||||
"a 1280px viewport would scroll")
|
||||
|
||||
def test_cards_stay_legible_at_the_floor(self):
|
||||
"""Shrinking must stop somewhere: a floor under ~240px would start
|
||||
crushing card internals instead of ellipsising them."""
|
||||
self.assertGreaterEqual(self.token("--col-min"), 240)
|
||||
|
||||
def test_overflow_fallback_survives(self):
|
||||
"""Below the floor the old behaviour is the fallback: #board still
|
||||
scrolls horizontally rather than clipping."""
|
||||
board = re.search(r"#board\{([^}]*)\}", self.html).group(1)
|
||||
self.assertIn("overflow-x:auto", board.replace(" ", ""))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,143 @@
|
||||
"""install.py's first-boot cleaning: a vendored clone's very first run
|
||||
clears the distribution's own cards so a new host starts with a pristine
|
||||
board, and no later run ever touches the host's own. Run with:
|
||||
python3 -m unittest discover -s tests
|
||||
|
||||
install.py is exercised end-to-end as a subprocess against scratch host
|
||||
layouts — the same entry point start.sh uses — so what is asserted is
|
||||
what a real first boot does to disk.
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
REPO = Path(__file__).resolve().parents[1]
|
||||
STAGES = ["backlog", "to-do", "in-progress", "review", "done"]
|
||||
KEEP = {".gitkeep", "task-template.md"}
|
||||
|
||||
|
||||
def make_host(root: Path) -> Path:
|
||||
"""A host project with a freshly vendored .task-manager: the real
|
||||
install.py and claude adapter, plus the distribution's shipped cards."""
|
||||
host = root / "host"
|
||||
(host / ".claude").mkdir(parents=True)
|
||||
tm = host / ".task-manager"
|
||||
tm.mkdir()
|
||||
shutil.copy(REPO / "install.py", tm / "install.py")
|
||||
shutil.copytree(REPO / "manager" / "core" / "adapters" / "claude",
|
||||
tm / "manager" / "core" / "adapters" / "claude")
|
||||
for stage in STAGES + ["archive"]:
|
||||
d = tm / "tasks" / stage
|
||||
d.mkdir(parents=True)
|
||||
(d / ".gitkeep").touch()
|
||||
(d / "00-shipped-card.md").write_text("# Shipped\n", encoding="utf-8")
|
||||
(tm / "tasks" / "task-template.md").write_text("# Template\n", encoding="utf-8")
|
||||
for extra in ["plans", "reference"]:
|
||||
d = tm / extra
|
||||
d.mkdir()
|
||||
(d / ".gitkeep").touch()
|
||||
(d / "shipped.md").write_text("shipped\n", encoding="utf-8")
|
||||
(tm / "reference" / "shots").mkdir()
|
||||
(tm / "reference" / "shots" / "board.png").write_bytes(b"png")
|
||||
return tm
|
||||
|
||||
|
||||
def run_install(tm: Path, *args: str) -> subprocess.CompletedProcess:
|
||||
env = {k: v for k, v in os.environ.items() if not k.startswith("BOARD_")}
|
||||
return subprocess.run(
|
||||
[sys.executable, str(tm / "install.py"), *args],
|
||||
capture_output=True, text=True, cwd=tm.parent, env=env)
|
||||
|
||||
|
||||
def shipped_files(tm: Path) -> list[Path]:
|
||||
"""Every file under the cleaned directories that first boot should
|
||||
have removed — empty means the board is pristine."""
|
||||
return [p
|
||||
for top in [tm / "tasks", tm / "plans", tm / "reference"]
|
||||
for p in top.rglob("*")
|
||||
if p.is_file() and p.name not in KEEP]
|
||||
|
||||
|
||||
class FirstBoot(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.scratch = Path(tempfile.mkdtemp()).resolve()
|
||||
self.addCleanup(shutil.rmtree, self.scratch, True)
|
||||
self.tm = make_host(self.scratch)
|
||||
|
||||
def test_first_run_clears_shipped_content_and_prints_each_removal(self):
|
||||
result = run_install(self.tm)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertEqual(shipped_files(self.tm), [])
|
||||
for stage in STAGES + ["archive"]:
|
||||
self.assertTrue((self.tm / "tasks" / stage / ".gitkeep").is_file())
|
||||
self.assertTrue((self.tm / "tasks" / "task-template.md").is_file())
|
||||
self.assertTrue((self.tm / "plans" / ".gitkeep").is_file())
|
||||
self.assertTrue((self.tm / "reference" / ".gitkeep").is_file())
|
||||
for line in ["tasks/backlog/00-shipped-card.md",
|
||||
"tasks/archive/00-shipped-card.md",
|
||||
"plans/shipped.md", "reference/shots"]:
|
||||
self.assertIn(f"removed {line}", result.stdout)
|
||||
self.assertTrue((self.tm / "manager" / "local" / "state").is_dir())
|
||||
|
||||
def test_second_run_removes_nothing_and_host_cards_survive(self):
|
||||
run_install(self.tm)
|
||||
card = self.tm / "tasks" / "backlog" / "20-host-card.md"
|
||||
card.write_text("# The host's own\n", encoding="utf-8")
|
||||
result = run_install(self.tm)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertNotIn("removed", result.stdout)
|
||||
self.assertTrue(card.is_file())
|
||||
self.assertIn("ok", result.stdout)
|
||||
|
||||
def test_dry_run_lists_without_removing(self):
|
||||
result = run_install(self.tm, "--dry-run")
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertIn("would remove tasks/backlog/00-shipped-card.md",
|
||||
result.stdout)
|
||||
self.assertNotIn("removed ", result.stdout)
|
||||
self.assertNotEqual(shipped_files(self.tm), [])
|
||||
self.assertFalse((self.tm / "manager" / "local" / "state").exists())
|
||||
|
||||
def test_existing_env_file_disarms_the_guard(self):
|
||||
local = self.tm / "manager" / "local"
|
||||
local.mkdir(parents=True)
|
||||
(local / ".env").write_text("BOARD_PORT=26071\n", encoding="utf-8")
|
||||
result = run_install(self.tm)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertNotIn("removed", result.stdout)
|
||||
self.assertNotEqual(shipped_files(self.tm), [])
|
||||
self.assertFalse((local / "state").exists())
|
||||
|
||||
def test_symlinked_leftover_is_unlinked_not_followed(self):
|
||||
"""A symlink among the leftovers is removed as a link — the
|
||||
directory it points to survives untouched."""
|
||||
outside = self.scratch / "outside"
|
||||
outside.mkdir()
|
||||
(outside / "precious.md").write_text("keep me\n", encoding="utf-8")
|
||||
link = self.tm / "tasks" / "backlog" / "10-linked"
|
||||
link.symlink_to(outside)
|
||||
result = run_install(self.tm)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertFalse(link.is_symlink())
|
||||
self.assertFalse(link.exists())
|
||||
self.assertTrue((outside / "precious.md").is_file())
|
||||
|
||||
def test_self_hosted_repo_is_never_cleaned(self):
|
||||
"""When the manager IS the repo (bench itself, or a dev clone of
|
||||
it), tasks/ is that repo's history — even unwired, never touched."""
|
||||
subprocess.run(["git", "init", "-q", str(self.tm)], check=True,
|
||||
capture_output=True)
|
||||
(self.tm / ".claude").mkdir()
|
||||
result = run_install(self.tm)
|
||||
self.assertNotIn("removed", result.stdout)
|
||||
self.assertNotEqual(shipped_files(self.tm), [])
|
||||
self.assertFalse((self.tm / "manager" / "local" / "state").exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,97 @@
|
||||
"""update.sh's brief rename round-trip: a project installed on the old
|
||||
layout (a full vendor-named CLAUDE.md, no AGENTS.md) updates to a core
|
||||
that ships AGENTS.md as the brief plus a pointer CLAUDE.md — the brief
|
||||
must arrive, the pointer must replace the old full copy, and nothing a
|
||||
project owns may move. Run with: python3 -m unittest discover -s tests
|
||||
|
||||
update.sh is exercised end-to-end as a subprocess against a scratch
|
||||
install and a scratch distribution repo built from this repo's real
|
||||
top-level files, so what is asserted is what a real update does to disk.
|
||||
"""
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
REPO = Path(__file__).resolve().parents[1]
|
||||
TOP_FILES = ["AGENTS.md", "CLAUDE.md", "README.md", "install.py",
|
||||
"start.sh", "stop.sh", "update.sh"]
|
||||
|
||||
OLD_BRIEF = "# Task Workflow\n\nThe old full vendor-named brief.\n"
|
||||
OLD_LOCAL_NOTES = "# Project notes\n\nThe project's own, old-style.\n"
|
||||
|
||||
|
||||
def make_dist(root: Path) -> Path:
|
||||
"""A distribution repo carrying this repo's real top-level files and a
|
||||
minimal manager/core/, committed so update.sh can clone it."""
|
||||
dist = root / "dist"
|
||||
(dist / "manager" / "core" / "adapters").mkdir(parents=True)
|
||||
# A different length than the installed "old" — rsync's quick check
|
||||
# (size+mtime) must see a change, as any real version bump would.
|
||||
(dist / "manager" / "core" / "VERSION").write_text("new-version\n",
|
||||
encoding="utf-8")
|
||||
for f in TOP_FILES:
|
||||
shutil.copy(REPO / f, dist / f)
|
||||
for cmd in (["git", "init", "-q"], ["git", "add", "-A"],
|
||||
["git", "-c", "user.name=t", "-c", "user.email=t@t",
|
||||
"commit", "-qm", "dist"]):
|
||||
subprocess.run(cmd, cwd=dist, check=True, capture_output=True)
|
||||
return dist
|
||||
|
||||
|
||||
def make_old_install(root: Path) -> Path:
|
||||
"""An installed .task-manager on the pre-rename layout: the full brief
|
||||
under the vendor name, no AGENTS.md anywhere."""
|
||||
tm = root / "host" / ".task-manager"
|
||||
(tm / "manager" / "core").mkdir(parents=True)
|
||||
(tm / "manager" / "local").mkdir()
|
||||
(tm / "tasks" / "backlog").mkdir(parents=True)
|
||||
(tm / "manager" / "core" / "VERSION").write_text("old\n", encoding="utf-8")
|
||||
(tm / "CLAUDE.md").write_text(OLD_BRIEF, encoding="utf-8")
|
||||
(tm / "manager" / "local" / "CLAUDE.md").write_text(
|
||||
OLD_LOCAL_NOTES, encoding="utf-8")
|
||||
(tm / "tasks" / "backlog" / "01-card.md").write_text(
|
||||
"# Card\n\n**Status:** Backlog\n", encoding="utf-8")
|
||||
shutil.copy(REPO / "update.sh", tm / "update.sh")
|
||||
(tm / "update.sh").chmod(0o755)
|
||||
return tm
|
||||
|
||||
|
||||
class UpdateRoundTrip(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(shutil.rmtree, self.tmp, True)
|
||||
self.dist = make_dist(self.tmp)
|
||||
self.tm = make_old_install(self.tmp)
|
||||
result = subprocess.run(
|
||||
["bash", str(self.tm / "update.sh")],
|
||||
env={"PATH": "/usr/bin:/bin:/usr/local/bin",
|
||||
"BENCH_SOURCE": self.dist.as_uri()},
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_brief_arrives_under_the_cross_vendor_name(self):
|
||||
agents = (self.tm / "AGENTS.md").read_text(encoding="utf-8")
|
||||
self.assertEqual(agents,
|
||||
(REPO / "AGENTS.md").read_text(encoding="utf-8"))
|
||||
self.assertIn("# Task Workflow", agents)
|
||||
|
||||
def test_pointer_replaces_the_old_full_copy(self):
|
||||
pointer = (self.tm / "CLAUDE.md").read_text(encoding="utf-8")
|
||||
self.assertIn("@AGENTS.md", pointer)
|
||||
self.assertNotEqual(pointer, OLD_BRIEF)
|
||||
|
||||
def test_core_updated_but_project_halves_untouched(self):
|
||||
self.assertEqual(
|
||||
(self.tm / "manager" / "core" / "VERSION").read_text(),
|
||||
"new-version\n")
|
||||
self.assertEqual(
|
||||
(self.tm / "manager" / "local" / "CLAUDE.md").read_text(
|
||||
encoding="utf-8"), OLD_LOCAL_NOTES)
|
||||
self.assertTrue((self.tm / "tasks" / "backlog" / "01-card.md").exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user