mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-23 05:55:16 +08:00
core/config+cli: /model --persist and /models --persist to TOML
ensure_model / merge_models update the provider catalog in memory; --persist writes plyngent.toml so next launch has a warmer model list.
This commit is contained in:
@@ -341,6 +341,36 @@ async def test_verbose_toggle(state: ReplState) -> None:
|
||||
assert get_verbose_tool_results() is False
|
||||
|
||||
|
||||
async def test_model_persist_writes_config(
|
||||
state: ReplState, tmp_path: Path, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
# Seed a TOML-backed store so write() has a real path.
|
||||
path = tmp_path / "plyngent.toml"
|
||||
_ = path.write_text(
|
||||
"""
|
||||
[providers.local]
|
||||
preset = "openai"
|
||||
access_key_or_token = "sk-test"
|
||||
|
||||
[providers.local.models.gpt-test]
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
from plyngent.config import load as load_config
|
||||
|
||||
state.config = load_config(path)
|
||||
state.provider_name = "local"
|
||||
state.provider = state.config.providers["local"]
|
||||
state.model = "gpt-new-id"
|
||||
assert await handle_slash(state, "/model --persist") is True
|
||||
out = capsys.readouterr().out
|
||||
assert "persisted model" in out
|
||||
assert "gpt-new-id" in out
|
||||
state.config.reload()
|
||||
assert "gpt-new-id" in state.config.providers["local"].models
|
||||
assert "gpt-test" in state.config.providers["local"].models
|
||||
|
||||
|
||||
async def test_yolo_toggle(state: ReplState, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
assert state.effective_yolo() == "off"
|
||||
assert state.soft_confirm_enabled() is True
|
||||
|
||||
@@ -179,6 +179,39 @@ def test_write_new_config() -> None:
|
||||
assert config.providers["foo2"].access_key_or_token == "sk-00301212"
|
||||
|
||||
|
||||
def test_ensure_model_and_merge_models(tmp_path: Path) -> None:
|
||||
path = tmp_path / "models-persist.toml"
|
||||
_ = path.write_text(
|
||||
"""
|
||||
[providers.local]
|
||||
preset = "openai-compatible"
|
||||
access_key_or_token = "sk-test"
|
||||
url = "https://example/v1"
|
||||
|
||||
[providers.local.models.base]
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
config = plyngent.config.load(path)
|
||||
assert "base" in config.providers["local"].models
|
||||
assert "extra" not in config.providers["local"].models
|
||||
|
||||
provider = config.ensure_model("local", "extra")
|
||||
assert "extra" in provider.models
|
||||
assert "base" in provider.models
|
||||
# idempotent
|
||||
_ = config.ensure_model("local", "extra")
|
||||
config.write()
|
||||
config.reload()
|
||||
assert set(config.providers["local"].models) == {"base", "extra"}
|
||||
assert config.providers["local"].access_key_or_token == "sk-test"
|
||||
|
||||
_ = config.merge_models("local", ["extra", "remote-a", "remote-b"])
|
||||
config.write()
|
||||
config.reload()
|
||||
assert set(config.providers["local"].models) == {"base", "extra", "remote-a", "remote-b"}
|
||||
|
||||
|
||||
def test_update_config() -> None:
|
||||
file = Path(__file__).parent / "plyngent-edit-2.toml"
|
||||
_ = shutil.copy(Path(__file__).parent / "plyngent-valid.toml", file)
|
||||
|
||||
Reference in New Issue
Block a user