From 9597433cc02c9fe1402cbc61ba8433cebd9ecde9 Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 11 Jun 2026 09:45:29 +0530 Subject: [PATCH] style(sidecar): trim non-load-bearing comments from this PR's driver code and tests --- .../dev/sanderling/sidecar/DriverBackend.kt | 23 +++++++------------ .../dev/sanderling/sidecar/InputTextTest.kt | 18 +-------------- .../dev/sanderling/sidecar/RetryOpenTest.kt | 2 -- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/sidecar/src/main/kotlin/dev/sanderling/sidecar/DriverBackend.kt b/sidecar/src/main/kotlin/dev/sanderling/sidecar/DriverBackend.kt index ba1fa0e..94ee73b 100644 --- a/sidecar/src/main/kotlin/dev/sanderling/sidecar/DriverBackend.kt +++ b/sidecar/src/main/kotlin/dev/sanderling/sidecar/DriverBackend.kt @@ -682,12 +682,9 @@ internal fun chunkForInput(text: String, size: Int): List { return chunks } -// typeChunks sends each chunk via `send`, re-reading the foreground owner with -// `currentForeground` before every chunk after the first. If the owner changed -// from `startOwner`, it stops (returning the count already typed) so keystrokes -// never spray into a window that stole focus mid-type. The first chunk is always -// sent (there is nothing typed yet to leak), and a null startOwner (foreground -// unknown) disables the check so typing proceeds. Returns the chars sent. +// typeChunks sends each chunk, stopping if the foreground owner changed from +// startOwner so the remaining keystrokes can't spray into a window that stole +// focus. The first chunk always sends; a null startOwner skips the check. internal fun typeChunks( chunks: List, startOwner: String?, @@ -712,11 +709,9 @@ internal fun typeChunks( private val resumedActivityPackage = Regex("""([a-zA-Z][a-zA-Z0-9_.]*)/[a-zA-Z0-9_.$]+""") -// parseResumedPackage extracts the foreground package from `dumpsys activity -// activities` output. It reads any *ResumedActivity line (topResumedActivity=, -// mResumedActivity:, ResumedActivity:) rather than one OEM-specific phrasing, so -// a ROM that words the line differently does not silently disable the mid-type -// foreground guard. Returns null when no such line is present. +// parseResumedPackage reads the foreground package off any *ResumedActivity line, +// matching the Go guard's marker set so OEM wording can't disable the mid-type +// guard. Null if none present. internal fun parseResumedPackage(dumpsys: String): String? { for (line in dumpsys.lineSequence()) { if (!line.contains("ResumedActivity")) continue @@ -1101,10 +1096,8 @@ internal class WdaRecovery( } } -// maestroKeyFor resolves a logical key name to a maestro KeyCode. It lowercases -// and rejects an unknown name (matching StubDriverBackend's contract, so an -// unmapped or wrong-case key fails loudly instead of being silently dropped), -// and returns null only when the key is known but maestro has no enum for it. +// maestroKeyFor rejects an unknown key (matching StubDriverBackend) so an +// unmapped or wrong-case key fails loudly instead of being silently dropped. internal fun maestroKeyFor(key: String): maestro.KeyCode? { val keyCode = StubDriverBackend.KEY_MAP[key.lowercase()] ?: throw IllegalArgumentException("unsupported pressKey value: $key") diff --git a/sidecar/src/test/kotlin/dev/sanderling/sidecar/InputTextTest.kt b/sidecar/src/test/kotlin/dev/sanderling/sidecar/InputTextTest.kt index c81fb21..c466d00 100644 --- a/sidecar/src/test/kotlin/dev/sanderling/sidecar/InputTextTest.kt +++ b/sidecar/src/test/kotlin/dev/sanderling/sidecar/InputTextTest.kt @@ -146,8 +146,6 @@ class InputTextTest { assertTrue("-5" == StubDriverBackend.escapeForAdbInputText("-5")) } - // typeChunks sends every chunk while the foreground holds steady, so a normal - // type completes in full. @Test fun typeChunksSendsAllChunksWhenForegroundStable() { val sent = mutableListOf() val typed = @@ -158,14 +156,10 @@ class InputTextTest { assertEquals(8, typed) } - // The core guard: once the app under test loses the foreground mid-type, the - // remaining chunks must NOT be sent (they would spray into the window that - // stole focus, e.g. the launcher search box). @Test fun typeChunksStopsWhenForegroundLeavesMidType() { val sent = mutableListOf() var calls = 0 - // Foreground holds for the check before chunk 2, then goes foreign before - // chunk 3: two chunks land, the third is suppressed. + // Foreground holds before chunk 2, then goes foreign before chunk 3. val typed = typeChunks(listOf("aaa", "bbb", "ccc"), "app.folio", { calls++ if (calls == 1) "app.folio" else "com.android.launcher" @@ -178,8 +172,6 @@ class InputTextTest { assertEquals(6, typed) } - // The first chunk is always sent: there is nothing typed yet to leak, so the - // guard must not check before the very first send. @Test fun typeChunksAlwaysSendsFirstChunkEvenIfForegroundAlreadyForeign() { val sent = mutableListOf() val typed = @@ -190,17 +182,12 @@ class InputTextTest { assertEquals(3, typed) } - // A null start owner (foreground unreadable) disables the guard so typing is - // not blocked where the signal is unavailable. @Test fun typeChunksWithUnknownOwnerSendsEverything() { val sent = mutableListOf() typeChunks(listOf("aaa", "bbb"), null, { "anything" }) { sent.add(it) } assertEquals(listOf("aaa", "bbb"), sent) } - // parseResumedPackage must read the foreground package off any *ResumedActivity - // wording, not one OEM-specific phrasing, or the mid-type guard silently - // no-ops on ROMs that word the line differently. @Test fun parseResumedPackageReadsEachResumedActivityWording() { val cases = mapOf( " topResumedActivity=ActivityRecord{8b u0 app.folio/.MainActivity t42}" to @@ -219,9 +206,6 @@ class InputTextTest { ) } - // maestroKeyFor resolves the production pressKey path: it lowercases and - // rejects an unknown key (the Maestro backend used to silently drop both - // unknown and wrong-case keys). @Test fun maestroKeyForResolvesAndRejects() { assertEquals(maestro.KeyCode.BACK, maestroKeyFor("back")) assertEquals(maestro.KeyCode.BACK, maestroKeyFor("BACK")) diff --git a/sidecar/src/test/kotlin/dev/sanderling/sidecar/RetryOpenTest.kt b/sidecar/src/test/kotlin/dev/sanderling/sidecar/RetryOpenTest.kt index 700cc0c..88c0011 100644 --- a/sidecar/src/test/kotlin/dev/sanderling/sidecar/RetryOpenTest.kt +++ b/sidecar/src/test/kotlin/dev/sanderling/sidecar/RetryOpenTest.kt @@ -35,8 +35,6 @@ class RetryOpenTest { ) } - // The exact failure this guards: a slow device that never opens must surface - // the last error after exhausting attempts, not loop forever or swallow it. @Test fun rethrowsLastErrorAfterExhaustingAttempts() { var opens = 0 var sleeps = 0