Keep configs in ~/.config/build-release/ and tool state in ~/.local/state/build-release/, under XDG_* where set
CI / tests (pull_request) Successful in 6m34s

This commit is contained in:
2026-12-03 18:56:28 +01:00
parent 20c83f861f
commit 1ca2c8efe0
142 changed files with 1095 additions and 933 deletions
+3 -2
View File
@@ -1,3 +1,4 @@
from collections.abc import Mapping
import pathlib
from failure import Failure
@@ -7,11 +8,11 @@ from project_config.main import located
from record_store.stores import store
def history_changes(default: str, home: pathlib.Path) -> list[HistoryChange] | Failure:
def history_changes(default: str, home: pathlib.Path, env: Mapping[str, str]) -> list[HistoryChange] | Failure:
"""Each merged change on the default branch that touched the history, newest first. A Failure where no commit holds the history, as for one the project's config puts outside the checkout."""
if partial := full_history():
return partial
config = located(None, home)
config = located(None, home, env)
if isinstance(config, Failure):
return config
record = store(config, "comprehension-history")
+24 -24
View File
@@ -18,9 +18,9 @@ from larv_review.scoring_setup import removed_setup
Say = typing.Callable[[str], None]
def record_ruling(votes_file: pathlib.Path, home: pathlib.Path, now: float) -> str | Failure:
def record_ruling(votes_file: pathlib.Path, home: pathlib.Path, env: typing.Mapping[str, str], now: float) -> str | Failure:
"""Records the ruling the votes file's seats reach, and returns what the tool prints: the ruling and where it went, or which seats to launch where they split."""
read = read_seats(votes_file, True, home, now)
read = read_seats(votes_file, True, home, env, now)
if isinstance(read, Failure):
return read
heading_read, seats_read = read
@@ -35,25 +35,25 @@ def record_ruling(votes_file: pathlib.Path, home: pathlib.Path, now: float) -> s
if split(overall_votes):
return f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the votes file, and run this again."
ruled = ruling(overall_votes)
appended_to = append(seats_read.read, ruling_entry(heading_read.title, seats_read.seats, written, counts, ruled), home)
appended_to = append(seats_read.read, ruling_entry(heading_read.title, seats_read.seats, written, counts, ruled), home, env)
return appended_to if isinstance(appended_to, Failure) else f"Ruling: {ruled}. Overall votes as counted: {tally}.\n{appended_to}"
def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int], home: pathlib.Path, now: float, say: Say, warn: Say) -> Failure | None:
def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int], home: pathlib.Path, env: typing.Mapping[str, str], now: float, say: Say, warn: Say) -> Failure | None:
"""Records the scoring run the scores file holds in the comprehension history, and ranks the plan again. It says each result as soon as it has it, since a later step may fail after the run is recorded."""
read = read_seats(scores_file, False, home, now)
read = read_seats(scores_file, False, home, env, now)
if isinstance(read, Failure):
return read
named, given = read
scoring = scored_seats(given)
if isinstance(scoring, Failure):
return scoring
reasons = plan_reasons(default, ids, home)
reasons = plan_reasons(default, ids, home, env)
if isinstance(reasons, Failure):
return reasons
if not reasons:
return Failure("no plan item or release calls this scoring run; name the item IDs the chunk ships, as needs-scoring-run took them")
config = located(None, home)
config = located(None, home, env)
if isinstance(config, Failure):
return config
checkout = str(config.top)
@@ -61,7 +61,7 @@ def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int], home
if isinstance(todo, Failure):
return todo
plan = todo.items
appended_to = append(given.read, scoring_entry(named.title, scoring), home)
appended_to = append(given.read, scoring_entry(named.title, scoring), home, env)
if isinstance(appended_to, Failure):
return appended_to
say(appended_to)
@@ -70,14 +70,14 @@ def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int], home
say(f"Floor: {', '.join(under)} under the floor of {config.readability_floor}.")
if step := floor_step(scoring.means, plan, ids, config.readability_floor):
say(step)
reranked = rerank(home, warn)
removed = removed_setup(checkout, home)
reranked = rerank(home, env, warn)
removed = removed_setup(checkout, home, env)
return reranked or (removed and Failure(f"recorded the run, but {removed.reason}"))
def rerank(home: pathlib.Path, warn: Say) -> Failure | None:
def rerank(home: pathlib.Path, env: typing.Mapping[str, str], warn: Say) -> Failure | None:
"""Rank the project's todo.md again as rank_todo.py does, since the overall sets code health's weight, and fail where rank_todo.py would. The run stays recorded whatever happens, so those failures say to settle todo.md and run rank_todo.py on it, not to record the run again."""
config = located(None, home)
config = located(None, home, env)
if isinstance(config, Failure):
return config
todo = config.plan_file
@@ -102,13 +102,13 @@ def scored_seats(given: SeatsFile) -> ScoringRun | Failure:
return ScoringRun(given.seats, found, means(list(found.values())))
def read_seats(path: pathlib.Path, paired: bool, home: pathlib.Path, now: float) -> tuple[Heading, SeatsFile] | Failure:
def read_seats(path: pathlib.Path, paired: bool, home: pathlib.Path, env: typing.Mapping[str, str], now: float) -> tuple[Heading, SeatsFile] | Failure:
"""The heading the seats file's entry goes under, and the file, as decided says. Its callers run it first, so a file it refuses fails before anything is printed."""
try:
text = path.read_text(encoding="utf-8")
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"could not read {path}: {failure}")
history = history_file(home)
history = history_file(home, env)
if isinstance(history, Failure):
return history
return decided(text, now, paired, commit_exists, history)
@@ -129,8 +129,8 @@ def decided(text: str, now: float, paired: bool, commit_known: typing.Callable[[
return named, given
def read_places(home: pathlib.Path) -> str | Failure:
history = history_file(home)
def read_places(home: pathlib.Path, env: typing.Mapping[str, str]) -> str | Failure:
history = history_file(home, env)
return history if isinstance(history, Failure) else places_report(history[1])
@@ -139,20 +139,20 @@ def places_report(history: str) -> str:
return (latest_places(history) or "Seats found no places hard.").rstrip("\n")
def read_agreement(home: pathlib.Path) -> str | Failure:
history = history_file(home)
def read_agreement(home: pathlib.Path, env: typing.Mapping[str, str]) -> str | Failure:
history = history_file(home, env)
return history if isinstance(history, Failure) else agreement_report(history[1])
def history_file(home: pathlib.Path) -> tuple[RecordStore, str] | Failure:
def history_file(home: pathlib.Path, env: typing.Mapping[str, str]) -> tuple[RecordStore, str] | Failure:
"""The store the project's config names for its comprehension history, and the history's text, empty where there is none yet."""
held = held_history(home)
held = held_history(home, env)
return held if isinstance(held, Failure) else (held[0], held[1].text)
def held_history(home: pathlib.Path) -> tuple[RecordStore, Held] | Failure:
def held_history(home: pathlib.Path, env: typing.Mapping[str, str]) -> tuple[RecordStore, Held] | Failure:
"""The store the project's config names for its comprehension history, and the history as it stands, with the version a write over it names."""
config = located(None, home)
config = located(None, home, env)
if isinstance(config, Failure):
return config
history = store(config, "comprehension-history")
@@ -160,9 +160,9 @@ def held_history(home: pathlib.Path) -> tuple[RecordStore, Held] | Failure:
return held if isinstance(held, Failure) else (history, held)
def append(read: str, entry: str, home: pathlib.Path) -> str | Failure:
def append(read: str, entry: str, home: pathlib.Path, env: typing.Mapping[str, str]) -> str | Failure:
"""Appends entry and returns the line the tool prints; a Failure where the history already holds an entry on what the seats read."""
read_history = held_history(home)
read_history = held_history(home, env)
return read_history if isinstance(read_history, Failure) else appended_to(*read_history, read, entry)
+21 -20
View File
@@ -15,8 +15,8 @@ stderr; the other four exit 1.
The history is docs/comprehension-history.md in the checkout.
review-folder makes the chunk's review folder, where each reviewer writes its report, and prints its
path: ~/.local/state/larv-review/ followed by the worktree's path relative to ~, or to / outside it.
It leaves ~/.local/state/larv-review readable by you alone.
path: ~/.local/state/build-release/larv-review/ followed by the worktree's path relative to ~, or to / outside it.
It leaves ~/.local/state/build-release/larv-review readable by you alone.
ruling-base prints the commit a paired ruling reads against, then which of these found it. The last
measured commit is the default branch's newest merged change that adds a paired ruling or a scoring
@@ -165,6 +165,7 @@ when git cannot start, finds no checkout or no default branch, cannot fetch orig
needs-scoring-run, scoring-run-owed or record-scoring, or cannot read or write the history, todo.md, the review
folder or a file prepare-scoring reads.
"""
import os
import pathlib
import re
import sys
@@ -209,11 +210,11 @@ def are_ids(given: list[str]) -> bool:
def run_needs_scoring_run(given: list[str]) -> Failure | None:
return with_default_branch(lambda default: needs_scoring_run(default, [int(id_) for id_ in given], pathlib.Path.home()), stale_ok=False)
return with_default_branch(lambda default: needs_scoring_run(default, [int(id_) for id_ in given], pathlib.Path.home(), os.environ), stale_ok=False)
def run_record_scoring(given: list[str]) -> Failure | None:
return with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]], pathlib.Path.home(), time.time(), print, warn), stale_ok=False)
return with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]], pathlib.Path.home(), os.environ, time.time(), print, warn), stale_ok=False)
def fits_reviewer_header(given: list[str]) -> bool:
@@ -221,23 +222,23 @@ def fits_reviewer_header(given: list[str]) -> bool:
def run_reviewer_header(given: list[str]) -> Failure | None:
return with_default_branch(lambda default: printed(reviewer_header(default, given[0], given[1:] == ["--rerun"], pathlib.Path.home())), stale_ok=True)
return with_default_branch(lambda default: printed(reviewer_header(default, given[0], given[1:] == ["--rerun"], pathlib.Path.home(), os.environ)), stale_ok=True)
# One row per subcommand: main, USAGE and `--help` all read this table.
COMMANDS = {
"review-folder": Command("review-folder", no_arguments, lambda given: make_review_folder()),
"ruling-base": Command("ruling-base", no_arguments, lambda given: with_default_branch(lambda default: show_ruling_base(default, pathlib.Path.home()), stale_ok=False)),
"ruling-base": Command("ruling-base", no_arguments, lambda given: with_default_branch(lambda default: show_ruling_base(default, pathlib.Path.home(), os.environ), stale_ok=False)),
"round-count": Command("round-count", no_arguments, lambda given: with_default_branch(round_count, stale_ok=True)),
"needs-scoring-run": Command("needs-scoring-run [<item ID>...]", are_ids, run_needs_scoring_run, ids_from=0),
"scoring-run-owed": Command("scoring-run-owed", no_arguments, lambda given: with_default_branch(lambda default: owed(default, pathlib.Path.home()), stale_ok=False)),
"record-ruling": Command("record-ruling <votes file>", lambda given: len(given) == 1, lambda given: printed(record_ruling(pathlib.Path(given[0]), pathlib.Path.home(), time.time()))),
"scoring-run-owed": Command("scoring-run-owed", no_arguments, lambda given: with_default_branch(lambda default: owed(default, pathlib.Path.home(), os.environ), stale_ok=False)),
"record-ruling": Command("record-ruling <votes file>", lambda given: len(given) == 1, lambda given: printed(record_ruling(pathlib.Path(given[0]), pathlib.Path.home(), os.environ, time.time()))),
"prepare-scoring": Command("prepare-scoring", no_arguments, lambda given: prepared_scoring()),
"record-scoring": Command("record-scoring <scores file> [<item ID>...]", lambda given: bool(given) and are_ids(given[1:]), run_record_scoring, ids_from=1),
"places": Command("places", no_arguments, lambda given: printed(read_places(pathlib.Path.home()))),
"agreement": Command("agreement", no_arguments, lambda given: printed(read_agreement(pathlib.Path.home()))),
"places": Command("places", no_arguments, lambda given: printed(read_places(pathlib.Path.home(), os.environ))),
"agreement": Command("agreement", no_arguments, lambda given: printed(read_agreement(pathlib.Path.home(), os.environ))),
"reviewer-header": Command("reviewer-header <pass> [--rerun]", fits_reviewer_header, run_reviewer_header),
"round-title": Command("round-title <pass>", lambda given: len(given) == 1 and given[0] in REVIEWERS, lambda given: with_default_branch(lambda default: printed(round_title(default, given[0], pathlib.Path.home())), stale_ok=True)),
"round-title": Command("round-title <pass>", lambda given: len(given) == 1 and given[0] in REVIEWERS, lambda given: with_default_branch(lambda default: printed(round_title(default, given[0], pathlib.Path.home(), os.environ)), stale_ok=True)),
"reviewer-context": Command("reviewer-context", no_arguments, lambda given: printed(hook_reply(sys.stdin.read(), pathlib.Path.home()))),
}
SHAPES = " | ".join(command.shape for command in COMMANDS.values())
@@ -291,22 +292,22 @@ def with_default_branch(command: typing.Callable[[str], Failure | None], stale_o
def prepared_scoring() -> Failure | None:
worktree = top()
return worktree if isinstance(worktree, Failure) else printed(prepare_scoring(worktree, pathlib.Path.home()))
return worktree if isinstance(worktree, Failure) else printed(prepare_scoring(worktree, pathlib.Path.home(), os.environ))
def make_review_folder() -> Failure | None:
worktree = top()
if isinstance(worktree, Failure):
return worktree
folder = made_review_folder(worktree, pathlib.Path.home())
folder = made_review_folder(worktree, pathlib.Path.home(), os.environ)
if isinstance(folder, Failure):
return folder
print(folder)
return None
def show_ruling_base(default: str, home: pathlib.Path) -> Failure | None:
changes = history_changes(default, home)
def show_ruling_base(default: str, home: pathlib.Path, env: typing.Mapping[str, str]) -> Failure | None:
changes = history_changes(default, home, env)
if isinstance(changes, Failure):
return changes
if found := measured_commit(changes):
@@ -320,7 +321,7 @@ def show_ruling_base(default: str, home: pathlib.Path) -> Failure | None:
def round_count(default: str) -> Failure | None:
summaries = branch_summaries(default, pathlib.Path.home())
summaries = branch_summaries(default, pathlib.Path.home(), os.environ)
if isinstance(summaries, Failure):
return summaries
for name, count in round_counts(summaries).items():
@@ -334,15 +335,15 @@ def cap_note(count: int, most: int) -> str:
return f", {'at' if count == most else 'past'} the cap: no more rounds"
def owed(default: str, home: pathlib.Path) -> Failure | None:
unrecorded = owed_scoring_run(default, home, warn)
def owed(default: str, home: pathlib.Path, env: typing.Mapping[str, str]) -> Failure | None:
unrecorded = owed_scoring_run(default, home, env, warn)
if unrecorded is None:
print("No scoring run owed.")
return unrecorded
def needs_scoring_run(default: str, ids: list[int], home: pathlib.Path) -> Failure | None:
reasons = plan_reasons(default, ids, home)
def needs_scoring_run(default: str, ids: list[int], home: pathlib.Path, env: typing.Mapping[str, str]) -> Failure | None:
reasons = plan_reasons(default, ids, home, env)
if isinstance(reasons, Failure):
return reasons
print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.")
+3 -3
View File
@@ -12,12 +12,12 @@ from plan_store.plans import PlanStore
from record_store.stores import store
def owed_scoring_run(default: str, home: pathlib.Path, warn: typing.Callable[[str], None]) -> Failure | None:
def owed_scoring_run(default: str, home: pathlib.Path, env: typing.Mapping[str, str], warn: typing.Callable[[str], None]) -> Failure | None:
"""A Failure saying which scoring runs the chunk owes and has not recorded; None where it owes 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. Neither does one whose plan or history is outside the checkout: it warns that it cannot tell. 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.
"""
config = located(None, home)
config = located(None, home, env)
if isinstance(config, Failure):
return config
checkout = str(config.top)
@@ -33,7 +33,7 @@ def owed_scoring_run(default: str, home: pathlib.Path, warn: typing.Callable[[st
base = git("merge-base", default, "HEAD", cwd=checkout)
if isinstance(base, Failure):
return base
reasons = plan_reasons(base.strip(), None, home)
reasons = plan_reasons(base.strip(), None, home, env)
if isinstance(reasons, Failure):
return reasons
if not reasons:
+10 -9
View File
@@ -1,5 +1,6 @@
"""reviewer-header: write the branch diff, the places and the plan into the chunk's review folder, and print the header of a reviewer's prompt."""
import dataclasses
from collections.abc import Mapping
import pathlib
from git_cli.git_repo import branch_titles, git, top
@@ -80,18 +81,18 @@ def unanswered_round(titles: list[str], pass_: str) -> int | Failure:
return done + 1
def branch_summaries(default: str, home: pathlib.Path) -> list[str] | Failure:
def branch_summaries(default: str, home: pathlib.Path, env: Mapping[str, str]) -> list[str] | Failure:
"""The branch's commit titles since default, each read as its summary in the project's title templates, so round titles count under any template. rule-hook's round-cap reads them its own way: guarded, and counting zero rounds where git fails."""
titles = branch_titles(default)
if isinstance(titles, Failure):
return titles
templates = title_templates(None, home)
templates = title_templates(None, home, env)
return templates if isinstance(templates, Failure) else [templates.summary(title) for title in titles]
def reviewer_header(default: str, pass_: str, rerun: bool, home: pathlib.Path) -> str | Failure:
def reviewer_header(default: str, pass_: str, rerun: bool, home: pathlib.Path, env: Mapping[str, str]) -> str | Failure:
"""Writes the branch diff, the places and the plan's listing into the review folder, and returns the header that launches pass_'s reviewer in the pass's unanswered round, or its relaunch one rung up where rerun."""
summaries = branch_summaries(default, home)
summaries = branch_summaries(default, home, env)
round_ = summaries if isinstance(summaries, Failure) else unanswered_round(summaries, pass_)
if isinstance(round_, Failure):
return round_
@@ -100,10 +101,10 @@ def reviewer_header(default: str, pass_: str, rerun: bool, home: pathlib.Path) -
if failed is not None:
return failed
worktree, branch, head, base = (str(answer).strip() for answer in found)
folder = made_review_folder(worktree, home)
folder = made_review_folder(worktree, home, env)
if isinstance(folder, Failure):
return folder
config = located(None, home)
config = located(None, home, env)
if isinstance(config, Failure):
return config
principles, standards = config.paths["principles"], config.paths["standards"]
@@ -125,18 +126,18 @@ def reviewer_header(default: str, pass_: str, rerun: bool, home: pathlib.Path) -
launch = Launch(pass_, round_, rerun, pull_named(worktree, branch), worktree, branch, base, default, folder, folder / f"branch-{head}.diff", principles, standards, goals, folder / "plan.md", starts_bare(next((agent for name, agent in REVIEWERS.items() if name == pass_), ""), home), config.paths["working-rules"], decisions, config.language, config.coding_conventions)
if rerun and not launch.asked().exists():
return Failure(f"no report asked for a rerun of {pass_}'s round {round_}: {launch.asked()} is missing; relaunch before you commit the round's answers")
written = write_inputs(launch, base, home, plan_listing(plan_store(config)))
written = write_inputs(launch, base, home, env, plan_listing(plan_store(config)))
if isinstance(written, Failure):
return written
return launch.header()
def write_inputs(launch: Launch, base: str, home: pathlib.Path, listing: str) -> Failure | None:
def write_inputs(launch: Launch, base: str, home: pathlib.Path, env: Mapping[str, str], listing: str) -> Failure | None:
"""Writes the branch diff from base to HEAD, what `larv-review places` prints, and the plan's listing into the review folder."""
diff = git("diff", base, "HEAD", errors="replace")
if isinstance(diff, Failure):
return diff
history = history_file(home)
history = history_file(home, env)
if isinstance(history, Failure):
return history
try:
+4 -3
View File
@@ -1,4 +1,5 @@
"""round-title: print the opening of a round commit's title, counted from the round's report."""
from collections.abc import Mapping
import pathlib
from larv_review.reviewer_header import branch_summaries, unanswered_round
@@ -8,14 +9,14 @@ from review_rules.round_titles import round_prefix
from git_cli.git_repo import top
def round_title(default: str, pass_: str, home: pathlib.Path) -> str | Failure:
def round_title(default: str, pass_: str, home: pathlib.Path, env: Mapping[str, str]) -> str | Failure:
"""The title prefix of pass_'s unanswered round, counted from that round's report in the chunk's review folder."""
summaries = branch_summaries(default, home)
summaries = branch_summaries(default, home, env)
round_ = summaries if isinstance(summaries, Failure) else unanswered_round(summaries, pass_)
if isinstance(round_, Failure):
return round_
worktree = top()
if isinstance(worktree, Failure):
return worktree
findings = findings_in(standing_report(pathlib.Path(review_folder(str(home), worktree)), pass_, round_))
findings = findings_in(standing_report(pathlib.Path(review_folder(str(home), env, worktree)), pass_, round_))
return findings if isinstance(findings, Failure) else round_prefix(pass_, round_, findings)
+3 -2
View File
@@ -1,5 +1,6 @@
"""When the plan calls a scoring run: a chunk that ships a floor item, one that empties a release that work has already landed towards, or one after a release cut unmeasured; and each reason it gives."""
from collections.abc import Mapping
import pathlib
from release_plan.release_standing import Cut, LastCut, next_release, project_plan, standing_of, Unknown
@@ -79,9 +80,9 @@ def finished_unseen(config: ProjectConfig, ids: list[int], chunk: list[Item]) ->
return None
def plan_reasons(ref: str, ids: list[int] | None, home: pathlib.Path) -> list[str] | Failure:
def plan_reasons(ref: str, ids: list[int] | None, home: pathlib.Path, env: Mapping[str, str]) -> list[str] | Failure:
"""Why the plan calls a scoring run, from todo.md at ref and the checkout's, each file where the project's config puts it; empty where the project opts out of the comprehension check. ref is the default branch, or the commit where the chunk began. Where ids is None, the chunk ships each item the plan at ref holds and the checkout's does not."""
config = located(None, home)
config = located(None, home, env)
if isinstance(config, Failure):
return config
checkout = str(config.top)
+10 -9
View File
@@ -1,4 +1,5 @@
"""Set up a scoring run: the worktree its seats read and each seat's prompt, filled from skills/comprehension-panel/seat-prompts.md."""
from collections.abc import Mapping
import pathlib
import re
import shutil
@@ -127,18 +128,18 @@ def prompt_parts() -> dict[str, str] | Failure:
return parts
def scoring_folder(worktree: str, home: pathlib.Path) -> pathlib.Path:
return pathlib.Path(review_folder(str(home), worktree)) / "scoring"
def scoring_folder(worktree: str, home: pathlib.Path, env: Mapping[str, str]) -> pathlib.Path:
return pathlib.Path(review_folder(str(home), env, worktree)) / "scoring"
def prepare_scoring(worktree: str, home: pathlib.Path, run: Git = git) -> str | Failure:
def prepare_scoring(worktree: str, home: pathlib.Path, env: Mapping[str, str], run: Git = git) -> str | Failure:
"""Makes the scoring run's worktree at worktree's HEAD and writes each seat's prompt beside it, in the chunk's review folder; what it made, as the tool prints it."""
folder = scoring_folder(worktree, home)
folder = scoring_folder(worktree, home, env)
# A setup record-scoring never removed, as where the seats failed, would otherwise block every later run.
replaced = folder.exists()
if replaced and isinstance(removed := removed_setup(worktree, home, run), Failure):
if replaced and isinstance(removed := removed_setup(worktree, home, env, run), Failure):
return removed
config = located(worktree, home, run)
config = located(worktree, home, env, run)
if isinstance(config, Failure):
return config
source = config.paths["working-rules"]
@@ -170,7 +171,7 @@ def prepare_scoring(worktree: str, home: pathlib.Path, run: Git = git) -> str |
if isinstance(head, Failure):
return head
main = listing.splitlines()[0].removeprefix("worktree ")
made = made_review_folder(worktree, home)
made = made_review_folder(worktree, home, env)
if isinstance(made, Failure):
return made
checkout = folder / "checkout"
@@ -206,9 +207,9 @@ def prepare_scoring(worktree: str, home: pathlib.Path, run: Git = git) -> str |
return before + f"Scoring worktree, at {head.strip()}: {checkout}\nPrompts, each for one {SEAT_AGENT} agent:\n" + "\n".join(written)
def removed_setup(worktree: str, home: pathlib.Path, run: Git = git) -> Failure | None:
def removed_setup(worktree: str, home: pathlib.Path, env: Mapping[str, str], run: Git = git) -> Failure | None:
"""Removes the scoring worktree and prompts prepare_scoring made for the chunk at worktree, where they exist."""
folder = scoring_folder(worktree, home)
folder = scoring_folder(worktree, home, env)
if not folder.exists():
return None
if (folder / "checkout").exists() and isinstance(removed := run("worktree", "remove", "--force", str(folder / "checkout"), cwd=worktree), Failure):
+21 -21
View File
@@ -512,7 +512,7 @@ class LarvReviewTool(unittest.TestCase):
self.git("remote", "set-head", "origin", "main")
self.git("switch", "-q", "-c", "chunk")
self.start = self.git("rev-parse", "--short", "HEAD").strip()
self.config = root / ".claude-projects" / "proj" / "config.toml"
self.config = root / ".config/build-release" / "proj" / "config.toml"
self.config.parent.mkdir(parents=True)
self.config.write_text(PROJECT_CONFIG)
(root / "principles").mkdir()
@@ -613,16 +613,16 @@ class LarvReviewTool(unittest.TestCase):
(self.config.parent / "todo.md").write_text(todo(row, "| 2 | 0.2.0 | | **Reach the comprehension floor: do it.** | 1 | 1 | 3 | 1 | 1 | 1 | 9.0 |"))
self.addCleanup(os.chdir, os.getcwd())
os.chdir(self.checkout)
home = self.config.parents[2]
self.assertEqual(plan_reasons("origin/main", [2], home), ["ships item 2, a floor item", "leaves release 0.2.0 with no plan item"])
home = self.config.parents[3]
self.assertEqual(plan_reasons("origin/main", [2], home, {}), ["ships item 2, a floor item", "leaves release 0.2.0 with no plan item"])
(self.config.parent / "decisions.md").write_text("# Decisions\n\n## review opt-out: the comprehension check\n\nServes goal 1.\n")
self.assertEqual(plan_reasons("origin/main", [2], home), [])
self.assertEqual(plan_reasons("origin/main", [2], home, {}), [])
(self.config.parent / "decisions.md").unlink()
gone = plan_reasons("origin/main", [1, 7], home)
gone = plan_reasons("origin/main", [1, 7], home, {})
assert isinstance(gone, Failure), gone
self.assertEqual(gone.reason, f"the plan as it stands holds no item 7, and larv-review doesn't support a plan outside the checkout, so it cannot read the plan as it stood before the item was finished: {self.config.parent}/todo.md")
(self.config.parent / "todo.md").write_bytes(b"\xff")
unreadable = plan_reasons("origin/main", [2], home)
unreadable = plan_reasons("origin/main", [2], home, {})
assert isinstance(unreadable, Failure), unreadable
self.assertEqual(unreadable.reason, f"the project's plan: {self.config.parent}/todo.md: not UTF-8")
@@ -782,7 +782,7 @@ class LarvReviewTool(unittest.TestCase):
def test_refuses_where_the_default_branchs_unreleased_changes_cannot_be_read(self):
self.addCleanup(os.chdir, os.getcwd())
os.chdir(self.checkout)
self.assertIsInstance(plan_reasons("no-such-ref", [], pathlib.Path.home()), Failure)
self.assertIsInstance(plan_reasons("no-such-ref", [], pathlib.Path.home(), {}), Failure)
def test_refuses_a_checkout_plan_whose_renamed_section_does_not_parse(self):
self.commit("Break the mark", {"todo.md": todo("| 1 | 0.2.0 | | **Do it.** | 1 | 1 | 3 | 1 | 1 | 1 | 9.0 |") + "\n## Renamed\n\nsoon\n"})
@@ -935,7 +935,7 @@ class LarvReviewTool(unittest.TestCase):
self.plan()
ran = self.record_sevens()
self.assertEqual(ran.returncode, 0, ran.stderr)
self.assertFalse((self.checkout.parent / ".local" / "state" / "larv-review" / "proj" / "scoring").exists())
self.assertFalse((self.checkout.parent / ".local" / "state" / "build-release" / "larv-review" / "proj" / "scoring").exists())
self.assertEqual(len(self.git("worktree", "list").splitlines()), 1)
VALUES = {"AGENTS.md": "## Scoring run\n\n- Language: Python\n- Kind: a CLI\n- Domain: parsing\n- Domain docs: the spec\n- 3am question: the parse hangs\n"}
@@ -991,7 +991,7 @@ class LarvReviewTool(unittest.TestCase):
(checkout / "todo.md").write_text("the owners' own notes\n")
self.enterContext(contextlib.chdir(checkout))
said: list[str] = []
self.assertIsNone(rerank(config.parents[2], said.append))
self.assertIsNone(rerank(config.parents[3], {}, said.append))
self.assertEqual((said, (checkout / "todo.md").read_text()), ([], "the owners' own notes\n"))
def test_reranks_todo_md_by_the_overall_it_records(self):
@@ -1044,21 +1044,21 @@ class LarvReviewTool(unittest.TestCase):
self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "No scoring run due.\n")
def test_makes_and_prints_the_worktrees_review_folder_from_anywhere_in_it(self):
reports = self.checkout.parent / ".local" / "state" / "larv-review"
reports = self.checkout.parent / ".local" / "state" / "build-release" / "larv-review"
(self.checkout / "sub").mkdir()
ran = subprocess.run([sys.executable, str(TOOL), "review-folder"], capture_output=True, cwd=self.checkout / "sub", env=self.env, text=True)
self.assertEqual((ran.returncode, ran.stdout), (0, f"{reports}/proj\n"), ran.stderr)
self.assertTrue((reports / "proj").is_dir())
def test_leaves_the_reports_folder_readable_by_the_user_alone_where_it_was_not(self):
reports = self.checkout.parent / ".local" / "state" / "larv-review"
reports = self.checkout.parent / ".local" / "state" / "build-release" / "larv-review"
reports.mkdir(parents=True, mode=0o755)
self.assertEqual(self.run_tool("review-folder").returncode, 0)
self.assertEqual(reports.stat().st_mode & 0o777, 0o700)
def test_fails_where_it_cannot_make_the_review_folder(self):
(self.checkout.parent / ".local" / "state").mkdir(parents=True)
(self.checkout.parent / ".local" / "state" / "larv-review").write_text("")
(self.checkout.parent / ".local" / "state" / "build-release").mkdir(parents=True)
(self.checkout.parent / ".local" / "state" / "build-release" / "larv-review").write_text("")
ran = self.run_tool("review-folder")
self.assertEqual(ran.returncode, 1)
self.assertIn("could not make the review folder", ran.stderr)
@@ -1125,7 +1125,7 @@ class LarvReviewTool(unittest.TestCase):
self.commit("Unpushed fix", {"a.txt": "two\n"})
short = self.git("rev-parse", "--short", "HEAD").strip()
base = self.git("rev-parse", self.start).strip()
folder = self.checkout.parent / ".local" / "state" / "larv-review" / "proj"
folder = self.checkout.parent / ".local" / "state" / "build-release" / "larv-review" / "proj"
ran = self.run_tool("reviewer-header", "stability")
self.assertEqual((ran.returncode, ran.stdout), (0, (
"Pass: stability, round 1.\n"
@@ -1152,7 +1152,7 @@ class LarvReviewTool(unittest.TestCase):
def test_counts_the_round_from_the_branchs_answers_and_names_the_report_that_asked_for_a_rerun(self):
self.commit("Answer prose round 1: a")
folder = self.checkout.parent / ".local" / "state" / "larv-review" / "proj"
folder = self.checkout.parent / ".local" / "state" / "build-release" / "larv-review" / "proj"
missing = self.run_tool("reviewer-header", "prose", "--rerun")
self.assertEqual(missing.returncode, 1)
self.assertIn(f"{folder}/prose-round-2.md is missing", missing.stderr)
@@ -1166,7 +1166,7 @@ class LarvReviewTool(unittest.TestCase):
self.assertFalse(any(line.startswith("Places:") for line in lines), "only architecture and stability take the places")
def test_round_title_counts_the_unanswered_rounds_report_and_names_one_that_is_missing(self):
folder = self.checkout.parent / ".local" / "state" / "larv-review" / "proj"
folder = self.checkout.parent / ".local" / "state" / "build-release" / "larv-review" / "proj"
folder.mkdir(parents=True)
(folder / "prose-round-1.md").write_text("BLOCK\n\n### 🔴 [misread] `a.md:1`: wrong\n\n### 🟡 `b.md:2`: worse\n\n### 🟢 `c.md:3`: nit\n")
ran = self.run_tool("round-title", "prose")
@@ -1192,7 +1192,7 @@ class LarvReviewTool(unittest.TestCase):
def test_reviewer_header_leaves_an_unchanged_diff_places_and_plan_untouched_so_an_earlier_rounds_replay_keeps_them(self):
self.commit("Work", {"a.txt": "one\n"})
folder = self.checkout.parent / ".local" / "state" / "larv-review" / "proj"
folder = self.checkout.parent / ".local" / "state" / "build-release" / "larv-review" / "proj"
self.assertEqual(self.run_tool("reviewer-header", "stability").returncode, 0)
written = [folder / f"branch-{self.git('rev-parse', '--short', 'HEAD').strip()}.diff", folder / "places.md", folder / "plan.md"]
for path in written:
@@ -1229,8 +1229,8 @@ class LarvReviewTool(unittest.TestCase):
detached = self.run_tool("reviewer-header", "prose")
self.assertEqual((detached.returncode, detached.stdout), (1, ""))
self.git("switch", "-q", "chunk")
(self.checkout.parent / ".local" / "state").mkdir(parents=True)
(self.checkout.parent / ".local" / "state" / "larv-review").write_text("")
(self.checkout.parent / ".local" / "state" / "build-release").mkdir(parents=True)
(self.checkout.parent / ".local" / "state" / "build-release" / "larv-review").write_text("")
unmade = self.run_tool("reviewer-header", "prose")
self.assertEqual(unmade.returncode, 1)
self.assertIn("could not make the review folder", unmade.stderr)
@@ -1267,7 +1267,7 @@ class LarvReviewTool(unittest.TestCase):
def test_reviewer_header_fails_naming_the_epic_where_it_cannot_read_goals_kept_in_jira(self):
# Port 1 on the loopback refuses the connection, so the read fails without leaving the machine.
epic = "jira:https://127.0.0.1:1/browse/ABC-12"
credentials = self.config.parents[2] / "acme.env"
credentials = self.config.parents[3] / "acme.env"
credentials.write_text("ATLASSIAN_EMAIL=me@example.com\nATLASSIAN_API_TOKEN=s3cret\n")
credentials.chmod(0o600)
self.config.write_text(PROJECT_CONFIG.replace('"checkout:todo.md"', f'"{epic}"').replace('"checkout:README.md"', f'"{epic}"') + 'env-file = "~/acme.env"\njira-score-formula = "V"\njira-score-bar = 1\n')
@@ -1317,7 +1317,7 @@ class LarvReviewTool(unittest.TestCase):
self.assertIn(f"{self.checkout}/CONVENTIONS.md is not a file; {self.config} sets it in `coding-conventions`", ran.stderr)
def test_reviewer_header_gives_the_architect_the_places(self):
folder = self.checkout.parent / ".local" / "state" / "larv-review" / "proj"
folder = self.checkout.parent / ".local" / "state" / "build-release" / "larv-review" / "proj"
self.assertEqual(self.header_line("Places:", "architecture"), f"Places: {folder}/places.md")
def test_reviewer_header_names_the_file_that_holds_the_principles_last_where_the_project_keeps_one(self):
+6 -6
View File
@@ -104,7 +104,7 @@ class PrepareScoring(unittest.TestCase):
def prepare(self):
"""What prepare-scoring returns in the checkout, run in this process so mutation tests see the lines it runs."""
return prepare_scoring(str(self.checkout), self.root, functools.partial(git, env=self.env))
return prepare_scoring(str(self.checkout), self.root, {}, functools.partial(git, env=self.env))
def run_tool(self, *args):
return subprocess.run([sys.executable, str(TOOL), *args], capture_output=True, cwd=self.checkout, env=self.env, text=True)
@@ -112,7 +112,7 @@ class PrepareScoring(unittest.TestCase):
def test_writes_each_seats_prompt_with_every_placeholder_filled_and_a_worktree_at_head(self):
self.commit("# A\n\n## Scoring run\n\n- Language: Python\n- Kind: a CLI\n- Domain: parsing\n- Domain docs: the spec\n- 3am question: the parse hangs\n")
ran = self.prepare()
folder = self.root / ".local" / "state" / "larv-review" / "proj" / "scoring"
folder = self.root / ".local" / "state" / "build-release" / "larv-review" / "proj" / "scoring"
worktree = folder / "checkout"
prompts = [folder / f"{seat}.md" for seat in ("junior-a", "mid-a", "maintainability-senior", "inherited-architect")]
self.assertEqual(ran, f"Scoring worktree, at {self.git('rev-parse', '--short', 'HEAD').strip()}: {worktree}\nPrompts, each for one comprehension-seat agent:\n" + "\n".join(str(prompt) for prompt in prompts))
@@ -137,9 +137,9 @@ class PrepareScoring(unittest.TestCase):
def test_says_it_could_not_remove_a_checkout_git_does_not_hold(self):
self.commit()
checkout = self.root / ".local" / "state" / "larv-review" / "proj" / "scoring" / "checkout"
checkout = self.root / ".local" / "state" / "build-release" / "larv-review" / "proj" / "scoring" / "checkout"
checkout.mkdir(parents=True)
removed = removed_setup(str(self.checkout), self.root, functools.partial(git, env=self.env))
removed = removed_setup(str(self.checkout), self.root, {}, functools.partial(git, env=self.env))
self.assertIsInstance(removed, Failure)
self.assertTrue(removed.reason.startswith(f"could not remove the scoring worktree {checkout}: "), removed.reason)
self.assertTrue(checkout.exists())
@@ -176,7 +176,7 @@ class PrepareScoring(unittest.TestCase):
ran = self.prepare()
assert isinstance(ran, str), ran
self.assertIn("Your background: ~2 years in Go, first codebase of this kind (a CLI)", pathlib.Path(ran.splitlines()[2]).read_text())
self.assertIsNone(removed_setup(str(self.checkout), self.root, functools.partial(git, env=self.env)))
self.assertIsNone(removed_setup(str(self.checkout), self.root, {}, functools.partial(git, env=self.env)))
def test_keeps_the_working_rules_values_where_the_checkout_has_seat_prompts_too(self):
own = self.checkout / "skills" / "comprehension-panel" / "seat-prompts.md"
@@ -192,7 +192,7 @@ class PrepareScoring(unittest.TestCase):
ran = self.run_tool("prepare-scoring")
self.assertEqual(ran.returncode, 1)
self.assertIn("AGENTS.md has no \"Scoring run\" section", ran.stderr)
self.assertFalse((self.root / ".local" / "state" / "larv-review" / "proj" / "scoring").exists())
self.assertFalse((self.root / ".local" / "state" / "build-release" / "larv-review" / "proj" / "scoring").exists())
self.assertEqual(len(self.git("worktree", "list").splitlines()), 1)
def test_fails_before_it_makes_the_worktree_where_a_file_it_reads_does_not_decode(self):