From b586047080fbeecc7b4cf3ce9da13a1870c7eff5 Mon Sep 17 00:00:00 2001 From: prateeksingh Date: Wed, 18 Nov 2026 01:34:03 +0530 Subject: [PATCH 1/2] fix(cli): show full task and parent IDs in rich views (#1340) --- changelog.d/1340-task-rich-full-ids.fixed.md | 1 + pyrite/cli/task_commands.py | 10 +- tests/test_task_rich_ids.py | 123 +++++++++++++++++++ 3 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 changelog.d/1340-task-rich-full-ids.fixed.md create mode 100644 tests/test_task_rich_ids.py diff --git a/changelog.d/1340-task-rich-full-ids.fixed.md b/changelog.d/1340-task-rich-full-ids.fixed.md new file mode 100644 index 000000000..20c321260 --- /dev/null +++ b/changelog.d/1340-task-rich-full-ids.fixed.md @@ -0,0 +1 @@ +- `pyrite task list` and `pyrite task get` in rich format now display full task and parent IDs instead of truncating them to 12 characters (#1340). diff --git a/pyrite/cli/task_commands.py b/pyrite/cli/task_commands.py index 2e89ad521..7cd6a1030 100644 --- a/pyrite/cli/task_commands.py +++ b/pyrite/cli/task_commands.py @@ -302,21 +302,21 @@ def _status_cell(item: dict) -> str: def _render_list(console, data: dict) -> None: table = Table(title="Tasks") - table.add_column("ID", style="cyan", max_width=12) + table.add_column("ID", style="cyan", overflow="fold") table.add_column("Title") table.add_column("Status", style="green") table.add_column("Pri", justify="right") table.add_column("Assignee", style="yellow") - table.add_column("Parent", style="dim", max_width=12) + table.add_column("Parent", style="dim", overflow="fold") for item in data["tasks"]: table.add_row( - item["id"][:12], + item["id"], item["title"], _status_cell(item), str(item["priority"]), item["assignee"], - item["parent"][:12] if item["parent"] else "", + item["parent"] or "", ) console.print(table) @@ -395,7 +395,7 @@ def _render_task(console, result: dict) -> None: if children: console.print(f"\n [bold]Children ({len(children)}):[/bold]") for c in children: - console.print(f" {c['id'][:12]} {c['status']:12} {c['title']}") + console.print(f" {c['id']} {c['status']:12} {c['title']}") def _task_get_impl(task_id: str, kb_name: str | None) -> Outcome: diff --git a/tests/test_task_rich_ids.py b/tests/test_task_rich_ids.py new file mode 100644 index 000000000..e5dc19920 --- /dev/null +++ b/tests/test_task_rich_ids.py @@ -0,0 +1,123 @@ +"""Tests for task list and task get (rich) showing full task and parent IDs (#1340). + +Regression coverage for: +- Task ID and Parent ID in `task list --format rich` are not sliced to 12 chars. +- Child task IDs in `task get --format rich` are not sliced to 12 chars. +- Long IDs render fully on wide terminals and fold rather than being truncated on narrow terminals. +""" + +from __future__ import annotations + +import tempfile +from pathlib import Path +from unittest.mock import patch + +import pytest +from typer.testing import CliRunner + +from pyrite.cli import app +from pyrite.config import KBConfig, PyriteConfig, Settings +from pyrite.services.task_service import TaskService +from pyrite.storage.database import PyriteDB + +runner = CliRunner() + + +@pytest.fixture +def long_id_task_cli_env(): + """Temp task KB with parent and child tasks having IDs longer than 12 characters.""" + with tempfile.TemporaryDirectory() as tmpdir: + tmpdir = Path(tmpdir) + tasks_path = tmpdir / "tasks-kb" + (tasks_path / "tasks").mkdir(parents=True) + + kb_config = KBConfig( + name="test-tasks", path=tasks_path, kb_type="task", description="Test task KB" + ) + config = PyriteConfig( + knowledge_bases=[kb_config], + settings=Settings(index_path=tmpdir / "index.db"), + ) + db = PyriteDB(config.settings.index_path) + db.register_kb( + name="test-tasks", kb_type="task", path=str(tasks_path), description="Test task KB" + ) + svc = TaskService(config, db) + + # Create parent task with id > 12 chars: parent-epic-for-login + parent = svc.create_task( + kb_name="test-tasks", + title="Parent epic for login", + ) + # Create child task with id > 12 chars: write-the-login-form + child = svc.create_task( + kb_name="test-tasks", + title="Write the login form", + parent=parent["entry_id"], + ) + # Create task with exactly 12 chars: exactly twel + exact = svc.create_task( + kb_name="test-tasks", + title="Exactly twel", + ) + db.close() + + with patch("pyrite.cli.context.load_config", return_value=config): + yield { + "config": config, + "parent_id": parent["entry_id"], + "child_id": child["entry_id"], + "exact_id": exact["entry_id"], + } + + +@pytest.mark.cli +def test_task_list_rich_displays_full_ids_and_parent_id(long_id_task_cli_env): + """`task list --format rich` displays the full task ID and parent ID without 12-char cut.""" + parent_id = long_id_task_cli_env["parent_id"] + child_id = long_id_task_cli_env["child_id"] + exact_id = long_id_task_cli_env["exact_id"] + + res = runner.invoke( + app, + ["task", "list", "-k", "test-tasks", "--format", "rich"], + env={"COLUMNS": "200"}, + ) + assert res.exit_code == 0, res.output + + # The full IDs must be present in the rich table output + assert parent_id in res.output + assert child_id in res.output + assert exact_id in res.output + + +@pytest.mark.cli +def test_task_get_rich_displays_full_child_ids(long_id_task_cli_env): + """`task get --format rich` displays child tasks by their full IDs.""" + parent_id = long_id_task_cli_env["parent_id"] + child_id = long_id_task_cli_env["child_id"] + + res = runner.invoke( + app, + ["task", "get", parent_id, "-k", "test-tasks", "--format", "rich"], + env={"COLUMNS": "200"}, + ) + assert res.exit_code == 0, res.output + + # The full child ID must appear in the children section + assert child_id in res.output + + +@pytest.mark.cli +def test_task_list_rich_narrow_terminal_folds_without_crash(long_id_task_cli_env): + """In a narrow terminal (COLUMNS=60), task list folds IDs across lines without truncating.""" + res = runner.invoke( + app, + ["task", "list", "-k", "test-tasks", "--format", "rich"], + env={"COLUMNS": "60"}, + ) + assert res.exit_code == 0, res.output + # Long IDs fold across lines rather than being cut or replaced with ellipsis + assert "..." not in res.output + assert "write-th" in res.output and "form" in res.output + assert "parent-" in res.output and "login" in res.output From 5a4867ddd53f36efeab42962254b08e99d6946de Mon Sep 17 00:00:00 2001 From: prateeksingh Date: Wed, 18 Nov 2026 02:06:27 +0530 Subject: [PATCH 2/2] test(task): use cli_world fixture and verify reassembled columns (#1340) --- tests/test_task_rich_ids.py | 150 ++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/tests/test_task_rich_ids.py b/tests/test_task_rich_ids.py index e5dc19920..35da3e165 100644 --- a/tests/test_task_rich_ids.py +++ b/tests/test_task_rich_ids.py @@ -8,81 +8,73 @@ from __future__ import annotations -import tempfile +import json from pathlib import Path -from unittest.mock import patch import pytest from typer.testing import CliRunner from pyrite.cli import app -from pyrite.config import KBConfig, PyriteConfig, Settings -from pyrite.services.task_service import TaskService -from pyrite.storage.database import PyriteDB - -runner = CliRunner() +from pyrite.config import KBConfig @pytest.fixture -def long_id_task_cli_env(): +def long_id_task_world(cli_world, tmp_path: Path): """Temp task KB with parent and child tasks having IDs longer than 12 characters.""" - with tempfile.TemporaryDirectory() as tmpdir: - tmpdir = Path(tmpdir) - tasks_path = tmpdir / "tasks-kb" - (tasks_path / "tasks").mkdir(parents=True) + kb_path = tmp_path / "tasks-kb" + (kb_path / "tasks").mkdir(parents=True) - kb_config = KBConfig( - name="test-tasks", path=tasks_path, kb_type="task", description="Test task KB" - ) - config = PyriteConfig( - knowledge_bases=[kb_config], - settings=Settings(index_path=tmpdir / "index.db"), - ) - db = PyriteDB(config.settings.index_path) - db.register_kb( - name="test-tasks", kb_type="task", path=str(tasks_path), description="Test task KB" - ) - svc = TaskService(config, db) + world = cli_world( + kbs=[KBConfig(name="test-tasks", path=kb_path, kb_type="task", description="Test task KB")] + ) - # Create parent task with id > 12 chars: parent-epic-for-login - parent = svc.create_task( - kb_name="test-tasks", - title="Parent epic for login", - ) - # Create child task with id > 12 chars: write-the-login-form - child = svc.create_task( - kb_name="test-tasks", - title="Write the login form", - parent=parent["entry_id"], - ) - # Create task with exactly 12 chars: exactly twel - exact = svc.create_task( - kb_name="test-tasks", - title="Exactly twel", - ) - db.close() + # Create parent task with id > 12 chars: parent-epic-for-login + parent_res = world.cli( + "task", "create", "Parent epic for login", "-k", "test-tasks", "--format", "json" + ) + parent_id = json.loads(parent_res.output)["entry_id"] + + # Create child task with id > 12 chars: write-the-login-form + child_res = world.cli( + "task", + "create", + "Write the login form", + "-k", + "test-tasks", + "--parent", + parent_id, + "--format", + "json", + ) + child_id = json.loads(child_res.output)["entry_id"] + + # Create task with exactly 12 chars: exactly-twlv + exact_res = world.cli("task", "create", "Exactly twlv", "-k", "test-tasks", "--format", "json") + exact_id = json.loads(exact_res.output)["entry_id"] + assert len(exact_id) == 12 - with patch("pyrite.cli.context.load_config", return_value=config): - yield { - "config": config, - "parent_id": parent["entry_id"], - "child_id": child["entry_id"], - "exact_id": exact["entry_id"], - } + return { + "world": world, + "parent_id": parent_id, + "child_id": child_id, + "exact_id": exact_id, + } @pytest.mark.cli -def test_task_list_rich_displays_full_ids_and_parent_id(long_id_task_cli_env): +def test_task_list_rich_displays_full_ids_and_parent_id(long_id_task_world): """`task list --format rich` displays the full task ID and parent ID without 12-char cut.""" - parent_id = long_id_task_cli_env["parent_id"] - child_id = long_id_task_cli_env["child_id"] - exact_id = long_id_task_cli_env["exact_id"] - - res = runner.invoke( - app, - ["task", "list", "-k", "test-tasks", "--format", "rich"], - env={"COLUMNS": "200"}, - ) + world = long_id_task_world["world"] + parent_id = long_id_task_world["parent_id"] + child_id = long_id_task_world["child_id"] + exact_id = long_id_task_world["exact_id"] + + with world.pointed(): + res = CliRunner().invoke( + app, + ["task", "list", "-k", "test-tasks", "--format", "rich"], + env={"COLUMNS": "200"}, + ) assert res.exit_code == 0, res.output # The full IDs must be present in the rich table output @@ -92,16 +84,18 @@ def test_task_list_rich_displays_full_ids_and_parent_id(long_id_task_cli_env): @pytest.mark.cli -def test_task_get_rich_displays_full_child_ids(long_id_task_cli_env): +def test_task_get_rich_displays_full_child_ids(long_id_task_world): """`task get --format rich` displays child tasks by their full IDs.""" - parent_id = long_id_task_cli_env["parent_id"] - child_id = long_id_task_cli_env["child_id"] - - res = runner.invoke( - app, - ["task", "get", parent_id, "-k", "test-tasks", "--format", "rich"], - env={"COLUMNS": "200"}, - ) + world = long_id_task_world["world"] + parent_id = long_id_task_world["parent_id"] + child_id = long_id_task_world["child_id"] + + with world.pointed(): + res = CliRunner().invoke( + app, + ["task", "get", parent_id, "-k", "test-tasks", "--format", "rich"], + env={"COLUMNS": "200"}, + ) assert res.exit_code == 0, res.output # The full child ID must appear in the children section @@ -109,15 +103,21 @@ def test_task_get_rich_displays_full_child_ids(long_id_task_cli_env): @pytest.mark.cli -def test_task_list_rich_narrow_terminal_folds_without_crash(long_id_task_cli_env): +def test_task_list_rich_narrow_terminal_folds_without_crash(long_id_task_world): """In a narrow terminal (COLUMNS=60), task list folds IDs across lines without truncating.""" - res = runner.invoke( - app, - ["task", "list", "-k", "test-tasks", "--format", "rich"], - env={"COLUMNS": "60"}, - ) + world = long_id_task_world["world"] + with world.pointed(): + res = CliRunner().invoke( + app, + ["task", "list", "-k", "test-tasks", "--format", "rich"], + env={"COLUMNS": "60"}, + ) assert res.exit_code == 0, res.output # Long IDs fold across lines rather than being cut or replaced with ellipsis assert "..." not in res.output - assert "write-th" in res.output and "form" in res.output - assert "parent-" in res.output and "login" in res.output + # Reassemble columns from table rows to verify full IDs are preserved across folded cells + lines = res.output.splitlines() + id_col = "".join(line.split("│")[1].strip() for line in lines if len(line.split("│")) >= 3) + parent_col = "".join(line.split("│")[6].strip() for line in lines if len(line.split("│")) >= 7) + assert "write-the-login-form" in id_col + assert "parent-epic-for-login" in parent_col