fix(cloud): tolerate slow plugin runtime reconciliation (#2405)

Co-authored-by: Chan <dadachann@users.noreply.github.com>
This commit is contained in:
Hyu
2026-08-06 20:39:20 +08:00
committed by GitHub
parent f59343fd5b
commit ddb6dbf593
6 changed files with 96 additions and 6 deletions
@@ -153,6 +153,31 @@ async def test_empty_projected_workspaces_do_not_retain_installation_sets():
connector.handler.reconcile_plugin_installations.assert_awaited_once_with(())
@pytest.mark.asyncio
async def test_shared_reconcile_logs_workspace_installation_counts_and_elapsed_time():
binding_a = execution_binding('workspace-a')
binding_b = execution_binding('workspace-b')
setting_a = plugin_setting('01', 'a' * 64)
setting_b = plugin_setting('02', 'b' * 64)
connector = shared_connector(
[[binding_a, binding_b]],
{'workspace-a': [setting_a], 'workspace-b': [setting_b]},
)
connector.handler = runtime_handler()
await connector._prepare_connected_runtime()
matching_calls = [
call
for call in connector.ap.logger.info.call_args_list
if call.args
and call.args[0]
== 'Shared plugin runtime reconcile completed: workspaces=%d desired_installations=%d elapsed_seconds=%.3f'
]
assert len(matching_calls) == 1
assert matching_calls[0].args[1:3] == (2, 2)
assert matching_calls[0].args[3] >= 0
@pytest.mark.asyncio
async def test_fresh_shared_runtime_cache_replays_persisted_local_package():
package = b'local-lbpkg-bytes'
@@ -6,9 +6,10 @@ Tests cover:
from __future__ import annotations
import pytest
from importlib import import_module
import pytest
def get_connector_module():
"""Lazy import to avoid circular import issues."""
@@ -60,3 +61,28 @@ def test_runtime_id_is_stable_across_core_restarts(monkeypatch):
monkeypatch.setattr(connector.constants, 'instance_id', 'instance-a')
assert connector.PluginRuntimeConnector._build_runtime_id() == 'instance-a:plugin-runtime'
def test_runtime_connect_timeout_defaults_to_three_minutes():
connector = get_connector_module()
assert connector.PluginRuntimeConnector._runtime_connect_timeout({}) == 180.0
def test_runtime_connect_timeout_reads_typed_plugin_config():
connector = get_connector_module()
assert connector.PluginRuntimeConnector._runtime_connect_timeout({'connect_timeout_seconds': 45.5}) == 45.5
@pytest.mark.parametrize('value', [True, False, None, 0, -1, float('nan'), float('inf'), '180', object()])
def test_runtime_connect_timeout_rejects_invalid_values(value):
connector = get_connector_module()
with pytest.raises(ValueError, match='plugin.connect_timeout_seconds'):
connector.PluginRuntimeConnector._runtime_connect_timeout({'connect_timeout_seconds': value})
def test_runtime_connect_timeout_error_displays_actual_seconds():
connector = get_connector_module()
assert connector.PluginRuntimeConnector._runtime_connect_timeout_error(45.5) == (
'Plugin runtime did not become ready within 45.5 seconds'
)