99from wildedge .integrations .registry import IntegrationSpec
1010from wildedge .runtime import bootstrap
1111from wildedge .runtime import runner as runtime_runner
12+ from wildedge .settings import read_runtime_env
1213
1314
1415def _fake_execle (captured : dict ):
@@ -55,7 +56,7 @@ def test_cli_run_execs_command_with_env(monkeypatch):
5556 assert captured ["env" ][constants .ENV_STRICT_INTEGRATIONS ] == "0"
5657 assert captured ["env" ][constants .ENV_PRINT_STARTUP_REPORT ] == "0"
5758 assert captured ["env" ][constants .ENV_FLUSH_TIMEOUT ] == str (
58- constants .DEFAULT_SHUTDOWN_FLUSH_TIMEOUT_SEC
59+ constants .DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC
5960 )
6061
6162
@@ -148,7 +149,7 @@ def test_install_runtime_requires_dsn(monkeypatch):
148149 bootstrap .install_runtime ()
149150
150151
151- def test_install_runtime_default_flush_timeout_is_shutdown_budget (monkeypatch ):
152+ def test_install_runtime_default_flush_timeout_is_runtime_budget (monkeypatch ):
152153 class FakeWildEdge :
153154 SUPPORTED_INTEGRATIONS = {"onnx" }
154155
@@ -171,7 +172,7 @@ def close(self): # type: ignore[no-untyped-def]
171172
172173 context = bootstrap .install_runtime ()
173174 try :
174- assert context .flush_timeout == constants .DEFAULT_SHUTDOWN_FLUSH_TIMEOUT_SEC
175+ assert context .flush_timeout == constants .DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC
175176 finally :
176177 context .shutdown ()
177178
@@ -471,3 +472,42 @@ def test_parse_run_args_only_double_dash_raises():
471472 """['--'] with nothing after raises ValueError."""
472473 with pytest .raises (ValueError , match = "missing command" ):
473474 cli .parse_run_args (["--" ])
475+
476+
477+ def test_cli_run_default_flush_timeout_is_nonzero (monkeypatch ):
478+ """CLI must pass a non-zero flush timeout so reservoir events are sent at shutdown."""
479+ captured : dict = {}
480+ monkeypatch .setattr (cli .os , "execle" , _fake_execle (captured ))
481+ monkeypatch .setattr (cli .shutil , "which" , lambda cmd : f"/usr/bin/{ cmd } " )
482+
483+ cli .main (["run" , "--" , "gunicorn" , "myapp.wsgi:app" ])
484+
485+ flush_timeout = float (captured ["env" ][constants .ENV_FLUSH_TIMEOUT ])
486+ assert flush_timeout > 0 , (
487+ "flush timeout must be > 0 so reservoir inference events are flushed at shutdown"
488+ )
489+ assert flush_timeout == constants .DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC
490+
491+
492+ def test_cli_run_flush_timeout_override (monkeypatch ):
493+ """--flush-timeout arg is forwarded to child process."""
494+ captured : dict = {}
495+ monkeypatch .setattr (cli .os , "execle" , _fake_execle (captured ))
496+ monkeypatch .setattr (cli .shutil , "which" , lambda cmd : f"/usr/bin/{ cmd } " )
497+
498+ cli .main (["run" , "--flush-timeout" , "10.0" , "--" , "gunicorn" , "myapp.wsgi:app" ])
499+
500+ assert captured ["env" ][constants .ENV_FLUSH_TIMEOUT ] == "10.0"
501+
502+
503+ def test_read_runtime_env_default_flush_timeout_is_nonzero ():
504+ """read_runtime_env must default to a non-zero flush timeout when env var is absent."""
505+ env = {constants .ENV_DSN : "https://secret@ingest.wildedge.dev/key" }
506+ result = read_runtime_env (all_integrations = [], all_hubs = [], environ = env )
507+ assert result .flush_timeout > 0
508+ assert result .flush_timeout == constants .DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC
509+
510+
511+ def test_runtime_flush_timeout_constant_is_nonzero ():
512+ """Guard: DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC must stay > 0."""
513+ assert constants .DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC > 0
0 commit comments