"""Stage/backstage detection — Mercury kernels carry MERCURY_CONFIG_DIR."""

from discoverylib import staging


def test_backstage_prints_only_off_stage(monkeypatch, capsys):
    monkeypatch.delenv("MERCURY_CONFIG_DIR", raising=False)
    assert not staging.on_stage()
    staging.backstage("visible")
    assert capsys.readouterr().out == "visible\n"

    monkeypatch.setenv("MERCURY_CONFIG_DIR", "/tmp/app")
    assert staging.on_stage()
    staging.backstage("hidden")
    assert capsys.readouterr().out == ""


def test_backstage_md_renders_only_off_stage(monkeypatch, capsys):
    # Off stage it must emit SOMETHING (rich markdown under a kernel;
    # IPython's display degrades to print under plain pytest) …
    monkeypatch.delenv("MERCURY_CONFIG_DIR", raising=False)
    staging.backstage_md("**visible**")
    assert capsys.readouterr().out != ""

    # … and on stage, nothing at all.
    monkeypatch.setenv("MERCURY_CONFIG_DIR", "/tmp/app")
    staging.backstage_md("**hidden**")
    assert capsys.readouterr().out == ""
