@@ -569,13 +569,64 @@ def fake_run(cmd: list[str], cwd: str | None = None):
569569 cmd , cwd = docker_calls [0 ]
570570 assert cwd == str (ctx )
571571 assert "--load" in cmd
572+ assert "--platform" in cmd and "linux/amd64" in cmd
572573 assert "--target" in cmd and "source-minimal" in cmd
573574 assert "--build-arg" in cmd
574575 assert "BASE_IMAGE=python:3.12" in cmd
575576 for tag in opts .all_tags :
576577 assert tag in cmd
577578
578579
580+ def test_local_build_with_multiple_platforms_skips_platform_flag (tmp_path : Path ):
581+ from openhands .agent_server .docker .build import (
582+ BuildOptions ,
583+ _default_sdk_project_root ,
584+ build ,
585+ )
586+
587+ ctx = tmp_path / "ctx"
588+ ctx .mkdir ()
589+ docker_calls : list [tuple [list [str ], str | None ]] = []
590+
591+ def fake_run (cmd : list [str ], cwd : str | None = None ):
592+ if cmd [:3 ] != ["docker" , "buildx" , "build" ]:
593+ raise AssertionError (f"unexpected command: { cmd } " )
594+ docker_calls .append ((cmd , cwd ))
595+ return subprocess .CompletedProcess (cmd , 0 , stdout = "ok" , stderr = "" )
596+
597+ opts = BuildOptions (
598+ base_image = "python:3.12" ,
599+ custom_tags = "python" ,
600+ git_sha = "abc1234567890" ,
601+ git_ref = "refs/heads/main" ,
602+ target = "source-minimal" ,
603+ platforms = ["linux/amd64" , "linux/arm64" ],
604+ push = False ,
605+ sdk_project_root = _default_sdk_project_root (),
606+ )
607+
608+ with (
609+ patch (
610+ "openhands.agent_server.docker.build._make_build_context" , return_value = ctx
611+ ),
612+ patch ("openhands.agent_server.docker.build._run" , side_effect = fake_run ),
613+ patch (
614+ "openhands.agent_server.docker.build._active_buildx_driver" ,
615+ return_value = "docker-container" ,
616+ ),
617+ patch (
618+ "openhands.agent_server.docker.build._default_local_cache_dir" ,
619+ return_value = tmp_path / "cache" ,
620+ ),
621+ patch ("openhands.agent_server.docker.build.shutil.rmtree" ),
622+ ):
623+ build (opts )
624+
625+ cmd = docker_calls [0 ][0 ]
626+ assert "--load" in cmd
627+ assert "--platform" not in cmd
628+
629+
579630def test_build_can_reuse_same_prebuilt_sdist_multiple_times (tmp_path : Path ):
580631 from openhands .agent_server .docker .build import (
581632 BuildOptions ,
0 commit comments