"""Integration-scope console: a trivial static site served by the stdlib.

The `console_launch` contract says "here is how to start my console". A real
console repo points it at its own CLI; here we point it at ``python -m
http.server`` over a two-element site. That makes the `Console` wrapper's own
contract provable with nothing but the interpreter and a browser — no console
repo present — so the library's CI gate covers the API its consumers actually
use. Overrides the fed-web `console_launch` from ``tests/conftest.py`` for this
directory only (the documented child-conftest pattern).
"""

from __future__ import annotations

import sys
from pathlib import Path

import pytest

from mgf.uitest_web import ConsoleLaunch

_PAGE = """<!doctype html>
<html lang="en">
  <head><meta charset="utf-8"><title>Static console</title></head>
  <body style="margin:0">
    <main>
      <h1>Static console</h1>
      <p id="hello">Nothing spills here.</p>
    </main>
  </body>
</html>
"""


@pytest.fixture
def console_launch(tmp_path: Path, console_port: int) -> ConsoleLaunch:
    """Serve a tiny, deterministic static site as the console under test."""
    site = tmp_path / "site"
    site.mkdir()
    (site / "index.html").write_text(_PAGE, encoding="utf-8")
    return ConsoleLaunch(
        command=[
            sys.executable,
            "-m",
            "http.server",
            str(console_port),
            "-b",
            "127.0.0.1",
            "-d",
            str(site),
        ],
        ready_path="/",
        name="static",
    )
