docs(worker): document SIENTIA_RUNTIME_READY, log the skipped install, test install failure (SIENTIAPDE-2214)

From the code-review-python pass on #34:
- README, CLAUDE.md and the module docstring: the worker re-executes
  itself after install_runtime, and SIENTIA_RUNTIME_READY is internal;
  setting it in .env/the chart would skip the install silently.
- "Installing runtime" is now logged only on the pass that installs; the
  re-executed pass logs that the install was skipped.
- The ponytail comment notes that the install success metrics are lost
  to the exec.
- New test: a failed install propagates without setting the flag or
  calling os.execv (locks the install -> flag -> exec order).
This commit is contained in:
PedroHMCosme
2026-10-20 16:30:23 -03:00
parent 0c9c5f300b
commit 262ba8d658
4 changed files with 55 additions and 4 deletions

View File

@@ -967,6 +967,49 @@ async def test_main_skips_install_when_runtime_ready(
mock_activities_class.assert_called_once()
@pytest.mark.asyncio
@patch('model_manager.worker.worker.RUNTIME', 'basic')
@patch('model_manager.worker.worker.Activities', side_effect=_StopBootError)
@patch('model_manager.worker.worker.NotificationHandler')
@patch('model_manager.worker.worker.PluginStore')
@patch('model_manager.worker.worker.build_plugin_store_config', return_value=_PLUGIN_STORE_CONFIG)
@patch(
'model_manager.worker.worker.build_mongodb_config',
return_value={'connection_string': 'mongodb://test', 'database_name': 'db', 'uri': 'u'},
)
@patch('model_manager.worker.worker.get_logger')
@patch('model_manager.worker.worker.start_prometheus_server')
@patch('model_manager.worker.worker.ensure_runtime_directories')
async def test_main_install_failure_does_not_reexec(
_mock_dirs,
_mock_prometheus,
_mock_get_logger,
_mock_mongo,
_mock_ps_config,
mock_plugin_store_class,
_mock_notification,
mock_activities_class,
monkeypatch,
):
"""A failed install propagates without marking the runtime ready or replacing the process."""
from model_manager.worker import worker as worker_module
monkeypatch.setenv('SIENTIA_RUNTIME_READY', '0')
mock_plugin_store_class.return_value.install_runtime = AsyncMock(
side_effect=RuntimeError('pip failed')
)
with (
patch('model_manager.worker.worker.os.execv') as m_execv,
pytest.raises(RuntimeError, match='pip failed'),
):
await worker_module.main()
assert os.environ['SIENTIA_RUNTIME_READY'] == '0'
m_execv.assert_not_called()
mock_activities_class.assert_not_called()
@patch('model_manager.worker.worker.asyncio.run')
def test_main_entrypoint(mock_asyncio_run):
"""Test the __main__ entrypoint."""