Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1393-importance-range.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create and update now refuse an --importance outside 1-10 with a usage error instead of accepting it. (#1393)
8 changes: 6 additions & 2 deletions pyrite/cli/entry_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ def create_entry(
body: str = typer.Option("", "--body", "-b", help="Entry body text"),
tags: str = typer.Option("", "--tags", help="Comma-separated tags"),
date: str = typer.Option("", "--date", "-d", help="Date (YYYY-MM-DD, for events)"),
importance: int = typer.Option(5, "--importance", "-i", help="Importance (1-10)"),
importance: int = typer.Option(
5, "--importance", "-i", min=1, max=10, help="Importance (1-10)"
),
status: str = typer.Option("", "--status", help="Entry status (e.g., draft, confirmed)"),
field: list[str] | None = typer.Option(
None, "--field", "-f", help="Extra field as key=value"
Expand Down Expand Up @@ -539,7 +541,9 @@ def update_entry(
body_file: Path | None = typer.Option(None, "--body-file", help="Read body from file"),
stdin_flag: bool = typer.Option(False, "--stdin", help="Read body from stdin"),
tags: str = typer.Option(None, "--tags", help="New comma-separated tags"),
importance: int = typer.Option(None, "--importance", "-i", help="New importance (1-10)"),
importance: int = typer.Option(
None, "--importance", "-i", min=1, max=10, help="New importance (1-10)"
),
lifecycle: str = typer.Option(
None, "--lifecycle", help="Lifecycle state: active or archived"
),
Expand Down
81 changes: 81 additions & 0 deletions tests/test_cli_importance_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""#1393: create and update refuse an --importance outside 1-10.

The help text says "Importance (1-10)", but both commands accepted any
integer: 999, 0, and -5 were all written to the entry without complaint.
"""

import json

import pytest
from typer.testing import CliRunner

from pyrite.cli import app

runner = CliRunner()


def _md_files(world):
return list(world.kb_path("test-kb").rglob("*.md"))


def _create(world, importance):
return world.cli(
"create",
"-k",
"test-kb",
"-t",
"note",
"--title",
"Test",
"-b",
"x",
"--importance",
str(importance),
"--format",
"json",
)


@pytest.mark.cli
class TestCreateImportanceRange:
@pytest.mark.parametrize("bad", [999, 0, -5])
def test_create_refuses_out_of_range_importance(self, cli_world, bad):
world = cli_world()
result = _create(world, bad)
assert result.exit_code == 2, result.output
assert "Invalid value for '--importance'" in result.output
assert _md_files(world) == []

@pytest.mark.parametrize("good", [1, 10])
def test_create_accepts_the_bounds(self, cli_world, good):
world = cli_world()
result = _create(world, good)
assert result.exit_code == 0, result.output
assert len(_md_files(world)) == 1


@pytest.mark.cli
class TestUpdateImportanceRange:
def _made_entry(self, world):
made = _create(world, 5)
assert made.exit_code == 0, made.output
return json.loads(made.output)["entry_id"]

@pytest.mark.parametrize("bad", [11, 0, -1])
def test_update_refuses_out_of_range_importance(self, cli_world, bad):
world = cli_world()
entry_id = self._made_entry(world)
path = next(world.kb_path("test-kb").rglob("*.md"))
before = path.read_text(encoding="utf-8")

result = world.cli("update", entry_id, "-k", "test-kb", "--importance", str(bad))
assert result.exit_code == 2, result.output
assert "Invalid value for '--importance'" in result.output
assert path.read_text(encoding="utf-8") == before

@pytest.mark.parametrize("good", [1, 10])
def test_update_accepts_the_bounds(self, cli_world, good):
world = cli_world()
entry_id = self._made_entry(world)
result = world.cli("update", entry_id, "-k", "test-kb", "--importance", str(good))
assert result.exit_code == 0, result.output
Loading