import json import os import subprocess from pathlib import Path def test_create_instance_writes_default_max_tool_iterations(tmp_path) -> None: app_instance_dir = Path(__file__).resolve().parents[3] fake_bin = tmp_path / "bin" fake_bin.mkdir() docker = fake_bin / "docker" docker.write_text( """#!/usr/bin/env bash set -euo pipefail case "${1:-}" in image) [[ "${2:-}" == "inspect" ]] exit 0 ;; container) [[ "${2:-}" == "inspect" ]] exit 1 ;; run) exit 0 ;; *) echo "unexpected docker command: $*" >&2 exit 1 ;; esac """, encoding="utf-8", ) docker.chmod(0o755) env = os.environ.copy() env["PATH"] = f"{fake_bin}:{env['PATH']}" instances_root = tmp_path / "instances" result = subprocess.run( [ str(app_instance_dir / "create-instance.sh"), "--instance-id", "default-tools", "--auth-username", "steven", "--auth-password", "secret", "--skip-provider-config", "--host-port", "29001", "--instances-root", str(instances_root), "--registry", str(tmp_path / "registry.json"), "--skip-initial-skills", ], cwd=app_instance_dir, env=env, text=True, capture_output=True, check=False, ) assert result.returncode == 0, result.stderr config_path = instances_root / "default-tools" / "beaver-home" / "config.json" config = json.loads(config_path.read_text(encoding="utf-8")) assert config["agents"]["defaults"]["maxToolIterations"] == 100