refactor: remove verified dead code across data, UI, and resources (#680)

* refactor: remove unused dead code across data, UI, and resources

* fix: resolve dangling references left by dead-code removal

Restore empty object Motion (braces required) and remove the 12 stale
test usages that still called the now-deleted production symbols:
- ServerStoreTest: removeServer/switchToServer tests
- ServerEndpointTest: isCleartext assertions
- ConnectViewModelTest: onHostChange/onPortChange tests + 3 dropped R.string refs
- SettingsViewModelTest: renameProfile tests + clearNavigateToLogin
- E2eIntegrationTest: previewSkill tests + onHostChange/onPortChange calls

Verified locally: compileDebugUnitTestKotlin + 48 tests pass.

* fix: remove unused imports flagged by ktlint

Drops 4 no-longer-referenced imports left by the dead-code removal:
- HermesApiService: SkillScanResponse (scanHubSkill removed)
- ServerEndpointTest: assertFalse, assertTrue (isCleartext assertions dropped)
- SettingsViewModelTest: assertFalse (rename tests removed)

---------

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-07-22 15:51:07 +03:00
1 parent 58420d7b2a
commit 2e97ee9a84
29 files changed
+10 -550

No files matched your search

@@ -38,7 +38,6 @@ import com.m57.hermescontrol.data.model.ProfilesResponse
import com.m57.hermescontrol.data.model.SessionInfo
import com.m57.hermescontrol.data.model.SessionListResponse
import com.m57.hermescontrol.data.model.Skill
import com.m57.hermescontrol.data.model.SkillContentResponse
import com.m57.hermescontrol.data.model.SkillHubSearchResponse
import com.m57.hermescontrol.data.model.StatusResponse
import com.m57.hermescontrol.data.model.SystemStatsResponse
@@ -100,8 +99,6 @@ class E2eIntegrationTest {
every { AuthManager.getPort() } returns 9119
every { AuthManager.getBaseUrl() } returns "https://127.0.0.1:9119/"
every { AuthManager.setToken(any()) } returns Unit
every { AuthManager.setHost(any()) } returns Unit
every { AuthManager.setPort(any()) } returns Unit
every { AuthManager.setBaseUrl(any()) } returns Unit
every {
AuthManager.endpoint()
@@ -471,47 +468,6 @@ class E2eIntegrationTest {
// ── Skills Preview ────────────────────────────────────────────────────
@Test
fun testSkillsPreview_success() =
runTest {
val content = SkillContentResponse("my-skill", "# My Skill\n\nDo stuff")
coEvery { mockApiService.getSkillContent(any()) } returns
Response.success(content)
val viewModel = SkillsViewModel(mockApp)
viewModel.previewSkill("my-skill")
advanceUntilIdle()
assertFalse(viewModel.uiState.value.isLoadingPreview)
assertEquals(
"my-skill",
viewModel.uiState.value.previewSkillName,
)
assertEquals(
content.content,
viewModel.uiState.value.previewSkillContent,
)
}
@Test
fun testSkillsPreview_error() =
runTest {
coEvery { mockApiService.getSkillContent(any()) } returns
createErrorResponse(500)
val viewModel = SkillsViewModel(mockApp)
viewModel.previewSkill("failing-skill")
advanceUntilIdle()
assertFalse(viewModel.uiState.value.isLoadingPreview)
assertNull(viewModel.uiState.value.previewSkillContent)
assertNotNull(viewModel.uiState.value.toastMessage)
assertTrue(
viewModel.uiState.value.toastMessage!!
.contains("HTTP 500"),
)
}
// Cron Jobs Screen:
@Test
fun testCronJobsListing_success() =
@@ -1031,8 +987,6 @@ class E2eIntegrationTest {
val connectViewModel = ConnectViewModel(mockApp)
connectViewModel.onTokenChange("valid-token")
connectViewModel.onHostChange("127.0.0.1")
connectViewModel.onPortChange("9119")
connectViewModel.connect()
advanceUntilIdle()
@@ -35,29 +35,6 @@ class ServerStoreTest {
assertEquals("10.0.0.2", finalState.connectionProfiles[0].host)
}
@Test
fun testPureOps_removeServer() {
val profile1 = ConnectionProfile(id = "1", name = "Test1", host = "10.0.0.1", port = 8080)
val profile2 = ConnectionProfile(id = "2", name = "Test2", host = "10.0.0.2", port = 8081)
val state =
ServerStoreState(
connectionProfiles = listOf(profile1, profile2),
selectedProfileId = "2",
)
val newState = state.removeServer("2")
assertEquals(1, newState.connectionProfiles.size)
assertEquals("1", newState.connectionProfiles[0].id)
assertNull(newState.selectedProfileId)
}
@Test
fun testPureOps_switchToServer() {
val state = ServerStoreState(selectedProfileId = null)
val newState = state.switchToServer("prof-1")
assertEquals("prof-1", newState.selectedProfileId)
}
@Test
fun testPureOps_selfHealed() {
// Test orphaned selected profile ID
@@ -130,14 +130,9 @@ class AuthManagerTest {
}
@Test
fun testGetAndSetHost() {
AuthManager.setHost("10.0.0.1")
fun testGetHostAndPortFromBaseUrl() {
AuthManager.setBaseUrl("https://10.0.0.1:9090/")
assertEquals("10.0.0.1", AuthManager.getHost())
}
@Test
fun testGetAndSetPort() {
AuthManager.setPort(9090)
assertEquals(9090, AuthManager.getPort())
}
@@ -149,10 +144,7 @@ class AuthManagerTest {
@Test
fun testBaseUrl() {
AuthManager.setHost("hermes.local")
AuthManager.setPort(1234)
// setHost/setPort derive from the canonical base URL (default is https),
// so the result keeps the https scheme and swaps host/port.
AuthManager.setBaseUrl("https://hermes.local:1234/")
assertEquals("https://hermes.local:1234/", AuthManager.getBaseUrl())
}
@@ -181,8 +173,7 @@ class AuthManagerTest {
AuthManager.ensureDefaultProfile()
every { mockPrefs.getString("token_${AuthManager.DEFAULT_PROFILE_ID}", null) } returns "token123"
AuthManager.setSelectedProfileId(AuthManager.DEFAULT_PROFILE_ID)
AuthManager.setHost("hermes.local")
AuthManager.setPort(1234)
AuthManager.setBaseUrl("https://hermes.local:1234/")
// Scheme tracks the canonical base URL (default https) → wss.
assertEquals("wss://hermes.local:1234/api/ws?token=token123", AuthManager.wsUrl())
}
@@ -192,8 +183,7 @@ class AuthManagerTest {
AuthManager.ensureDefaultProfile()
every { mockPrefs.getString("token_${AuthManager.DEFAULT_PROFILE_ID}", null) } returns null
AuthManager.setSelectedProfileId(AuthManager.DEFAULT_PROFILE_ID)
AuthManager.setHost("hermes.local")
AuthManager.setPort(1234)
AuthManager.setBaseUrl("https://hermes.local:1234/")
assertEquals("wss://hermes.local:1234/api/ws?token=", AuthManager.wsUrl())
}
@@ -265,34 +255,21 @@ class AuthManagerTest {
AuthManager.ensureDefaultProfile()
AuthManager.setSelectedProfileId("nonexistent")
AuthManager.saveConnectionProfiles(emptyList())
AuthManager.setHost("192.168.1.1")
AuthManager.setBaseUrl("http://192.168.1.1:9119/")
assertEquals("192.168.1.1", AuthManager.getHost())
}
@Test
fun testSetHost_updatesProfileWhenSelected() {
fun testSetBaseUrl_updatesProfileWhenSelected() {
val profile = ConnectionProfile(id = "prof-1", name = "Home", baseUrl = "http://10.0.0.1:9119/")
AuthManager.saveConnectionProfiles(listOf(profile))
AuthManager.setSelectedProfileId("prof-1")
AuthManager.setHost("10.0.0.99")
AuthManager.setBaseUrl("http://10.0.0.99:9999/")
val updated = AuthManager.getConnectionProfiles().first()
// host/port are now canonicalized into the base URL (profile was http)
assertEquals("http://10.0.0.99:9119/", updated.resolvedBaseUrl)
}
@Test
fun testSetPort_updatesProfileWhenSelected() {
val profile = ConnectionProfile(id = "prof-1", name = "Home", baseUrl = "http://10.0.0.1:9119/")
AuthManager.saveConnectionProfiles(listOf(profile))
AuthManager.setSelectedProfileId("prof-1")
AuthManager.setPort(9999)
val updated = AuthManager.getConnectionProfiles().first()
assertEquals("http://10.0.0.1:9999/", updated.resolvedBaseUrl)
assertEquals("http://10.0.0.99:9999/", updated.resolvedBaseUrl)
}
@Test
@@ -1,9 +1,7 @@
package com.m57.hermescontrol.data.remote
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Test
@@ -13,7 +11,6 @@ class ServerEndpointTest {
val ep = ServerEndpoint.parse("https://example.com/hermes", CleartextPolicy.ALLOW_WITH_WARNING)
assertEquals("https://example.com/hermes/", ep.baseUrl.toString())
assertNull(ep.securityWarning)
assertFalse(ep.isCleartext)
}
@Test
@@ -21,7 +18,6 @@ class ServerEndpointTest {
val ep = ServerEndpoint.parse("http://127.0.0.1:9119/", CleartextPolicy.ALLOW_WITH_WARNING)
assertEquals("http://127.0.0.1:9119/", ep.baseUrl.toString())
assertEquals(ServerEndpoint.CLEARTEXT_WARNING, ep.securityWarning)
assertTrue(ep.isCleartext)
}
@Test
@@ -130,7 +126,6 @@ class ServerEndpointTest {
fun `fromLegacy preserves http host and port`() {
val ep = ServerEndpoint.fromLegacy("10.0.0.1", 8080)
assertEquals("http://10.0.0.1:8080/", ep.baseUrl.toString())
assertTrue(ep.isCleartext)
}
@Test
@@ -79,13 +79,6 @@ class ConnectViewModelTest {
every { mockApp.getString(R.string.connect_error_refused) } returns "Connection refused – is Hermes running?"
every { mockApp.getString(R.string.connect_error_timeout) } returns "Connection timed out"
every { mockApp.getString(R.string.connect_error_connection_failed) } returns "Connection failed: %1\$s"
every {
mockApp.getString(R.string.connect_error_malformed)
} returns "Malformed pairing string — expected URL or Base64-encoded JSON"
every {
mockApp.getString(R.string.connect_error_missing_fields)
} returns "Malformed pairing string — missing host, port, or token"
every { mockApp.getString(R.string.connect_error_parse_failed) } returns "Failed to parse pairing string: %1\$s"
}
@After
@@ -117,22 +110,6 @@ class ConnectViewModelTest {
assertNull(viewModel.uiState.value.errorMessage)
}
@Test
fun testOnHostChange() {
val viewModel = ConnectViewModel(mockApp)
viewModel.onHostChange(" 192.168.1.50 ")
assertEquals("https://192.168.1.50:9119/", viewModel.uiState.value.baseUrl)
assertNull(viewModel.uiState.value.errorMessage)
}
@Test
fun testOnPortChange() {
val viewModel = ConnectViewModel(mockApp)
viewModel.onPortChange("90abc90")
assertEquals("https://127.0.0.1:9090/", viewModel.uiState.value.baseUrl)
assertNull(viewModel.uiState.value.errorMessage)
}
@Test
fun testConnect_blankToken_showsError() {
val viewModel = ConnectViewModel(mockApp)
@@ -16,7 +16,6 @@ import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Before
import org.junit.Test
@@ -67,8 +66,6 @@ class SettingsViewModelTest {
every { AuthManager.getConnectionProfiles() } returns emptyList()
every { AuthManager.getSelectedProfileId() } answers { storedSelectedProfileId }
every { AuthManager.baseUrl() } returns "http://127.0.0.1:9119/"
every { AuthManager.setHost(any()) } returns Unit
every { AuthManager.setPort(any()) } returns Unit
every { AuthManager.setBaseUrl(any()) } returns Unit
every { AuthManager.setToken(any()) } returns Unit
every { AuthManager.setAutoReconnect(any()) } returns Unit
@@ -146,47 +143,6 @@ class SettingsViewModelTest {
assertEquals(AuthManager.DEFAULT_PROFILE_ID, viewModel.uiState.value.selectedProfileId)
}
@Test
fun testOnRenameProfileNameChange_updatesState() {
val viewModel = createViewModel()
viewModel.onRenameProfileNameChange("New Name")
assertEquals("New Name", viewModel.uiState.value.renameProfileName)
assertFalse(viewModel.uiState.value.isSaved)
}
@Test
fun testRenameProfile_updatesProfileName() {
every { AuthManager.getConnectionProfiles() } returns testProfiles
every { AuthManager.getSelectedProfileId() } returns "prof-1"
val viewModel = createViewModel()
viewModel.onRenameProfileNameChange("Renamed Work")
viewModel.renameProfile()
verify { AuthManager.saveConnectionProfiles(any()) }
}
@Test
fun testRenameProfile_withBlankName_doesNothing() {
every { AuthManager.getConnectionProfiles() } returns testProfiles
every { AuthManager.getSelectedProfileId() } returns "prof-1"
val viewModel = createViewModel()
viewModel.onRenameProfileNameChange(" ")
viewModel.renameProfile()
verify(exactly = 0) { AuthManager.saveConnectionProfiles(any()) }
}
@Test
fun testRenameProfile_noSelectedProfile_doesNothing() {
val viewModel = createViewModel()
viewModel.onRenameProfileNameChange("New Name")
viewModel.renameProfile()
verify(exactly = 0) { AuthManager.saveConnectionProfiles(any()) }
}
@Test
fun testDeleteProfile_removesProfileAndToken() {
every { AuthManager.getConnectionProfiles() } returns testProfiles
@@ -233,8 +189,5 @@ class SettingsViewModelTest {
verify { AuthManager.saveConnectionProfiles(any()) }
verify { AuthManager.setSelectedProfileId(any()) }
assertEquals(true, viewModel.uiState.value.navigateToLogin)
viewModel.clearNavigateToLogin()
assertEquals(false, viewModel.uiState.value.navigateToLogin)
}
}