"""Smoke: the broker binary is at least as fresh as its Zig sources.

The 2026-05-25 session lost ~30 min to a stale `mgf-hrb-server`
binary: source had advanced through commit `e93a54f` (Part 7.1
thread-per-client), but `hrb-code/zig-out/bin/mgf-hrb-server` was
still the pre-7.1 build. The first concurrent connect deadlocked
silently; no test fixture flagged the mismatch because all four
broker fixtures only checked `binary.exists()`, never mtime.

This test makes the trap loud. It fails (not skips) when the
binary is older than any `hrb-code/src/**/*.zig` file, with the
exact rebuild command in the failure message. Tests requesting
the `broker` fixture share the same check (`tests/conftest.py`);
this smoke test is the EARLY-DETECTION path so contributors hit
it before any opt-in suite runs.

Skips cleanly when the binary doesn't exist — that's a different
diagnostic (run `zig build`), and `_broker.broker_is_stale`
correctly returns `(False, "")` for that case to keep the two
concerns separated.
"""

from __future__ import annotations

import pytest

from tests import _broker

pytestmark = pytest.mark.smoke


def test_broker_binary_is_not_stale() -> None:
    """Fails when the binary is older than the newest Zig source
    under `hrb-code/src/`. Carries the rebuild command in the
    failure message so the fix is one copy-paste away."""
    if not _broker.server_exists():
        pytest.skip(
            f"Broker binary not built at {_broker.server_path()}. Run: {_broker.build_command()}"
        )
    is_stale, reason = _broker.broker_is_stale()
    if is_stale:
        pytest.fail(reason, pytrace=False)
