"""Unit tests for the tool instance service.""" import pytest from src.services.tool.instance_service import modify_compose_file @pytest.mark.unit class TestModifyComposeFile: """Tests for modify_compose_file home-directory expansion.""" def test_extra_volumes_expand_home_dir(self, tmp_path): compose_path = tmp_path / "docker-compose.yml" compose_path.write_text( 'services:\n app:\n image: test:latest\n volumes: []\n' ) modify_compose_file( str(compose_path), extra_volumes=[ {"source": "/host/config", "target": "~/.config", "type": "bind"}, {"source": "/host/code", "target": "$HOME/code", "type": "bind"}, ], home_dir="/home/user", ) content = compose_path.read_text() assert "/host/config:/home/user/.config" in content assert "/host/code:/home/user/code" in content def test_working_directory_expands_home_dir(self, tmp_path): compose_path = tmp_path / "docker-compose.yml" compose_path.write_text( 'services:\n app:\n image: test:latest\n' ) modify_compose_file( str(compose_path), working_directory="~/workspace", home_dir="/home/user", ) content = compose_path.read_text() assert "working_dir: /home/user/workspace" in content