Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/container_magic/core/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ def _add_mount_volumes(
args.extend(["-v", f"{resolved}:{container_path}:z"])

manifest_lines.append(f"{resolved}:{container_path}")
command_fragments.append(f"{spec.prefix}{container_path}")
if spec.prefix and spec.prefix != spec.prefix.rstrip():
prefix_parts = spec.prefix.rstrip().split()
command_fragments.extend(prefix_parts + [container_path])
else:
command_fragments.append(f"{spec.prefix}{container_path}")

return command_fragments, manifest_lines

Expand Down
41 changes: 41 additions & 0 deletions tests/unit/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from container_magic.core.config import ContainerMagicConfig, CustomCommand
from container_magic.core.runner import (
_add_mount_volumes,
_build_feature_flags,
_detect_container_home,
_detect_shell,
Expand Down Expand Up @@ -216,6 +217,46 @@ def test_unknown_name_value_stays_in_remaining(self):
assert remaining == ["unknown=value"]


class TestAddMountVolumes:
def _make_command(self, mounts=None):
data = {"command": "test-cmd"}
if mounts:
data["mounts"] = mounts
return CustomCommand(**data)

def test_space_prefix_splits_into_separate_fragments(self, tmp_path):
test_file = tmp_path / "input.txt"
test_file.write_text("test")
cmd = self._make_command(mounts={"data": {"mode": "ro", "prefix": "--data "}})
args = []
fragments, _ = _add_mount_volumes(args, cmd, {"data": str(test_file)})
assert fragments == ["--data", f"/mnt/data/{test_file.name}"]

def test_equals_prefix_stays_as_one_fragment(self, tmp_path):
test_file = tmp_path / "input.txt"
test_file.write_text("test")
cmd = self._make_command(mounts={"data": {"mode": "ro", "prefix": "--data="}})
args = []
fragments, _ = _add_mount_volumes(args, cmd, {"data": str(test_file)})
assert fragments == ["--data=/mnt/data/input.txt"]

def test_no_prefix_produces_path_only(self, tmp_path):
test_file = tmp_path / "input.txt"
test_file.write_text("test")
cmd = self._make_command(mounts={"data": {"mode": "ro"}})
args = []
fragments, _ = _add_mount_volumes(args, cmd, {"data": str(test_file)})
assert fragments == [f"/mnt/data/{test_file.name}"]

def test_rw_mount_with_space_prefix(self, tmp_path):
output_dir = tmp_path / "output"
output_dir.mkdir()
cmd = self._make_command(mounts={"results": {"mode": "rw", "prefix": "--output "}})
args = []
fragments, _ = _add_mount_volumes(args, cmd, {"results": str(output_dir)})
assert fragments == ["--output", "/mnt/results"]


class TestParseRunArgs:
def test_no_args(self):
detach, passthrough, remaining = _parse_run_args([])
Expand Down
Loading