"""mgf-test-supervisor — the Magogi Foundation test supervisor.

A budget-aware, crash-survivable, resumable test runner that drives
pytest from the OUTSIDE so it can detect hangs, crashes, and
freezes that pytest itself cannot. Writes one append-only JSONL
record per test outcome plus a per-failure detail bundle that
collects everything a contributor needs to diagnose, in one file.

History: originated as mgf-hrb's `scripts/_mtest/` (sibling-#0,
pre-2026). Adopted by mgf-common 2026-05-26 as sibling-#1. Rolled
out across all 7 federation siblings (mgf-common + fastapi +
django + sqlalchemy + alembic + http + apiprobe) by 2026-05-26.
Extracted to this published library 2026-05-26 with the L6 lesson
(plugin-flag hygiene) and the diagnostic-visibility fix baked in
from the very first commit.

Reusability note (federation standard, TS-22..TS-27 — see
``mgf-standard/docs/standards/TESTING.md`` §19): install
``mgf-test-supervisor`` in your project's dev extras, add the
pyproject pytest config (timeout=30, faulthandler_timeout=60, the
twelve-marker taxonomy), then run ``mgf-test-supervisor
--self-check`` to verify the install + ``mgf-test-supervisor
--tier 0`` for fast sanity.
The CLI walks up from CWD looking for ``pyproject.toml`` — no
adoption knobs needed (the old 4-knob abstraction from the copy-
paste era is gone; configuration lives in the consumer's
pyproject).

Module map:
  records.py       — TestRecord; JSONL writer/reader. Schema is
                     pinned against mgf.common.testing.TestRecord
                     via an alignment contract (mgf-common's tests
                     enforce it; this library is stdlib-only and
                     does not import mgf-common).
  tiers.py         — Marker → tier overlay + auto-tier from
                     durations. Mirrors mgf.common.testing.MARKER_TIER.
  selection.py     — Budget knapsack + tier filter + quarantine skip.
  quarantine.py    — 3-of-5-fail in / 3-consecutive-pass-out eviction.
  diagnostics.py   — Daemon state, wchan, dmesg, env fingerprint.
  supervisor.py    — Chunked pytest runs, hang/crash detection,
                     per-failure bundles, resume. The core.
  self_check.py    — Supervisor verifies its own pass/fail/hang/
                     crash detection in temp dirs.
  __main__.py      — argparse CLI; entry points are
                     ``mgf-test-supervisor`` and ``mtest``.

Stdlib only. No third-party runtime imports. The supervisor must
run even when the project's venv is half-broken — which means it
must not depend on anything that might also be broken.
"""

from __future__ import annotations

from mgf.test_supervisor.diagnostics import (
    DAEMON_PROCESS_NAME,
    daemon_state,
    dmesg_tail,
    env_fingerprint,
    process_tree,
    recent_history,
)
from mgf.test_supervisor.perf import (
    PerfStore,
    aggregate_self_time,
    render_perf_section,
    render_run_summary,
    slowest_tests,
)
from mgf.test_supervisor.quarantine import (
    FAILURE_OUTCOMES,
    FAILURES_TO_QUARANTINE,
    PASS_OUTCOMES,
    PASSES_TO_EVICT,
    WINDOW_SIZE,
    QuarantineEntry,
    QuarantineStore,
)
from mgf.test_supervisor.records import (
    OUTCOMES,
    SCHEMA_VERSION,
    SECTION_HEADER_FMT,
    SECTION_ORDER,
    SEVERITIES,
    JsonlWriter,
    TestRecord,
    now_iso,
    read_jsonl,
    severity_for_outcome,
)
from mgf.test_supervisor.selection import (
    SelectionReport,
    TestCandidate,
    build_candidates,
    select_tests,
)
from mgf.test_supervisor.self_check import (
    run_self_check,
)
from mgf.test_supervisor.supervisor import (
    DEFAULT_CHUNK_SIZE,
    DEFAULT_PER_TEST_TIMEOUT_S,
    SIGTERM_GRACE_S,
    ChunkResult,
    RunConfig,
    Supervisor,
    collect_test_markers,
    collect_tests,
)
from mgf.test_supervisor.tiers import (
    DEFAULT_TIER,
    MARKER_TIER,
    TIERS,
    TierBudget,
    auto_tier,
    parse_tier_range,
    tier_for_markers,
)

__version__ = "0.1.19"

__all__ = [
    "DAEMON_PROCESS_NAME",
    "DEFAULT_CHUNK_SIZE",
    "DEFAULT_PER_TEST_TIMEOUT_S",
    "DEFAULT_TIER",
    "FAILURES_TO_QUARANTINE",
    "FAILURE_OUTCOMES",
    "MARKER_TIER",
    "OUTCOMES",
    "PASSES_TO_EVICT",
    "PASS_OUTCOMES",
    "SCHEMA_VERSION",
    "SECTION_HEADER_FMT",
    "SECTION_ORDER",
    "SEVERITIES",
    "SIGTERM_GRACE_S",
    "TIERS",
    "WINDOW_SIZE",
    "ChunkResult",
    "JsonlWriter",
    "PerfStore",
    "QuarantineEntry",
    "QuarantineStore",
    "RunConfig",
    "SelectionReport",
    "Supervisor",
    "TestCandidate",
    "TestRecord",
    "TierBudget",
    "__version__",
    "aggregate_self_time",
    "auto_tier",
    "build_candidates",
    "collect_test_markers",
    "collect_tests",
    "daemon_state",
    "dmesg_tail",
    "env_fingerprint",
    "now_iso",
    "parse_tier_range",
    "process_tree",
    "read_jsonl",
    "recent_history",
    "render_perf_section",
    "render_run_summary",
    "run_self_check",
    "select_tests",
    "severity_for_outcome",
    "slowest_tests",
    "tier_for_markers",
]
