"""Structured logging smoke — AZ-263 AC-7 (schema-compliant per AZ-266)."""

import io
import json
import logging

from gps_denied_onboard.logging import get_logger
from gps_denied_onboard.logging.structured import JsonFormatter


def test_get_logger_returns_logger_instance() -> None:
    # Act
    logger = get_logger("test.smoke")

    # Assert
    assert isinstance(logger, logging.Logger)


def test_log_lines_are_single_json_objects() -> None:
    # Arrange
    stream = io.StringIO()
    handler = logging.StreamHandler(stream)
    handler.setFormatter(JsonFormatter())
    logger = logging.getLogger("test.json.unit")
    logger.handlers = [handler]
    logger.setLevel(logging.DEBUG)
    logger.propagate = False

    # Act
    logger.error(
        "hello world",
        extra={"kind": "test.smoke", "kv": {"event": "smoke", "value": 42}},
    )

    # Assert
    line = stream.getvalue().strip().splitlines()[-1]
    payload = json.loads(line)
    assert payload["level"] == "ERROR"
    assert payload["msg"] == "hello world"
    assert payload["kind"] == "test.smoke"
    assert payload["kv"] == {"event": "smoke", "value": 42}
