2525 BlueprintOps ,
2626 StorageObjectOps ,
2727)
28- from runloop_api_client .lib ._ignore import DockerIgnoreMatcher
2928from runloop_api_client .lib .polling import PollingConfig
3029
3130
@@ -483,10 +482,10 @@ def test_upload_from_dir_with_string_path(
483482 http_client .put .assert_called_once ()
484483 mock_client .objects .complete .assert_called_once ()
485484
486- def test_upload_from_dir_respects_dockerignore (
485+ def test_upload_from_dir_respects_filter (
487486 self , mock_client : Mock , object_view : MockObjectView , tmp_path : Path
488487 ) -> None :
489- """upload_from_dir should respect .dockerignore patterns by default ."""
488+ """upload_from_dir should respect a tar filter when provided ."""
490489 mock_client .objects .create .return_value = object_view
491490
492491 test_dir = tmp_path / "ctx"
@@ -497,90 +496,20 @@ def test_upload_from_dir_respects_dockerignore(
497496 build_dir .mkdir ()
498497 (build_dir / "ignored.txt" ).write_text ("ignored" , encoding = "utf-8" )
499498
500- dockerignore = test_dir / ".dockerignore"
501- dockerignore .write_text ("*.log\n build/\n " , encoding = "utf-8" )
502-
503499 http_client = Mock ()
504500 mock_response = create_mock_httpx_response ()
505501 http_client .put .return_value = mock_response
506502 mock_client ._client = http_client
507503
508504 client = StorageObjectOps (mock_client )
509- obj = client .upload_from_dir (test_dir )
510-
511- assert isinstance (obj , StorageObject )
512- http_client .put .assert_called_once ()
513- uploaded_content = http_client .put .call_args [1 ]["content" ]
514-
515- with tarfile .open (fileobj = io .BytesIO (uploaded_content ), mode = "r:gz" ) as tar :
516- names = {m .name for m in tar .getmembers ()}
517-
518- assert "keep.txt" in names
519- assert "ignore.log" not in names
520- assert not any (name .startswith ("build/" ) for name in names )
521505
522- def test_upload_from_dir_with_extra_ignore_file (
523- self , mock_client : Mock , object_view : MockObjectView , tmp_path : Path
524- ) -> None :
525- """upload_from_dir should merge .dockerignore and an extra ignore file."""
526- mock_client .objects .create .return_value = object_view
527-
528- test_dir = tmp_path / "ctx"
529- test_dir .mkdir ()
530- (test_dir / "keep.txt" ).write_text ("keep" , encoding = "utf-8" )
531- (test_dir / "ignore.log" ).write_text ("ignore" , encoding = "utf-8" )
532- build_dir = test_dir / "build"
533- build_dir .mkdir ()
534- (build_dir / "ignored.txt" ).write_text ("ignored" , encoding = "utf-8" )
535-
536- # Only ignore logs in .dockerignore
537- dockerignore = test_dir / ".dockerignore"
538- dockerignore .write_text ("*.log\n " , encoding = "utf-8" )
539-
540- extra_ignore = tmp_path / "extra.ignore"
541- extra_ignore .write_text ("build/\n " , encoding = "utf-8" )
542-
543- http_client = Mock ()
544- mock_response = create_mock_httpx_response ()
545- http_client .put .return_value = mock_response
546- mock_client ._client = http_client
506+ # Tar filter: drop logs and anything under build/
507+ def ignore_logs_and_build (ti : tarfile .TarInfo ) -> tarfile .TarInfo | None :
508+ if ti .name .endswith (".log" ) or ti .name .startswith ("build/" ):
509+ return None
510+ return ti
547511
548- client = StorageObjectOps (mock_client )
549- matcher = DockerIgnoreMatcher (extra_ignorefile = extra_ignore )
550- obj = client .upload_from_dir (test_dir , ignore = matcher )
551-
552- assert isinstance (obj , StorageObject )
553- uploaded_content = http_client .put .call_args [1 ]["content" ]
554-
555- with tarfile .open (fileobj = io .BytesIO (uploaded_content ), mode = "r:gz" ) as tar :
556- names = {m .name for m in tar .getmembers ()}
557-
558- assert "keep.txt" in names
559- assert "ignore.log" not in names
560- assert not any (name .startswith ("build/" ) for name in names )
561-
562- def test_upload_from_dir_with_inline_ignore_patterns (
563- self , mock_client : Mock , object_view : MockObjectView , tmp_path : Path
564- ) -> None :
565- """upload_from_dir should respect inline ignore patterns."""
566- mock_client .objects .create .return_value = object_view
567-
568- test_dir = tmp_path / "ctx"
569- test_dir .mkdir ()
570- (test_dir / "keep.txt" ).write_text ("keep" , encoding = "utf-8" )
571- (test_dir / "ignore.log" ).write_text ("ignore" , encoding = "utf-8" )
572- build_dir = test_dir / "build"
573- build_dir .mkdir ()
574- (build_dir / "ignored.txt" ).write_text ("ignored" , encoding = "utf-8" )
575-
576- http_client = Mock ()
577- mock_response = create_mock_httpx_response ()
578- http_client .put .return_value = mock_response
579- mock_client ._client = http_client
580-
581- client = StorageObjectOps (mock_client )
582- matcher = DockerIgnoreMatcher (patterns = ["*.log" , "build/" ])
583- obj = client .upload_from_dir (test_dir , ignore = matcher )
512+ obj = client .upload_from_dir (test_dir , ignore = ignore_logs_and_build )
584513
585514 assert isinstance (obj , StorageObject )
586515 uploaded_content = http_client .put .call_args [1 ]["content" ]
0 commit comments