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')
