agent-manifesto-kit 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,578 @@
1
+ """Tests for roadmap.py: python3 -m unittest discover -s .claude/skills/roadmap/scripts"""
2
+ import contextlib
3
+ import datetime as dt
4
+ import io
5
+ import json
6
+ import os
7
+ import re
8
+ import shutil
9
+ import subprocess
10
+ import sys
11
+ import tempfile
12
+ import unittest
13
+ from pathlib import Path
14
+
15
+ sys.path.insert(0, str(Path(__file__).parent))
16
+ import roadmap # noqa: E402
17
+
18
+ SKILL = Path(roadmap.__file__).resolve().parents[1]
19
+
20
+ T0 = dt.datetime(2026, 10, 1, tzinfo=dt.timezone.utc)
21
+
22
+
23
+ def at(days):
24
+ return T0 + dt.timedelta(days=days)
25
+
26
+
27
+ def row(iid, status="backlog", parent=None, children=(), blocks=(), bars=()):
28
+ return {"id": iid, "status": status, "parent": parent, "children": list(children), "blocks": list(blocks),
29
+ "bars": [dict(b) for b in bars], "updated": T0, "type": "task"}
30
+
31
+
32
+ class MiniYaml(unittest.TestCase):
33
+ def test_item_subset(self):
34
+ text = ("id: LM-1\ntitle: 'It''s a title: with colon'\nstatus: done\ndescription: 'first line\n folded on\n\n"
35
+ " new paragraph'\ntags:\n- a\n- b\nlinks:\n blocks:\n - LM-2\n relates_to:\n - LM-3\n")
36
+ d = roadmap.mini_yaml(text)
37
+ self.assertEqual(d["title"], "It's a title: with colon")
38
+ self.assertEqual(d["description"], "first line folded on\nnew paragraph")
39
+ self.assertEqual(d["tags"], ["a", "b"])
40
+ self.assertEqual(d["links"], {"blocks": ["LM-2"], "relates_to": ["LM-3"]})
41
+
42
+
43
+ class Segments(unittest.TestCase):
44
+ def item(self, status, created=0, updated=9):
45
+ return {"created_at": roadmap.iso(at(created)), "updated_at": roadmap.iso(at(updated)), "status": status}
46
+
47
+ def test_reopen_is_rework_and_recommit_is_not(self):
48
+ hist = [(at(0), "backlog"), (at(1), "done"), (at(1), "done"), (at(2), "in_progress"), (at(3), "done")]
49
+ bars = roadmap.segments(self.item("done", updated=3), hist, at(5))
50
+ self.assertEqual([(b["kind"], b["s"], b["e"]) for b in bars],
51
+ [("work", at(0), at(1)), ("rework", at(2), at(3))])
52
+
53
+ def test_open_without_history_starts_at_creation(self):
54
+ bars = roadmap.segments(self.item("in_progress", created=0, updated=2), [], at(5))
55
+ self.assertEqual([(b["kind"], b["s"], b["e"]) for b in bars], [("ongoing", at(0), at(5))])
56
+
57
+
58
+ class CommitRework(unittest.TestCase):
59
+ def test_every_closed_gap_counts(self):
60
+ bars = [{"s": at(1), "e": at(2), "kind": "work", "closed": True},
61
+ {"s": at(5), "e": at(6), "kind": "rework", "closed": True}]
62
+ ticks = [(at(2) + dt.timedelta(hours=1), "a", "closing commit"), (at(3), "b", "fix after close"),
63
+ (at(5.5), "c", "inside the reopened bar"), (at(8), "d", "Merge branch x"), (at(9), "e", "late fix")]
64
+ out = roadmap.commit_rework(bars, ticks)
65
+ self.assertEqual([(b["s"] + dt.timedelta(minutes=30), b["e"]) for b in out], [(at(3), at(3)), (at(9), at(9))])
66
+
67
+
68
+ class CommitReworkFromHistory(unittest.TestCase):
69
+ def item(self, status, updated):
70
+ return {"created_at": roadmap.iso(at(0)), "updated_at": roadmap.iso(at(updated)), "status": status}
71
+
72
+ def test_rework_kept_after_reopen(self):
73
+ hist = [(at(0), "backlog"), (at(2), "done"), (at(6), "in_progress")]
74
+ bars = roadmap.segments(self.item("in_progress", 6), hist, at(7))
75
+ out = roadmap.commit_rework(bars, [(at(4), "a", "fix after close")])
76
+ self.assertEqual(len(out), 1)
77
+
78
+ def test_pause_is_not_a_closure(self):
79
+ hist = [(at(1), "in_progress"), (at(2), "ready"), (at(4), "in_progress"), (at(5), "done")]
80
+ bars = roadmap.segments(self.item("done", 5), hist, at(7))
81
+ self.assertEqual(roadmap.commit_rework(bars, [(at(3), "a", "work while paused")]), [])
82
+
83
+
84
+ class Schedule(unittest.TestCase):
85
+ def test_blocking_feature_finishes_with_its_children(self):
86
+ rows = {"LM-1": row("LM-1", "in_progress", children=["LM-2"], blocks=["LM-3"]),
87
+ "LM-2": row("LM-2", "backlog", parent="LM-1"), "LM-3": row("LM-3")}
88
+ self.assertEqual(roadmap.schedule(rows, {"plan": {"LM-2": {"estimate_days": 2}}}, at(0)), [])
89
+ self.assertEqual(rows["LM-3"]["bars"][-1]["s"], at(2))
90
+
91
+ def test_children_wait_for_their_parents_blockers(self):
92
+ rows = {"LM-1": row("LM-1", blocks=["LM-2"]), "LM-2": row("LM-2", children=["LM-3"]),
93
+ "LM-3": row("LM-3", parent="LM-2")}
94
+ roadmap.schedule(rows, {}, at(0))
95
+ self.assertEqual(rows["LM-3"]["bars"][-1]["s"], at(1))
96
+
97
+ def test_cycle_is_reported(self):
98
+ rows = {"LM-1": row("LM-1", blocks=["LM-2"]), "LM-2": row("LM-2", blocks=["LM-1"])}
99
+ cycles = roadmap.schedule(rows, {}, at(0))
100
+ self.assertEqual(cycles, [["LM-1", "LM-2", "LM-1"]])
101
+
102
+ def test_done_blocker_uses_its_actual_end(self):
103
+ rows = {"LM-1": row("LM-1", "done", blocks=["LM-2"], bars=[{"s": at(0), "e": at(3), "kind": "work"}]),
104
+ "LM-2": row("LM-2", "ready")}
105
+ roadmap.schedule(rows, {}, at(1))
106
+ self.assertEqual(rows["LM-2"]["bars"][-1]["s"], at(3))
107
+
108
+
109
+ class Phases(unittest.TestCase):
110
+ def test_leaves_size_and_problems(self):
111
+ rows = {"LM-1": row("LM-1", children=["LM-2", "LM-3"]), "LM-2": row("LM-2", "done", parent="LM-1"),
112
+ "LM-3": row("LM-3", "backlog", parent="LM-1"), "LM-4": row("LM-4", "done")}
113
+ phases = [{"title": "P", "blocks": [{"title": "A", "items": ["LM-1", "LM-9"]},
114
+ {"title": "B", "items": ["LM-4", "LM-1"], "size": 4},
115
+ {"title": "C", "size": 3}]}]
116
+ out, problems = roadmap.phase_progress(rows, phases)
117
+ a, b, c = out[0]["blocks"]
118
+ self.assertEqual((a["done"], a["total"], a["open"]), (1, 2, ["LM-3"]))
119
+ self.assertEqual((b["done"], b["total"]), (2, 4)) # LM-4 plus LM-1's leaves, raised to size 4
120
+ self.assertEqual((c["done"], c["total"], out[0]["done"], out[0]["total"]), (0, 3, 3, 9))
121
+ self.assertEqual(len(problems), 2) # LM-9 unknown, LM-1 in two blocks
122
+
123
+ def test_block_done_outside_taskpilot(self):
124
+ out, _ = roadmap.phase_progress({}, [{"title": "P", "blocks": [{"title": "T", "size": 3, "done": True}]}])
125
+ self.assertEqual((out[0]["done"], out[0]["total"], out[0]["blocks"][0]["open"]), (3, 3, []))
126
+
127
+
128
+ class PhaseOf(unittest.TestCase):
129
+ def test_nearest_listed_ancestor(self):
130
+ rows = {"LM-1": row("LM-1", children=["LM-2"]), "LM-2": row("LM-2", parent="LM-1", children=["LM-3"]),
131
+ "LM-3": row("LM-3", parent="LM-2"), "LM-4": row("LM-4"), "LM-5": row("LM-5")}
132
+ phases = [{"id": "a", "blocks": [{"title": "X", "items": ["LM-1"]}]},
133
+ {"id": "b", "blocks": [{"title": "Y", "items": ["LM-2", "LM-4"]}]}]
134
+ self.assertEqual(roadmap.phase_of(rows, phases), {"LM-1": "a", "LM-2": "b", "LM-3": "b", "LM-4": "b"})
135
+
136
+
137
+ class Prefixes(unittest.TestCase):
138
+ def test_idnum_sorts_numerically_across_widths(self):
139
+ ids = ["AV-100", "AV-9", "AV-20", "AV-1"]
140
+ self.assertEqual(sorted(ids, key=roadmap.idnum), ["AV-1", "AV-9", "AV-20", "AV-100"])
141
+ self.assertEqual(roadmap.idnum("PROJ-12"), 12)
142
+
143
+ def test_prefixes_come_from_item_ids(self):
144
+ self.assertEqual(roadmap.prefixes(["AV-1", "AV-20", "LM-3"]), ["AV", "LM"])
145
+
146
+ def test_phase_progress_and_phase_of_work_with_av_ids(self):
147
+ rows = {"AV-10": row("AV-10", children=["AV-9", "AV-100"]), "AV-9": row("AV-9", "done", parent="AV-10"),
148
+ "AV-100": row("AV-100", "backlog", parent="AV-10")}
149
+ out, problems = roadmap.phase_progress(rows, [{"title": "P", "blocks": [{"title": "A", "items": ["AV-10"]}]}])
150
+ self.assertEqual((out[0]["done"], out[0]["total"], out[0]["blocks"][0]["open"]), (1, 2, ["AV-100"]))
151
+ self.assertEqual(problems, [])
152
+ self.assertEqual(roadmap.phase_of(rows, [{"id": "a", "blocks": [{"title": "A", "items": ["AV-10"]}]}]),
153
+ {"AV-10": "a", "AV-9": "a", "AV-100": "a"})
154
+
155
+ def test_schedule_orders_by_number_not_text(self):
156
+ rows = {"AV-9": row("AV-9", blocks=["AV-100"]), "AV-100": row("AV-100")}
157
+ self.assertEqual(roadmap.schedule(rows, {}, at(0)), [])
158
+ self.assertEqual(rows["AV-100"]["bars"][-1]["s"], at(1))
159
+
160
+
161
+ ITEM = ("schema_version: 1\nid: {id}\ntitle: {title}\npriority: normal\ntype: {type}\nstatus: {status}\n"
162
+ "created_at: '{created}'\nupdated_at: '{updated}'\n{extra}")
163
+
164
+
165
+ def git_env(when):
166
+ env = dict(os.environ, GIT_AUTHOR_NAME="t", GIT_AUTHOR_EMAIL="t@t", GIT_COMMITTER_NAME="t",
167
+ GIT_COMMITTER_EMAIL="t@t", GIT_AUTHOR_DATE=when, GIT_COMMITTER_DATE=when)
168
+ return env
169
+
170
+
171
+ class Repo:
172
+ """A temp git repo with TaskPilot-style items (prefix AV) and a plan file."""
173
+
174
+ def __init__(self):
175
+ self.dir = Path(tempfile.mkdtemp(prefix="roadmap-test-"))
176
+ self.git("init", "-q", "-b", "main")
177
+ (self.dir / ".taskpilot" / "items").mkdir(parents=True)
178
+ (self.dir / "docs").mkdir()
179
+ self.item("AV-1", "Epic", "epic", "in_progress")
180
+ self.item("AV-2", "First task", "task", "done", parent="AV-1", extra="links:\n blocks:\n - AV-3\n")
181
+ self.item("AV-3", "Second task", "task", "backlog", parent="AV-1")
182
+ self.item("AV-4", "Loose task", "task", "ready")
183
+ self.item("AV-5", "Dropped", "task", "cancelled")
184
+ self.plan({"title": "Demo", "phases": [{"id": "p1", "title": "Phase 1", "goal": "g",
185
+ "blocks": [{"title": "Core", "items": ["AV-1"]},
186
+ {"title": "Later", "size": 2}]}],
187
+ "milestones": [{"date": "2026-10-03T00:00:00Z", "label": "Fork", "since": True}]})
188
+ self.commit("Start", "2026-10-01T10:00:00+00:00")
189
+ (self.dir / "work.txt").write_text("1")
190
+ self.commit("AV-2: first work", "2026-10-02T10:00:00+00:00")
191
+
192
+ def git(self, *args, when="2026-10-01T10:00:00+00:00"):
193
+ return subprocess.run(["git", *args], cwd=self.dir, env=git_env(when), capture_output=True, text=True,
194
+ check=True).stdout
195
+
196
+ def commit(self, msg, when):
197
+ self.git("add", "-A", when=when)
198
+ self.git("commit", "-q", "-m", msg, when=when)
199
+
200
+ def item(self, iid, title, typ, status, parent=None, extra="", created="2026-10-01T09:00:00Z",
201
+ updated="2026-10-02T09:00:00Z"):
202
+ extra = (f"parent_id: {parent}\n" if parent else "") + extra
203
+ (self.dir / ".taskpilot" / "items" / f"{iid}.yaml").write_text(ITEM.format(
204
+ id=iid, title=title, type=typ, status=status, created=created, updated=updated, extra=extra))
205
+
206
+ def plan(self, data):
207
+ (self.dir / "docs" / "roadmap_plan.json").write_text(json.dumps(data, indent=2))
208
+
209
+ def read_plan(self):
210
+ return json.loads((self.dir / "docs" / "roadmap_plan.json").read_text())
211
+
212
+ @property
213
+ def out(self):
214
+ return self.dir / "docs" / "roadmap.html"
215
+
216
+ def cli(self, *args):
217
+ """(exit code, stdout, stderr) of roadmap.main run in-process against this repo."""
218
+ out, err = io.StringIO(), io.StringIO()
219
+ with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
220
+ try:
221
+ code = roadmap.main([args[0], "--project", str(self.dir), *args[1:]])
222
+ except SystemExit as e:
223
+ code = e.code
224
+ return code or 0, out.getvalue(), err.getvalue()
225
+
226
+ def codes(self, *args):
227
+ code, out, _ = self.cli("check", "--json", *args)
228
+ data = json.loads(out)
229
+ assert (code == 0) == data["ok"], (code, data)
230
+ return sorted(p["code"] for p in data["problems"])
231
+
232
+ def cleanup(self):
233
+ shutil.rmtree(self.dir, ignore_errors=True)
234
+
235
+
236
+ def page_meta(html):
237
+ return re.search(r'<meta name="roadmap-template" content="([^"]+)">', html).group(1)
238
+
239
+
240
+ def page_data(html):
241
+ m = re.search(r'<script type="application/json" id="roadmap-data">(.*?)</script>', html, re.S)
242
+ return json.loads(m.group(1))
243
+
244
+
245
+ class RepoCase(unittest.TestCase):
246
+ def setUp(self):
247
+ self.repo = Repo()
248
+ self.addCleanup(self.repo.cleanup)
249
+
250
+
251
+ class Build(RepoCase):
252
+ def test_build_is_deterministic_and_follows_the_contract(self):
253
+ self.assertEqual(self.repo.cli("build")[0], 0)
254
+ first = self.repo.out.read_bytes()
255
+ self.assertEqual(self.repo.cli("build")[0], 0)
256
+ self.assertEqual(first, self.repo.out.read_bytes())
257
+ html = first.decode("utf-8")
258
+ self.assertNotIn("/*DATA*/", html)
259
+ self.assertNotIn("/*TEMPLATE*/", html)
260
+ self.assertEqual(page_meta(html), roadmap.template_id(roadmap.TEMPLATE))
261
+ self.assertRegex(page_meta(html), r"^1-[0-9a-f]{12}$")
262
+ self.assertIn("<title>Demo", html)
263
+ self.assertIn("JSON.parse", html)
264
+ data = page_data(html)
265
+ self.assertEqual((data["schema"], data["title"], data["lang"], data["id_prefixes"]), (1, "Demo", "en", ["AV"]))
266
+ for key in ("now", "milestones", "phases", "rows", "summary"):
267
+ self.assertIn(key, data)
268
+ self.assertEqual(data["milestones"][0]["since"], True)
269
+
270
+ def test_item_text_cannot_end_the_data_script(self):
271
+ text = "use <!-- <script> x </script> here"
272
+ self.repo.item("AV-9", "Tricky", "task", "backlog", extra="description: 'use <!-- <script> x </script> here'\n")
273
+ self.repo.cli("build")
274
+ html = self.repo.out.read_text(encoding="utf-8")
275
+ data_part = html.split('id="roadmap-data">', 1)[1].split("</script>", 1)[0]
276
+ self.assertNotIn("<", data_part)
277
+ self.assertIn(text, [r["desc"] for r in page_data(html)["rows"] if r["id"] == "AV-9"])
278
+
279
+ def test_summary_counts_shown_leaves_only(self):
280
+ self.repo.cli("build")
281
+ data = page_data(self.repo.out.read_text(encoding="utf-8"))
282
+ self.assertEqual(data["summary"], {"leaves": {"backlog": 1, "done": 1, "ready": 1}, "done": 1, "total": 3})
283
+ ids = [r["id"] for r in data["rows"]]
284
+ self.assertNotIn("AV-5", ids) # cancelled items are off the roadmap
285
+ self.assertIn("loose", ids)
286
+ self.assertEqual([p["done"] for p in data["phases"]], [1])
287
+ self.assertEqual(data["phases"][0]["total"], 4) # AV-1's two leaves, "Later" estimated at 2
288
+
289
+ def test_row_data_matches_items_and_commit_ticks(self):
290
+ self.repo.cli("build")
291
+ rows = {r["id"]: r for r in page_data(self.repo.out.read_text(encoding="utf-8"))["rows"]}
292
+ self.assertEqual(rows["AV-1"]["children"], ["AV-2", "AV-3"])
293
+ self.assertEqual(rows["AV-2"]["blocks"], ["AV-3"])
294
+ self.assertEqual([t[2] for t in rows["AV-2"]["ticks"]], ["AV-2: first work"])
295
+
296
+ def test_language_changes_the_loose_group_and_template_strings(self):
297
+ self.repo.cli("build")
298
+ en = self.repo.out.read_text(encoding="utf-8")
299
+ titles = {r["id"]: r["title"] for r in page_data(en)["rows"]}
300
+ self.assertEqual(titles["loose"], "No epic: standalone tasks")
301
+ plan = self.repo.read_plan()
302
+ plan["lang"] = "ru"
303
+ self.repo.plan(plan)
304
+ self.repo.cli("build")
305
+ ru = self.repo.out.read_text(encoding="utf-8")
306
+ self.assertEqual(page_data(ru)["lang"], "ru")
307
+ self.assertEqual({r["id"]: r["title"] for r in page_data(ru)["rows"]}["loose"], "Без эпика: отдельные задачи")
308
+ self.assertIn('lang="en"', en)
309
+ self.assertIn('document.documentElement.lang', ru)
310
+
311
+ def test_title_defaults_to_the_directory_name_and_out_overrides_the_path(self):
312
+ plan = self.repo.read_plan()
313
+ del plan["title"]
314
+ self.repo.plan(plan)
315
+ target = self.repo.dir / "elsewhere" / "r.html"
316
+ self.assertEqual(self.repo.cli("build", "--out", str(target))[0], 0)
317
+ self.assertEqual(page_data(target.read_text(encoding="utf-8"))["title"], self.repo.dir.name)
318
+ self.assertFalse(self.repo.out.exists())
319
+
320
+ def test_plan_keys_move_the_output_and_items(self):
321
+ plan = self.repo.read_plan()
322
+ plan["output"] = "site/r.html"
323
+ self.repo.plan(plan)
324
+ code, out, _ = self.repo.cli("path")
325
+ self.assertEqual((code, out.strip()), (0, "site/r.html"))
326
+ self.repo.cli("build")
327
+ self.assertTrue((self.repo.dir / "site" / "r.html").exists())
328
+
329
+ def test_build_prints_a_one_line_summary(self):
330
+ code, out, _ = self.repo.cli("build")
331
+ self.assertEqual(code, 0)
332
+ self.assertEqual(len(out.strip().splitlines()), 1)
333
+ self.assertIn("rows", out)
334
+
335
+
336
+ class Init(unittest.TestCase):
337
+ def setUp(self):
338
+ self.dir = Path(tempfile.mkdtemp(prefix="roadmap-init-"))
339
+ self.addCleanup(shutil.rmtree, self.dir, True)
340
+ subprocess.run(["git", "init", "-q", "-b", "main"], cwd=self.dir, check=True)
341
+ (self.dir / ".taskpilot" / "items").mkdir(parents=True)
342
+ (self.dir / ".taskpilot" / "items" / "XY-1.yaml").write_text(ITEM.format(
343
+ id="XY-1", title="One", type="task", status="backlog", created="2026-10-01T09:00:00Z",
344
+ updated="2026-10-01T09:00:00Z", extra=""))
345
+
346
+ def run_cli(self, *args):
347
+ out = io.StringIO()
348
+ with contextlib.redirect_stdout(out):
349
+ code = roadmap.main([args[0], "--project", str(self.dir), *args[1:]])
350
+ return code, out.getvalue()
351
+
352
+ def test_init_writes_a_skeleton_that_passes_check_after_the_first_build(self):
353
+ code, out = self.run_cli("init", "--title", "Shown", "--lang", "ru")
354
+ self.assertEqual(code, 0)
355
+ plan = json.loads((self.dir / "docs" / "roadmap_plan.json").read_text())
356
+ self.assertEqual((plan["title"], plan["lang"]), ("Shown", "ru"))
357
+ self.assertIn("build", out)
358
+ self.assertEqual(self.run_cli("build")[0], 0)
359
+ code, out = self.run_cli("check", "--json")
360
+ self.assertEqual((code, json.loads(out)["ok"]), (0, True))
361
+
362
+ def test_init_never_overwrites(self):
363
+ self.run_cli("init")
364
+ path = self.dir / "docs" / "roadmap_plan.json"
365
+ path.write_text('{"title": "mine"}')
366
+ code, _ = self.run_cli("init", "--title", "other")
367
+ self.assertEqual(code, 0)
368
+ self.assertEqual(path.read_text(), '{"title": "mine"}')
369
+
370
+
371
+ class PlanNotes(unittest.TestCase):
372
+ def test_underscore_keys_are_notes_everywhere(self):
373
+ plan = {"plan": {"_note": "x"}, "rework_of": {"_n": "free text"}, "_note": "y"}
374
+ self.assertEqual(roadmap.validate_plan(plan, set()), [])
375
+ self.assertEqual([c for c, _ in roadmap.validate_plan({"plan": {"AV-1": {}}}, set())], ["unknown-id"])
376
+
377
+
378
+ class Check(RepoCase):
379
+ def setUp(self):
380
+ super().setUp()
381
+ self.repo.cli("build")
382
+
383
+ def test_fresh_build_is_ok(self):
384
+ self.assertEqual(self.repo.codes(), [])
385
+ self.assertEqual(self.repo.cli("check")[0], 0)
386
+
387
+ def test_text_output_lists_problems_and_exits_1(self):
388
+ self.repo.out.unlink()
389
+ code, out, _ = self.repo.cli("check")
390
+ self.assertEqual(code, 1)
391
+ self.assertIn("output-missing", out)
392
+
393
+ def test_missing_output(self):
394
+ self.repo.out.unlink()
395
+ self.assertEqual(self.repo.codes(), ["output-missing"])
396
+
397
+ def test_stale_after_a_new_commit(self):
398
+ (self.repo.dir / "work.txt").write_text("2")
399
+ self.repo.commit("AV-3: more", "2026-10-05T10:00:00+00:00")
400
+ self.assertEqual(self.repo.codes(), ["output-stale"])
401
+
402
+ def test_hand_edited_html_is_stale(self):
403
+ self.repo.out.write_text(self.repo.out.read_text(encoding="utf-8").replace("Demo", "Hacked", 1), encoding="utf-8")
404
+ self.assertEqual(self.repo.codes(), ["output-stale"])
405
+
406
+ def test_html_without_the_contract_is_invalid(self):
407
+ self.repo.out.write_text("<html></html>", encoding="utf-8")
408
+ self.assertIn("output-invalid", self.repo.codes())
409
+
410
+ def test_plan_missing(self):
411
+ (self.repo.dir / "docs" / "roadmap_plan.json").unlink()
412
+ self.assertIn("plan-missing", self.repo.codes())
413
+
414
+ def test_plan_not_json(self):
415
+ (self.repo.dir / "docs" / "roadmap_plan.json").write_text("{nope")
416
+ self.assertIn("plan-json", self.repo.codes())
417
+
418
+ def test_unknown_and_cancelled_ids_in_phases(self):
419
+ plan = self.repo.read_plan()
420
+ plan["phases"][0]["blocks"][0]["items"] = ["AV-1", "AV-99", "AV-5"]
421
+ self.repo.plan(plan)
422
+ codes = self.repo.codes()
423
+ self.assertEqual(codes.count("unknown-id"), 2)
424
+
425
+ def test_id_in_two_blocks(self):
426
+ plan = self.repo.read_plan()
427
+ plan["phases"][0]["blocks"][1]["items"] = ["AV-1"]
428
+ self.repo.plan(plan)
429
+ self.assertIn("duplicate-item", self.repo.codes())
430
+
431
+ def test_phase_schema(self):
432
+ plan = self.repo.read_plan()
433
+ plan["phases"] = [{"id": "a", "title": "A", "blocks": [{"items": ["AV-1"]}]},
434
+ {"id": "a", "title": "B", "blocks": []}, {"id": "", "title": "C", "blocks": []},
435
+ {"id": "d", "title": "D", "blocks": [{"title": "X", "items": "AV-1"}]}]
436
+ self.repo.plan(plan)
437
+ codes = self.repo.codes()
438
+ self.assertGreaterEqual(codes.count("plan-schema"), 4) # block title, duplicate id, empty id, items type
439
+
440
+ def test_bad_dates_and_estimates(self):
441
+ plan = self.repo.read_plan()
442
+ plan["milestones"] = [{"date": "tomorrow", "label": "x"}]
443
+ plan["plan"] = {"AV-3": {"start": "2026-13-01", "end": "2026-10-09T00:00:00Z"},
444
+ "AV-4": {"estimate_days": -1}, "AV-99": {"estimate_days": 2}}
445
+ self.repo.plan(plan)
446
+ codes = self.repo.codes()
447
+ self.assertEqual(codes.count("bad-date"), 2)
448
+ self.assertEqual(codes.count("bad-estimate"), 1)
449
+ self.assertEqual(codes.count("unknown-id"), 1)
450
+
451
+ def test_unknown_rework_ids(self):
452
+ plan = self.repo.read_plan()
453
+ plan["rework_of"] = {"AV-3": ["AV-2"], "AV-98": ["AV-2"], "AV-4": ["AV-97"]}
454
+ self.repo.plan(plan)
455
+ self.assertEqual(self.repo.codes().count("unknown-id"), 2)
456
+
457
+ def test_template_changed_after_the_build(self):
458
+ tmp = Path(tempfile.mkdtemp(prefix="roadmap-tpl-"))
459
+ self.addCleanup(shutil.rmtree, tmp, True)
460
+ changed = tmp / "template.html"
461
+ changed.write_text(roadmap.TEMPLATE.read_text(encoding="utf-8") + "\n<!-- edited -->\n", encoding="utf-8")
462
+ old = roadmap.TEMPLATE
463
+ roadmap.TEMPLATE = changed
464
+ self.addCleanup(setattr, roadmap, "TEMPLATE", old)
465
+ self.assertIn("template-mismatch", self.repo.codes())
466
+
467
+ def test_drift_from_the_canonical_template(self):
468
+ tmp = Path(tempfile.mkdtemp(prefix="roadmap-tpl-"))
469
+ self.addCleanup(shutil.rmtree, tmp, True)
470
+ other = tmp / "canonical.html"
471
+ other.write_text(roadmap.TEMPLATE.read_text(encoding="utf-8") + "\n<!-- newer -->\n", encoding="utf-8")
472
+ self.assertEqual(self.repo.codes("--template-from", str(other)), ["template-drift"])
473
+ same = tmp / "same.html"
474
+ same.write_bytes(roadmap.TEMPLATE.read_bytes().replace(b"\n", b"\r\n")) # CRLF copies hash the same
475
+ self.assertEqual(self.repo.codes("--template-from", str(same)), [])
476
+
477
+
478
+ class TemplateId(unittest.TestCase):
479
+ def test_crlf_does_not_change_the_id(self):
480
+ d = Path(tempfile.mkdtemp())
481
+ self.addCleanup(shutil.rmtree, d, True)
482
+ (d / "a").write_bytes(b"x\ny\n")
483
+ (d / "b").write_bytes(b"x\r\ny\r\n")
484
+ self.assertEqual(roadmap.template_id(d / "a"), roadmap.template_id(d / "b"))
485
+ self.assertRegex(roadmap.template_id(d / "a"), r"^1-[0-9a-f]{12}$")
486
+
487
+
488
+ class Cli(RepoCase):
489
+ def test_subprocess_run_from_the_project_dir_defaults_to_the_git_toplevel(self):
490
+ script = Path(roadmap.__file__).resolve()
491
+ sub = self.repo.dir / "docs"
492
+ r = subprocess.run([sys.executable, str(script), "build"], cwd=sub, capture_output=True, text=True)
493
+ self.assertEqual(r.returncode, 0, r.stderr)
494
+ self.assertTrue(self.repo.out.exists())
495
+ r = subprocess.run([sys.executable, str(script), "check"], cwd=sub, capture_output=True, text=True)
496
+ self.assertEqual(r.returncode, 0, r.stdout)
497
+
498
+
499
+ class Hook(RepoCase):
500
+ def test_hook_rebuilds_and_commits_the_page_after_a_work_commit_on_main(self):
501
+ hook = self.repo.dir / ".git" / "hooks" / "post-commit"
502
+ shutil.copy(SKILL / "assets" / "post-commit.sh", hook)
503
+ hook.chmod(0o755)
504
+ env = dict(git_env("2026-10-06T10:00:00+00:00"), ROADMAP_PY=str(Path(roadmap.__file__).resolve()))
505
+ (self.repo.dir / "work.txt").write_text("3")
506
+ subprocess.run(["git", "add", "-A"], cwd=self.repo.dir, env=env, check=True)
507
+ subprocess.run(["git", "commit", "-q", "-m", "AV-3: hooked work"], cwd=self.repo.dir, env=env, check=True)
508
+ log = self.repo.git("log", "--format=%s", "-3").splitlines()
509
+ self.assertEqual(log[0], "Roadmap: rebuild docs/roadmap.html")
510
+ self.assertEqual(self.repo.git("status", "--porcelain"), "")
511
+ self.assertEqual(self.repo.codes(), [])
512
+ # a commit that names no id does nothing
513
+ (self.repo.dir / "work.txt").write_text("4")
514
+ subprocess.run(["git", "add", "-A"], cwd=self.repo.dir, env=env, check=True)
515
+ subprocess.run(["git", "commit", "-q", "-m", "plain change"], cwd=self.repo.dir, env=env, check=True)
516
+ self.assertEqual(self.repo.git("log", "--format=%s", "-1").strip(), "plain change")
517
+
518
+
519
+ class HookLocations(RepoCase):
520
+ def commit_with_hook(self, text, message):
521
+ hook = self.repo.dir / ".git" / "hooks" / "post-commit"
522
+ shutil.copy(SKILL / "assets" / "post-commit.sh", hook)
523
+ hook.chmod(0o755)
524
+ env = git_env("2026-10-06T10:00:00+00:00")
525
+ (self.repo.dir / "work.txt").write_text(text)
526
+ subprocess.run(["git", "add", "-A"], cwd=self.repo.dir, env=env, check=True)
527
+ return subprocess.run(["git", "commit", "-q", "-m", message], cwd=self.repo.dir, env=env,
528
+ capture_output=True, text=True)
529
+
530
+ def test_hook_finds_the_script_in_the_codex_skills_directory(self):
531
+ shutil.copytree(SKILL, self.repo.dir / ".agents" / "skills" / "roadmap",
532
+ ignore=shutil.ignore_patterns("__pycache__"))
533
+ self.commit_with_hook("5", "AV-3: codex layout")
534
+ self.assertEqual(self.repo.git("log", "--format=%s", "-1").strip(), "Roadmap: rebuild docs/roadmap.html")
535
+
536
+ def test_hook_says_so_when_the_script_is_missing(self):
537
+ done = self.commit_with_hook("6", "AV-3: nothing installed")
538
+ self.assertIn("roadmap.py not found", done.stderr)
539
+ self.assertEqual(self.repo.git("log", "--format=%s", "-1").strip(), "AV-3: nothing installed")
540
+
541
+
542
+ # Optional regression against the project this skill was generalised from: ROADMAP_LM_REPO=/path/to/last-man-isometry.
543
+ LM = Path(os.environ.get("ROADMAP_LM_REPO") or "/nonexistent")
544
+
545
+
546
+ @unittest.skipUnless((LM / "tools" / "roadmap" / "build.py").exists() and (LM / ".taskpilot" / "items").is_dir(),
547
+ "set ROADMAP_LM_REPO to the Last Man Iso repo to run this")
548
+ class LastManRegression(unittest.TestCase):
549
+ """The generalised builder reproduces the rows of the original LM-only builder."""
550
+
551
+ def test_rows_equal_the_original_builders(self):
552
+ now = "2026-10-29T12:00:00Z"
553
+ tmp = Path(tempfile.mkdtemp(prefix="roadmap-lm-"))
554
+ self.addCleanup(shutil.rmtree, tmp, True)
555
+ venv = LM / "tools" / ".venv" / "bin" / "python"
556
+ py = str(venv) if venv.exists() else sys.executable
557
+ old = subprocess.run([py, str(LM / "tools" / "roadmap" / "build.py"), "--out", str(tmp / "old.html"),
558
+ "--now", now], capture_output=True, text=True)
559
+ self.assertEqual(old.returncode, 0, old.stderr)
560
+ new = subprocess.run([sys.executable, str(Path(roadmap.__file__)), "build", "--project", str(LM),
561
+ "--out", str(tmp / "new.html"), "--now", now], capture_output=True, text=True)
562
+ self.assertEqual(new.returncode, 0, new.stderr)
563
+ text = (tmp / "old.html").read_text(encoding="utf-8")
564
+ old_data = json.loads(re.search(r"const DATA = (.*?);\nconst H = ", text, re.S).group(1))
565
+ new_data = page_data((tmp / "new.html").read_text(encoding="utf-8"))
566
+ for data in (old_data, new_data):
567
+ for r in data["rows"]:
568
+ if r["id"] == "loose":
569
+ r["title"] = ""
570
+ self.assertEqual(len(old_data["rows"]), len(new_data["rows"]))
571
+ for a, b in zip(old_data["rows"], new_data["rows"]):
572
+ self.assertEqual(a, b, a["id"])
573
+ self.assertEqual(old_data["phases"], new_data["phases"])
574
+ self.assertEqual(old_data["now"], new_data["now"])
575
+
576
+
577
+ if __name__ == "__main__":
578
+ unittest.main()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-manifesto-kit",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "CLI to discover and adopt Agent Manifesto Kit capabilities (skills, agents, pipelines) into your project for Claude, Codex, or AI-agnostic targets.",
5
5
  "type": "module",
6
6
  "bin": {