Answer stability round 1: 1 🔴, 12 🟡 (0 misread); wait-for waits out a half-written line, prepare-scoring honours claudeMdExcludes, and a merge by another method waits for the checks
CI / tests (pull_request) Successful in 2m38s

This commit is contained in:
2026-11-12 09:13:37 +01:00
parent 37f19d1677
commit 58133e69fe
8 changed files with 90 additions and 23 deletions
+22 -9
View File
@@ -27,14 +27,19 @@ class Clock(typing.Protocol):
def sleep(self, seconds: float) -> None: ...
def line_in(path: pathlib.Path, pattern: re.Pattern[str] | None) -> str | None | Failure:
"""The first line matching pattern, or without one the last line, where the file holds anything; else None."""
def text_of(path: pathlib.Path) -> str | None | Failure:
"""What the file holds; None where it doesn't exist."""
try:
lines = path.read_text(errors="replace").splitlines()
return path.read_text(errors="replace")
except FileNotFoundError:
return None
except OSError as error:
return Failure(f"cannot read {path}: {error.strerror}")
def line_in(text: str, pattern: re.Pattern[str] | None) -> str | None:
"""The first line of text matching pattern, or without one its last line; None where there is none."""
lines = text.splitlines()
if pattern is None:
return lines[-1] if lines else None
return next((line for line in lines if pattern.search(line)), None)
@@ -44,18 +49,26 @@ def waited(file: str, pattern: str | None, timeout: float, clock: Clock = time)
path = pathlib.Path(file)
compiled = re.compile(pattern) if pattern is not None else None
deadline = clock.monotonic() + timeout
while (found := line_in(path, compiled)) is None:
before = None
while True:
text = text_of(path)
if isinstance(text, Failure):
return text
# A last line without its newline may still be being written: it counts once a poll finds it unchanged.
settled = text is None or text.endswith("\n") or text == before
whole = text if settled or text is None else text[:text.rfind("\n") + 1]
# Without a pattern the last line is wanted, so an unsettled one waits.
if whole is not None and (settled or compiled is not None) and (found := line_in(whole, compiled)) is not None:
return found
before = text
left = deadline - clock.monotonic()
if left <= 0:
if not path.exists():
if text is None:
return Failure(f"{file} did not appear in {timeout:g} s")
last = line_in(path, None)
if isinstance(last, Failure):
return last
last = line_in(text, None)
wanted = f"no line matching `{pattern}`" if pattern is not None else "nothing"
return Failure(f"{file} held {wanted} after {timeout:g} s" + (f"; its last line: {last}" if last is not None else ""))
clock.sleep(min(POLL_SECONDS, left))
return found
def arguments(argv: list[str]) -> tuple[str, str | None, float] | Failure: