mirror of
https://github.com/chatmail/core.git
synced 2026-05-06 16:36:59 +03:00
feat: report ready/init_error on startup via JSON-RPC notification
Why: When the deltachat-rpc-server encounters a fatal error during early startup (e.g., when the accounts directory is invalid, a file instead of a dir, or otherwise inaccessible), it exits. The Python RPC client previously lacked a structured way to wait for the server to be fully initialized or to detect early startup failures gracefully. This led to hanging tests or obscure broken pipe errors rather than clear initialization errors. How: - The RPC server now sends a JSON-RPC notification on stdout at startup: - "ready" with core_version, server_path, and accounts_dir on success - "init_error" with error message if accounts directory initialization fails - The Python RPC client reads the first line from stdout to ensure the server is ready. - The Python client raises JsonRpcError on init_error, enabling early failure detection and fast-failing rather than stalling. - Added tests to ensure the client fails immediately on invalid dirs.
This commit is contained in:
@@ -13,7 +13,7 @@ import pytest
|
||||
from deltachat_rpc_client import EventType, events
|
||||
from deltachat_rpc_client.const import DownloadState, MessageState
|
||||
from deltachat_rpc_client.pytestplugin import E2EE_INFO_MSGS
|
||||
from deltachat_rpc_client.rpc import JsonRpcError
|
||||
from deltachat_rpc_client.rpc import JsonRpcError, Rpc
|
||||
|
||||
|
||||
def test_system_info(rpc) -> None:
|
||||
@@ -665,6 +665,24 @@ def test_openrpc_command_line() -> None:
|
||||
assert "methods" in openrpc
|
||||
|
||||
|
||||
def test_early_failure(tmp_path) -> None:
|
||||
"""Test that Rpc.start() raises on invalid accounts directories."""
|
||||
# A file instead of a directory.
|
||||
file_path = tmp_path / "not_a_dir"
|
||||
file_path.write_text("I am a file, not a directory")
|
||||
rpc = Rpc(accounts_dir=str(file_path))
|
||||
with pytest.raises(JsonRpcError, match="initialization failed"):
|
||||
rpc.start()
|
||||
|
||||
# A non-empty directory that is not a deltachat accounts directory.
|
||||
non_dc_dir = tmp_path / "invalid_dir"
|
||||
non_dc_dir.mkdir()
|
||||
(non_dc_dir / "some_file").write_text("content")
|
||||
rpc = Rpc(accounts_dir=str(non_dc_dir))
|
||||
with pytest.raises(JsonRpcError, match="initialization failed"):
|
||||
rpc.start()
|
||||
|
||||
|
||||
def test_provider_info(rpc) -> None:
|
||||
account_id = rpc.add_account()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user