Merge remote-tracking branch 'origin/main' into item-409
CI / tests (pull_request) Successful in 5m26s
CI / tests (pull_request) Successful in 5m26s
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
@@ -296,10 +295,10 @@ def test_container_run_passes_an_image_failure_through(tmp_path):
|
||||
assert convert.container_run("to-adf", "text", scripted(down), shim_dir(tmp_path)) == down
|
||||
|
||||
|
||||
@pytest.mark.skipif(shutil.which("docker") is None or subprocess.run(["docker", "info"], capture_output=True, timeout=20).returncode != 0, reason="needs a docker daemon")
|
||||
def test_round_trip_through_the_real_container():
|
||||
doc = convert.markdown_to_adf("# Title\n\nSome **bold** text.\n")
|
||||
assert isinstance(doc, dict) and doc["type"] == "doc" and doc["content"][0]["type"] == "heading"
|
||||
assert isinstance(doc, dict), doc
|
||||
assert doc["type"] == "doc" and doc["content"][0]["type"] == "heading"
|
||||
markdown = convert.adf_to_markdown(doc)
|
||||
assert isinstance(markdown, str) and markdown.startswith("# Title") and "**bold**" in markdown
|
||||
refused = convert.adf_to_markdown({"type": "nope"})
|
||||
@@ -324,10 +323,9 @@ JIRA_DESCRIPTION = {
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.skipif(shutil.which("docker") is None or subprocess.run(["docker", "info"], capture_output=True, timeout=20).returncode != 0, reason="needs a docker daemon")
|
||||
def test_the_lossless_pair_gives_back_a_jira_description_identical_and_the_portable_pair_does_not():
|
||||
markdown = convert.adf_to_markdown_lossless(JIRA_DESCRIPTION)
|
||||
assert isinstance(markdown, str)
|
||||
assert isinstance(markdown, str), markdown
|
||||
assert convert.markdown_to_adf_lossless(markdown) == JIRA_DESCRIPTION
|
||||
assert convert.adfs_to_markdown_lossless([JIRA_DESCRIPTION, JIRA_DESCRIPTION]) == [markdown, markdown]
|
||||
portable = convert.markdown_to_adf(convert.adf_to_markdown(JIRA_DESCRIPTION))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""What every backend of an epic's plan must hold, as tests. A backend's test case inherits EpicStoreContract and unittest.TestCase, and builds an epic with no issues in new_store. Its comments_on reads an issue's comments, and its assign and close change an issue as a person would in the tracker."""
|
||||
"""What every backend of an epic's plan must hold, as tests. A backend's test case inherits EpicStoreContract and unittest.TestCase, and builds an epic with no issues in new_store. Its comments_on reads an issue's comments. Its assign, close, person_files, score and block change the tracker as a person or the plan store would."""
|
||||
import re
|
||||
import typing
|
||||
|
||||
@@ -26,6 +26,18 @@ class EpicStoreContract:
|
||||
"""The text of each comment on the issue named key, in the order posted, as markdown."""
|
||||
raise NotImplementedError
|
||||
|
||||
def person_files(self, store: EpicStore, summary: str) -> str:
|
||||
"""Files a child issue of the epic as a person does in the tracker, not through the store, and answers its key."""
|
||||
raise NotImplementedError
|
||||
|
||||
def score(self, store: EpicStore, key: str, scores: dict[str, object]) -> None:
|
||||
"""Sets the scores of the issue named key as `plan_store` writes them: each column's name with its value, a whole number for a score and text for Moves and Exempt, such as {"L": 2, "Moves": "1 by 5"}."""
|
||||
raise NotImplementedError
|
||||
|
||||
def block(self, store: EpicStore, key: str, blocker: str) -> None:
|
||||
"""Makes the issue named key blocked by the issue named blocker, as a person would link them in the tracker."""
|
||||
raise NotImplementedError
|
||||
|
||||
def filed(self, store: EpicStore, parent: str, summary: str, detail: str = "", labels: tuple[str, ...] = ()) -> str:
|
||||
key = store.file(parent, summary, detail, labels)
|
||||
assert isinstance(key, str), key
|
||||
@@ -42,7 +54,7 @@ class EpicStoreContract:
|
||||
def test_reads_back_a_child_issue_it_filed(self) -> None:
|
||||
store = self.new_store()
|
||||
key = self.filed(store, store.epic_key, "Count the runs.", "Why it counts.\n\nA second paragraph.", ("security", "api"))
|
||||
self.assertEqual(self.issues(store), [EpicIssue(key, "Count the runs.", "Why it counts.\n\nA second paragraph.", ("api", "security"), None, "To Do", False, store.epic_key)])
|
||||
self.assertEqual(self.issues(store), [EpicIssue(key, "Count the runs.", "Why it counts.\n\nA second paragraph.", ("api", "security"), None, "To Do", False, store.epic_key, by_loop=True)])
|
||||
|
||||
def test_reads_back_a_sub_task_it_filed_after_its_parent(self) -> None:
|
||||
store = self.new_store()
|
||||
@@ -127,3 +139,34 @@ class EpicStoreContract:
|
||||
self.assertEqual(store.comment(child, " \n"), Failure("the comment must hold some text"))
|
||||
self.assertIsInstance(store.comment("ZZZ-1", "Hello."), Failure)
|
||||
self.assertEqual([self.comments_on(store, key) for key in (child, task)], [[], []])
|
||||
|
||||
def test_reads_an_issue_without_scores_or_blockers_as_one_with_none(self) -> None:
|
||||
store = self.new_store()
|
||||
key = self.filed(store, store.epic_key, "Count the runs.")
|
||||
[issue] = self.issues(store)
|
||||
self.assertEqual((issue.key, issue.scores, issue.moves, issue.exempt, issue.blockers), (key, {}, (), "", ()))
|
||||
|
||||
def test_reads_the_scores_a_person_or_the_plan_store_set(self) -> None:
|
||||
store = self.new_store()
|
||||
key = self.filed(store, store.epic_key, "Count the runs.")
|
||||
self.score(store, key, {"L": 2, "E": 3, "I": 4, "S": 3, "Moves": "1 by 5", "Exempt": "security"})
|
||||
[issue] = self.issues(store)
|
||||
self.assertEqual((issue.scores, issue.moves, issue.exempt), ({"L": 2, "E": 3, "I": 4, "S": 3}, (("1", 5),), "security"))
|
||||
|
||||
def test_reads_each_blocker_of_an_issue_and_none_for_a_blocker_of_another(self) -> None:
|
||||
store = self.new_store()
|
||||
first, second, third = (self.filed(store, store.epic_key, f"Item {n}.") for n in range(3))
|
||||
self.block(store, third, first)
|
||||
self.block(store, third, second)
|
||||
read = {issue.key: issue for issue in self.issues(store)}
|
||||
self.assertEqual([read[key].blockers for key in (first, second, third)], [(), (), (first, second)])
|
||||
|
||||
def test_reads_whether_the_loop_filed_an_issue(self) -> None:
|
||||
store = self.new_store()
|
||||
ours = self.filed(store, store.epic_key, "Count the runs.")
|
||||
theirs = self.person_files(store, "A person's issue.")
|
||||
# The plan store scores an issue a person filed without making it the loop's.
|
||||
self.score(store, theirs, {"L": 2, "E": 3, "I": 4, "S": 3, "Moves": "1 by 5"})
|
||||
task = self.filed(store, ours, "Count them in the api.")
|
||||
read = {issue.key: issue for issue in self.issues(store)}
|
||||
self.assertEqual([read[key].by_loop for key in (ours, theirs, task)], [True, False, True])
|
||||
|
||||
@@ -26,7 +26,7 @@ class MemoryEpic:
|
||||
if parent != self.epic_key and parent not in {issue.key for issue in self.issues if issue.parent == self.epic_key}:
|
||||
return no_parent(self.epic_key, parent)
|
||||
key = f"{self.epic_key.rpartition('-')[0]}-{len(self.issues) + 100}"
|
||||
self.issues.append(EpicIssue(key, summary, detail.strip(), tuple(sorted(labels)), None, "To Do", False, parent))
|
||||
self.issues.append(EpicIssue(key, summary, detail.strip(), tuple(sorted(labels)), None, "To Do", False, parent, by_loop=True))
|
||||
return key
|
||||
|
||||
def add_label(self, key: str, label: str) -> None | Failure:
|
||||
|
||||
@@ -5,12 +5,12 @@ import typing
|
||||
|
||||
from adf_codec.convert import adfs_to_markdown, markdown_to_adf, Refused
|
||||
from atlassian.client import basic_auth, Http, jira_json, ToAdf, ToMarkdown
|
||||
from plan_store.jira_epic import blocked_by_links, FILED_BY, ISSUE_KEY, ISSUE_TYPE, project_of, PROPERTY, scores, searched
|
||||
from project_config.settings import Epic
|
||||
from do_epic.backend.protocol import EpicIssue, no_child, no_parent, no_words, unfit, unfit_label
|
||||
from failure import Failure
|
||||
from plan_store.jira_epic import ISSUE_KEY, ISSUE_TYPE, project_of, searched
|
||||
|
||||
FIELDS = ["summary", "description", "labels", "assignee", "status", "parent"]
|
||||
FIELDS = ["summary", "description", "labels", "assignee", "status", "parent", "issuelinks"]
|
||||
# How many child issues one search for sub-tasks names, which keeps its JQL well inside the length Jira takes.
|
||||
PARENTS_PER_SEARCH = 50
|
||||
PERHAPS_FILED = "unless Jira refused the request, the issue may exist: look under {parent} before filing it again"
|
||||
@@ -60,6 +60,8 @@ class JiraEpic:
|
||||
if refused := unfit(summary, labels) or self.not_a_parent(parent, authorization):
|
||||
return refused
|
||||
fields: dict[str, typing.Any] = {"project": {"key": project_of(parent)}, "parent": {"key": parent}, "summary": summary, "labels": list(labels)}
|
||||
# Marks the issue as the loop's, as plan_store marks the items it files.
|
||||
properties = [{"key": PROPERTY, "value": {FILED_BY[0]: FILED_BY[1]}}]
|
||||
kind = {"name": ISSUE_TYPE} if parent == self.epic_key else self.sub_task_type(project_of(parent), authorization)
|
||||
if isinstance(kind, Failure):
|
||||
return kind
|
||||
@@ -68,7 +70,7 @@ class JiraEpic:
|
||||
if isinstance(description, Failure):
|
||||
return Failure(f"cannot convert the detail to a Jira description: {description.reason}")
|
||||
fields["description"] = description
|
||||
created = self.http("POST", f"{self.epic.site}/rest/api/3/issue", authorization, {"fields": fields | {"issuetype": kind}})
|
||||
created = self.http("POST", f"{self.epic.site}/rest/api/3/issue", authorization, {"fields": fields | {"issuetype": kind}, "properties": properties})
|
||||
if isinstance(created, Failure):
|
||||
return Failure(f"cannot file the issue under {parent}: {created.reason}; {PERHAPS_FILED.format(parent=parent)}")
|
||||
key = created.get("key") if isinstance(created, dict) else None
|
||||
@@ -147,7 +149,7 @@ class JiraEpic:
|
||||
def searched(self, what: str, parents: tuple[str, ...], authorization: str) -> list[Found] | Failure:
|
||||
"""The issues whose parent is one of parents, in rank order."""
|
||||
named = ", ".join(f'"{key}"' for key in parents)
|
||||
answered = searched(self.epic.site, what, f"parent in ({named}) ORDER BY Rank ASC", {"fields": FIELDS}, authorization, self.http)
|
||||
answered = searched(self.epic.site, what, f"parent in ({named}) ORDER BY Rank ASC", {"fields": FIELDS, "properties": [PROPERTY]}, authorization, self.http)
|
||||
if isinstance(answered, Failure):
|
||||
return answered
|
||||
found = [found_of(raw) for raw in answered]
|
||||
@@ -176,9 +178,16 @@ def found_of(raw: object) -> Found | Failure:
|
||||
summary, labels, assignee, status, parent, description = fields["summary"], fields["labels"], fields["assignee"], fields["status"], fields["parent"]["key"], fields["description"]
|
||||
name = assignee["displayName"] if assignee is not None else None
|
||||
state, done = status["name"], status["statusCategory"]["key"] == "done"
|
||||
blockers = tuple(link.blocker for link in blocked_by_links(fields))
|
||||
held = raw.get("properties", {}).get(PROPERTY, {})
|
||||
except (AttributeError, KeyError, TypeError) as failure:
|
||||
return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: {failure!r}")
|
||||
texts = (summary, *labels, state, parent) if isinstance(labels, list) else ()
|
||||
if not texts or not all(isinstance(text, str) for text in texts) or not isinstance(name, str | None) or not ISSUE_KEY.fullmatch(parent) or not isinstance(description, dict | None):
|
||||
return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: its summary, labels, assignee, status, parent or description holds another kind of value")
|
||||
return Found(EpicIssue(key, summary.strip(), "", tuple(sorted(labels)), name, state, done, parent), description)
|
||||
texts = (summary, *labels, state, parent, *blockers) if isinstance(labels, list) else ()
|
||||
if not texts or not all(isinstance(text, str) for text in texts) or not isinstance(name, str | None) or not all(ISSUE_KEY.fullmatch(each) for each in (parent, *blockers)) or not isinstance(description, dict | None):
|
||||
return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: its summary, labels, assignee, status, parent, description or a linked issue's key holds another kind of value")
|
||||
if not isinstance(held, dict):
|
||||
return Failure(f"{key}'s issue property {PROPERTY} is not a JSON object")
|
||||
read = scores(key, held)
|
||||
if isinstance(read, Failure):
|
||||
return read
|
||||
return Found(EpicIssue(key, summary.strip(), "", tuple(sorted(labels)), name, state, done, parent, read.scores, read.moves, read.exempt, blockers, held.get(FILED_BY[0]) == FILED_BY[1]), description)
|
||||
|
||||
@@ -5,6 +5,7 @@ import dataclasses
|
||||
import re
|
||||
import typing
|
||||
|
||||
from plan.todo_table import Exempt, Moves
|
||||
from failure import Failure
|
||||
|
||||
# What a tracker accepts as a label: Jira refuses a label holding white space.
|
||||
@@ -28,6 +29,16 @@ class EpicIssue:
|
||||
done: bool
|
||||
# The epic's key for a child issue, the child's key for a sub-task.
|
||||
parent: str
|
||||
# The score of each column the issue has one for, such as {"L": 2}, as `plan_store` reads them from the issue's `plan-item` property. Empty where the issue has no scores.
|
||||
scores: dict[str, int] = dataclasses.field(default_factory=dict)
|
||||
# The goals the issue moves, and how far (the plan's Moves cell); empty where it names none.
|
||||
moves: Moves = ()
|
||||
# Why the issue is exempt from the plan's score bar, as the plan's Exempt cell names it; empty where it isn't.
|
||||
exempt: Exempt = ""
|
||||
# The key of each issue that blocks this one, in the tracker's order.
|
||||
blockers: tuple[str, ...] = ()
|
||||
# True where the loop filed the issue through EpicStore.file; False for an issue a person filed.
|
||||
by_loop: bool = False
|
||||
|
||||
|
||||
class EpicStore(typing.Protocol):
|
||||
@@ -41,7 +52,7 @@ class EpicStore(typing.Protocol):
|
||||
"""Each child issue, open or done, in the tracker's rank order, each followed by its sub-tasks in theirs."""
|
||||
|
||||
def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...]) -> str | Failure:
|
||||
"""Files an open issue under parent and answers its key: a child issue where parent is the epic, a sub-task where parent is one of its child issues. detail is markdown, and may be empty."""
|
||||
"""Files an open issue under parent, marked as filed by the loop, and answers its key: a child issue where parent is the epic, a sub-task where parent is one of its child issues. detail is markdown, and may be empty."""
|
||||
|
||||
def add_label(self, key: str, label: str) -> None | Failure:
|
||||
"""Adds label to the epic's child issue named key, leaving its other labels as they are; adding one it already has leaves the labels as they are. A sub-task, or an issue outside the epic, is refused."""
|
||||
|
||||
@@ -6,6 +6,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2]))
|
||||
|
||||
from do_epic.backend.contract import EpicStoreContract
|
||||
from failure import Failure
|
||||
from plan_store import jira_epic
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
|
||||
|
||||
@@ -22,6 +23,19 @@ class MemoryEpicContract(EpicStoreContract, unittest.TestCase):
|
||||
def close(self, store: MemoryEpic, key: str, status: str) -> None: # type: ignore[override]
|
||||
store.change(key, status=status, done=True)
|
||||
|
||||
def person_files(self, store: MemoryEpic, summary: str) -> str: # type: ignore[override]
|
||||
key = self.filed(store, store.epic_key, summary)
|
||||
store.change(key, by_loop=False)
|
||||
return key
|
||||
|
||||
def score(self, store: MemoryEpic, key: str, scores: dict[str, object]) -> None: # type: ignore[override]
|
||||
read = jira_epic.scores(key, scores)
|
||||
assert not isinstance(read, Failure), read
|
||||
store.change(key, scores=read.scores, moves=read.moves, exempt=read.exempt)
|
||||
|
||||
def block(self, store: MemoryEpic, key: str, blocker: str) -> None: # type: ignore[override]
|
||||
store.change(key, blockers=(*next(issue for issue in store.issues if issue.key == key).blockers, blocker))
|
||||
|
||||
|
||||
class Failing(unittest.TestCase):
|
||||
def test_every_read_filing_label_and_comment_fails_with_the_reason_given(self) -> None:
|
||||
|
||||
@@ -77,7 +77,7 @@ class FakeJira:
|
||||
if matched is None:
|
||||
return Failure("Jira answered 400: the JQL is not valid")
|
||||
parents = re.findall(r'"([A-Z]+-[0-9]+)"', matched[1])
|
||||
found = [{"key": issue["key"], "fields": {name: value for name, value in issue["fields"].items() if name in body.get("fields", [])}} for issue in self.issues if issue["fields"]["parent"]["key"] in parents] # type: ignore[index, attr-defined]
|
||||
found = [{"key": issue["key"], "fields": {name: value for name, value in issue["fields"].items() if name in body.get("fields", [])}, "properties": {name: value for name, value in issue.get("properties", {}).items() if name in body.get("properties", [])}} for issue in self.issues if issue["fields"]["parent"]["key"] in parents] # type: ignore[index, attr-defined]
|
||||
start = int(body.get("nextPageToken", 0))
|
||||
return {"issues": found[start:start + 2]} | ({"nextPageToken": str(start + 2)} if start + 2 < len(found) else {})
|
||||
|
||||
@@ -89,12 +89,21 @@ class FakeJira:
|
||||
if fields["project"] != {"key": "ABC"} or kind is None or fields["issuetype"] != kind:
|
||||
return Failure("Jira answered 400: the project, parent or issue type is not valid")
|
||||
key = f"ABC-{len(self.issues) + 100}"
|
||||
self.issues.append({"key": key, "fields": {"summary": fields["summary"], "description": fields.get("description"), "labels": fields["labels"], "assignee": None, "status": TO_DO, "parent": {"key": parent}}})
|
||||
self.issues.append({"key": key, "fields": {"summary": fields["summary"], "description": fields.get("description"), "labels": fields["labels"], "assignee": None, "status": TO_DO, "parent": {"key": parent}, "issuelinks": []}, "properties": {entry["key"]: entry["value"] for entry in body["properties"]}})
|
||||
return {"id": "1", "key": key}
|
||||
|
||||
def change(self, key: str, **fields: object) -> None:
|
||||
next(issue for issue in self.issues if issue["key"] == key)["fields"].update(fields) # type: ignore[union-attr]
|
||||
|
||||
def person_files(self, summary: str) -> str:
|
||||
"""Files a child issue as the Jira website does: with no issue property."""
|
||||
key = f"ABC-{len(self.issues) + 100}"
|
||||
self.issues.append({"key": key, "fields": {"summary": summary, "description": None, "labels": [], "assignee": None, "status": TO_DO, "parent": {"key": "ABC-12"}, "issuelinks": []}})
|
||||
return key
|
||||
|
||||
def set_property(self, key: str, value: dict[str, object]) -> None:
|
||||
next(issue for issue in self.issues if issue["key"] == key).setdefault("properties", {})["plan-item"] = value # type: ignore[attr-defined, union-attr]
|
||||
|
||||
|
||||
class Case(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
@@ -119,6 +128,17 @@ class JiraEpicContract(Case, EpicStoreContract):
|
||||
def close(self, store: JiraEpic, key: str, status: str) -> None: # type: ignore[override]
|
||||
self.jira.change(key, status={"name": status, "statusCategory": {"key": "done"}})
|
||||
|
||||
def person_files(self, store: JiraEpic, summary: str) -> str: # type: ignore[override]
|
||||
return self.jira.person_files(summary)
|
||||
|
||||
def score(self, store: JiraEpic, key: str, scores: dict[str, object]) -> None: # type: ignore[override]
|
||||
held = next(issue for issue in self.jira.issues if issue["key"] == key).get("properties", {}).get("plan-item", {}) # type: ignore[attr-defined, union-attr]
|
||||
self.jira.set_property(key, held | scores)
|
||||
|
||||
def block(self, store: JiraEpic, key: str, blocker: str) -> None: # type: ignore[override]
|
||||
links = next(issue for issue in self.jira.issues if issue["key"] == key)["fields"]["issuelinks"] # type: ignore[index]
|
||||
links.append({"id": str(len(links) + 1), "type": {"inward": "is blocked by", "outward": "blocks"}, "inwardIssue": {"key": blocker}})
|
||||
|
||||
|
||||
class Jira(Case):
|
||||
def test_reads_the_sub_tasks_of_more_children_than_one_search_names(self) -> None:
|
||||
@@ -154,16 +174,21 @@ class Jira(Case):
|
||||
self.assertEqual(len(self.jira.issues), 1)
|
||||
|
||||
def test_an_issue_in_another_shape_fails_the_read(self) -> None:
|
||||
valid = {"summary": "Count the runs.", "description": None, "labels": [], "assignee": None, "status": TO_DO, "parent": {"key": "ABC-12"}}
|
||||
valid = {"summary": "Count the runs.", "description": None, "labels": [], "assignee": None, "status": TO_DO, "parent": {"key": "ABC-12"}, "issuelinks": []}
|
||||
linked = {"id": "1", "type": {"inward": "is blocked by"}, "inwardIssue": {"key": "ABC-2"}}
|
||||
shape = "ABC-34 is not in the shape Jira Cloud's REST API version 3 documents"
|
||||
for raw, reason in (
|
||||
("ABC-34", "the search answered an issue without an issue key"),
|
||||
({"fields": valid}, "the search answered an issue without an issue key"),
|
||||
({"key": "abc-34", "fields": valid}, "the search answered an issue without an issue key"),
|
||||
({"key": "ABC-34", "fields": {"summary": "Count the runs.", "parent": {"key": "ABC-12"}}}, shape + ": KeyError('labels')"),
|
||||
*((({"key": "ABC-34", "fields": valid | changed}, shape + ": its summary, labels, assignee, status, parent or description holds another kind of value") for changed in (
|
||||
{"summary": 3}, {"labels": "api"}, {"labels": [3]}, {"assignee": {"displayName": 0}}, {"status": {"name": 0, "statusCategory": {"key": "new"}}}, {"parent": {"key": "ABC"}}, {"parent": {"key": 12}}, {"description": "text"},
|
||||
*((({"key": "ABC-34", "fields": valid | changed}, shape + ": its summary, labels, assignee, status, parent, description or a linked issue's key holds another kind of value") for changed in (
|
||||
{"summary": 3}, {"labels": "api"}, {"labels": [3]}, {"assignee": {"displayName": 0}}, {"status": {"name": 0, "statusCategory": {"key": "new"}}}, {"parent": {"key": "ABC"}}, {"parent": {"key": 12}}, {"description": "text"}, {"issuelinks": [linked | {"inwardIssue": {"key": 7}}]}, {"issuelinks": [linked | {"inwardIssue": {"key": "ABC-x"}}]},
|
||||
))),
|
||||
({"key": "ABC-34", "fields": {key: value for key, value in valid.items() if key != "issuelinks"}}, shape + ": KeyError('issuelinks')"),
|
||||
({"key": "ABC-34", "fields": valid, "properties": {"plan-item": "L 2"}}, "ABC-34's issue property plan-item is not a JSON object"),
|
||||
({"key": "ABC-34", "fields": valid, "properties": {"plan-item": {"L": "many"}}}, "item ABC-34's L 'many' is not a whole number from 1 to 4; ABC-34 holds it in its issue property plan-item"),
|
||||
({"key": "ABC-34", "fields": valid, "properties": None}, shape + ": AttributeError(\"'NoneType' object has no attribute 'get'\")"),
|
||||
):
|
||||
with self.subTest(raw=raw):
|
||||
self.jira.answers[("POST", SEARCH)] = {"issues": [raw]}
|
||||
|
||||
@@ -18,7 +18,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from test_env import isolated_env
|
||||
from test_env import assert_not_root, isolated_env
|
||||
from project_config.test_project_config import write_config
|
||||
|
||||
BIN = pathlib.Path(__file__).resolve().parents[1]
|
||||
@@ -753,8 +753,8 @@ class Cycles(unittest.TestCase):
|
||||
self.assertIn("past the noise", run.stdout)
|
||||
self.assertIn("past the noise", run.calls[1]["stdin"])
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root reads an unreadable file")
|
||||
def test_exits_1_when_the_transcript_cannot_be_read(self):
|
||||
assert_not_root(self)
|
||||
checkout = Checkout(self)
|
||||
run = checkout.run([worker(unreadable=True)])
|
||||
self.assertEqual((run.code, run.roles()), (1, ["worker"]))
|
||||
@@ -1000,8 +1000,8 @@ class Interrupt(unittest.TestCase):
|
||||
self.assertFalse(run.calls[2]["ctrl_c_ignored"])
|
||||
self.assertIn("[human] B", run.calls[3]["stdin"])
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root reads an unreadable file")
|
||||
def test_exits_1_when_the_transcript_cannot_be_read_after_the_interrupt(self):
|
||||
assert_not_root(self)
|
||||
checkout = Checkout(self)
|
||||
run = checkout.run([worker(say="A or B?"), judge(interrupt=True, evidence="A or B?", question="A or B?"), interrupt(type="B", unreadable=True)], terminal_input="/talk\n", before_typing=ANSWERING)
|
||||
self.assertEqual((run.code, run.roles()), (1, ["worker", "judge", "interrupt"]))
|
||||
@@ -1082,8 +1082,8 @@ class Models(unittest.TestCase):
|
||||
self.assertIn("no model catalog cached", run.stderr)
|
||||
self.assertEqual(argument(run.calls[0], "--model"), "1")
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory")
|
||||
def test_exits_1_when_the_models_file_cannot_be_written(self):
|
||||
assert_not_root(self)
|
||||
checkout = Checkout(self)
|
||||
del checkout.env["LOOP_CLAUDE_JUDGE_MODEL"], checkout.env["LOOP_CLAUDE_WORKER_MODEL"]
|
||||
checkout.models_file().parent.mkdir(parents=True, mode=0o500)
|
||||
|
||||
@@ -19,6 +19,7 @@ import uuid
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from routing_figures import archive, state
|
||||
from test_env import assert_not_root
|
||||
from claude_code.output_limits import BASH_CEILING_CHARACTERS
|
||||
from routing_figures.calls import Call
|
||||
from loop_claude.project import checkout, model_choice, records
|
||||
@@ -519,8 +520,8 @@ Spent since 2026-09-21T14:13:20Z, in tokens of input, cache write 5m, cache writ
|
||||
[next_chunk] = set(self.archive.iterdir()) - {chunk}
|
||||
self.assertEqual(sorted(path.read_text() for path in (next_chunk / "session" / str(self.session.id)).glob("custom-title.json*")), ["third"])
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root reads an unreadable folder")
|
||||
def test_stops_on_a_session_folder_it_cannot_read_whole(self):
|
||||
assert_not_root(self)
|
||||
locked = self.paths.claude_code_transcripts / "-fake" / str(self.session.id) / "subagents"
|
||||
locked.mkdir(parents=True)
|
||||
locked.chmod(0)
|
||||
@@ -689,8 +690,8 @@ Spent since 2026-09-21T14:13:20Z, in tokens of input, cache write 5m, cache writ
|
||||
self.assertIn(f"\n{STAMP} Which one?\a\n", said.getvalue())
|
||||
self.assertNotIn("Use ... A.", said.getvalue())
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory")
|
||||
def test_stops_keeping_the_transcript_when_the_finished_chunks_session_cannot_be_deleted(self):
|
||||
assert_not_root(self)
|
||||
folder = self.paths.claude_code_transcripts / "-fake" / str(self.session.id)
|
||||
(folder / "subagents").mkdir(parents=True)
|
||||
folder.chmod(0o500)
|
||||
@@ -967,8 +968,8 @@ class RoutingCheck(unittest.TestCase):
|
||||
stop, _ = self.check(FakeEffects(on_terminal_claude=[OSError(2, "No such file or directory")], git=[UNREAD] * 3))
|
||||
self.assertEqual(stop, Stop(1, f"could not start claude for the routing calls in {self.home / 'code' / 'claude-config'}, the setup's development clone: No such file or directory"))
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory")
|
||||
def test_says_a_figure_it_cannot_write_and_goes_on(self):
|
||||
assert_not_root(self)
|
||||
self.chunks(5, 4)
|
||||
(self.root / "routing-figures.lock").touch()
|
||||
self.root.chmod(0o555)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
@@ -22,9 +20,6 @@ Touches:
|
||||
More prose, with `bin/b.py` named.
|
||||
"""
|
||||
|
||||
needs_docker = unittest.skipIf(shutil.which("docker") is None or subprocess.run(["docker", "info"], capture_output=True, timeout=20).returncode != 0, "adf_codec runs in a container, which needs a docker daemon")
|
||||
|
||||
|
||||
def text(words: str, code: bool = False) -> dict:
|
||||
return {"type": "text", "text": words, **({"marks": [{"type": "code"}]} if code else {})}
|
||||
|
||||
@@ -90,15 +85,14 @@ class PredictedTest(unittest.TestCase):
|
||||
def test_a_longer_run_with_a_space_at_one_end_only_keeps_it(self) -> None:
|
||||
self.assertEqual(predicted("Touches:\n- `a.md`: `` x``, ``y ``, `` a ``\n"), {"a.md": (Part(" x"), Part("y "), Part("a"))})
|
||||
|
||||
@needs_docker
|
||||
def test_a_list_written_in_markdown_and_read_back_from_a_jira_description_reads_as_written(self) -> None:
|
||||
description = convert.markdown_to_adf(DETAIL)
|
||||
assert isinstance(description, dict)
|
||||
assert isinstance(description, dict), description
|
||||
self.assertEqual(predicted(convert.adf_to_markdown(description)), predicted(DETAIL))
|
||||
|
||||
@needs_docker
|
||||
def test_a_list_typed_in_jiras_editor_reads_as_its_files_and_parts(self) -> None:
|
||||
read = convert.adf_to_markdown(JIRA_TOUCHES)
|
||||
assert isinstance(read, str), read
|
||||
self.assertEqual(predicted(read), {
|
||||
"bin/a.py": (Part("main"), Part("Plan.branch", small=True)),
|
||||
"a`b.md": (Part("## The `foo` tool", small=True), Part("`x`")),
|
||||
|
||||
@@ -476,7 +476,7 @@ def issue_of(raw: object) -> Issue | Failure:
|
||||
# The answer's nested fields are read as Jira documents them; one missing or of another type ends the read here, as a Failure, so no later step meets it.
|
||||
try:
|
||||
fields = raw["fields"]
|
||||
links = tuple(Link(link["inwardIssue"]["key"], link["id"]) for link in fields["issuelinks"] if "inwardIssue" in link and link["type"]["inward"] == "is blocked by")
|
||||
links = blocked_by_links(fields)
|
||||
held = raw.get("properties", {}).get(PROPERTY, {})
|
||||
summary, description, versions = fields["summary"].strip(), fields["description"], tuple(version["name"] for version in fields["fixVersions"])
|
||||
except (AttributeError, KeyError, TypeError) as failure:
|
||||
@@ -489,6 +489,11 @@ def issue_of(raw: object) -> Issue | Failure:
|
||||
return issue
|
||||
|
||||
|
||||
def blocked_by_links(fields: dict[str, typing.Any]) -> tuple[Link, ...]:
|
||||
"""The "is blocked by" links among an issue's `issuelinks` field. A field not in the shape Jira documents raises a KeyError or TypeError, which the caller turns into a Failure."""
|
||||
return tuple(Link(link["inwardIssue"]["key"], link["id"]) for link in fields["issuelinks"] if "inwardIssue" in link and link["type"]["inward"] == "is blocked by")
|
||||
|
||||
|
||||
def keys_of(answered: list[object]) -> set[object]:
|
||||
"""The key of each issue in the search's answer."""
|
||||
return {raw.get("key") for raw in answered if isinstance(raw, dict)}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import dataclasses
|
||||
import decimal
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -8,6 +7,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from test_env import assert_not_root
|
||||
from project_config.settings import DEFAULT_FLOOR, Epic, Finish, JiraScoring, ProjectConfig, SETTINGS
|
||||
from failure import Failure
|
||||
from record_store.stores import FileStore, goals_store, store as record_store
|
||||
@@ -136,8 +136,8 @@ class FilePlan(FilePlanContract):
|
||||
self.assertEqual(store.edit(id_, {}, "### Why\n"), Failure(split))
|
||||
self.assertEqual((self.folder / "todo.md").read_text(), before)
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory")
|
||||
def test_a_file_it_cannot_write_fails_naming_it(self):
|
||||
assert_not_root(self)
|
||||
store = self.new_store()
|
||||
self.folder.chmod(0o555)
|
||||
self.addCleanup(self.folder.chmod, 0o755)
|
||||
|
||||
@@ -15,6 +15,7 @@ import unittest.mock
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from routing_figures import archive, state
|
||||
from test_env import assert_not_root, isolated_env
|
||||
from project_config.templates import BARE, Titles
|
||||
from branch_chunks.cut import BranchChunk
|
||||
from routing_figures.calls import Call, calls, totals
|
||||
@@ -25,7 +26,6 @@ from routing_figures.state import due
|
||||
from claude_code.entries import entry_from
|
||||
from failure import Failure
|
||||
from git_cli import git_repo
|
||||
from test_env import isolated_env
|
||||
from plan.todo_table import Item
|
||||
from transcript_archive import outcomes, write
|
||||
from model_routing.ladder_file import read_ladder, SHIPPED
|
||||
@@ -495,8 +495,8 @@ class Archive(unittest.TestCase):
|
||||
self.assertIsNone(state.mark_raised(self.root, [a], "2026-10-15T02:00:00Z"))
|
||||
self.assertEqual(state.raised(self.root), state.Raised("2026-10-15T01:00:00Z", frozenset({a})))
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory")
|
||||
def test_fails_when_it_cannot_keep_the_state(self):
|
||||
assert_not_root(self)
|
||||
self.root.chmod(0o555)
|
||||
self.addCleanup(self.root.chmod, 0o755)
|
||||
self.assertIsInstance(state.mark_measured(self.root, 40), Failure)
|
||||
|
||||
@@ -94,8 +94,7 @@ class RunHeavy(unittest.TestCase):
|
||||
|
||||
def test_a_docker_run_without_limits_gets_three_quarters_of_the_memory_split_across_the_slots(self):
|
||||
memory = read_memory()
|
||||
if memory is None:
|
||||
self.skipTest("no /proc/meminfo to read the share from")
|
||||
assert memory is not None, "this test needs MemTotal and MemAvailable from /proc/meminfo: run it on Linux"
|
||||
share = f"{memory.total * 3 // 4 // slot_count(usable_cpus()) // 1024}m"
|
||||
result = self.run_tool("docker", "run", "--rm", "img", "true", env=self.fake_docker())
|
||||
self.assertEqual((result.returncode, result.stdout), (0, f"run --memory {share} --memory-swap {share} --rm img true\n"))
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import contextlib
|
||||
import importlib.util
|
||||
import io
|
||||
from unittest import mock
|
||||
import os
|
||||
@@ -14,10 +13,8 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from run_tests import main
|
||||
|
||||
BIN = pathlib.Path(__file__).resolve().parents[1]
|
||||
# The suite runs under pytest, and `python3 -m unittest` may run it where pytest is not installed.
|
||||
HAS_PYTEST = importlib.util.find_spec("pytest") is not None
|
||||
HAS_XDIST = importlib.util.find_spec("xdist") is not None
|
||||
PYTEST_HERE = [sys.executable, "-m", "pytest", "-p", "no:cacheprovider"]
|
||||
# run-tests' own pytest command, without its worker count. uvx fetches pytest for it, so the Run tests need no pytest installed.
|
||||
PYTEST_PINNED = [*main.PYTEST[:main.PYTEST.index("-n")], "-p", "no:cacheprovider"]
|
||||
|
||||
|
||||
class PytestArgs(unittest.TestCase):
|
||||
@@ -109,7 +106,6 @@ class RunWithAStandIn(unittest.TestCase):
|
||||
self.assertEqual(err.getvalue(), "run-tests: cannot start /no/such/uvx: No such file or directory\n")
|
||||
|
||||
|
||||
@unittest.skipUnless(HAS_PYTEST, "needs pytest importable")
|
||||
class Run(unittest.TestCase):
|
||||
def run_in(self, folder: str, pytest: list[str], *args: str) -> tuple[int, str]:
|
||||
out = io.StringIO()
|
||||
@@ -127,8 +123,8 @@ class Run(unittest.TestCase):
|
||||
def test_a_passing_run_prints_the_summary_line_and_the_log_path(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
pathlib.Path(folder, "test_ok.py").write_text("def test_ok():\n\tprint('noise from a passing test')\n")
|
||||
code, output = self.run_in(folder, PYTEST_HERE, "-s", folder)
|
||||
self.assertEqual(code, 0)
|
||||
code, output = self.run_in(folder, PYTEST_PINNED, "-s", folder)
|
||||
self.assertEqual(code, 0, output)
|
||||
lines = output.rstrip("\n").splitlines()
|
||||
self.assertEqual(len(lines), 2, output)
|
||||
self.assertRegex(lines[0], r"^=+ 1 passed in .* =+$")
|
||||
@@ -136,10 +132,9 @@ class Run(unittest.TestCase):
|
||||
|
||||
def test_a_failing_run_prints_each_failing_test_with_its_error(self):
|
||||
# pytest-xdist drops the error from the short summary's lines, so the run takes it from the FAILURES section.
|
||||
workers = ["-n", "2"] if HAS_XDIST else []
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
pathlib.Path(folder, "test_bad.py").write_text("def test_ok():\n\tpass\n\ndef test_bad():\n\tassert 1 == 2, 'one is not two'\n\ndef test_long():\n\traise ValueError('\\n'.join(map(str, range(30))))\n")
|
||||
code, output = self.run_in(folder, PYTEST_HERE, *workers, folder)
|
||||
code, output = self.run_in(folder, PYTEST_PINNED, "-n", "2", folder)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertRegex(output, r"(?m)^_+ test_bad _+\nE +AssertionError: one is not two\n(E .*\n)*.*test_bad\.py:5: AssertionError$")
|
||||
self.assertRegex(output, r"(?m)^FAILED .*test_bad\.py::test_bad\b")
|
||||
@@ -158,7 +153,7 @@ class Run(unittest.TestCase):
|
||||
|
||||
def test_a_run_that_prints_no_summary_line_shows_the_logs_last_lines(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
code, output = self.run_in(folder, PYTEST_HERE, "--no-such-option", folder)
|
||||
code, output = self.run_in(folder, PYTEST_PINNED, "--no-such-option", folder)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("run-tests: pytest printed no summary line; the log ends:", output)
|
||||
self.assertIn("--no-such-option", output)
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
|
||||
# A git hook's GIT_DIR, the host's LOOP_CLAUDE_* or PYTHONPATH would point the program under test at the host's own state,
|
||||
# and the host's CLAUDE_CODE_SANDBOXED would hide whether loop-claude sets it.
|
||||
def isolated_env() -> dict[str, str]:
|
||||
return {name: value for name, value in os.environ.items() if not name.startswith(("GIT_", "LOOP_CLAUDE_", "PYTHON")) and name != "CLAUDE_CODE_SANDBOXED"}
|
||||
|
||||
|
||||
# Call it first in a test that takes a file's or a folder's permissions away.
|
||||
def assert_not_root(test: unittest.TestCase) -> None:
|
||||
test.assertNotEqual(os.geteuid(), 0, "root ignores file permissions, which this test checks: run the tests as a user other than root")
|
||||
|
||||
Reference in New Issue
Block a user