@@ -2194,3 +2194,128 @@ def test_ctrl_c_during_build_streaming_shows_cancelled(
21942194
21952195 assert "🟡" in result .output
21962196 assert "Cancelled." in result .output
2197+
2198+
2199+ def _create_file (path : Path , size_bytes : int ) -> None :
2200+ """Create a file of the given size."""
2201+ path .parent .mkdir (parents = True , exist_ok = True )
2202+ with open (path , "wb" ) as f :
2203+ if size_bytes > 0 :
2204+ f .seek (size_bytes - 1 )
2205+ f .write (b"\0 " )
2206+
2207+
2208+ @pytest .mark .respx
2209+ def test_large_file_threshold_warning (
2210+ logged_in_cli : None , tmp_path : Path , respx_mock : respx .MockRouter
2211+ ) -> None :
2212+ app_data = _get_random_app ()
2213+ app_id = app_data ["id" ]
2214+ team_id = "some-team-id"
2215+ deployment_data = _get_random_deployment (app_id = app_id )
2216+
2217+ _setup_deployment_mocks (
2218+ respx_mock , app_id , team_id , deployment_data , tmp_path
2219+ )
2220+ respx_mock .get (f"/apps/{ app_id } /deployments/{ deployment_data ['id' ]} " ).mock (
2221+ return_value = Response (200 , json = {** deployment_data , "status" : "success" })
2222+ )
2223+
2224+ _create_file (tmp_path / "model.bin" , 12 * 1024 * 1024 ) # 12 MB
2225+ _create_file (tmp_path / "data.csv" , 11 * 1024 * 1024 ) # 11 MB
2226+
2227+ with changing_dir (tmp_path ):
2228+ result = runner .invoke (app , ["deploy" ])
2229+
2230+ assert result .exit_code == 0
2231+ assert "Some uploaded files are larger than 10 MB" in result .output
2232+ assert "model.bin" in result .output
2233+ assert "12 MB" in result .output
2234+ assert "data.csv" in result .output
2235+ assert "11 MB" in result .output
2236+
2237+
2238+ @pytest .mark .respx
2239+ def test_large_file_threshold_only_top_three_files_with_more_indicator (
2240+ logged_in_cli : None , tmp_path : Path , respx_mock : respx .MockRouter
2241+ ) -> None :
2242+ app_data = _get_random_app ()
2243+ app_id = app_data ["id" ]
2244+ team_id = "some-team-id"
2245+ deployment_data = _get_random_deployment (app_id = app_id )
2246+
2247+ _setup_deployment_mocks (
2248+ respx_mock , app_id , team_id , deployment_data , tmp_path
2249+ )
2250+ respx_mock .get (f"/apps/{ app_id } /deployments/{ deployment_data ['id' ]} " ).mock (
2251+ return_value = Response (200 , json = {** deployment_data , "status" : "success" })
2252+ )
2253+
2254+ _create_file (tmp_path / "huge.bin" , 50 * 1024 * 1024 )
2255+ _create_file (tmp_path / "big.bin" , 40 * 1024 * 1024 )
2256+ _create_file (tmp_path / "medium.bin" , 30 * 1024 * 1024 )
2257+ _create_file (tmp_path / "smaller.bin" , 20 * 1024 * 1024 )
2258+ _create_file (tmp_path / "smallest.bin" , 15 * 1024 * 1024 )
2259+
2260+ with changing_dir (tmp_path ):
2261+ result = runner .invoke (app , ["deploy" ])
2262+
2263+ assert result .exit_code == 0
2264+ assert "huge.bin" in result .output
2265+ assert "big.bin" in result .output
2266+ assert "medium.bin" in result .output
2267+ assert "smaller.bin" not in result .output
2268+ assert "smallest.bin" not in result .output
2269+ assert "...and 2 more" in result .output
2270+
2271+
2272+ @pytest .mark .respx
2273+ def test_large_file_threshold_does_not_warn_when_no_large_files (
2274+ logged_in_cli : None , tmp_path : Path , respx_mock : respx .MockRouter
2275+ ) -> None :
2276+ app_data = _get_random_app ()
2277+ app_id = app_data ["id" ]
2278+ team_id = "some-team-id"
2279+ deployment_data = _get_random_deployment (app_id = app_id )
2280+
2281+ _setup_deployment_mocks (
2282+ respx_mock , app_id , team_id , deployment_data , tmp_path
2283+ )
2284+ respx_mock .get (f"/apps/{ app_id } /deployments/{ deployment_data ['id' ]} " ).mock (
2285+ return_value = Response (200 , json = {** deployment_data , "status" : "success" })
2286+ )
2287+
2288+ (tmp_path / "main.py" ).write_text ("print('hello')" )
2289+
2290+ with changing_dir (tmp_path ):
2291+ result = runner .invoke (app , ["deploy" ])
2292+
2293+ assert result .exit_code == 0
2294+ assert "Some uploaded files are larger than" not in result .output
2295+
2296+
2297+ @pytest .mark .respx
2298+ def test_large_file_threshold_custom_threshold (
2299+ logged_in_cli : None , tmp_path : Path , respx_mock : respx .MockRouter
2300+ ) -> None :
2301+ app_data = _get_random_app ()
2302+ app_id = app_data ["id" ]
2303+ team_id = "some-team-id"
2304+ deployment_data = _get_random_deployment (app_id = app_id )
2305+
2306+ _setup_deployment_mocks (
2307+ respx_mock , app_id , team_id , deployment_data , tmp_path
2308+ )
2309+ respx_mock .get (f"/apps/{ app_id } /deployments/{ deployment_data ['id' ]} " ).mock (
2310+ return_value = Response (200 , json = {** deployment_data , "status" : "success" })
2311+ )
2312+
2313+ # 5 MB file: above a 1 MB threshold, below the default 10 MB threshold
2314+ _create_file (tmp_path / "data.bin" , 5 * 1024 * 1024 )
2315+
2316+ with changing_dir (tmp_path ):
2317+ result = runner .invoke (app , ["deploy" , "--large-file-threshold" , "1" ])
2318+
2319+ assert result .exit_code == 0
2320+ assert "Some uploaded files are larger than 1 MB" in result .output
2321+ assert "data.bin" in result .output
0 commit comments