fix(kvb-git-hotfix): adopt the register task the hotfix belongs to
hotfix.py add now adopts an existing rasci task of the same branch and repository: the adding session becomes R and A, the former A keeps its other letters, and a task on another branch or repository is refused instead of overwritten. 🎯 Fix: 92 % 💥 Break: 4 % 💸 Tokens: 100 % ⏱️ Velocity: 100 % 🛡️ Security: 100 % 🏆 Score: 88 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a2a03995cb
commit
d9ccb74e3d
2 files changed
+97
-8
No files matched your search
@@ -20,7 +20,12 @@ Args:
|
|||||||
repeat around another unbounded repeat or around an alternation whose
|
repeat around another unbounded repeat or around an alternation whose
|
||||||
branches can start alike; bounded repeats such as {3} pass. Each
|
branches can start alike; bounded repeats such as {3} pass. Each
|
||||||
--target is a make target or `deploy` the fix turns green, none listed
|
--target is a make target or `deploy` the fix turns green, none listed
|
||||||
means every target; --pr is the pull request number.
|
means every target; --pr is the pull request number. A register
|
||||||
|
task of that name without hotfix fields, as `rasci.py set` leaves
|
||||||
|
it (for example for a `queue.py hold`), takes them and keeps its
|
||||||
|
other fields and roles, with the adding session as R and A and its
|
||||||
|
status set from --status; one that already is a hotfix, records
|
||||||
|
another branch or works in another repository is refused.
|
||||||
update <slug> --status staged|pr|merged [--sha <commit>] [--pr <n>]
|
update <slug> --status staged|pr|merged [--sha <commit>] [--pr <n>]
|
||||||
[--repo <abs clone>] [--default <branch>] [--session <id>]: move a
|
[--repo <abs clone>] [--default <branch>] [--session <id>]: move a
|
||||||
hotfix on. --sha resolves in the recorded git common dir or in
|
hotfix on. --sha resolves in the recorded git common dir or in
|
||||||
@@ -563,12 +568,45 @@ def pr_cell(row: dict) -> str:
|
|||||||
return f"#{row['pr']}" if row.get("pr") else "-"
|
return f"#{row['pr']}" if row.get("pr") else "-"
|
||||||
|
|
||||||
|
|
||||||
|
def adoptable(task: str, row: dict | None, branch: str, repository: tuple[str, str]) -> dict:
|
||||||
|
if row is None:
|
||||||
|
return {}
|
||||||
|
if "stage" in row:
|
||||||
|
fail(f"{task} is already in the register; move it on with update")
|
||||||
|
if row.get("branch") not in (None, "", branch):
|
||||||
|
fail(f"{task} works on {row['branch']}, --branch says {branch}")
|
||||||
|
there = identity(row.get("workdir") or "")
|
||||||
|
if there is not None and not same(there, repository):
|
||||||
|
fail(f"{task} works in {row['workdir']}, another repository than --repo")
|
||||||
|
return row
|
||||||
|
|
||||||
|
|
||||||
|
def authored(roles: dict, author: str) -> dict:
|
||||||
|
"""Args:
|
||||||
|
roles: the adopted task's roles.
|
||||||
|
author: the adding session.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The roles with the author as R and A besides its own letters, and A
|
||||||
|
taken from every other party.
|
||||||
|
"""
|
||||||
|
others = {party: "".join(letter for letter in letters if letter != "A") for party, letters in roles.items() if party != author}
|
||||||
|
mine = "".join(letter for letter in "RASCI" if letter in roles.get(author, "") + "RA")
|
||||||
|
return {**{party: letters for party, letters in others.items() if letters}, author: mine}
|
||||||
|
|
||||||
|
|
||||||
|
def set_status(rasci: ModuleType, row: dict, status: str) -> None:
|
||||||
|
final = "stopped" if status == "done" and rasci.open_results(row) else status
|
||||||
|
if row.get("status") != final:
|
||||||
|
row.pop("end", None)
|
||||||
|
rasci.apply_status(row, final)
|
||||||
|
|
||||||
|
|
||||||
def cmd_add(rasci: ModuleType, args: argparse.Namespace) -> int:
|
def cmd_add(rasci: ModuleType, args: argparse.Namespace) -> int:
|
||||||
task = task_of(rasci, args.slug)
|
task = task_of(rasci, args.slug)
|
||||||
if task in rasci.load():
|
|
||||||
fail(f"{task} is already in the register; move it on with update")
|
|
||||||
repo = clone(args.repo)
|
repo = clone(args.repo)
|
||||||
common, origin = identity(repo)
|
common, origin = identity(repo)
|
||||||
|
adoptable(task, rasci.load().get(task), args.branch, (common, origin))
|
||||||
entry = {
|
entry = {
|
||||||
"common_dir": common,
|
"common_dir": common,
|
||||||
"origin": origin,
|
"origin": origin,
|
||||||
@@ -583,11 +621,11 @@ def cmd_add(rasci: ModuleType, args: argparse.Namespace) -> int:
|
|||||||
entry["sha"] = landed(repo, args.sha, args.default) if args.status == "merged" else commit(repo, args.sha)
|
entry["sha"] = landed(repo, args.sha, args.default) if args.status == "merged" else commit(repo, args.sha)
|
||||||
council = module("council", rasci.COUNCIL)
|
council = module("council", rasci.COUNCIL)
|
||||||
sid, _ = council.caller(args.session)
|
sid, _ = council.caller(args.session)
|
||||||
entry["roles"] = {council.live_sessions().get(sid) or sid: "RA"}
|
author = council.live_sessions().get(sid) or sid
|
||||||
rasci.apply_status(entry, REGISTER_STATUS[args.status])
|
|
||||||
with rasci.database() as tasks:
|
with rasci.database() as tasks:
|
||||||
if task in tasks:
|
row = adoptable(task, tasks.get(task), entry["branch"], (common, origin))
|
||||||
fail(f"{task} is already in the register; move it on with update")
|
entry = {**row, **entry, "roles": authored(row.get("roles") or {}, author)}
|
||||||
|
set_status(rasci, entry, REGISTER_STATUS[args.status])
|
||||||
tasks[task] = entry
|
tasks[task] = entry
|
||||||
print(f"added {task}")
|
print(f"added {task}")
|
||||||
if args.status == "merged":
|
if args.status == "merged":
|
||||||
@@ -656,7 +694,7 @@ def cmd_update(rasci: ModuleType, args: argparse.Namespace) -> int:
|
|||||||
fail(f"{task}: no hotfix in the register; record it with add")
|
fail(f"{task}: no hotfix in the register; record it with add")
|
||||||
entry.update(fields)
|
entry.update(fields)
|
||||||
entry["stage"] = args.status
|
entry["stage"] = args.status
|
||||||
rasci.apply_status(entry, REGISTER_STATUS[args.status])
|
set_status(rasci, entry, REGISTER_STATUS[args.status])
|
||||||
print(f"updated {task}")
|
print(f"updated {task}")
|
||||||
if args.status == "merged":
|
if args.status == "merged":
|
||||||
announce(task, entry, args.session)
|
announce(task, entry, args.session)
|
||||||
|
|||||||
@@ -289,6 +289,57 @@ class TestHotfix(unittest.TestCase):
|
|||||||
self.assertIn("| hotfix/lint | running | - | One |", shown)
|
self.assertIn("| hotfix/lint | running | - | One |", shown)
|
||||||
self.assertNotIn("hotfix/db", shown)
|
self.assertNotIn("hotfix/db", shown)
|
||||||
|
|
||||||
|
def test_add_adopts_a_register_task_without_hotfix_fields_and_keeps_its_own(self):
|
||||||
|
self.rasci("set", "hotfix/queued", "--title", "held for a gate", "--branch", "fix/q", "--workdir", str(self.work), "--status", "running")
|
||||||
|
self.rasci("role", "hotfix/queued", "Two", "RA")
|
||||||
|
before = self.rows()["hotfix/queued"]
|
||||||
|
self.assertEqual(self.out("add", "queued", *self.flags({"--branch": "fix/q", "--status": "pr", "--pr": "1950"})),
|
||||||
|
["added hotfix/queued"])
|
||||||
|
row = self.rows()["hotfix/queued"]
|
||||||
|
self.assertEqual((row["title"], row["workdir"], row["start"]), ("held for a gate", str(self.work), before["start"]))
|
||||||
|
self.assertEqual((row["roles"]["One"], row["roles"]["Two"]), ("RA", "R"))
|
||||||
|
self.assertEqual([party for party, letters in row["roles"].items() if "A" in letters], ["One"])
|
||||||
|
self.assertEqual((row["branch"], row["stage"], row["pr"], row["sha"], row["status"]),
|
||||||
|
("fix/q", "pr", 1950, self.lint, "running"))
|
||||||
|
self.assertIn("hotfix/queued", "\n".join(self.out("pending", "--repo", str(self.seed))))
|
||||||
|
self.assertEqual(self.out("update", "queued", "--status", "staged"), ["updated hotfix/queued"])
|
||||||
|
self.rasci("set", "hotfix/elsewhere", "--branch", "fix/other")
|
||||||
|
foreign = self.base / "foreign"
|
||||||
|
self.git(self.base, "init", "-q", str(foreign))
|
||||||
|
self.rasci("set", "hotfix/foreign", "--workdir", str(foreign))
|
||||||
|
register = self.root / "rasci.json"
|
||||||
|
kept = register.read_text(encoding="utf-8")
|
||||||
|
for slug, branch, message in (("queued", "fix/q", "already in the register; move it on with update"),
|
||||||
|
("elsewhere", "fix/x", "works on fix/other, --branch says fix/x"),
|
||||||
|
("foreign", "fix/f", f"works in {foreign}, another repository than --repo")):
|
||||||
|
with self.subTest(slug=slug):
|
||||||
|
result = self.hotfix("add", slug, *self.flags({"--branch": branch}))
|
||||||
|
self.assertEqual(result.returncode, 2)
|
||||||
|
self.assertIn(message, result.stderr)
|
||||||
|
self.assertEqual(register.read_text(encoding="utf-8"), kept)
|
||||||
|
|
||||||
|
def test_an_adopted_task_takes_its_status_from_the_hotfix_and_keeps_open_key_results_open(self):
|
||||||
|
self.rasci("set", "hotfix/ended", "--status", "done")
|
||||||
|
self.assertIn("end", self.rows()["hotfix/ended"])
|
||||||
|
self.out("add", "ended", *self.flags({"--branch": "fix/e", "--status": "pr"}))
|
||||||
|
row = self.rows()["hotfix/ended"]
|
||||||
|
self.assertEqual((row["status"], "end" in row), ("running", False))
|
||||||
|
self.rasci("set", "hotfix/landed", "--status", "running")
|
||||||
|
self.rasci("kr", "hotfix/landed", "add", "the deploy is green")
|
||||||
|
self.out("add", "landed", *self.flags({"--branch": "fix/db", "--sha": self.fix, "--status": "merged"}))
|
||||||
|
row = self.rows()["hotfix/landed"]
|
||||||
|
self.assertEqual((row["stage"], row["status"], "end" in row), ("merged", "stopped", True))
|
||||||
|
old = "2000-01-01T00:00:00+00:00"
|
||||||
|
self.rasci("set", "hotfix/landed", "--end", old)
|
||||||
|
self.rasci("kr", "hotfix/landed", "met", "1")
|
||||||
|
self.assertEqual(self.out("update", "landed", "--status", "merged", "--sha", self.fix), ["updated hotfix/landed"])
|
||||||
|
row = self.rows()["hotfix/landed"]
|
||||||
|
self.assertEqual(row["status"], "done")
|
||||||
|
self.assertNotEqual(row["end"], old)
|
||||||
|
self.rasci("set", "hotfix/closed", "--status", "done", "--end", old)
|
||||||
|
self.out("add", "closed", *self.flags({"--branch": "fix/db", "--sha": self.fix, "--status": "merged"}))
|
||||||
|
self.assertEqual(self.rows()["hotfix/closed"]["end"], old)
|
||||||
|
|
||||||
def test_pending_reports_missing_and_open_hotfixes_of_the_repository(self):
|
def test_pending_reports_missing_and_open_hotfixes_of_the_repository(self):
|
||||||
expected = [
|
expected = [
|
||||||
f"missing (merge main)\thotfix/db\tmerged\tfix/db\t{self.fix}\t#12",
|
f"missing (merge main)\thotfix/db\tmerged\tfix/db\t{self.fix}\t#12",
|
||||||
|
|||||||
Reference in new issue
Block a user