import argparse import sys from pathlib import Path, PurePosixPath import yaml def safe_relative_path(value): if not isinstance(value, str) or not value: return False path = PurePosixPath(value) return not path.is_absolute() and ".." not in path.parts def validate_mod_host_chain(routing, source_by_id): errors = [] chains = routing.get("mod_host_chains") if not isinstance(chains, dict): return ["routing.mod_host_chains must be a mapping"] if set(chains) != {"guitar"}: errors.append("routing.mod_host_chains must declare the guitar chain exactly once") chain = chains.get("guitar") if not isinstance(chain, dict): return errors + ["routing.mod_host_chains.guitar must be a mapping"] guitar = source_by_id.get("guitar") physical_input = guitar.get("capture_port") if isinstance(guitar, dict) else None if chain.get("physical_input_port") != physical_input: errors.append( "routing.mod_host_chains.guitar.physical_input_port must match the guitar capture port" ) if chain.get("source_port") != "rigforge.mod-host-input.capture:capture_AUX0": errors.append( "routing.mod_host_chains.guitar.source_port must be the mod-ui-visible input boundary" ) if chain.get("pipewire_input_port") != "rigforge.mod-host-input:playback_AUX0": errors.append( "routing.mod_host_chains.guitar.pipewire_input_port must be the Rigforge input sink" ) if chain.get("pipewire_output_port") != "rigforge.mod-host-output:capture_AUX0": errors.append( "routing.mod_host_chains.guitar.pipewire_output_port must be the Rigforge output source" ) if chain.get("mod_ui_output_port") != "rigforge.mod-host-output.playback:playback_AUX0": errors.append( "routing.mod_host_chains.guitar.mod_ui_output_port must be the mod-ui-visible output boundary" ) bypass = chain.get("bypass_link") mix_input = chain.get("mix_input") if not isinstance(bypass, dict): errors.append("routing.mod_host_chains.guitar.bypass_link must be a mapping") elif bypass != {"from": physical_input, "to": mix_input}: errors.append("routing.mod_host_chains.guitar.bypass_link must identify the direct capture-to-mix edge") if mix_input != "rigforge.direct-mix.input:playback_AUX0": errors.append("routing.mod_host_chains.guitar.mix_input must be the guitar mixer's AUX0 input") processors = chain.get("processors") if not isinstance(processors, list) or len(processors) != 2: return errors + ["routing.mod_host_chains.guitar.processors must contain NAM followed by one cabinet IR"] expected_processors = ( { "id": "amp-head", "instance": 0, "plugin_uri": "http://github.com/mikeoliphant/neural-amp-modeler-lv2", "mod_ui_instance": "/graph/rigforge_nam", "bundle_path": ".lv2/neural_amp_modeler.lv2", "file_property": "http://github.com/mikeoliphant/neural-amp-modeler-lv2#model", "asset_path": "amp_emul/amphead/VOX_AC15/Vox_AC15CH_Crunch_TB.nam", "input_port": "effect_0:input", "output_port": "effect_0:output", }, { "id": "cabinet-ir", "instance": 1, "plugin_uri": "http://lsp-plug.in/plugins/lv2/impulse_responses_mono", "mod_ui_instance": "/graph/rigforge_ir", "bundle_path": ".lv2/lsp-plugins.lv2", "file_property": "http://lsp-plug.in/plugins/lv2/impulse_responses_mono/ports#ifn", "asset_path": "amp_emul/cabinet/VOX_AC30_1964/VOX_AC30_1964_celestion.wav", "input_port": "effect_1:in", "output_port": "effect_1:out", }, ) for index, (processor, expected) in enumerate(zip(processors, expected_processors)): location = f"routing.mod_host_chains.guitar.processors[{index}]" if not isinstance(processor, dict): errors.append(f"{location} must be a mapping") continue for key, value in expected.items(): if processor.get(key) != value: errors.append(f"{location}.{key} must be {value}") for key in ("bundle_path", "asset_path"): if not safe_relative_path(processor.get(key)): errors.append(f"{location}.{key} must be a safe relative path") if index == 0: expected_models = { "crystal_clean_tb": "amp_emul/amphead/VOX_AC15/Vox_AC15CH_Crystal_Clean_TB.nam", "edge_of_breakup_tb": "amp_emul/amphead/VOX_AC15/Vox_AC15CH_Edge_of_Breakup_TB.nam", "crunch_tb": "amp_emul/amphead/VOX_AC15/Vox_AC15CH_Crunch_TB.nam", "overdriven_tb": "amp_emul/amphead/VOX_AC15/Vox_AC15CH_Overdriven_TB.nam", } models = processor.get("available_models") if not isinstance(models, dict) or models != expected_models: errors.append(f"{location}.available_models must declare the four approved Vox TB models") elif any(not safe_relative_path(path) for path in models.values()): errors.append(f"{location}.available_models paths must be safe relative paths") elif processor.get("asset_path") not in models.values(): errors.append(f"{location}.asset_path must be one of the declared available_models") if isinstance(processors[0], dict): parameters = processors[0].get("parameters") if not isinstance(parameters, dict): errors.append("routing.mod_host_chains.guitar.processors[0].parameters must be a mapping") else: output_level = parameters.get("output_level") if ( not isinstance(output_level, (int, float)) or isinstance(output_level, bool) or not -20.0 <= output_level <= 20.0 ): errors.append("NAM output_level must be between -20 and 20 dB") links = routing.get("managed_links") if isinstance(links, list) and len(processors) == 2: actual_edges = { (link.get("from"), link.get("to")) for link in links if ( isinstance(link, dict) and isinstance(link.get("from"), str) and isinstance(link.get("to"), str) ) } if isinstance(processors[0], dict) and isinstance(processors[1], dict): expected_candidates = ( (physical_input, chain.get("pipewire_input_port")), (chain.get("pipewire_output_port"), mix_input), (chain.get("pipewire_output_port"), "sooperlooper:loop0_in_1"), ) for edge in expected_candidates: if not all(isinstance(endpoint, str) for endpoint in edge): continue if edge not in actual_edges: errors.append(f"mod-host guitar boundary link must be declared: {edge[0]} -> {edge[1]}") internal_edge = ( processors[0].get("output_port"), processors[1].get("input_port"), ) if internal_edge in actual_edges: errors.append( "the NAM-to-IR link is owned by mod-ui and must not be a Rigforge managed link" ) if isinstance(bypass, dict): bypass_edge = (bypass.get("from"), bypass.get("to")) if all(isinstance(endpoint, str) for endpoint in bypass_edge) and bypass_edge in actual_edges: errors.append("the guitar capture-to-mix bypass must not be a managed link") managed_unlinks = routing.get("managed_unlinks") unlink_edges = { (item.get("from"), item.get("to")) for item in managed_unlinks if isinstance(item, dict) } if isinstance(managed_unlinks, list) else set() if ( all(isinstance(endpoint, str) for endpoint in bypass_edge) and bypass_edge not in unlink_edges ): errors.append("the guitar capture-to-mix bypass must be declared in routing.managed_unlinks") return errors def validate_state(state): errors = [] if not isinstance(state, dict): return ["document root must be a mapping"] # Establish the declared source map before validating looper references. sources = state.get("sources") if not isinstance(sources, list): return ["sources must be a list"] source_by_id = {} physical_inputs = set() capture_ports = set() for index, source in enumerate(sources): location = f"sources[{index}]" if not isinstance(source, dict): errors.append(f"{location} must be a mapping") continue source_id = source.get("id") if not isinstance(source_id, str) or not source_id: errors.append(f"{location}.id must be a non-empty string") elif source_id in source_by_id: errors.append(f"duplicate source id: {source_id}") else: source_by_id[source_id] = source physical_input = source.get("physical_input") if not isinstance(physical_input, int) or isinstance(physical_input, bool): errors.append(f"{location}.physical_input must be an integer") elif physical_input in physical_inputs: errors.append(f"duplicate physical input: {physical_input}") else: physical_inputs.add(physical_input) capture_port = source.get("capture_port") if not isinstance(capture_port, str) or not capture_port: errors.append(f"{location}.capture_port must be a non-empty string") elif capture_port in capture_ports: errors.append(f"duplicate capture port: {capture_port}") else: capture_ports.add(capture_port) # Keep the first four-channel milestone tied to its four named instruments. expected_source_ids = {"guitar", "bass", "voice", "synth"} if set(source_by_id) != expected_source_ids: errors.append("source ids must be guitar, bass, voice, and synth exactly once") if len(sources) != 4: errors.append(f"exactly four sources are required, got {len(sources)}") if physical_inputs != {1, 2, 3, 4}: errors.append("physical inputs must cover 1 through 4 exactly once") # The required looper is one instance containing one four-channel loop. system = state.get("system") components = system.get("components") if isinstance(system, dict) else None if not isinstance(components, list): errors.append("system.components must be a list") components = [] loopers = [item for item in components if isinstance(item, dict) and item.get("id") == "looper"] if len(loopers) != 1: errors.append(f"exactly one looper component is required, got {len(loopers)}") elif loopers[0].get("instance_count") != 1: errors.append("looper.instance_count must be 1") elif loopers[0].get("loop_count") != 1: errors.append("looper.loop_count must be 1") elif loopers[0].get("channels_per_loop") != 4: errors.append("looper.channels_per_loop must be 4") routing = state.get("routing") if not isinstance(routing, dict): errors.append("routing must be a mapping") return errors looper_inputs = routing.get("looper_inputs") if not isinstance(looper_inputs, list): errors.append("routing.looper_inputs must be a list") looper_inputs = [] # Check that each source is assigned exactly once across all loop channels. input_channels = set() input_sources = set() for index, loop_input in enumerate(looper_inputs): location = f"routing.looper_inputs[{index}]" if not isinstance(loop_input, dict): errors.append(f"{location} must be a mapping") continue source_id = loop_input.get("source") channel = loop_input.get("channel") if source_id not in source_by_id: errors.append(f"{location}.source references unknown source: {source_id}") if source_id in input_sources: errors.append(f"source is assigned to multiple looper inputs: {source_id}") input_sources.add(source_id) if not isinstance(channel, int) or isinstance(channel, bool) or channel not in range(1, 5): errors.append(f"{location}.channel must be an integer from 1 through 4") elif channel in input_channels: errors.append(f"duplicate looper input channel: {channel}") else: input_channels.add(channel) if len(looper_inputs) != 4 or input_channels != {1, 2, 3, 4}: errors.append("looper inputs must cover channels 1 through 4 exactly once") if input_sources != set(source_by_id): errors.append("each declared source must map to exactly one looper input") mix = routing.get("mix") if not isinstance(mix, dict): errors.append("routing.mix must be a mapping") else: output_port = mix.get("output_port") if not isinstance(output_port, str) or not output_port: errors.append("routing.mix.output_port must be a non-empty string") mix_id = mix.get("id") if not isinstance(mix_id, str) or not mix_id: errors.append("routing.mix.id must be a non-empty string") includes = mix.get("includes") if not isinstance(includes, list) or "looper_returns" not in includes: errors.append("routing.mix.includes must include looper_returns") # Loop returns join the output mix but must never feed the loop inputs. returns = routing.get("looper_returns") if not isinstance(returns, dict): errors.append("routing.looper_returns must be a mapping") elif returns.get("feed_looper_inputs") is not False: errors.append("routing.looper_returns.feed_looper_inputs must be false") errors.extend(validate_mod_host_chain(routing, source_by_id)) parameters = state.get("parameters") if not isinstance(parameters, dict): errors.append("parameters must be a mapping") else: for key in ("sample_rate_hz", "quantum_frames"): value = parameters.get(key) if ( not isinstance(value, int) or isinstance(value, bool) or value <= 0 ): errors.append(f"parameters.{key} must be a positive integer") controls = state.get("controls") if not isinstance(controls, dict): errors.append("controls must be a mapping") else: midi_bridge = controls.get("midi_bridge") if not isinstance(midi_bridge, dict): errors.append("controls.midi_bridge must be a mapping") else: if midi_bridge.get("bindings_file") != "config/midi-bindings.yaml": errors.append("controls.midi_bridge.bindings_file must be config/midi-bindings.yaml") if ( not isinstance(midi_bridge.get("input_port_name_contains"), str) or not midi_bridge["input_port_name_contains"].strip() ): errors.append("controls.midi_bridge.input_port_name_contains must be non-empty") mod_ui = midi_bridge.get("mod_ui") if not isinstance(mod_ui, dict): errors.append("controls.midi_bridge.mod_ui must be a mapping") else: if mod_ui.get("host") != "127.0.0.1": errors.append("controls.midi_bridge.mod_ui.host must be 127.0.0.1") port = mod_ui.get("port") if ( not isinstance(port, int) or isinstance(port, bool) or not 1 <= port <= 65535 ): errors.append("controls.midi_bridge.mod_ui.port must be a valid TCP port") elif isinstance(deployment := state.get("deployment"), dict): ui_deployment = deployment.get("mod_ui") if ( isinstance(ui_deployment, dict) and ui_deployment.get("websocket_port") != port ): errors.append( "controls.midi_bridge.mod_ui.port must match deployment.mod_ui.websocket_port" ) websocket_path = mod_ui.get("websocket_path") if websocket_path != "/websocket": errors.append("controls.midi_bridge.mod_ui.websocket_path must be /websocket") connections = state.get("connections", []) if not isinstance(connections, list): errors.append("connections must be a list") connections = [] # An explicitly-forbidden connection documents policy; any other status is actionable. for index, connection in enumerate(connections): if not isinstance(connection, dict): errors.append(f"connections[{index}] must be a mapping") continue if ( connection.get("from") == "looper_returns" and connection.get("to") in { "looper_inputs", "looper_input_1", "looper_input_2", "looper_input_3", "looper_input_4", } and connection.get("status") != "explicitly-forbidden" ): errors.append(f"connections[{index}] routes looper returns into looper inputs") deployment = state.get("deployment") if not isinstance(deployment, dict): errors.append("deployment must be a mapping") else: for component, repository, asset, archive_format, bundle_paths in ( ( "lsp", "lsp-plugins/lsp-plugins", "lsp-plugins-{tag}-Linux-aarch64.7z", "7z", {"lsp-plugins.lv2": "lsp-plugins-{tag}-Linux-aarch64/LV2/lsp-plugins.lv2"}, ), ( "dragonfly_reverb", "michaelwillis/dragonfly-reverb", "dragonfly-reverb-{tag}-linux-arm64.tar.xz", "tar.xz", { "DragonflyEarlyReflections.lv2": "dragonfly-reverb-{tag}/DragonflyEarlyReflections.lv2", "DragonflyHallReverb.lv2": "dragonfly-reverb-{tag}/DragonflyHallReverb.lv2", "DragonflyPlateReverb.lv2": "dragonfly-reverb-{tag}/DragonflyPlateReverb.lv2", "DragonflyRoomReverb.lv2": "dragonfly-reverb-{tag}/DragonflyRoomReverb.lv2", }, ), ): plugin = deployment.get(component) if not isinstance(plugin, dict): errors.append(f"deployment.{component} must be a mapping") continue tag = plugin.get("tag") if not isinstance(tag, str) or not tag or any( character not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-" for character in tag ): errors.append(f"deployment.{component}.tag must be a simple version tag") expected_url = f"https://github.com/{repository}/releases/download/{tag}/{asset.format(tag=tag)}" if plugin.get("archive_url") != expected_url: errors.append(f"deployment.{component}.archive_url must match its tag and approved release asset") if plugin.get("archive_format") != archive_format: errors.append(f"deployment.{component}.archive_format must be {archive_format}") expected_paths = { name: path.format(tag=tag) for name, path in bundle_paths.items() } if plugin.get("bundle_paths") != expected_paths: errors.append(f"deployment.{component}.bundle_paths are invalid") for bundle_name, bundle_path in expected_paths.items(): if bundle_name not in bundle_path: errors.append(f"deployment.{component}.bundle_paths keys must name their bundle directories") namlv2 = deployment.get("namlv2") if not isinstance(namlv2, dict): errors.append("deployment.namlv2 must be a mapping") else: tag = namlv2.get("tag") allowed_tag_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-" if not isinstance(tag, str) or not tag or any( character not in allowed_tag_characters for character in tag ): errors.append("deployment.namlv2.tag must be a simple version tag") archive_url = namlv2.get("archive_url") expected_url = ( f"https://github.com/mikeoliphant/neural-amp-modeler-lv2/releases/download/{tag}/" "neural_amp_modeler_lv2_rpi5.tgz" ) if archive_url != expected_url: errors.append("deployment.namlv2.archive_url must match its tag and approved RPi 5 release asset") if namlv2.get("bundle_directory") != "neural_amp_modeler.lv2": errors.append("deployment.namlv2.bundle_directory must be neural_amp_modeler.lv2") sooperlooper = deployment.get("sooperlooper") if not isinstance(sooperlooper, dict): errors.append("deployment.sooperlooper must be a mapping") else: source_url = sooperlooper.get("source_url") if source_url != "https://github.com/abarker/sooperlooper-mods": errors.append("deployment.sooperlooper.source_url must match the approved GitHub repository") tag = sooperlooper.get("tag") if not isinstance(tag, str) or not tag or any( character not in allowed_tag_characters for character in tag ): errors.append("deployment.sooperlooper.tag must be a simple version tag") for key, expected in ( ("binary_source", "artifacts/sooperlooper/arm64/current/sooperlooper"), ( "service_source", "config/systemd/user/rigforge-sooperlooper.service.in", ), ( "service_destination", ".config/systemd/user/rigforge-sooperlooper.service", ), ("user_service", "rigforge-sooperlooper.service"), ("binding_file", "config/sooperlooper/fcb1010.slb"), ("pw_jack_path", "/usr/bin/pw-jack"), ("oscsend_path", "/usr/bin/oscsend"), ): if sooperlooper.get(key) != expected: errors.append(f"deployment.sooperlooper.{key} must be {expected}") timeout_seconds = sooperlooper.get("timeout_seconds") if ( not isinstance(timeout_seconds, int) or isinstance(timeout_seconds, bool) or not 1 <= timeout_seconds <= 300 ): errors.append("deployment.sooperlooper.timeout_seconds must be between 1 and 300") osc = sooperlooper.get("osc") if not isinstance(osc, dict): errors.append("deployment.sooperlooper.osc must be a mapping") else: if osc.get("host") != "127.0.0.1": errors.append("deployment.sooperlooper.osc.host must be 127.0.0.1") port = osc.get("port") if ( not isinstance(port, int) or isinstance(port, bool) or not 1 <= port <= 65535 ): errors.append("deployment.sooperlooper.osc.port must be a valid UDP port") delay = osc.get("post_start_delay_seconds") if ( not isinstance(delay, int) or isinstance(delay, bool) or not 0 <= delay <= 30 ): errors.append( "deployment.sooperlooper.osc.post_start_delay_seconds must be between 0 and 30" ) prefader = osc.get("discrete_prefader") if ( not isinstance(prefader, int) or isinstance(prefader, bool) or prefader not in (0, 1) ): errors.append( "deployment.sooperlooper.osc.discrete_prefader must be 0 or 1" ) mod_host = deployment.get("mod_host") if not isinstance(mod_host, dict): errors.append("deployment.mod_host must be a mapping") else: source_url = mod_host.get("source_url") if source_url != "https://github.com/mod-audio/mod-host": errors.append("deployment.mod_host.source_url must match the approved GitHub repository") tag = mod_host.get("tag") if not isinstance(tag, str) or not tag or any( character not in allowed_tag_characters for character in tag ): errors.append("deployment.mod_host.tag must be a simple version tag") for key, expected in ( ("binary_source", "artifacts/mod-host/arm64/current/mod-host"), ("service_source", "config/systemd/user/rigforge-mod-host.service.in"), ("service_destination", ".config/systemd/user/rigforge-mod-host.service"), ("user_service", "rigforge-mod-host.service"), ("readiness_script", "scripts/wait_mod_host_ports.py"), ("pw_jack_path", "/usr/bin/pw-jack"), ("python_path", "/usr/bin/python3"), ): if mod_host.get(key) != expected: errors.append(f"deployment.mod_host.{key} must be {expected}") socket_port = mod_host.get("socket_port") if ( not isinstance(socket_port, int) or isinstance(socket_port, bool) or not 1 <= socket_port <= 65535 ): errors.append("deployment.mod_host.socket_port must be a valid TCP port") feedback_port = mod_host.get("feedback_port") if ( not isinstance(feedback_port, int) or isinstance(feedback_port, bool) or not 1 <= feedback_port <= 65535 ): errors.append("deployment.mod_host.feedback_port must be a valid TCP port") elif feedback_port == socket_port: errors.append("deployment.mod_host.feedback_port must differ from socket_port") port_wait_timeout = mod_host.get("port_wait_timeout_seconds") if ( not isinstance(port_wait_timeout, int) or isinstance(port_wait_timeout, bool) or not 5 <= port_wait_timeout <= 300 ): errors.append( "deployment.mod_host.port_wait_timeout_seconds must be between 5 and 300" ) mod_ui = deployment.get("mod_ui") if not isinstance(mod_ui, dict): errors.append("deployment.mod_ui must be a mapping") else: if mod_ui.get("source_url") != "https://github.com/mod-audio/mod-ui": errors.append("deployment.mod_ui.source_url must match the approved GitHub repository") tag = mod_ui.get("tag") if not isinstance(tag, str) or not tag or any( character not in allowed_tag_characters for character in tag ): errors.append("deployment.mod_ui.tag must be a simple version tag") if mod_ui.get("artifact_directory") != "artifacts/mod-ui/arm64/current": errors.append( "deployment.mod_ui.artifact_directory must be artifacts/mod-ui/arm64/current" ) for key, expected in ( ("launcher", "artifacts/mod-ui/arm64/current/run-mod-ui"), ("runner_script", "scripts/run_mod_ui_service.py"), ("service_source", "config/systemd/user/rigforge-mod-ui.service.in"), ("service_destination", ".config/systemd/user/rigforge-mod-ui.service"), ("user_service", "rigforge-mod-ui.service"), ("pw_jack_path", "/usr/bin/pw-jack"), ("python_path", "/usr/bin/python3"), ("websocket_host", "127.0.0.1"), ("reference_directory", ".local/share/rigforge/mod-ui/references"), ("pedalboards_directory", ".local/share/rigforge/mod-ui/pedalboards"), ("last_state_file", ".local/share/rigforge/mod-ui/last-rigforge.json"), ("hardware_input_port", "rigforge.mod-host-input.capture:capture_AUX0"), ("hardware_output_port", "rigforge.mod-host-output.playback:playback_AUX0"), ): if mod_ui.get(key) != expected: errors.append(f"deployment.mod_ui.{key} must be {expected}") ui_port = mod_ui.get("websocket_port") if ( not isinstance(ui_port, int) or isinstance(ui_port, bool) or not 1 <= ui_port <= 65535 ): errors.append("deployment.mod_ui.websocket_port must be a valid TCP port") elif isinstance(mod_host, dict) and ( ui_port == mod_host.get("socket_port") or ui_port == mod_host.get("feedback_port") ): errors.append("deployment.mod_ui.websocket_port must differ from mod-host TCP ports") mod_host_ports = deployment.get("mod_host_ports") if not isinstance(mod_host_ports, dict): errors.append("deployment.mod_host_ports must be a mapping") else: for key, expected in ( ("binary_path", "/usr/bin/pw-loopback"), ("runner_script", "scripts/run_mod_host_ports.py"), ("service_source", "config/systemd/user/rigforge-mod-host-ports.service.in"), ("service_destination", ".config/systemd/user/rigforge-mod-host-ports.service"), ("user_service", "rigforge-mod-host-ports.service"), ("python_path", "/usr/bin/python3"), ("channel_map", "AUX0"), ("input_sink_name", "rigforge.mod-host-input"), ("input_source_name", "rigforge.mod-host-input.capture"), ("output_sink_name", "rigforge.mod-host-output.playback"), ("output_source_name", "rigforge.mod-host-output"), ): if mod_host_ports.get(key) != expected: errors.append(f"deployment.mod_host_ports.{key} must be {expected}") reconcile = deployment.get("reconcile") if not isinstance(reconcile, dict): errors.append("deployment.reconcile must be a mapping") else: for key, expected in ( ("observer_script", "scripts/observe_pipewire.py"), ( "service_source", "config/systemd/user/rigforge-pipewire-reconcile.service.in", ), ( "service_destination", ".config/systemd/user/rigforge-pipewire-reconcile.service", ), ("user_service", "rigforge-pipewire-reconcile.service"), ( "timer_source", "config/systemd/user/rigforge-pipewire-reconcile.timer.in", ), ( "timer_destination", ".config/systemd/user/rigforge-pipewire-reconcile.timer", ), ("user_timer", "rigforge-pipewire-reconcile.timer"), ("python_path", "/usr/bin/python3"), ): if reconcile.get(key) != expected: errors.append(f"deployment.reconcile.{key} must be {expected}") interval = reconcile.get("interval_seconds") if ( not isinstance(interval, int) or isinstance(interval, bool) or not 5 <= interval <= 300 ): errors.append( "deployment.reconcile.interval_seconds must be between 5 and 300" ) midi_bridge = deployment.get("midi_bridge") if not isinstance(midi_bridge, dict): errors.append("deployment.midi_bridge must be a mapping") else: for key, expected in ( ("bridge_script", "scripts/midi_action_bridge.py"), ( "service_source", "config/systemd/user/rigforge-midi-bridge.service.in", ), ( "service_destination", ".config/systemd/user/rigforge-midi-bridge.service", ), ("user_service", "rigforge-midi-bridge.service"), ("python_path", "/usr/bin/python3"), ): if midi_bridge.get(key) != expected: errors.append(f"deployment.midi_bridge.{key} must be {expected}") pipewire = deployment.get("pipewire") if not isinstance(pipewire, dict): errors.append("deployment.pipewire must be a mapping") else: expected_fragment_source = "config/pipewire/filter-chain.conf.d/rigforge-direct-mix.conf" if pipewire.get("fragment_source") != expected_fragment_source: errors.append("deployment.pipewire.fragment_source must name the managed repository fragment") expected_fragment_destination = ".config/pipewire/filter-chain.conf.d/rigforge-direct-mix.conf" if pipewire.get("fragment_destination") != expected_fragment_destination: errors.append("deployment.pipewire.fragment_destination must be the user filter-chain fragment path") if pipewire.get("user_service") != "filter-chain.service": errors.append("deployment.pipewire.user_service must be filter-chain.service") return errors def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument( "state_file", nargs="?", type=Path, default=Path(__file__).resolve().parents[1] / "config" / "desired-state.yaml", ) args = parser.parse_args(argv) try: with args.state_file.open(encoding="utf-8") as state_stream: state = yaml.safe_load(state_stream) except (OSError, yaml.YAMLError) as error: print(f"Unable to load {args.state_file}: {error}", file=sys.stderr) return 2 errors = validate_state(state) if errors: for error in errors: print(f"ERROR: {error}", file=sys.stderr) return 1 print(f"Valid desired state: {args.state_file}") return 0 if __name__ == "__main__": raise SystemExit(main())