From b1a0456a05247198a280b225cbbc3610c09a868d Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Tue, 24 Feb 2026 18:40:35 -0800 Subject: [PATCH] Carve out some dead code --- app/repository.py | 7 --- frontend/src/test/radioPresets.test.ts | 75 +------------------------- frontend/src/utils/radioPresets.ts | 14 ----- frontend/src/utils/visualizerUtils.ts | 15 ------ tests/test_event_handlers.py | 4 +- tests/test_repository.py | 31 ----------- 6 files changed, 3 insertions(+), 143 deletions(-) diff --git a/app/repository.py b/app/repository.py index fdb9f77..f4eaa1f 100644 --- a/app/repository.py +++ b/app/repository.py @@ -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.""" diff --git a/frontend/src/test/radioPresets.test.ts b/frontend/src/test/radioPresets.test.ts index e95d051..27c5b7a 100644 --- a/frontend/src/test/radioPresets.test.ts +++ b/frontend/src/test/radioPresets.test.ts @@ -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) { diff --git a/frontend/src/utils/radioPresets.ts b/frontend/src/utils/radioPresets.ts index 5855d1d..7d70f12 100644 --- a/frontend/src/utils/radioPresets.ts +++ b/frontend/src/utils/radioPresets.ts @@ -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); -} diff --git a/frontend/src/utils/visualizerUtils.ts b/frontend/src/utils/visualizerUtils.ts index a171f44..e9659f5 100644 --- a/frontend/src/utils/visualizerUtils.ts +++ b/frontend/src/utils/visualizerUtils.ts @@ -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'; } diff --git a/tests/test_event_handlers.py b/tests/test_event_handlers.py index b06d92d..aee87d6 100644 --- a/tests/test_event_handlers.py +++ b/tests/test_event_handlers.py @@ -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() diff --git a/tests/test_repository.py b/tests/test_repository.py index b6aa522..7291689 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -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."""