llamacppctl/tests/test_lock_ops.py
dschlueter 3158d16f9b Initial commit: llamacppctl – llama.cpp Docker server control CLI
Steuert einen llama.cpp-Server als Docker-Container: --start/--check/--stop/
--change/--chat, INI-Konfiguration (builtin defaults -> [default] ->
[model.<profile>] -> CLI), SSRF-gehärtete Prompt-Eingabe (Datei/HTTPS-URL),
File-Locking für --start/--change und ein OpenAI-kompatibler HTTP-Layer.

Enthält u. a.:
- Env-Var-Expansion in hf_home (hf_home = ${HF_HOME})
- konfigurierbares Chat-Antwortbudget (max_tokens/chat_temperature,
  CLI: --max-tokens/--chat-temp); temperature defer an Server-Default
- DNS-Pinning gegen DNS-Rebinding bei URL-Quellen
- dry-run als nebenwirkungsfreie Vorschau (kein Lock/Removal/Modell-Check)
- 98 Tests (pytest)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 16:36:27 +02:00

31 lines
799 B
Python

import sys
from pathlib import Path
import pytest
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from llamacppctl.lock_ops import FileLock, LockError # noqa: E402
def test_lock_acquire_and_release(tmp_path):
lock_path = tmp_path / "test.lock"
with FileLock(lock_path):
assert lock_path.exists()
# released cleanly, can acquire again
with FileLock(lock_path):
pass
def test_lock_busy_raises(tmp_path):
lock_path = tmp_path / "busy.lock"
with FileLock(lock_path):
with pytest.raises(LockError):
with FileLock(lock_path):
pass
def test_lock_creates_parent_dirs(tmp_path):
lock_path = tmp_path / "nested" / "dir" / "test.lock"
with FileLock(lock_path):
assert lock_path.exists()