provozni zaloha

This commit is contained in:
lachtan
2026-06-24 08:11:12 +02:00
parent 9295dba19f
commit 1db3ec4756
97 changed files with 7698 additions and 817 deletions

View File

@@ -217,6 +217,61 @@ def test_remove_by_id_disambiguates_duplicates(tmp_path, capsys):
assert "drink water" in captured.out
def test_display_id_renumbers_after_remove(tmp_path, capsys):
db_path = tmp_path / "test.sqlite"
init_db(db_path)
for text in ("first", "second", "third"):
_run(db_path, ["add", "--text", text, "--cron", "0 9 * * *"])
capsys.readouterr()
# Display IDs follow insertion order: #1 first, #2 second, #3 third.
_run(db_path, ["remove", "--id", "1"]) # removes "first"
capsys.readouterr()
ret = _run(db_path, ["list"])
captured = capsys.readouterr()
assert ret == 0
assert "#1 second [enabled]" in captured.out
assert "#2 third [enabled]" in captured.out
assert "first" not in captured.out
# After renumbering, display #1 is now "second".
ret = _run(db_path, ["remove", "--id", "1"])
captured = capsys.readouterr()
assert ret == 0
assert json.loads(captured.out)["removed"]["text"] == "second"
def test_id_out_of_range_reports_display_id(tmp_path, capsys):
db_path = tmp_path / "test.sqlite"
init_db(db_path)
_run(db_path, ["add", "--text", "only one", "--cron", "0 9 * * *"])
capsys.readouterr()
ret = _run(db_path, ["remove", "--id", "5"])
captured = capsys.readouterr()
assert ret == 1
assert json.loads(captured.err) == {"error": "no match", "display_id": 5}
def test_ambiguous_keyword_returns_display_ids(tmp_path, capsys):
db_path = tmp_path / "test.sqlite"
init_db(db_path)
_run(db_path, ["add", "--text", "drink water", "--cron", "0 9 * * *"])
_run(db_path, ["add", "--text", "drink water", "--cron", "0 10 * * *"])
capsys.readouterr()
ret = _run(db_path, ["remove", "--keyword", "drink"])
captured = capsys.readouterr()
assert ret == 1
err = json.loads(captured.err)
assert err["error"] == "ambiguous"
assert sorted(m["display_id"] for m in err["matches"]) == [1, 2]
def test_resolve_requires_id_or_keyword(tmp_path, capsys):
db_path = tmp_path / "test.sqlite"
init_db(db_path)