Update tests with new out_path_hash_mode field and surface error on path hash mode set failure

This commit is contained in:
Jack Kingsman
2026-03-08 00:04:11 -08:00
parent b3625b4937
commit 564cd65496
13 changed files with 40 additions and 1 deletions

View File

@@ -123,7 +123,12 @@ async def update_radio_config(update: RadioConfigUpdate) -> RadioConfigResponse:
status_code=400, detail="Firmware does not support path hash mode setting"
)
logger.info("Setting path hash mode to %d", update.path_hash_mode)
await mc.commands.set_path_hash_mode(update.path_hash_mode)
result = await mc.commands.set_path_hash_mode(update.path_hash_mode)
if result is not None and result.type == EventType.ERROR:
raise HTTPException(
status_code=500,
detail=f"Failed to set path hash mode: {result.payload}",
)
radio_manager.path_hash_mode = update.path_hash_mode
# Sync time with system clock

View File

@@ -288,6 +288,7 @@ function makeContact(overrides: Partial<Contact> = {}): Contact {
last_read_at: null,
first_seen: null,
...overrides,
out_path_hash_mode: overrides.out_path_hash_mode ?? 0,
};
}

View File

@@ -24,6 +24,7 @@ const mockContact: Contact = {
flags: 0,
last_path: null,
last_path_len: -1,
out_path_hash_mode: 0,
last_advert: null,
lat: null,
lon: null,

View File

@@ -29,6 +29,7 @@ function createContact(overrides: Partial<Contact> = {}): Contact {
last_read_at: null,
first_seen: null,
...overrides,
out_path_hash_mode: overrides.out_path_hash_mode ?? 0,
};
}

View File

@@ -80,6 +80,7 @@ const contacts: Contact[] = [
flags: 0,
last_path: null,
last_path_len: -1,
out_path_hash_mode: 0,
last_advert: null,
lat: null,
lon: null,

View File

@@ -228,6 +228,7 @@ describe('SearchView', () => {
flags: 0,
last_path: null,
last_path_len: -1,
out_path_hash_mode: 0,
last_advert: null,
lat: null,
lon: null,

View File

@@ -23,6 +23,7 @@ function makeContact(public_key: string, name: string, type = 1): Contact {
flags: 0,
last_path: null,
last_path_len: -1,
out_path_hash_mode: 0,
last_advert: null,
lat: null,
lon: null,

View File

@@ -196,6 +196,7 @@ describe('resolveContactFromHashToken', () => {
flags: 0,
last_path: null,
last_path_len: -1,
out_path_hash_mode: 0,
last_advert: null,
lat: null,
lon: null,
@@ -212,6 +213,7 @@ describe('resolveContactFromHashToken', () => {
flags: 0,
last_path: null,
last_path_len: -1,
out_path_hash_mode: 0,
last_advert: null,
lat: null,
lon: null,
@@ -228,6 +230,7 @@ describe('resolveContactFromHashToken', () => {
flags: 0,
last_path: null,
last_path_len: -1,
out_path_hash_mode: 0,
last_advert: null,
lat: null,
lon: null,

View File

@@ -49,6 +49,7 @@ function makeContact(suffix: string): Contact {
flags: 0,
last_path: null,
last_path_len: -1,
out_path_hash_mode: 0,
last_advert: null,
lat: null,
lon: null,

View File

@@ -45,6 +45,7 @@ function makeContact(pubkey: string): Contact {
flags: 0,
last_path: null,
last_path_len: -1,
out_path_hash_mode: 0,
last_advert: null,
lat: null,
lon: null,

View File

@@ -66,6 +66,7 @@ export interface Contact {
flags: number;
last_path: string | null;
last_path_len: number;
out_path_hash_mode: number;
last_advert: number | null;
lat: number | null;
lon: number | null;

View File

@@ -90,6 +90,7 @@ export interface Contact {
flags: number;
last_path: string | null;
last_path_len: number;
out_path_hash_mode: number;
last_advert: number | null;
lat: number | null;
lon: number | null;

View File

@@ -161,6 +161,27 @@ class TestUpdateRadioConfig:
assert exc.value.status_code == 400
@pytest.mark.asyncio
async def test_propagates_radio_error_when_setting_path_hash_mode(self):
mc = _mock_meshcore_with_info()
mc.commands.set_path_hash_mode = AsyncMock(
return_value=_radio_result(EventType.ERROR, {"error": "nope"})
)
with (
patch("app.routers.radio.require_connected", return_value=mc),
patch.object(radio_manager, "_meshcore", mc),
patch.object(radio_manager, "path_hash_mode_supported", True),
patch.object(radio_manager, "path_hash_mode", 0),
):
with pytest.raises(HTTPException) as exc:
await update_radio_config(RadioConfigUpdate(path_hash_mode=1))
assert exc.value.status_code == 500
assert "Failed to set path hash mode" in str(exc.value.detail)
assert radio_manager.path_hash_mode == 0
mc.commands.send_appstart.assert_not_awaited()
class TestPrivateKeyImport:
@pytest.mark.asyncio