left4me/deploy/scripts/tests/conftest.py
mwiegand 2834ad4911
deploy: move scripts/{libexec,sbin}/ into deploy/scripts/
Layout consistency: everything ckn-bw deploys to the host now lives
under deploy/. ckn-bw's install_left4me_scripts copy-action goes away
in lockstep with this commit and is replaced by target-side symlinks.

Also updates all path references in docs, tests (conftest.py parents[]
depth, test_overlay_helper.py HELPER_SOURCE), and deploy/README.md.

Part of 2026-05-15-deployment-responsibility-design.md migration step 4.
2026-05-15 19:38:42 +02:00

36 lines
1.2 KiB
Python

"""Shared fixtures and path constants for `deploy/scripts/tests/`."""
import os
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
SCRIPTS = ROOT / "deploy" / "scripts"
LIBEXEC = SCRIPTS / "libexec"
SBIN = SCRIPTS / "sbin"
# `deploy/` is also the parent of the scripts/ tree. The sudoers example
# lives at `deploy/files/etc/sudoers.d/left4me` and is the canonical
# statement of which paths sudo grants to the `left4me` uid.
# `deploy/scripts/tests/test_sudoers_grants.py` reads it from there.
DEPLOY = ROOT / "deploy"
def fake_command(tmp_path, command_name):
"""Drop a no-op stub of `command_name` into `tmp_path`. Returns the
marker file the stub writes its args to, so tests can assert that the
helper rejected bad input before invoking the real command.
"""
marker = tmp_path / f"{command_name}.args"
command = tmp_path / command_name
command.write_text(f"#!/bin/sh\nprintf '%s\\n' \"$*\" > '{marker}'\nexit 0\n")
command.chmod(0o755)
return marker
def env_with_fake_commands(tmp_path):
"""Build an environment that prepends `tmp_path` onto PATH so helpers
find the fake commands first.
"""
env = os.environ.copy()
env["PATH"] = f"{tmp_path}{os.pathsep}{env.get('PATH', '')}"
return env