Files
pkgmgr/tests/unit/pkgmgr/actions/archive/test_inspect.py
Kevin Veen-Birkenbach a37b9ed8a7 feat(archive): add pkgmgr archive subcommand for task-tracked spec dirs
Walks a directory of numbered NNN-topic.md files, promotes every file
with zero unchecked task-list items into the directorys README under
the ## Archive section, then deletes the source file. Keeps spec
directories (typically docs/requirements) short and focused on open
work.

The action ships as pkgmgr.actions.archive with four leaf modules
(discovery, inspect, readme, workflow) and is wired into the CLI as
pkgmgr archive [DIR] [--readme PATH] [--dry-run] [--include-template].

Extracted verbatim from cli/contributing/requirements/archive in
infinito-nexus-core so every kpmx-managed repository can rely on the
same archival convention without copy-pasting helpers. Twenty unit
tests cover discovery, inspection, README merge, and end-to-end
workflow paths.

Also: realign tests/unit/pkgmgr/cli/commands/test_release.py with the
new run_release(retry=False) signature shipped in v1.14.0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-28 07:55:11 +02:00

63 lines
2.1 KiB
Python

"""Unit tests for `pkgmgr.actions.archive.inspect`."""
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from pkgmgr.actions.archive.inspect import count_unchecked_items, extract_h1
class TestExtractH1(unittest.TestCase):
def test_returns_first_h1_title(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "001-x.md"
path.write_text("\n# 001 - Title\n\n## Subsection\n# Later H1\n")
self.assertEqual(extract_h1(path), "001 - Title")
def test_returns_none_when_no_h1(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "001-x.md"
path.write_text("no heading here\n## h2 only\n")
self.assertIsNone(extract_h1(path))
class TestCountUncheckedItems(unittest.TestCase):
def test_zero_when_all_checked(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "001-x.md"
path.write_text(
"# 001 - Done\n\n## Acceptance Criteria\n\n- [x] A\n- [x] B\n"
)
self.assertEqual(count_unchecked_items(path), 0)
def test_counts_unchecked_anywhere_in_file(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "001-x.md"
path.write_text(
"# 001 - In progress\n\n"
"## Acceptance Criteria\n\n"
"- [x] A\n"
"- [ ] B\n\n"
"## Notes\n\n"
"- [ ] still tracking this one too\n"
" - [ ] nested unchecked\n"
)
self.assertEqual(count_unchecked_items(path), 3)
def test_ignores_non_task_dashes(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "001-x.md"
path.write_text(
"# 001 - X\n\n"
"- plain list item\n"
"- [x] checked\n"
"- not [ ] not a task marker\n"
)
self.assertEqual(count_unchecked_items(path), 0)
if __name__ == "__main__":
unittest.main()