Answer stability round 1: 2 🔴, 2 🟡 (2 misread); keep a page's version only after its text converts, read adf-codec's table separators, and let ranked records name a page only beside a plan in Jira

This commit is contained in:
2026-11-15 12:00:19 +01:00
parent 6326edcd5b
commit e3875d2b05
11 changed files with 74 additions and 32 deletions
+13 -6
View File
@@ -70,8 +70,15 @@ class ConfluencePage:
seen, held = answer
if not isinstance(held, str):
return Failure(f"{self.label} is {SHAPE}: it holds no body in atlas_doc_format")
if unkept := self.keep(seen):
return unkept
text = self.converted(held)
if isinstance(text, Failure):
return text
# Kept only once the text is in hand: a version kept for a read that failed would let a later write overwrite the save it saw.
unkept = self.keep(seen)
return unkept or text
def converted(self, held: str) -> str | Failure:
"""The markdown of the body held, the JSON of an ADF document; empty where held is."""
if not held:
return ""
try:
@@ -86,7 +93,7 @@ class ConfluencePage:
return texts[0]
def write(self, text: str) -> Failure | None:
"""Replaces the page's text with text, as the version after the one the store read. A store that read nothing replaces the page as it stands."""
"""Replaces the page's text with text, as the version after the one the store read. Where the store hasn't read the page, it replaces the page as it stands."""
seen = self.seen or self.recalled()
if seen is None:
fetched = self.fetched("")
@@ -104,13 +111,13 @@ class ConfluencePage:
body = {"id": self.page.page_id, "status": "current", "title": seen.title, "body": {"representation": "atlas_doc_format", "value": json.dumps(document)}, "version": {"number": seen.version + 1}}
answer = self.http("PUT", self.url, authorization, body)
if isinstance(answer, ErrorAnswer) and answer.status == CONFLICT:
return Failure(f"a teammate saved {self.label} since the loop read version {seen.version} of it, so the loop didn't write it: never overwrite their edit, but ask the human what to do ({answer.reason})")
return Failure(f"someone saved {self.label} since the loop read version {seen.version} of it, so the loop didn't write it: never overwrite their edit, but ask the human what to do ({answer.reason})")
if isinstance(answer, Failure):
return Failure(f"cannot write {self.label}: {answer.reason}")
return self.keep(Seen(seen.version + 1, seen.title))
def fetched(self, query: str) -> tuple[Seen, object] | Failure:
"""The page's version and title, and the value of its body in atlas_doc_format, which query asks for."""
"""The page's version and title, and the value of its body in atlas_doc_format where query asks for it; None where it doesn't."""
authorization = basic_auth(self.env_file)
if isinstance(authorization, Failure):
return authorization
@@ -138,7 +145,7 @@ class ConfluencePage:
return Failure(f"cannot write {self.kept}: {unwritten.reason}") if unwritten else None
def recalled(self) -> Seen | Failure | None:
"""The version and title kept's file holds; None where there is no such file."""
"""The version and title the file kept holds; None where kept is None or names no file."""
if self.kept is None:
return None
try:
+1 -1
View File
@@ -59,7 +59,7 @@ class FileStore:
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 kept, for a later process that writes it; None keeps it only in memory."""
"""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."""
if record not in RECORDS:
raise ValueError(f"{record} is not a record; the records are {', '.join(RECORDS)}")
if record not in config.pages:
+14 -2
View File
@@ -87,7 +87,7 @@ class ConfluencePageTest(ConfluenceCase):
self.confluence.teammate_saves("their edit\n")
written = store.write("my edit\n")
assert isinstance(written, Failure), written
self.assertIn("a teammate saved", written.reason)
self.assertIn("someone saved", written.reason)
self.assertIn("ask the human", written.reason)
self.assertIn(PAGE.spelling, written.reason)
self.assertEqual(self.new_store().read(), "their edit\n")
@@ -97,7 +97,19 @@ class ConfluencePageTest(ConfluenceCase):
self.confluence.teammate_saves("their edit\n")
written = self.new_store(self.kept).write("my edit\n")
assert isinstance(written, Failure), written
self.assertIn("a teammate saved", written.reason)
self.assertIn("someone saved", written.reason)
def test_a_read_that_fails_keeps_the_version_an_earlier_read_kept(self) -> None:
self.new_store(self.kept).read()
self.confluence.teammate_saves("their edit\n")
failing = ConfluencePage(PAGE, self.env, self.kept, self.confluence.http, lambda _: Refused(0, Failure("adf-codec refused the input")), to_adf)
self.assertIsInstance(failing.read(), Failure)
self.confluence.value = "{not json"
self.assertIsInstance(self.new_store(self.kept).read(), Failure)
written = self.new_store(self.kept).write("my edit\n")
assert isinstance(written, Failure), written
self.assertIn("someone saved", written.reason)
self.assertEqual(self.confluence.version, 2)
def test_a_later_process_writes_with_the_version_an_earlier_one_read_or_wrote(self) -> None:
self.new_store(self.kept).read()