Carve out some dead code

This commit is contained in:
Jack Kingsman
2026-02-24 18:40:35 -08:00
parent f7f696bf10
commit b1a0456a05
6 changed files with 3 additions and 143 deletions
-7
View File
@@ -618,13 +618,6 @@ class MessageRepository:
row = await cursor.fetchone()
return row["acked"] if row else 1
@staticmethod
async def get_ack_count(message_id: int) -> int:
"""Get the current ack count for a message."""
cursor = await db.conn.execute("SELECT acked FROM messages WHERE id = ?", (message_id,))
row = await cursor.fetchone()
return row["acked"] if row else 0
@staticmethod
async def get_ack_and_paths(message_id: int) -> tuple[int, list[MessagePath] | None]:
"""Get the current ack count and paths for a message."""
+1 -74
View File
@@ -1,80 +1,7 @@
import { describe, it, expect } from 'vitest';
import { RADIO_PRESETS, detectPreset, findPreset } from '../utils/radioPresets';
import { RADIO_PRESETS } from '../utils/radioPresets';
describe('Radio Presets', () => {
describe('detectPreset', () => {
it('detects USA/Canada preset', () => {
expect(detectPreset(910.525, 62.5, 7, 5)).toBe('USA/Canada');
});
it('detects Australia preset', () => {
expect(detectPreset(915.8, 250, 10, 5)).toBe('Australia');
});
it('detects Australia (narrow) preset', () => {
expect(detectPreset(916.575, 62.5, 7, 8)).toBe('Australia (narrow)');
});
it('detects EU/UK/Switzerland Long Range preset', () => {
expect(detectPreset(869.525, 250, 11, 5)).toBe('EU/UK/Switzerland Long Range');
});
it('detects EU/UK/Switzerland Medium Range preset', () => {
expect(detectPreset(869.525, 250, 10, 5)).toBe('EU/UK/Switzerland Medium Range');
});
it('detects EU/UK/Switzerland Narrow preset', () => {
expect(detectPreset(869.618, 62.5, 8, 8)).toBe('EU/UK/Switzerland Narrow');
});
it('returns custom for non-matching values', () => {
expect(detectPreset(900, 250, 10, 5)).toBe('custom');
});
it('returns custom when one value differs', () => {
// Same as USA/Canada but with different SF
expect(detectPreset(910.525, 62.5, 8, 5)).toBe('custom');
});
it('returns custom when bandwidth differs', () => {
// Same as USA/Canada but with different BW
expect(detectPreset(910.525, 125, 7, 5)).toBe('custom');
});
it('returns custom when coding rate differs', () => {
// Same as USA/Canada but with different CR
expect(detectPreset(910.525, 62.5, 7, 6)).toBe('custom');
});
});
describe('findPreset', () => {
it('finds preset by exact name', () => {
const preset = findPreset('USA/Canada');
expect(preset).toBeDefined();
expect(preset?.freq).toBe(910.525);
expect(preset?.bw).toBe(62.5);
expect(preset?.sf).toBe(7);
expect(preset?.cr).toBe(5);
});
it('returns undefined for unknown preset', () => {
expect(findPreset('Unknown Preset')).toBeUndefined();
});
it('returns undefined for custom', () => {
expect(findPreset('custom')).toBeUndefined();
});
});
describe('preset round-trip', () => {
it('all presets can be detected after being applied', () => {
for (const preset of RADIO_PRESETS) {
const detected = detectPreset(preset.freq, preset.bw, preset.sf, preset.cr);
expect(detected).toBe(preset.name);
}
});
});
describe('preset values are valid LoRa parameters', () => {
it('all frequencies are in valid ISM bands', () => {
for (const preset of RADIO_PRESETS) {
-14
View File
@@ -25,17 +25,3 @@ export const RADIO_PRESETS: RadioPreset[] = [
{ name: 'Vietnam', freq: 920.25, bw: 250, sf: 11, cr: 5 },
];
/** Detect which preset matches the given radio parameters, or 'custom' if none match. */
export function detectPreset(freq: number, bw: number, sf: number, cr: number): string {
for (const preset of RADIO_PRESETS) {
if (preset.freq === freq && preset.bw === bw && preset.sf === sf && preset.cr === cr) {
return preset.name;
}
}
return 'custom';
}
/** Find a preset by exact name. */
export function findPreset(name: string): RadioPreset | undefined {
return RADIO_PRESETS.find((p) => p.name === name);
}
-15
View File
@@ -210,21 +210,6 @@ export function getLinkId<
};
}
export function findContactByPrefix(prefix: string, contacts: Contact[]): Contact | null {
const normalized = prefix.toLowerCase();
const matches = contacts.filter((c) => c.public_key.toLowerCase().startsWith(normalized));
return matches.length === 1 ? matches[0] : null;
}
export function findContactsByPrefix(prefix: string, contacts: Contact[]): Contact[] {
const normalized = prefix.toLowerCase();
return contacts.filter((c) => c.public_key.toLowerCase().startsWith(normalized));
}
export function findContactByName(name: string, contacts: Contact[]): Contact | null {
return contacts.find((c) => c.name === name) || null;
}
export function getNodeType(contact: Contact | null | undefined): NodeType {
return contact?.type === CONTACT_TYPE_REPEATER ? 'repeater' : 'client';
}
+2 -2
View File
@@ -155,7 +155,7 @@ class TestAckEventHandler:
await on_ack(MockEvent())
# Verify ack count incremented (real DB)
ack_count = await MessageRepository.get_ack_count(msg_id)
ack_count, _ = await MessageRepository.get_ack_and_paths(msg_id)
assert ack_count == 1
# Verify broadcast sent with ack_count
@@ -188,7 +188,7 @@ class TestAckEventHandler:
await on_ack(MockEvent())
# Ack count should remain 0
ack_count = await MessageRepository.get_ack_count(msg_id)
ack_count, _ = await MessageRepository.get_ack_and_paths(msg_id)
assert ack_count == 0
mock_broadcast.assert_not_called()
-31
View File
@@ -267,37 +267,6 @@ class TestMessageRepositoryGetByContent:
assert result.paths is None
class TestMessageRepositoryGetAckCount:
"""Test MessageRepository.get_ack_count against a real SQLite database."""
@pytest.mark.asyncio
async def test_get_ack_count_returns_count(self, test_db):
"""Returns ack count for existing message."""
msg_id = await _create_message(test_db)
# Simulate acking by directly updating
await test_db.conn.execute("UPDATE messages SET acked = ? WHERE id = ?", (3, msg_id))
result = await MessageRepository.get_ack_count(message_id=msg_id)
assert result == 3
@pytest.mark.asyncio
async def test_get_ack_count_returns_zero_for_nonexistent(self, test_db):
"""Returns 0 for nonexistent message."""
result = await MessageRepository.get_ack_count(message_id=999999)
assert result == 0
@pytest.mark.asyncio
async def test_get_ack_count_returns_zero_for_unacked(self, test_db):
"""Returns 0 for message with no acks."""
msg_id = await _create_message(test_db)
result = await MessageRepository.get_ack_count(message_id=msg_id)
assert result == 0
class TestRepeaterAdvertPathRepository:
"""Test storing and retrieving recent unique repeater advert paths."""