Read the plan and the records where the config puts them in chunk-preflight and larv-review
This commit is contained in:
+19
-11
@@ -1,9 +1,11 @@
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from larv_review.plan import EMPTIED_WORDS, plan_reasons
|
||||
from review_rules.comprehension_history import entries, HISTORY
|
||||
from project_config.main import project
|
||||
from review_rules.comprehension_history import entries
|
||||
from failure import Failure
|
||||
from git_cli.git_repo import file_at, git, top
|
||||
from git_cli.git_repo import file_at, git
|
||||
from release_plan.todo_table import items, NoItemsTable
|
||||
|
||||
|
||||
@@ -12,10 +14,16 @@ def owed_scoring_run(default: str) -> Failure | None:
|
||||
|
||||
The chunk owes the runs `plan_reasons` calls, two where it empties a release, else one. It has recorded the scoring runs its committed history holds beyond those at the merge base, so a default branch that has moved on since the branch began doesn't count. A project with no plan owes none. A missing run blocks the merge and a low score never does, which keeps the decision `review: the comprehension check records …`: it bars only scores from blocking.
|
||||
"""
|
||||
checkout = top()
|
||||
if isinstance(checkout, Failure):
|
||||
return checkout
|
||||
if not has_plan(checkout):
|
||||
config = project()
|
||||
if isinstance(config, Failure):
|
||||
return config
|
||||
checkout = str(config.top)
|
||||
if not has_plan(config.paths["plan"]):
|
||||
return None
|
||||
history = config.tracked("comprehension-history")
|
||||
if history is None:
|
||||
# No commit holds a history outside the checkout, so the runs the branch recorded cannot be counted; the merge goes on, as `docs/decisions.md` → "project config: a tool that reads a file's commits …" says.
|
||||
print(f"larv-review doesn't support a comprehension history outside the checkout, so it cannot tell whether the chunk owes a scoring run: {config.paths['comprehension-history']}", file=sys.stderr)
|
||||
return None
|
||||
base = git("merge-base", default, "HEAD", cwd=checkout)
|
||||
if isinstance(base, Failure):
|
||||
@@ -25,10 +33,10 @@ def owed_scoring_run(default: str) -> Failure | None:
|
||||
return reasons
|
||||
if not reasons:
|
||||
return None
|
||||
before = file_at(base.strip(), HISTORY, checkout)
|
||||
before = file_at(base.strip(), history, checkout)
|
||||
if isinstance(before, Failure):
|
||||
return before
|
||||
after = file_at("HEAD", HISTORY, checkout)
|
||||
after = file_at("HEAD", history, checkout)
|
||||
if isinstance(after, Failure):
|
||||
return after
|
||||
return shortfall(reasons, len(scoring_runs(after)) - len(scoring_runs(before)))
|
||||
@@ -42,10 +50,10 @@ def shortfall(reasons: list[str], recorded: int) -> Failure | None:
|
||||
return Failure(f"the chunk owes {needed} scoring run{'s' if needed > 1 else ''} and the branch's committed history records {max(recorded, 0)}: it {' and '.join(reasons)}. larv-review's SKILL.md → 'Scoring run' says how to run and record {'them' if needed > 1 else 'it'}{"; → 'Second run' says how the second is titled" if needed > 1 else ""}")
|
||||
|
||||
|
||||
def has_plan(checkout: str) -> bool:
|
||||
"""Whether the checkout has a todo.md holding an items table. A file that can't be read counts, so `plan_reasons` reports it."""
|
||||
def has_plan(todo: pathlib.Path) -> bool:
|
||||
"""Whether todo, the project's plan, exists and holds an items table. A file that can't be read counts, so `plan_reasons` reports it."""
|
||||
try:
|
||||
return not isinstance(items(pathlib.Path(checkout, "todo.md").read_text(encoding="utf-8")), NoItemsTable)
|
||||
return not isinstance(items(todo.read_text(encoding="utf-8")), NoItemsTable)
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
except (OSError, UnicodeDecodeError):
|
||||
|
||||
Reference in New Issue
Block a user