Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s

This commit is contained in:
2026-11-19 12:42:03 +01:00
parent 8ca612b7a4
commit cb3135bc8c
124 changed files with 1437 additions and 793 deletions
+5 -3
View File
@@ -94,6 +94,7 @@ from plan_store.plans import no_item, PlanStore, TAGLINE, Written
from plan.release import parsed, Release, version as release_version
from plan_store.stores import store as plan_store
from plan.touches import predicted
from project_config.settings import ProjectConfig
from record_store.stores import RecordStore, store
from todo_item.table import shown, table
from todo_item.edits import with_bullet
@@ -104,16 +105,17 @@ LETTERS = ("L", "E", "I", "S")
NAMED = {"release": "Release", "blocked_by": BLOCKED_BY, "exempt": "Exempt", "tagline": TAGLINE, "moves": MOVES}
def main(argv: list[str], folder: pathlib.Path = pathlib.Path(), stdin: typing.TextIO = sys.stdin) -> int:
# plan_of is plan_store, but in the tests of a plan in Jira, which hand it a plan in memory.
def main(argv: list[str], folder: pathlib.Path, home: pathlib.Path, stdin: typing.TextIO, plan_of: typing.Callable[[ProjectConfig], PlanStore] = plan_store) -> int:
if argv[:1] in (["-h"], ["--help"]):
print(__doc__.strip())
return 0
args = parser().parse_args(argv)
config = located(str(folder), pathlib.Path.home())
config = located(str(folder), home)
if isinstance(config, Failure):
done: str | Failure = config
else:
plan = plan_store(config)
plan = plan_of(config)
match args.command:
case "list":
done = list_(args, plan)
+10 -10
View File
@@ -4,7 +4,6 @@ import pathlib
import sys
import tempfile
import unittest
import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent))
@@ -41,6 +40,9 @@ class TodoItem(unittest.TestCase):
self.addCleanup(temp.cleanup)
self.folder = pathlib.Path(temp.name)
self.config = configured(self, self.folder) / "config.toml"
self.home = self.config.parents[2]
# The plan main is handed in place of the one the config names.
self.plan_of = {}
self.todo = self.folder / "todo.md"
self.changelog = self.folder / "CHANGELOG.md"
(self.folder / "README.md").write_text(README)
@@ -52,16 +54,16 @@ class TodoItem(unittest.TestCase):
def run_main(self, *argv, stdin: str | io.StringIO = ""):
with contextlib.redirect_stdout(io.StringIO()) as out, contextlib.redirect_stderr(io.StringIO()) as err:
code = main.main(list(argv), self.folder, io.StringIO(stdin) if isinstance(stdin, str) else stdin)
code = main.main(list(argv), self.folder, self.home, io.StringIO(stdin) if isinstance(stdin, str) else stdin, **self.plan_of)
return code, out.getvalue(), err.getvalue()
def exit_code(self, *argv):
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()), self.assertRaises(SystemExit) as raised:
main.main(list(argv), self.folder, io.StringIO())
main.main(list(argv), self.folder, self.home, io.StringIO())
return raised.exception.code
def assert_ranked(self):
self.assertEqual(file_plan(located(str(self.folder), pathlib.Path.home()), self.todo).check(), [])
self.assertEqual(file_plan(located(str(self.folder), self.home), self.todo).check(), [])
def details(self):
text = self.todo.read_text()
@@ -275,9 +277,7 @@ class FinishInJira(TodoItem):
super().setUp()
self.config.write_text(self.config.read_text().replace('"checkout:todo.md"', f'"{JIRA_PLAN}"') + 'env-file = "~/acme.env"\n' + JIRA_SCORING)
self.plan = MemoryPlan({3: {"Release": "0.1.0", "Item": "**Count the runs.**", "L": "1", "E": "2", "I": "3", "S": "1"}})
patched = unittest.mock.patch.object(main, "plan_store", return_value=self.plan)
patched.start()
self.addCleanup(patched.stop)
self.plan_of = {"plan_of": lambda config: self.plan}
def test_finishes_without_either_flag_and_doesnt_touch_the_changelog(self):
self.changelog.write_text(CHANGELOG)
@@ -409,7 +409,7 @@ class List(TodoItem):
def test_fails_on_a_release_that_is_no_version(self):
errors = io.StringIO()
with contextlib.redirect_stderr(errors), self.assertRaises(SystemExit) as raised:
main.main(["list", "--release", "next"], self.folder, io.StringIO())
main.main(["list", "--release", "next"], self.folder, self.home, io.StringIO())
self.assertEqual(raised.exception.code, 2)
self.assertIn("argument --release: 'next' is not a semver version", errors.getvalue())
@@ -513,7 +513,7 @@ class UnreadableTouches(TodoItem):
def test_a_plan_in_jira_gets_no_unreadable_list_either(self):
self.config.write_text(self.config.read_text().replace('"checkout:todo.md"', f'"{JIRA_PLAN}"') + 'env-file = "~/acme.env"\n' + JIRA_SCORING)
plan = MemoryPlan({3: {"Release": "0.1.0", "Item": "**Count the runs.**", "L": "1", "E": "2", "I": "3", "S": "1"}})
self.enterContext(unittest.mock.patch.object(main, "plan_store", return_value=plan))
self.plan_of = {"plan_of": lambda config: plan}
detail = f"Touches:\n\n{UNREADABLE_BULLETS[0]}\n"
self.assertEqual(self.run_main(*ADD, stdin=detail)[:2], (1, ""))
self.assertEqual(self.run_main("edit", "3", "--detail", stdin=detail)[:2], (1, ""))
@@ -536,7 +536,7 @@ class Move(TodoItem):
class OtherFile(TodoItem):
def test_ranking_works_on_the_file_it_is_given_not_the_configured_plan(self):
config = located(str(self.folder), pathlib.Path.home())
config = located(str(self.folder), self.home)
other = self.folder / "other.md"
other.write_text("not a plan\n")
self.assertNotEqual(file_plan(config, other).check(), [])