"""Shared fixtures and path constants for `scripts/tests/`.""" import os from pathlib import Path ROOT = Path(__file__).resolve().parents[2] SCRIPTS = ROOT / "scripts" LIBEXEC = SCRIPTS / "libexec" SBIN = SCRIPTS / "sbin" # `deploy/` is reference material; the sudoers example lives there and is # the canonical statement of which paths sudo grants to the `left4me` uid. # `scripts/tests/test_sudoers_grants.py` reads it from across the dir # boundary because the contract being audited is about *scripts*, not deploy. 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