diff --git a/steam_backlog_enforcer/_todo_filing.py b/steam_backlog_enforcer/_todo_filing.py index 9d8f940..68c3a49 100644 --- a/steam_backlog_enforcer/_todo_filing.py +++ b/steam_backlog_enforcer/_todo_filing.py @@ -142,10 +142,17 @@ def _parse(ctype: str, body: str) -> dict[str, Any]: def _open_task(listing: str, title: str) -> str | None: - """The id of an open task in *listing* titled exactly *title*.""" + """The id of an open task in *listing* titled *title*. + + The server lists a new note as `` todos: ``, so the + title matches exactly or as that suffix. + """ for row in listing.splitlines(): parts = row.split("\t") - if len(parts) >= _COLUMNS and re.sub(r"^#+\s*", "", parts[4].strip()) == title: + if len(parts) < _COLUMNS: + continue + listed = re.sub(r"^#+\s*", "", parts[4].strip()) + if listed == title or listed.endswith(f": {title}"): return parts[0] return None diff --git a/steam_backlog_enforcer/tests/_fake_todo_mcp.py b/steam_backlog_enforcer/tests/_fake_todo_mcp.py index aa2ffe9..3eaf562 100644 --- a/steam_backlog_enforcer/tests/_fake_todo_mcp.py +++ b/steam_backlog_enforcer/tests/_fake_todo_mcp.py @@ -42,8 +42,18 @@ class FakeTodo(ThreadingHTTPServer): """Answer one tool call the way the real server words it.""" self.calls.append(name) if name == "list_tasks": + # The real server titles a new note "<repo name> todos: <title>". rows = [ - f"{t['id'][:8]}\ttodo\t{t['priority']}\t{t['repo']}\t{t['title']}\tclaude" + "\t".join( + ( + t["id"][:8], + "todo", + t["priority"], + t["repo"], + _listed(t), + "claude", + ) + ) for t in self.tasks if t["repo"] == args.get("repo") ] @@ -55,6 +65,11 @@ class FakeTodo(ThreadingHTTPServer): return f"added {task['id']}\n{task['id'][:8]}\ttodo\tmedium\t{task['repo']}" +def _listed(task: dict[str, Any]) -> str: + """The title list_tasks shows for *task*, as the real server words it.""" + return f"{task['repo'].split('/')[-1]} todos: {task['title']}" + + class _Handler(BaseHTTPRequestHandler): server: FakeTodo