Answer principles round 1: 2 🔴, 9 🟡 (0 misread); explicit record versions in place of the Confluence store's hidden state, the routing ruling filed as item 393 for 0.12.0, rule-hook catching heavy runs through uv, poetry, sudo and doas, one unreleased heading, one owner of the no-item message, typed Jira issues, a turn that gives its failure as a value, outcome tests for the Atlassian client, an Emptied reason type, an injected clock and git in touch-predictions, and paired record names

This commit is contained in:
2026-11-16 16:12:36 +01:00
parent a60bfdbc1c
commit ba21a1efcd
41 changed files with 406 additions and 280 deletions
+56 -21
View File
@@ -9,6 +9,7 @@ from record_store.confluence_page import ConfluencePage
from record_store.jira_description import EpicDescription
from failure import Failure
from git_cli.git_repo import file_at, git, Git
from record_store.held import Held
from project_config.settings import ProjectConfig, RECORDS, TOUCH_PREDICTIONS
from text_files.file_writes import replace_file
@@ -27,8 +28,11 @@ class RecordStore(typing.Protocol):
def read(self) -> str | Failure:
"""The record's text as it stands, empty where it doesn't exist yet."""
def write(self, text: str) -> Failure | None:
"""Replaces the record's whole text, creating the record where it doesn't exist yet."""
def held(self) -> Held | Failure:
"""The record as it stands, with the version a write over it names."""
def write(self, text: str, over: str | None = None) -> Held | Failure:
"""Replaces the record's whole text, creating the record where it doesn't exist yet, and gives the record as the write left it. over is the version held() gave: where someone saved the record since, the write refuses. None replaces the record as it stands."""
@dataclasses.dataclass(frozen=True)
@@ -41,6 +45,10 @@ class FileStore:
def label(self) -> str:
return str(self.path)
def held(self) -> Held | Failure:
text = self.read()
return text if isinstance(text, Failure) else Held(text)
def read(self) -> str | Failure:
try:
return self.path.read_text(encoding="utf-8")
@@ -51,24 +59,24 @@ class FileStore:
except OSError as failure:
return Failure(f"cannot read {self.path}: {failure.strerror}")
def write(self, text: str) -> Failure | None:
def write(self, text: str, over: str | None = None) -> Held | Failure:
try:
self.path.parent.mkdir(parents=True, exist_ok=True)
except OSError as failure:
return Failure(f"cannot write {self.path}: {failure.strerror}")
unwritten = replace_file(self.path, text.encode("utf-8"))
return Failure(f"cannot write {self.path}: {unwritten.reason}") if unwritten else None
return Failure(f"cannot write {self.path}: {unwritten.reason}") if unwritten else Held(text)
def store(config: ProjectConfig, record: str, kept: pathlib.Path | None = None) -> RecordStore:
"""The store config names for record, one of RECORDS. A record on a Confluence page keeps the version it read in the file the parameter kept names, for a later process that writes it; where kept is None, the store keeps the version only in memory."""
def store(config: ProjectConfig, record: str) -> RecordStore:
"""The store config names for record, one of RECORDS."""
if record not in RECORDS:
raise ValueError(f"{record} is not a record; the records are {', '.join(RECORDS)}")
if record not in config.pages:
return FileStore(config.paths[record], config.tracked(record))
# load refuses a config that names a page and no env-file.
assert config.env_file is not None
return ConfluencePage(config.pages[record], config.env_file, kept)
return ConfluencePage(config.pages[record], config.env_file)
def touch_predictions_store(config: ProjectConfig) -> RecordStore | None:
@@ -93,27 +101,54 @@ def held_at(revision: str, record: RecordStore, cwd: str, run: Git = git) -> str
def local_file(record: RecordStore, copy: pathlib.Path) -> pathlib.Path | Failure:
"""A file holding record's text, for an agent, which reads and edits files: the record's own file where a file is its backend, else copy, written with the text as it stands. Neither exists where the record doesn't yet. `stored` puts an edited copy back."""
"""A file holding record's text, for an agent, which reads and edits files: the record's own file where a file is its backend, else copy, written with the text as it stands, and its version beside it, for `stored`, a later process, to write over. Neither exists where the record doesn't yet. `stored` puts an edited copy back."""
if isinstance(record, FileStore):
return record.path
text = record.read()
if isinstance(text, Failure):
return text
if text:
return FileStore(copy, None).write(text) or copy
try:
# An earlier copy would read as the record's text, and `stored` would put it back.
copy.unlink(missing_ok=True)
except OSError as failure:
return Failure(f"cannot remove {copy}: {failure.strerror}")
return copy
held = record.held()
if isinstance(held, Failure):
return held
if held.text:
written = FileStore(copy, None).write(held.text)
if isinstance(written, Failure):
return written
else:
try:
# An earlier copy would read as the record's text, and `stored` would put it back.
copy.unlink(missing_ok=True)
except OSError as failure:
return Failure(f"cannot remove {copy}: {failure.strerror}")
# Kept only once the copy holds the text: a version kept for a read that failed would let a later save overwrite the save it saw.
return kept(copy, held.version) or copy
def stored(record: RecordStore, copy: pathlib.Path) -> Failure | None:
"""Stores in record the text of copy, the file `local_file` gave for it. Where that is the record's own file, the edit is already the record."""
"""Stores in record the text of copy, the file `local_file` gave for it, over the version kept beside it. Where that is the record's own file, the edit is already the record. The version the write left is kept for the next save."""
if isinstance(record, FileStore):
return None
text = FileStore(copy, None).read()
if isinstance(text, Failure):
return text
return record.write(text) if text else Failure(f"{copy} is missing or empty, so nothing is stored in {record.label}")
if not text:
return Failure(f"{copy} is missing or empty, so nothing is stored in {record.label}")
over = FileStore(version_file(copy), None).read()
if isinstance(over, Failure):
return over
written = record.write(text, over.strip() or None)
return written if isinstance(written, Failure) else kept(copy, written.version)
def version_file(copy: pathlib.Path) -> pathlib.Path:
"""The file beside copy that keeps the version of the record copy holds."""
return copy.with_suffix(".version")
def kept(copy: pathlib.Path, version: str | None) -> Failure | None:
"""Keeps version beside copy, or removes the file that kept an earlier one where version is None."""
if version is not None:
written = FileStore(version_file(copy), None).write(version)
return written if isinstance(written, Failure) else None
try:
version_file(copy).unlink(missing_ok=True)
except OSError as failure:
return Failure(f"cannot remove {version_file(copy)}: {failure.strerror}")
return None