"""Shared test loader and narrowly reversible command-boundary substitutions.""" from pathlib import Path import re import shlex ROOT = Path(__file__).resolve().parents[1] MODULE_DIR = ROOT / 'refactored/managed-container.d' LOAD = '''MC_PROMOTION_RESOURCE_INSTANCE="${OCF_RESOURCE_INSTANCE:-}" : "${OCF_ROOT:=/usr/lib/ocf}" . "$OCF_ROOT/lib/heartbeat/ocf-shellfuncs" : "${OCF_RUNNING_PROMOTED:=${OCF_RUNNING_MASTER:-8}}" MC_MODULE_DIR=''' + shlex.quote(str(MODULE_DIR)) + ''' . "$MC_MODULE_DIR/common.sh" . "$MC_MODULE_DIR/container.sh" . "$MC_MODULE_DIR/engine.sh" mc_engine_load || exit $? ''' def restore_boundaries(source): """Project only adapter calls back to their frozen original spelling. This is not whitespace normalization or a general semantic equivalence claim. All remaining function bytes must match the immutable reference. """ source = source.replace('mc_runtime_inspect', 'as_service_user podman inspect') source = source.replace('mc_runtime_info', 'as_service_user podman info') pattern = r'^([ \t]*)(.*?)mc_runtime_exec \\\n' source = re.sub(pattern, lambda m: m[1] + m[2] + 'as_service_user \\\n' + m[1] + ' podman exec \\\n', source, flags=re.M) pattern = r'^([ \t]*)(.*?)mc_lifecycle_(start|stop|cat|running) ' source = re.sub(pattern, lambda m: m[1] + m[2] + 'as_service_user \\\n' + m[1] + ' systemctl --user ' + ('is-active --quiet' if m[3] == 'running' else m[3]) + ' ', source, flags=re.M) return source