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
+29 -45
View File
@@ -1,6 +1,6 @@
"""A record kept on one Confluence Cloud page, read and written as markdown over Confluence's REST API version 2, with the credentials of the config's env-file, and converted by the adf-codec shim.
A write never overwrites a teammate's edit: it sends the version it read, and Confluence refuses it where someone saved the page since. The human then decides (lilleman, 2026-11-12)."""
A write never overwrites a teammate's edit: it sends the version it is handed, the one held() read, and Confluence refuses it where someone saved the page since. The human then decides (lilleman, 2026-11-12). The store keeps no version itself: its caller hands each write the version, as a Held's, and keeps the one the write leaves (lilleman, 2026-11-16)."""
import dataclasses
import json
import pathlib
@@ -10,8 +10,8 @@ from adf_codec.convert import adfs_to_markdown, markdown_to_adf, Refused
from atlassian.client import basic_auth, confluence_json, Http, ToAdf, ToMarkdown
from rest_client.json_request import ErrorAnswer
from failure import Failure
from record_store.held import Held
from project_config.settings import Page
from text_files.file_writes import replace_file
# What Confluence answers to a write whose version isn't the one after the version it holds.
CONFLICT = 409
@@ -20,23 +20,23 @@ SHAPE = "not in the shape Confluence Cloud's REST API version 2 documents"
@dataclasses.dataclass(frozen=True)
class Seen:
"""The page's version number and title as the store last read or wrote them. A write needs both."""
"""The page's version number and title as a read found them or a write left them. A write needs both, so a Held's version holds both, as JSON."""
version: int
title: str
@property
def token(self) -> str:
return json.dumps(dataclasses.asdict(self))
@dataclasses.dataclass
class ConfluencePage:
"""The text of page as markdown, read and written with the credentials env_file holds.
kept is a file that keeps the version the store read for a later process, such as `project-record save` after `project-record open`; None keeps it only in memory."""
"""The text of page as markdown, read and written with the credentials env_file holds."""
page: Page
env_file: pathlib.Path
kept: pathlib.Path | None = None
http: Http = confluence_json
to_markdown: ToMarkdown = adfs_to_markdown
to_adf: ToAdf = markdown_to_adf
seen: Seen | None = None
@property
def label(self) -> str:
@@ -52,18 +52,19 @@ class ConfluencePage:
def read(self) -> str | Failure:
"""The page's text as markdown; empty where the page is."""
held = self.held()
return held if isinstance(held, Failure) else held.text
def held(self) -> Held | Failure:
"""The page's text as markdown, with its version and title as the version a write over it names."""
answer = self.fetched("?body-format=atlas_doc_format")
if isinstance(answer, Failure):
return answer
seen, held = answer
if not isinstance(held, str):
seen, body = answer
if not isinstance(body, str):
return Failure(f"{self.label} is {SHAPE}: it holds no body in atlas_doc_format")
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
text = self.converted(body)
return text if isinstance(text, Failure) else Held(text, seen.token)
def converted(self, held: str) -> str | Failure:
"""The markdown of the body held, the JSON of an ADF document; empty where held is."""
@@ -80,14 +81,9 @@ class ConfluencePage:
return Failure(f"cannot convert {self.label} to markdown: {texts.reason}")
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. 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("")
if isinstance(fetched, Failure):
return fetched
seen = fetched[0]
def write(self, text: str, over: str | None = None) -> Held | Failure:
"""Replaces the page's text with text, as the version after over, the one held() gave. Where over is None, it replaces the page as it stands."""
seen = self.seen_of(over)
if isinstance(seen, Failure):
return seen
document = self.to_adf(text)
@@ -102,7 +98,7 @@ class ConfluencePage:
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))
return Held(text, Seen(seen.version + 1, seen.title).token)
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 where query asks for it; None where it doesn't."""
@@ -121,25 +117,13 @@ class ConfluencePage:
adf = body.get("atlas_doc_format") if isinstance(body, dict) else None
return Seen(number, title), adf.get("value") if isinstance(adf, dict) else None
def keep(self, seen: Seen) -> Failure | None:
self.seen = seen
if self.kept is None:
return None
def seen_of(self, over: str | None) -> Seen | Failure:
"""The version and title a write sends: those over holds, else the page's as it stands."""
if over is None:
fetched = self.fetched("")
return fetched if isinstance(fetched, Failure) else fetched[0]
try:
self.kept.parent.mkdir(parents=True, exist_ok=True)
except OSError as failure:
return Failure(f"cannot write {self.kept}: {failure.strerror}")
unwritten = replace_file(self.kept, json.dumps(dataclasses.asdict(seen)).encode())
return Failure(f"cannot write {self.kept}: {unwritten.reason}") if unwritten else None
def recalled(self) -> Seen | Failure | None:
"""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:
held: typing.Any = json.loads(self.kept.read_text(encoding="utf-8"))
held: typing.Any = json.loads(over)
return Seen(int(held["version"]), str(held["title"]))
except FileNotFoundError:
return None
except (OSError, ValueError, KeyError, TypeError) as failure:
return Failure(f"cannot read the version of {self.label} that {self.kept} keeps: {failure}")
except (ValueError, KeyError, TypeError) as failure:
return Failure(f"cannot read the version of {self.label} to write over, {over!r}: {failure}")
+14 -3
View File
@@ -1,6 +1,7 @@
"""What every record backend must hold, as tests. A backend's test case inherits RecordStoreContract and unittest.TestCase, and builds its store in new_store."""
import typing
from record_store.held import Held
from record_store.stores import RecordStore
@@ -8,6 +9,7 @@ class RecordStoreContract:
"""Runs against the store new_store returns: one that holds no record yet."""
assertEqual: typing.Callable[..., None]
assertIsNone: typing.Callable[..., None]
assertIsInstance: typing.Callable[..., None]
assertTrue: typing.Callable[..., None]
def new_store(self) -> RecordStore:
@@ -19,14 +21,23 @@ class RecordStoreContract:
def test_reads_back_what_it_wrote_to_the_character(self) -> None:
store = self.new_store()
text = "# Decisions\n\n- Å, 🔴 and a | pipe\n\n\n"
self.assertIsNone(store.write(text))
self.assertEqual(store.write(text), store.held())
self.assertEqual(store.read(), text)
def test_a_write_replaces_the_whole_record(self) -> None:
store = self.new_store()
store.write("first\nsecond\n")
self.assertIsNone(store.write("third\n"))
first = store.write("first\nsecond\n")
assert isinstance(first, Held), first
# A write over the version the last one left replaces the record, as a later save does.
self.assertIsInstance(store.write("third\n", first.version), Held)
self.assertEqual(store.read(), "third\n")
def test_holds_its_text_with_the_version_a_write_over_it_names(self) -> None:
store = self.new_store()
store.write("text\n")
held = store.held()
assert isinstance(held, Held), held
self.assertEqual(held.text, "text\n")
def test_names_itself_for_a_message(self) -> None:
self.assertTrue(self.new_store().label.strip())
+6 -2
View File
@@ -2,6 +2,7 @@
import dataclasses
from failure import Failure
from record_store.held import Held
@dataclasses.dataclass
@@ -15,8 +16,11 @@ class MemoryStore:
def read(self) -> str | Failure:
return Failure(self.fails) if self.fails else self.text
def write(self, text: str) -> Failure | None:
def held(self) -> Held | Failure:
return Failure(self.fails) if self.fails else Held(self.text)
def write(self, text: str, over: str | None = None) -> Held | Failure:
if self.fails:
return Failure(self.fails)
self.text = text
return None
return Held(text)
+9
View File
@@ -0,0 +1,9 @@
"""A record as a read found it or a write left it, which every record backend gives."""
import dataclasses
@dataclasses.dataclass(frozen=True)
class Held:
"""A record's text as one read found it or one write left it, with its version: what a write over it names, so the write refuses where someone saved the record since. None for a backend whose writes check no version, as a file's."""
text: str
version: str | None = None
+6 -1
View File
@@ -8,6 +8,7 @@ from adf_codec.convert import adfs_to_markdown, Refused
from atlassian.client import basic_auth, Http, jira_json, ToMarkdown
from project_config.settings import Epic
from failure import Failure
from record_store.held import Held
READ_ONLY = "goals and audience kept in Jira are only read: edit the epic's description in Jira"
@@ -49,5 +50,9 @@ class EpicDescription:
return Failure(f"cannot convert {key}'s description to markdown: {texts.reason}")
return texts[0]
def write(self, text: str) -> Failure | None:
def held(self) -> Held | Failure:
text = self.read()
return text if isinstance(text, Failure) else Held(text)
def write(self, text: str, over: str | None = None) -> Held | Failure:
return Failure(READ_ONLY)
+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
+60 -54
View File
@@ -10,9 +10,11 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from record_store.confluence_page import ConfluencePage
from rest_client.json_request import ErrorAnswer
from failure import Failure
from record_store.held import Held
from project_config.settings import Page
from record_store.contract import RecordStoreContract
from adf_codec.convert import Refused
from record_store import stores
PAGE = Page("https://acme.atlassian.net", "2293761", "confluence:https://acme.atlassian.net/wiki/spaces/ENG/pages/2293761")
URL = "https://acme.atlassian.net/wiki/api/v2/pages/2293761"
@@ -57,11 +59,10 @@ class ConfluenceCase(unittest.TestCase):
self.env = folder / "acme.env"
self.env.write_text("ATLASSIAN_EMAIL=me@example.com\nATLASSIAN_API_TOKEN=s3cret\n")
self.env.chmod(0o600)
self.kept = folder / "state" / "acme" / "decisions.version"
self.confluence = FakeConfluence()
def new_store(self, kept: pathlib.Path | None = None) -> ConfluencePage:
return ConfluencePage(PAGE, self.env, kept, self.confluence.http, to_markdown, to_adf)
def new_store(self) -> ConfluencePage:
return ConfluencePage(PAGE, self.env, self.confluence.http, to_markdown, to_adf)
class ConfluencePageContract(ConfluenceCase, RecordStoreContract):
@@ -74,60 +75,80 @@ class ConfluencePageTest(ConfluenceCase):
self.assertEqual(self.new_store().read(), "# Decisions\n")
self.assertEqual(self.confluence.calls, [("GET", f"{URL}?body-format=atlas_doc_format", AUTHORIZATION, None)])
def test_writes_markdown_as_the_version_it_read_plus_one(self) -> None:
def test_writes_markdown_as_the_version_it_is_handed_plus_one(self) -> None:
self.confluence.version = 7
store = self.new_store()
store.read()
self.assertIsNone(store.write("- a decision\n"))
held = store.held()
assert isinstance(held, Held), held
self.assertEqual(store.write("- a decision\n", held.version), Held("- a decision\n", '{"version": 8, "title": "Decisions"}'))
self.assertEqual(self.confluence.calls[-1], ("PUT", URL, AUTHORIZATION, {"id": PAGE.page_id, "status": "current", "title": "Decisions", "body": {"representation": "atlas_doc_format", "value": json.dumps(to_adf("- a decision\n"))}, "version": {"number": 8}}))
def test_refuses_to_overwrite_a_teammates_save_since_its_read_and_says_to_ask_the_human(self) -> None:
store = self.new_store()
store.read()
def test_refuses_to_overwrite_a_teammates_save_since_the_version_it_is_handed_and_says_to_ask_the_human(self) -> None:
held = self.new_store().held()
assert isinstance(held, Held), held
self.confluence.teammate_saves("their edit\n")
written = store.write("my edit\n")
written = self.new_store().write("my edit\n", held.version)
assert isinstance(written, Failure), written
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")
def test_keeps_the_version_it_read_in_its_file_for_a_later_process(self) -> None:
self.new_store(self.kept).read()
def test_keeps_no_version_itself_so_a_read_never_moves_the_version_a_write_names(self) -> None:
store = self.new_store()
held = store.held()
assert isinstance(held, Held), held
self.confluence.teammate_saves("their edit\n")
written = self.new_store(self.kept).write("my edit\n")
self.assertEqual(store.read(), "their edit\n")
written = store.write("my edit\n", held.version)
assert isinstance(written, Failure), written
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()
self.assertIsNone(self.new_store(self.kept).write("first\n"))
self.assertIsNone(self.new_store(self.kept).write("second\n"))
def test_a_later_write_over_the_version_an_earlier_one_left_lands(self) -> None:
held = self.new_store().held()
assert isinstance(held, Held), held
first = self.new_store().write("first\n", held.version)
assert isinstance(first, Held), first
self.assertIsInstance(self.new_store().write("second\n", first.version), Held)
self.assertEqual(self.new_store().read(), "second\n")
self.assertEqual(self.confluence.title, "Decisions")
def test_each_save_of_an_opened_copy_writes_over_the_version_the_open_or_the_last_save_left(self) -> None:
copy = self.env.parent / "copies" / "decisions.md"
self.confluence.teammate_saves("first\n")
self.assertEqual(stores.local_file(self.new_store(), copy), copy)
for text in ("mine\n", "again\n"):
copy.write_text(text)
self.assertIsNone(stores.stored(self.new_store(), copy))
self.assertEqual(self.new_store().read(), "again\n")
self.confluence.teammate_saves("theirs\n")
copy.write_text("third\n")
refused = stores.stored(self.new_store(), copy)
assert isinstance(refused, Failure), refused
self.assertIn("someone saved", refused.reason)
self.assertEqual(self.new_store().read(), "theirs\n")
def test_an_open_that_fails_keeps_the_version_an_earlier_open_kept(self) -> None:
copy = self.env.parent / "copies" / "decisions.md"
stores.local_file(self.new_store(), copy)
self.confluence.teammate_saves("their edit\n")
self.confluence.value = "{not json"
self.assertIsInstance(stores.local_file(self.new_store(), copy), Failure)
copy.write_text("my edit\n")
refused = stores.stored(self.new_store(), copy)
assert isinstance(refused, Failure), refused
self.assertIn("someone saved", refused.reason)
def test_a_write_with_no_read_replaces_the_page_as_it_stands(self) -> None:
self.confluence.teammate_saves("earlier\n")
self.assertIsNone(self.new_store().write("replaced\n"))
self.assertIsInstance(self.new_store().write("replaced\n"), Held)
self.assertEqual(self.confluence.calls[0], ("GET", URL, AUTHORIZATION, None))
self.assertEqual(self.new_store().read(), "replaced\n")
def test_fails_on_an_answer_not_shaped_as_a_page(self) -> None:
for answer in ({}, {"title": "Decisions", "version": {}, "body": {"atlas_doc_format": {"value": ""}}}, {"version": {"number": 3}, "body": {"atlas_doc_format": {"value": ""}}}, ["not", "a", "page"]):
with self.subTest(answer):
store = ConfluencePage(PAGE, self.env, None, lambda *_: answer, to_markdown, to_adf)
store = ConfluencePage(PAGE, self.env, lambda *_: answer, to_markdown, to_adf)
read = store.read()
assert isinstance(read, Failure), read
self.assertIn("not in the shape Confluence Cloud's REST API version 2 documents", read.reason)
@@ -136,7 +157,7 @@ class ConfluencePageTest(ConfluenceCase):
for body in ({}, "text", {"atlas_doc_format": "text"}, {"atlas_doc_format": {"value": 3}}):
with self.subTest(body):
answer = {"title": "Decisions", "version": {"number": 3}, "body": body}
store = ConfluencePage(PAGE, self.env, None, lambda *_: answer, to_markdown, to_adf)
store = ConfluencePage(PAGE, self.env, lambda *_: answer, to_markdown, to_adf)
self.assertEqual(store.read(), Failure(f"{PAGE.spelling} is not in the shape Confluence Cloud's REST API version 2 documents: it holds no body in atlas_doc_format"))
def test_fails_on_a_body_that_is_not_json(self) -> None:
@@ -145,43 +166,28 @@ class ConfluencePageTest(ConfluenceCase):
def test_fails_naming_the_page_where_the_text_cannot_be_converted(self) -> None:
self.confluence.teammate_saves("text\n")
store = ConfluencePage(PAGE, self.env, None, self.confluence.http, lambda _: Failure("the shim is down"), lambda _: Failure("the shim is down"))
store = ConfluencePage(PAGE, self.env, self.confluence.http, lambda _: Failure("the shim is down"), lambda _: Failure("the shim is down"))
self.assertEqual(store.read(), Failure(f"cannot convert {PAGE.spelling} to markdown: the shim is down"))
self.assertEqual(store.write("text\n"), Failure(f"cannot convert the text for {PAGE.spelling} to ADF: the shim is down"))
def test_fails_naming_the_page_where_adf_codec_refuses_its_document(self) -> None:
self.confluence.teammate_saves("text\n")
store = ConfluencePage(PAGE, self.env, None, self.confluence.http, lambda _: Refused(0, Failure("adf-codec refused the input")), to_adf)
store = ConfluencePage(PAGE, self.env, self.confluence.http, lambda _: Refused(0, Failure("adf-codec refused the input")), to_adf)
self.assertEqual(store.read(), Failure(f"{PAGE.spelling}: adf-codec refused the input"))
def test_fails_where_the_folder_of_its_file_cannot_be_made(self) -> None:
self.kept.parent.parent.mkdir(parents=True)
self.kept.parent.write_text("a file, not a folder")
read = self.new_store(self.kept).read()
assert isinstance(read, Failure), read
self.assertTrue(read.reason.startswith(f"cannot write {self.kept}: "), read.reason)
def test_a_write_confluence_refuses_otherwise_fails_naming_the_page_and_not_a_teammate(self) -> None:
answers = iter([{"title": "Decisions", "version": {"number": 3}}, ErrorAnswer("PUT /wiki/api/v2/pages/2293761 answered 403: Forbidden", 403)])
store = ConfluencePage(PAGE, self.env, None, lambda *_: next(answers), to_markdown, to_adf)
store = ConfluencePage(PAGE, self.env, lambda *_: next(answers), to_markdown, to_adf)
self.assertEqual(store.write("text\n"), Failure(f"cannot write {PAGE.spelling}: PUT /wiki/api/v2/pages/2293761 answered 403: Forbidden"))
def test_fails_where_its_file_cannot_keep_the_version(self) -> None:
self.kept.mkdir(parents=True)
read = self.new_store(self.kept).read()
assert isinstance(read, Failure), read
self.assertTrue(read.reason.startswith(f"cannot write {self.kept}: "), read.reason)
def test_fails_on_a_kept_version_it_cannot_read_and_writes_nothing(self) -> None:
self.kept.parent.mkdir(parents=True)
self.kept.write_text("{}")
written = self.new_store(self.kept).write("text\n")
def test_fails_on_a_version_it_cannot_read_and_writes_nothing(self) -> None:
written = self.new_store().write("text\n", "{}")
assert isinstance(written, Failure), written
self.assertTrue(written.reason.startswith(f"cannot read the version of {PAGE.spelling} that {self.kept} keeps: "), written.reason)
self.assertTrue(written.reason.startswith(f"cannot read the version of {PAGE.spelling} to write over, '{{}}': "), written.reason)
self.assertEqual(self.confluence.calls, [])
def test_fails_naming_the_page_when_confluence_answers_an_error(self) -> None:
store = ConfluencePage(PAGE, self.env, None, lambda *_: ErrorAnswer("GET /wiki/api/v2/pages/2293761 answered 404: Not Found", 404), to_markdown, to_adf)
store = ConfluencePage(PAGE, self.env, lambda *_: ErrorAnswer("GET /wiki/api/v2/pages/2293761 answered 404: Not Found", 404), to_markdown, to_adf)
self.assertEqual(store.read(), Failure(f"cannot read {PAGE.spelling}: GET /wiki/api/v2/pages/2293761 answered 404: Not Found"))
def test_fails_without_credentials_before_any_request(self) -> None:
+4 -4
View File
@@ -10,6 +10,7 @@ from record_store.confluence_page import ConfluencePage
from project_config.settings import Epic, Page, ProjectConfig
from record_store.jira_description import EpicDescription
from failure import Failure
from record_store.held import Held
from record_store.fakes import MemoryStore
from record_store.contract import RecordStoreContract
from record_store import stores
@@ -62,7 +63,7 @@ class FileStore(unittest.TestCase):
def test_a_write_makes_each_folder_the_file_lacks(self):
path = self.folder / "records" / "acme" / "decisions.md"
self.assertIsNone(stores.FileStore(path, None).write("text\n"))
self.assertEqual(stores.FileStore(path, None).write("text\n"), Held("text\n"))
self.assertEqual(path.read_text(), "text\n")
def test_a_write_onto_a_folder_is_a_failure_naming_it(self):
@@ -172,11 +173,10 @@ class Store(unittest.TestCase):
stores.store(self.config(pathlib.Path("/code/acme"), pathlib.Path("/home/me/.claude-projects/acme")), "plan")
self.assertEqual(str(refused.exception), "plan is not a record; the records are decisions, score-anchors, comprehension-history, reading-cost, changelog")
def test_a_record_on_a_confluence_page_is_that_page_keeping_its_version_where_asked(self):
def test_a_record_on_a_confluence_page_is_that_page(self):
page = Page("https://acme.atlassian.net", "2293761", "confluence:https://acme.atlassian.net/wiki/spaces/ENG/pages/2293761")
config = ProjectConfig("acme", pathlib.Path("/home/me/.claude-projects/acme"), pathlib.Path("/code/acme"), {}, pathlib.Path("/home/me/acme.env"), pages={"decisions": page})
kept = pathlib.Path("/home/me/decisions.version")
self.assertEqual(stores.store(config, "decisions", kept), ConfluencePage(page, pathlib.Path("/home/me/acme.env"), kept))
self.assertEqual(stores.store(config, "decisions"), ConfluencePage(page, pathlib.Path("/home/me/acme.env")))
class GoalsStore(unittest.TestCase):