Answer stability round 1: 0 🔴, 1 🟡 (0 misread); split the re-rank into the pure rank_moves, rank only just before, as the item says, and name ranking in the README and the protocol

This commit is contained in:
2026-11-18 19:56:29 +01:00
parent 7bd192735a
commit ddce0f2cb0
10 changed files with 93 additions and 57 deletions
+37 -18
View File
@@ -60,35 +60,54 @@ def ranked(items: list[EpicItem], formula: str, epic_goals: str, repos: dict[str
return blockers_first(scored)
def reranked(store: EpicStore, order: list[str]) -> None | Failure:
"""Ranks the epic's child issues named in order, each one the loop filed, so the tracker's backlog lists them in order. Each other child issue, such as one a person filed, keeps its slot; the slots of the named issues take them in order's order. A sub-task holds no slot and follows its parent.
@dataclasses.dataclass(frozen=True)
class Rank:
"""One rank to ask of a tracker: the issue named key just before the issue named before."""
key: str
before: str
The walk goes from the backlog's end: an issue not just before the one that follows it in the target ranks just before that one, so only the loop's issues move. The target's last issue, where it isn't already last, ranks just after the issue that is. A rank the tracker refuses stops the walk, which fails naming it, since a wrongly ranked team backlog takes hours to restore; the ranks made before it stay."""
def reranked(store: EpicStore, order: list[str]) -> None | Failure:
"""Re-ranks the tracker's backlog so that the child issues whose keys order lists come in that sequence. Each key must name a child issue the loop filed, and only once; otherwise the call fails before it ranks any issue. The listed issues change positions only with each other: every other child issue, such as one a person filed, stays at its position in the backlog. A sub-task has no position of its own and follows its parent.
The first rank the tracker refuses ends the re-rank with a Failure that names it, since a wrongly ranked team backlog takes hours to restore; the ranks made before it stay."""
read = store.read()
if isinstance(read, Failure):
return read
children = [issue for issue in read if issue.parent == store.epic_key]
if stray := next((key for key in order if key not in {issue.key for issue in children if issue.by_loop}), None):
ours = {issue.key for issue in children if issue.by_loop}
if stray := next((key for key in order if key not in ours), None):
return Failure(f"{stray} is not one of the child issues of the epic {store.epic_key} that the loop filed, so the backlog was not re-ranked")
if twice := next((key for key in order if order.count(key) > 1), None):
return Failure(f"the order names {twice} twice, so the backlog was not re-ranked")
now = [issue.key for issue in children]
slots = iter(order)
target = [next(slots) if key in order else key for key in now]
for place in reversed(range(len(target))):
key = target[place]
at = now.index(key)
# The slices are empty past the end, so the last issue already in place is skipped too.
if key not in order or now[at + 1:at + 2] == target[place + 1:place + 2]:
continue
other, after = (now[-1], True) if place == len(target) - 1 else (target[place + 1], False)
if refused := store.rank(key, other, after):
return Failure(f"cannot rank {key} just {'after' if after else 'before'} {other}: {refused.reason}; the re-rank stopped there, so rank the loop's issues in {store.epic_key}'s backlog by hand as {', '.join(order)}")
now.remove(key)
now.insert(now.index(other) + after, key)
for rank in rank_moves([issue.key for issue in children], order):
if refused := store.rank(rank.key, rank.before):
return Failure(f"cannot rank {rank.key} just before {rank.before}: {refused.reason}; the re-rank stopped there, so rank the loop's issues in {store.epic_key}'s backlog by hand to come in this sequence: {', '.join(order)}")
return None
def rank_moves(backlog: list[str], order: list[str]) -> list[Rank]:
"""The ranks, in the sequence to make them, that turn backlog, a list of keys, into one where the keys order lists come in that sequence, each at a position one of them held, while every other key keeps its position. order names each key once, and each is in backlog.
Working from the backlog's end, a listed key that isn't already just before the key due after it ranks just before that key. The key due last, where it isn't already last, ranks just before the key that is, which moves away in its own turn, since it is due earlier."""
listed = set(order)
sequence = iter(order)
target = [next(sequence) if key in listed else key for key in backlog]
now = list(backlog)
ranks = []
for position in reversed(range(len(target))):
key = target[position]
due_after = target[position + 1] if position + 1 < len(target) else None
at = now.index(key)
if key not in listed or (now[at + 1] if at + 1 < len(now) else None) == due_after:
continue
rank = Rank(key, now[-1] if due_after is None else due_after)
ranks.append(rank)
now.remove(key)
now.insert(now.index(rank.before), key)
return ranks
def chain_scoring(formula: ast.Expression, epic_goals: str, repo: str | None, own: RepoRanking | None) -> ranking.Scoring | Failure:
"""How an item in repo scores: the chain's goals, and what each achieve goal weighs. The bar is 0, since a bar decides what is filed, and the order holds every item that was.