@@ -24,12 +24,16 @@ def _run_pytest_host(pytest_target: str) -> int:
2424 return proc .returncode
2525
2626
27- def _build_docker_image (dockerfile_path : str , image_tag : str ) -> bool :
27+ def _build_docker_image (dockerfile_path : str , image_tag : str , platform : str | None = None ) -> bool :
2828 context_dir = os .path .dirname (dockerfile_path )
2929 print (f"Building Docker image '{ image_tag } ' from { dockerfile_path } ..." )
3030 try :
31+ cmd = ["docker" , "build" ]
32+ if platform :
33+ cmd += ["--platform" , platform ]
34+ cmd += ["-t" , image_tag , "-f" , dockerfile_path , context_dir ]
3135 proc = subprocess .run (
32- [ "docker" , "build" , "-t" , image_tag , "-f" , dockerfile_path , context_dir ] ,
36+ cmd ,
3337 stdout = subprocess .PIPE ,
3438 stderr = subprocess .STDOUT ,
3539 text = True ,
@@ -41,7 +45,7 @@ def _build_docker_image(dockerfile_path: str, image_tag: str) -> bool:
4145 return False
4246
4347
44- def _run_pytest_in_docker (project_root : str , image_tag : str , pytest_target : str ) -> int :
48+ def _run_pytest_in_docker (project_root : str , image_tag : str , pytest_target : str , platform : str | None = None ) -> int :
4549 workdir = "/workspace"
4650 # Mount read-only is safer; but tests may write artifacts. Use read-write.
4751 cmd = [
@@ -57,6 +61,8 @@ def _run_pytest_in_docker(project_root: str, image_tag: str, pytest_target: str)
5761 "-w" ,
5862 workdir ,
5963 ]
64+ if platform :
65+ cmd += ["--platform" , platform ]
6066 # Try to match host user to avoid permission problems on mounted volume
6167 try :
6268 uid = os .getuid () # type: ignore[attr-defined]
@@ -136,15 +142,19 @@ def local_test_command(args: argparse.Namespace) -> int:
136142 os .makedirs (os .path .join (project_root , ".eval_protocol" ), exist_ok = True )
137143 except Exception :
138144 pass
145+ # Choose platform to emulate Linux host (default to amd64 on macOS, override with EP_DOCKER_PLATFORM)
146+ selected_platform = os .environ .get ("EP_DOCKER_PLATFORM" )
147+ if not selected_platform and sys .platform == "darwin" :
148+ selected_platform = "linux/amd64"
139149 image_tag = "ep-evaluator:local"
140- ok = _build_docker_image (dockerfiles [0 ], image_tag )
150+ ok = _build_docker_image (dockerfiles [0 ], image_tag , platform = selected_platform )
141151 if not ok :
142152 print ("Docker build failed. See logs above." )
143153 return 1
144154 if not pytest_target :
145155 print ("Error: Failed to resolve a pytest target to run." )
146156 return 1
147- return _run_pytest_in_docker (project_root , image_tag , pytest_target )
157+ return _run_pytest_in_docker (project_root , image_tag , pytest_target , platform = selected_platform )
148158
149159 # No Dockerfile: run on host
150160 if not pytest_target :
0 commit comments