Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.
Rust
feat(macos): create macos switchyard deamon (#863)
Greg Clark7621d235f633
diff --git a/Makefile b/Makefileindex eadc87cff..a0dd77668 100644--- a/Makefile+++ b/Makefile@@ -2,12 +2,15 @@# SPDX-License-Identifier: Apache-2.0.DEFAULT_GOAL := help-.PHONY: help install-linux install-linux-dry-run uninstall-linux+.PHONY: help install-linux install-linux-dry-run uninstall-linux install-macos install-macos-dry-run uninstall-macoshelp:@echo "install-linux Install the systemd user service and Codex profile"@echo "install-linux-dry-run Preview installation without changes"@echo "uninstall-linux Remove the service and Codex profile"+ @echo "install-macos Install the background server"+ @echo "install-macos-dry-run Preview installation without changes"+ @echo "uninstall-macos Remove the LaunchAgents and Codex profile"## Install the Switchyard background server as a systemd user service.install-linux:@@ -20,3 +23,15 @@ install-linux-dry-run:## Remove the systemd user service, the sy Codex profile, and the codex alias.uninstall-linux:@scripts/linux/uninstall.sh++## Install the Switchyard background server for this user.+install-macos:+ @scripts/macos/install.sh++## Print what install-macos would do, without changing anything.+install-macos-dry-run:+ @scripts/macos/install.sh --dry-run++## Remove the LaunchAgent, the sy Codex profile, and the codex alias.+uninstall-macos:+ @scripts/macos/uninstall.shdiff --git a/scripts/common.sh b/scripts/common.shnew file mode 100644index 000000000..cd27254f1--- /dev/null+++ b/scripts/common.sh@@ -0,0 +1,117 @@+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.+# SPDX-License-Identifier: Apache-2.0++SY_HOME="${SY_HOME:-$HOME/.switchyard}"+SY_PORT="${SY_PORT:-4123}"+CODEX_DIR="${CODEX_HOME:-$HOME/.codex}"+# Both installers use Codex's standalone profile file for the CLI.+CODEX_PROFILE_CONFIG="$CODEX_DIR/sy.config.toml"+ALIAS_START="# >>> switchyard codex alias >>>"+ALIAS_END="# <<< switchyard codex alias <<<"++say() { printf '%s\n' "$*"; }+step() { printf '\n==> %s\n' "$*"; }++strip_block() {+ local path="$1" start="$2" end="$3" label="${4:-the switchyard block}"+ if [[ ! -f "$path" ]] || ! grep -qF "$start" "$path"; then+ return 1+ fi+ if ! grep -qF "$end" "$path"; then+ say " $path has no end marker for $label; not editing it" >&2+ return 1+ fi+ if (( DRY_RUN )); then+ say " would remove $label from $path"+ return 0+ fi+ local temp+ temp="$(mktemp)"+ awk -v start="$start" -v end="$end" '+ index($0, start) { skipping = 1 }+ !skipping { print }+ index($0, end) { skipping = 0 }+ END { if (skipping) exit 1 }+ ' "$path" > "$temp"+ cat "$temp" > "$path"+ rm -f "$temp"+ say " removed $label from $path"+ return 0+}++run() {+ if (( DRY_RUN )); then+ say " would run: $*"+ else+ "$@"+ fi+}++write_once() {+ local path="$1"+ if [[ -f "$path" ]]; then+ say " keeping existing $path"+ cat >/dev/null+ return+ fi+ if (( DRY_RUN )); then+ say " would create $path"+ cat >/dev/null+ else+ mkdir -p "$(dirname "$path")"+ cat > "$path"+ say " created $path"+ fi+}++write_with_backup() {+ local path="$1"+ if (( DRY_RUN )); then+ [[ -f "$path" ]] && say " would back up $path"+ say " would write $path"+ cat >/dev/null+ return+ fi+ mkdir -p "$(dirname "$path")"+ local incoming+ incoming="$(mktemp)"+ cat > "$incoming"+ if [[ -f "$path" ]] && cmp -s "$incoming" "$path"; then+ say " $path is already up to date"+ rm -f "$incoming"+ return+ fi+ if [[ -f "$path" ]]; then+ local backup+ backup="$path.switchyard-backup.$(date +%Y%m%d%H%M%S)"+ cp "$path" "$backup"+ say " backed up $path to $backup"+ fi+ cat "$incoming" > "$path"+ rm -f "$incoming"+ say " wrote $path"+}++write_always() {+ local path="$1"+ if (( DRY_RUN )); then+ say " would write $path"+ cat >/dev/null+ else+ mkdir -p "$(dirname "$path")"+ cat > "$path"+ say " wrote $path"+ fi+}++remove_file() {+ local path="$1"+ if [[ ! -e "$path" ]]; then+ say " nothing to remove at $path"+ elif (( DRY_RUN )); then+ say " would delete $path"+ else+ rm -f "$path"+ say " deleted $path"+ fi+}diff --git a/scripts/linux/common.sh b/scripts/linux/common.shindex 25b16dd83..3a9b7782e 100644--- a/scripts/linux/common.sh+++ b/scripts/linux/common.sh@@ -1,47 +1,8 @@# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0#-# Paths, markers, and helpers shared by install.sh and uninstall.sh.-# The markers must match between the two, which is why they live here.+# shellcheck source=scripts/common.sh+source "$(dirname "${BASH_SOURCE[0]}")/../common.sh"-SY_HOME="${SY_HOME:-$HOME/.switchyard}"-SY_PORT="${SY_PORT:-4123}"SERVICE_NAME="switchyard.service"SYSTEMD_USER_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"-CODEX_DIR="${CODEX_HOME:-$HOME/.codex}"-# Since Codex 0.134.0, `--profile sy` reads sy.config.toml and fails if-# config.toml still has [profiles.sy].-CODEX_PROFILE_CONFIG="$CODEX_DIR/sy.config.toml"-ALIAS_START="# >>> switchyard codex alias >>>"-ALIAS_END="# <<< switchyard codex alias <<<"--say() { printf '%s\n' "$*"; }-step() { printf '\n==> %s\n' "$*"; }--# Deletes the marked block, inclusive, leaving the rest of the file alone.-strip_block() {- local path="$1" start="$2" end="$3" label="${4:-the switchyard block}"- if [[ ! -f "$path" ]] || ! grep -qF "$start" "$path"; then- return 1- fi- if ! grep -qF "$end" "$path"; then- say " $path has no end marker for $label; not editing it" >&2- return 1- fi- if (( DRY_RUN )); then- say " would remove $label from $path"- return 0- fi- local temp- temp="$(mktemp)"- awk -v start="$start" -v end="$end" '- index($0, start) { skipping = 1 }- !skipping { print }- index($0, end) { skipping = 0 }- END { if (skipping) exit 1 }- ' "$path" > "$temp"- cat "$temp" > "$path"- rm -f "$temp"- say " removed $label from $path"- return 0-}diff --git a/scripts/linux/install.sh b/scripts/linux/install.shindex 247bf8c6f..c296ebcfc 100755--- a/scripts/linux/install.sh+++ b/scripts/linux/install.sh@@ -34,75 +34,6 @@ if [[ ! "$SY_PORT" =~ ^[0-9]+$ ]]; thenexit 1fi-# Runs a command, or prints it when dry running.-run() {- if (( DRY_RUN )); then- say " would run: $*"- else- "$@"- fi-}--# Writes stdin to a file, leaving an existing file untouched.-write_once() {- local path="$1"- if [[ -f "$path" ]]; then- say " keeping existing $path"- cat >/dev/null- return- fi- if (( DRY_RUN )); then- say " would create $path"- cat >/dev/null- else- mkdir -p "$(dirname "$path")"- cat > "$path"- say " created $path"- fi-}--# Writes stdin to a file, keeping any existing version as a timestamped backup.-write_with_backup() {- local path="$1"- if (( DRY_RUN )); then- [[ -f "$path" ]] && say " would back up $path"- say " would write $path"- cat >/dev/null- return- fi- mkdir -p "$(dirname "$path")"- local incoming- incoming="$(mktemp)"- cat > "$incoming"- if [[ -f "$path" ]] && cmp -s "$incoming" "$path"; then- say " $path is already up to date"- rm -f "$incoming"- return- fi- if [[ -f "$path" ]]; then- local backup- backup="$path.switchyard-backup.$(date +%Y%m%d%H%M%S)"- cp "$path" "$backup"- say " backed up $path to $backup"- fi- cat "$incoming" > "$path"- rm -f "$incoming"- say " wrote $path"-}--# Writes stdin to a file, replacing it. Used only for files this script owns.-write_always() {- local path="$1"- if (( DRY_RUN )); then- say " would write $path"- cat >/dev/null- else- mkdir -p "$(dirname "$path")"- cat > "$path"- say " wrote $path"- fi-}-if [[ "$(uname -s)" != "Linux" ]]; thensay "This installer is for Linux only." >&2exit 1diff --git a/scripts/linux/uninstall.sh b/scripts/linux/uninstall.shindex fe019ce27..f968a030d 100755--- a/scripts/linux/uninstall.sh+++ b/scripts/linux/uninstall.sh@@ -22,19 +22,6 @@ esac# shellcheck source=scripts/linux/common.shsource "$SCRIPT_DIR/common.sh"-# Deletes a file this script owns.-remove_file() {- local path="$1"- if [[ ! -e "$path" ]]; then- say " nothing to remove at $path"- elif (( DRY_RUN )); then- say " would delete $path"- else- rm -f "$path"- say " deleted $path"- fi-}-step "Removing the sy Codex profile"remove_file "$CODEX_PROFILE_CONFIG"diff --git a/scripts/macos/common.sh b/scripts/macos/common.shnew file mode 100644index 000000000..b63b4fcb8--- /dev/null+++ b/scripts/macos/common.sh@@ -0,0 +1,10 @@+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.+# SPDX-License-Identifier: Apache-2.0+#+# Paths shared by install.sh and uninstall.sh.++# shellcheck source=scripts/common.sh+source "$(dirname "${BASH_SOURCE[0]}")/../common.sh"++SERVER_LABEL="com.nvidia.switchyard.server"+LAUNCH_AGENTS="$HOME/Library/LaunchAgents"diff --git a/scripts/macos/install.sh b/scripts/macos/install.shnew file mode 100755index 000000000..3cb6cc1a2--- /dev/null+++ b/scripts/macos/install.sh@@ -0,0 +1,123 @@+#!/usr/bin/env bash+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.+# SPDX-License-Identifier: Apache-2.0+#+# Installs the Switchyard background server as a per-user LaunchAgent and sets+# up a `sy` Codex profile.+#+# Keeps existing composite.toml and backs up sy.config.toml before replacing it.+# Run with --dry-run to print what would happen.++set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"++DRY_RUN=0+case "$#:${1:-}" in+ 0:) ;;+ 1:--dry-run) DRY_RUN=1 ;;+ *) printf 'Usage: %s [--dry-run]\n' "$0" >&2; exit 2 ;;+esac++# shellcheck source=scripts/macos/common.sh+source "$SCRIPT_DIR/common.sh"++xml_escape_text() {+ printf '%s' "$1" | sed \+ -e 's/&/\&/g' \+ -e 's/</\</g' \+ -e 's/>/\>/g'+}++if [[ "$(uname -s)" != "Darwin" ]]; then+ say "This installer is for macOS only." >&2+ exit 1+fi++step "Building release binaries"+run cargo build --release --manifest-path "$REPO_ROOT/Cargo.toml" \+ -p switchyard-server++step "Installing binaries into $SY_HOME/bin"+run mkdir -p "$SY_HOME/bin" "$SY_HOME/logs"+run install -m 755 "$REPO_ROOT/target/release/switchyard-server" \+ "$SY_HOME/bin/switchyard-server"++step "Writing server config"+# Keep macOS and Linux on the same routing defaults.+write_once "$SY_HOME/composite.toml" < "$REPO_ROOT/scripts/config/composite.toml"++step "Validating the server config"+if (( DRY_RUN )); then+ say " would run: $SY_HOME/bin/switchyard-server --config $SY_HOME/composite.toml --dry-run"+else+ "$SY_HOME/bin/switchyard-server" --config "$SY_HOME/composite.toml" --dry-run+fi++step "Writing LaunchAgents"+XML_SY_HOME="$(xml_escape_text "$SY_HOME")"+write_always "$LAUNCH_AGENTS/$SERVER_LABEL.plist" <<EOF+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+<dict>+ <key>Label</key>+ <string>$SERVER_LABEL</string>+ <key>ProgramArguments</key>+ <array>+ <string>$XML_SY_HOME/bin/switchyard-server</string>+ <string>--config</string>+ <string>$XML_SY_HOME/composite.toml</string>+ <string>--host</string>+ <string>127.0.0.1</string>+ <string>--port</string>+ <string>$SY_PORT</string>+ <string>--routing-log-file</string>+ <string>$XML_SY_HOME/routing.jsonl</string>+ </array>+ <key>RunAtLoad</key>+ <true/>+ <key>KeepAlive</key>+ <true/>+ <key>ProcessType</key>+ <string>Background</string>+ <key>StandardOutPath</key>+ <string>$XML_SY_HOME/logs/server.log</string>+ <key>StandardErrorPath</key>+ <string>$XML_SY_HOME/logs/server.err.log</string>+ <key>EnvironmentVariables</key>+ <dict>+ <key>RUST_LOG</key>+ <string>info</string>+ </dict>+</dict>+</plist>+EOF++step "Loading LaunchAgents"+if (( DRY_RUN )); then+ say " would reload gui/$UID/$SERVER_LABEL"+else+ launchctl bootout "gui/$UID/$SERVER_LABEL" 2>/dev/null || true+ # bootout returns before the job leaves the domain, and bootstrapping a+ # service that is still shutting down fails with an I/O error.+ for _ in $(seq 50); do+ launchctl print "gui/$UID/$SERVER_LABEL" >/dev/null 2>&1 || break+ sleep 0.1+ done+ launchctl bootstrap "gui/$UID" "$LAUNCH_AGENTS/$SERVER_LABEL.plist"+ say " loaded $SERVER_LABEL"+fi++step "Adding the sy Codex profile"+# This profile only changes which router answers. Approval and sandbox+# settings are deliberately left out, so the profile cannot loosen how Codex+# asks before it acts. Set those yourself if you want them.+sed "s/@SY_PORT@/$SY_PORT/g" "$REPO_ROOT/scripts/config/codex.sy.toml" |+ write_with_backup "$CODEX_PROFILE_CONFIG"++step "Done"+say "Server: http://127.0.0.1:$SY_PORT (logs in $SY_HOME/logs)"+say "Use it with: codex -p sy (requires Codex CLI 0.134.0 or newer)"+say "Codex profile: $CODEX_PROFILE_CONFIG"diff --git a/scripts/macos/uninstall.sh b/scripts/macos/uninstall.shnew file mode 100755index 000000000..f431daef4--- /dev/null+++ b/scripts/macos/uninstall.sh@@ -0,0 +1,46 @@+#!/usr/bin/env bash+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.+# SPDX-License-Identifier: Apache-2.0+#+# Removes what install.sh added: the LaunchAgent, the `sy` Codex profile,+# and the codex alias. Your config, routing log, and binaries stay put; the+# paths are printed so you can delete them yourself.+#+# Run with --dry-run to print what would happen.++set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"++DRY_RUN=0+case "$#:${1:-}" in+ 0:) ;;+ 1:--dry-run) DRY_RUN=1 ;;+ *) printf 'Usage: %s [--dry-run]\n' "$0" >&2; exit 2 ;;+esac++# shellcheck source=scripts/macos/common.sh+source "$SCRIPT_DIR/common.sh"++step "Unloading LaunchAgents"+if (( DRY_RUN )); then+ say " would unload gui/$UID/$SERVER_LABEL and delete its plist"+else+ launchctl bootout "gui/$UID/$SERVER_LABEL" 2>/dev/null || true+ rm -f "$LAUNCH_AGENTS/$SERVER_LABEL.plist"+ say " unloaded $SERVER_LABEL"+fi++step "Removing the sy Codex profile"+remove_file "$CODEX_PROFILE_CONFIG"++step "Removing the codex alias"+for rc in "$HOME/.zshrc" "$HOME/.bashrc"; do+ strip_block "$rc" "$ALIAS_START" "$ALIAS_END" "the codex alias" ||+ say " no alias in $rc"+done++step "Done"+say "Left in place, delete them if you want:"+say " $SY_HOME (binaries, config, routing log, logs)"+say " $CODEX_PROFILE_CONFIG.switchyard-backup.* (profile backups)"diff --git a/tests/test_linux_install.py b/tests/test_linux_install.pyindex 33b029beb..7d070c8e3 100644--- a/tests/test_linux_install.py+++ b/tests/test_linux_install.py@@ -18,6 +18,7 @@ RC = f"before\n{START}\nalias codex='codex -p sy'\n{END}\nafter\n"def setup(tmp_path):scripts = tmp_path / "repo" / "scripts" / "linux"shutil.copytree(REPO / "scripts" / "linux", scripts)+ shutil.copy(REPO / "scripts" / "common.sh", scripts.parent / "common.sh")shutil.copytree(REPO / "scripts" / "config", scripts.parent / "config")home = tmp_path / "home"home.mkdir()diff --git a/tests/test_macos_install.py b/tests/test_macos_install.pynew file mode 100644index 000000000..94136260c--- /dev/null+++ b/tests/test_macos_install.py@@ -0,0 +1,212 @@+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.+# SPDX-License-Identifier: Apache-2.0++import os+import shutil+import subprocess+import xml.etree.ElementTree as ET+from pathlib import Path++import pytest++REPO = Path(__file__).resolve().parents[1]+++def setup(tmp_path):+ scripts = tmp_path / "repo" / "scripts" / "macos"+ shutil.copytree(REPO / "scripts" / "macos", scripts)+ shutil.copy(REPO / "scripts" / "common.sh", scripts.parent / "common.sh")+ shutil.copytree(REPO / "scripts" / "config", scripts.parent / "config")+ home = tmp_path / "home"+ home.mkdir()+ bin_dir = tmp_path / "bin"+ bin_dir.mkdir()+ switchyard_home = home / "Switchyard & Routing <local>"+ env = {+ **os.environ,+ "HOME": str(home),+ "SY_HOME": str(switchyard_home),+ "CODEX_HOME": str(home / ".codex"),+ "TMPDIR": str(tmp_path),+ "PATH": f"{bin_dir}:/usr/bin:/bin",+ }+ stubs = {+ "cargo": "exit 0\n",+ "uname": "echo Darwin\n",+ "install": 'printf "#!/bin/sh\\nexit 0\\n" > "$4"\nchmod +x "$4"\n',+ "launchctl": '[[ "$1" != print ]]\n',+ }+ for name, body in stubs.items():+ stub = bin_dir / name+ stub.write_text("#!/bin/bash\nset -eu\n" + body)+ stub.chmod(0o755)+ return scripts, home, switchyard_home, env+++def run(setup, script):+ scripts, _, _, env = setup+ return subprocess.run(+ ["bash", str(scripts / script)],+ env=env,+ capture_output=True,+ text=True,+ timeout=10,+ )+++def read_config(path):+ return path.read_text()+++def test_install_escapes_switchyard_path_in_launch_agent(setup):+ _, home, switchyard_home, _ = setup+ result = run(setup, "install.sh")+ assert result.returncode == 0, result.stderr+ plist = home / "Library" / "LaunchAgents" / "com.nvidia.switchyard.server.plist"+ root = ET.parse(plist).getroot()+ entries = list(root.find("dict"))+ values = {entries[index].text: entries[index + 1] for index in range(0, len(entries), 2)}+ program_arguments = [element.text for element in values["ProgramArguments"]]+ assert program_arguments[0] == str(switchyard_home / "bin" / "switchyard-server")+ assert program_arguments[2] == str(switchyard_home / "composite.toml")+ assert program_arguments[8] == str(switchyard_home / "routing.jsonl")+ assert values["StandardOutPath"].text == str(switchyard_home / "logs" / "server.log")+ assert values["StandardErrorPath"].text == str(switchyard_home / "logs" / "server.err.log")+++def test_missing_codex_config_creates_only_standalone_profile(setup):+ _, _, switchyard_home, env = setup+ env["SY_PORT"] = "5123"+ result = run(setup, "install.sh")+ assert result.returncode == 0, result.stderr+ codex = Path(env["CODEX_HOME"])+ assert sorted(path.name for path in codex.iterdir()) == ["sy.config.toml"]+ expected = read_config(REPO / "scripts" / "config" / "codex.sy.toml").replace(+ "@SY_PORT@", "5123"+ )+ assert read_config(codex / "sy.config.toml") == expected+ assert read_config(switchyard_home / "composite.toml") == read_config(+ REPO / "scripts" / "config" / "composite.toml"+ )+++def test_install_prints_profile_usage_without_editing_shell_files(setup):+ _, home, _, _ = setup+ zshrc = home / ".zshrc"+ bashrc = home / ".bashrc"+ zshrc.write_text("zsh settings\n")+ bashrc.write_text("bash settings\n")++ result = run(setup, "install.sh")++ assert result.returncode == 0, result.stderr+ assert "Use it with: codex -p sy" in result.stdout+ assert zshrc.read_text() == "zsh settings\n"+ assert bashrc.read_text() == "bash settings\n"++[email protected]("script", ["install.sh", "uninstall.sh"])+ "original",+ [+ 'model_provider = "sy"\n[model_providers."sy"]\nname = "Old"\n',+ 'developer_instructions = """\nmodel = "example"\n'+ "# >>> switchyard sy profile >>>\n[model_providers.sy]\n"+ '# <<< switchyard sy profile <<<\n"""\n'+ '# >>> switchyard sy profile >>>\n[profiles.sy]\nmodel_provider = "sy"\n'+ "# <<< switchyard sy profile <<<\n",+ "invalid TOML that must be left alone\n",+ ],+)+def test_scripts_leave_main_config_and_legacy_files_untouched(setup, script, original):+ _, _, _, env = setup+ codex = Path(env["CODEX_HOME"])+ codex.mkdir()+ files = {+ "config.toml": original,+ "config.toml.direct": 'model = "direct"\n',+ "config.sy.toml": 'model = "previous routed config"\n',+ }+ for name, content in files.items():+ (codex / name).write_text(content)+ (codex / "sy.config.toml").write_text('model = "old profile"\n')++ result = run(setup, script)++ assert result.returncode == 0, result.stderr+ for name, content in files.items():+ assert (codex / name).read_text() == content+ assert not list(codex.glob("config.toml.switchyard-*"))+ if script == "uninstall.sh":+ assert not (codex / "sy.config.toml").exists()+ else:+ assert (codex / "sy.config.toml").read_text() == read_config(+ REPO / "scripts" / "config" / "codex.sy.toml"+ ).replace("@SY_PORT@", env.get("SY_PORT", "4123"))+ backups = list(codex.glob("sy.config.toml.switchyard-backup.*"))+ assert len(backups) == 1+ assert backups[0].read_text() == 'model = "old profile"\n'++[email protected]("script", ["install.sh", "uninstall.sh"])+def test_scripts_dry_run_does_not_create_files(setup, script):+ scripts, home, _, env = setup+ result = subprocess.run(+ ["bash", str(scripts / script), "--dry-run"],+ env=env,+ capture_output=True,+ text=True,+ timeout=10,+ )+ assert result.returncode == 0, result.stderr+ assert "would" in result.stdout+ assert list(home.iterdir()) == []++[email protected]("script", ["install.sh", "uninstall.sh"])+ "args",+ [+ ["--dryrun"],+ ["unknown"],+ [""],+ ["--dry-run", "extra"],+ ["--dry-run", "--dry-run"],+ ],+)+def test_scripts_reject_unknown_arguments_before_any_work(setup, script, args):+ scripts, home, _, env = setup+ profile = Path(env["CODEX_HOME"]) / "sy.config.toml"+ plist = home / "Library" / "LaunchAgents" / "com.nvidia.switchyard.server.plist"+ for path in (profile, plist):+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_text("existing file\n")+ before = {+ path.relative_to(home): path.read_bytes() for path in home.rglob("*") if path.is_file()+ }+ command_log = home.parent / "commands.log"+ env["SY_TEST_COMMAND_LOG"] = str(command_log)+ for stub in Path(env["PATH"].split(":")[0]).iterdir():+ stub.write_text(+ stub.read_text().replace(+ "set -eu\n", 'set -eu\nprintf "%s\\n" "$0" >> "$SY_TEST_COMMAND_LOG"\n', 1+ )+ )++ result = subprocess.run(+ ["bash", str(scripts / script), *args],+ env=env,+ capture_output=True,+ text=True,+ timeout=10,+ )++ assert result.returncode == 2+ assert "Usage:" in result.stderr+ assert result.stdout == ""+ assert not command_log.exists()+ after = {+ path.relative_to(home): path.read_bytes() for path in home.rglob("*") if path.is_file()+ }+ assert after == before