Kod zyl tylko na dysku PIHA w /opt/llm-gateway (bez gita). Przeniesiony do
services/llm-gateway/ pod pelny wzorzec homelaba:
- app/main.py: kod 1:1 z PIHA + OLLAMA_URL/CHAT_MODEL/CODE_MODEL
nadpisywalne przez env (defaulty bez zmian)
- docker-compose.yml: bind TYLKO do Tailscale IP (${TAILSCALE_BIND_IP},
wzorzec fleet-prometheus), nie 0.0.0.0 jak w starym compose
- service.yaml, env.example (bez sekretow), healthcheck.sh, README, testy
- hosts/piha/runtime/llm-gateway: mem_limit 256m (PIHA jest RAM-bound)
- rejestracja w hosts/piha/services.yaml i inventory/topology.yaml
Zepsuty /opt/llm-gateway/docker-compose.yml (zduplikowany klucz ports)
celowo NIE przeniesiony.
DoD: pytest 4 passed; docker build + smoke run OK (GET / -> gateway ok).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
32 lines
954 B
Python
32 lines
954 B
Python
import pathlib
|
|
import sys
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
|
|
from app.main import app, looks_like_shell_command # noqa: E402
|
|
|
|
|
|
def test_root_health():
|
|
client = TestClient(app)
|
|
response = client.get('/')
|
|
assert response.status_code == 200
|
|
assert response.json() == {'status': 'gateway ok'}
|
|
|
|
|
|
def test_shell_command_heuristic_detects_commands():
|
|
assert looks_like_shell_command('ls -la /opt')
|
|
assert looks_like_shell_command('docker ps')
|
|
|
|
|
|
def test_shell_command_heuristic_rejects_natural_language():
|
|
assert not looks_like_shell_command('write a python function')
|
|
assert not looks_like_shell_command('Explain what this does')
|
|
|
|
|
|
def test_shell_command_heuristic_rejects_multiline_and_empty():
|
|
assert not looks_like_shell_command('')
|
|
assert not looks_like_shell_command(' ')
|
|
assert not looks_like_shell_command('ls -la\necho done')
|