Kill the mutants of the epic description write
CI / tests (pull_request) Successful in 2m48s

This commit is contained in:
2026-11-18 10:26:23 +01:00
parent 9e47b0d566
commit 0755291112
3 changed files with 39 additions and 3 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ import dataclasses
import re
import typing
from record_store.jira_description import APPROVED_SECTIONS, EpicDescription
from record_store.jira_description import EpicDescription
from failure import Failure
from text_files.markdown_text import fenced_lines
from record_store.held import Held
@@ -84,7 +84,7 @@ class EpicRecord:
def write_section(self, name: str, body: str, approved: bool = False) -> Held | Failure:
"""Writes body as the ## name section. approved says the human approved the change in an interrupt, which Goals and Audience need."""
return self.written(lambda text: with_section(text, name, body), frozenset({name} & set(APPROVED_SECTIONS)) if approved else frozenset())
return self.written(lambda text: with_section(text, name, body), frozenset({name}) if approved else frozenset())
def write_language(self, language: str) -> Held | Failure:
return self.written(lambda text: with_language(text, language), frozenset())
+28 -1
View File
@@ -1,3 +1,4 @@
import dataclasses
import pathlib
import sys
import tempfile
@@ -50,6 +51,12 @@ class SectionsTest(unittest.TestCase):
self.assertEqual(read_section(text, "Decisions"), "")
self.assertEqual(read_section(text, "Scoring"), "```\n## Decisions\n```")
def test_a_top_level_heading_ends_a_section_and_indented_text_stays_indented(self) -> None:
self.assertEqual(read_section("## Scoring\n code\n# Title\nB\n", "Scoring"), " code")
def test_appending_keeps_the_trailing_spaces_of_the_last_line(self) -> None:
self.assertEqual(with_section("## Goals\nShip. \n", "Scoring", "Value."), "## Goals\nShip. \n\n## Scoring\n\nValue.\n")
def test_replaces_one_section_and_leaves_every_other_line_as_it_was(self) -> None:
changed = with_section(DESCRIPTION, "Scoring", "Risk.\n")
self.assertEqual(changed, DESCRIPTION.replace("Value.\n\n### Bar\n7.\n", "\nRisk.\n"))
@@ -67,7 +74,7 @@ class SectionsTest(unittest.TestCase):
def test_refuses_a_repeated_section_and_a_name_that_is_no_section(self) -> None:
self.assertIsInstance(with_section("## Scoring\nA\n\n## Scoring\nB\n", "Scoring", "C"), Failure)
with self.assertRaises(ValueError):
with self.assertRaisesRegex(ValueError, "Language is not a section.*Goals, Audience, Scoring, Decisions"):
read_section(DESCRIPTION, "Language")
@@ -103,6 +110,26 @@ class EpicRecordTest(unittest.TestCase):
self.assertEqual(self.record.section("Audience"), "Me.")
self.assertEqual(self.record.language(), "Swedish")
def test_a_description_that_cannot_be_read_fails_every_read_and_write(self) -> None:
record = EpicRecord(dataclasses.replace(self.record.description, http=lambda *call: Failure("HTTP 404: gone")))
for found in (record.section("Goals"), record.language(), record.write_section("Scoring", "A"), record.write_language("Swedish")):
with self.subTest(found):
assert isinstance(found, Failure), found
self.assertIn("ABC-12", found.reason)
def test_refuses_a_write_over_a_description_a_teammate_saved_since_the_record_read_it(self) -> None:
def teammate_saves_after_the_read(method: str, url: str, authorization: str, body: object) -> object:
answer = self.jira.http(method, url, authorization, body)
if method == "GET" and len(self.jira.calls) == 1:
self.jira.teammate_saves("## Goals\nTheirs.\n")
return answer
record = EpicRecord(dataclasses.replace(self.record.description, http=teammate_saves_after_the_read))
found = record.write_section("Scoring", "Risk.")
assert isinstance(found, Failure), found
self.assertIn("someone saved", found.reason)
self.assertEqual(self.jira.puts(), [])
def test_writes_scoring_and_decisions_and_the_language_without_approval(self) -> None:
self.assertIsInstance(self.record.write_section("Scoring", "Risk."), Held)
self.assertIsInstance(self.record.write_section("Decisions", "- Another."), Held)
@@ -142,6 +142,15 @@ class EpicDescriptionWriteTest(WriteCase):
self.assertEqual(self.jira.puts(), [])
self.assertEqual(self.new_store().read(), "## Goals\n1. **Achieve:** Their goal.\n")
def test_refuses_to_write_over_the_version_of_an_epic_that_had_no_description(self) -> None:
held = self.new_store().held()
assert isinstance(held, Held), held
self.jira.teammate_saves("## Goals\nTheirs.\n")
found = self.new_store(frozenset({"Goals"})).write("## Goals\nMine.\n", held.version)
assert isinstance(found, Failure), found
self.assertIn("someone saved", found.reason)
self.assertEqual(self.jira.puts(), [])
def test_refuses_to_change_goals_or_audience_before_the_human_approves(self) -> None:
held = self.held(GOALS_AND_SCORING)
changes = [