repositories

NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor

clonegit clone https://git.daemon-sec.xyz/NixDaemon.git
test_sync_fastfetch.pyPython60 lines2.1 KiBraw download
import os
import pathlib

from test_crossfetch_masks import _load_crossfetch

TPL = pathlib.Path(__file__).parent.parent / "fastfetch.template.jsonc"

# Rendered once from the template under rose-pine dark and checked in, so this
# test doesn't chase a live config.jsonc that legitimately drifts whenever
# the user switches RICEFX_THEME. Regenerate with:
#   RICEFX_THEME=dark bin/crossfetch --sync-fastfetch
# then `cp ~/.config/fastfetch/config.jsonc tests/fixtures/config.rose-pine.jsonc`
# if the template's rose-pine output is meant to change.
FIXTURE_CFG = pathlib.Path(__file__).parent / "fixtures" / "config.rose-pine.jsonc"


def test_roundtrip_rose_pine_reproduces_current_config(tmp_path, monkeypatch):
    """Template + rose-pine dark must rebuild the checked-in fixture byte-identical."""
    cf = _load_crossfetch()
    monkeypatch.setenv("RICEFX_THEME", "dark")
    import importlib, ricefx
    importlib.reload(ricefx)
    cf.ricefx = ricefx
    out = tmp_path / "config.jsonc"
    rc = cf.sync_fastfetch(str(TPL), str(out))
    assert rc == 0
    assert out.read_text() == FIXTURE_CFG.read_text()


def test_other_theme_produces_different_config(tmp_path, monkeypatch):
    cf = _load_crossfetch()
    monkeypatch.setenv("RICEFX_THEME", "gruvbox")
    import importlib, ricefx
    importlib.reload(ricefx)
    cf.ricefx = ricefx
    out = tmp_path / "config.jsonc"
    assert cf.sync_fastfetch(str(TPL), str(out)) == 0
    text = out.read_text()
    assert "{{" not in text
    assert "38;2;250;189;47" in text          # gruvbox gold
    monkeypatch.setenv("RICEFX_THEME", "dark")
    importlib.reload(ricefx)


def test_missing_template_errors_and_leaves_output_alone(tmp_path):
    cf = _load_crossfetch()
    out = tmp_path / "config.jsonc"
    out.write_text("precious")
    rc = cf.sync_fastfetch(str(tmp_path / "nope.jsonc"), str(out))
    assert rc == 1
    assert out.read_text() == "precious"


def test_unknown_role_errors(tmp_path):
    cf = _load_crossfetch()
    tpl = tmp_path / "t.jsonc"
    tpl.write_text('{"color": "{{nonsense}}"}')
    out = tmp_path / "config.jsonc"
    assert cf.sync_fastfetch(str(tpl), str(out)) == 1
    assert not out.exists()