mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 07:17:54 +08:00
core/config: add the [trash] section
`[trash]` owns the one policy `delete_path` needs from the human: whether a delete is a move to the desktop's trash (`enabled = true`, the default) or a removal that cannot be undone (`false`, which is what the tool did before). Unknown keys degrade to the defaults, the way `[mcp]` does, so a typo cannot silently switch a destructive policy on. `reload()` re-reads the section.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from plyngent.config import load
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_trash_section_defaults(tmp_path: Path) -> None:
|
||||
"""Deletes go to the system trash unless the section says otherwise."""
|
||||
path = tmp_path / "c.toml"
|
||||
_ = path.write_text("", encoding="utf-8")
|
||||
assert load(path).trash_config.enabled is True
|
||||
|
||||
|
||||
def test_trash_section_parse(tmp_path: Path) -> None:
|
||||
path = tmp_path / "c.toml"
|
||||
_ = path.write_text("[trash]\nenabled = false\n", encoding="utf-8")
|
||||
assert load(path).trash_config.enabled is False
|
||||
|
||||
|
||||
def test_trash_section_typo_falls_back(tmp_path: Path) -> None:
|
||||
"""An unknown key or a bad type degrades to the defaults, like ``[mcp]``."""
|
||||
path = tmp_path / "c.toml"
|
||||
_ = path.write_text("[trash]\nenable = false\n", encoding="utf-8")
|
||||
assert load(path).trash_config.enabled is True
|
||||
|
||||
path2 = tmp_path / "d.toml"
|
||||
_ = path2.write_text('[trash]\nenabled = "no"\n', encoding="utf-8")
|
||||
assert load(path2).trash_config.enabled is True
|
||||
|
||||
|
||||
def test_trash_section_survives_reload(tmp_path: Path) -> None:
|
||||
path = tmp_path / "c.toml"
|
||||
_ = path.write_text("[trash]\nenabled = false\n", encoding="utf-8")
|
||||
store = load(path)
|
||||
assert store.trash_config.enabled is False
|
||||
_ = path.write_text("[trash]\nenabled = true\n", encoding="utf-8")
|
||||
store.reload()
|
||||
assert store.trash_config.enabled is True
|
||||
Reference in New Issue
Block a user