0.126.0 (versionCode 323): no server built into the app
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 3m12s
release-gate / verify (push) Successful in 8m58s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 2m41s

The address field starts empty on a new box, and its first server becomes
its original. A box from before reads its original server once from its own
saved sign-in and notes it beside its data; nothing else is moved or changed.
Paul's own decisions by item are kept to his server by a SHA-256 of its
address. The release gate refuses an APK that contains a server address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 01:11:08 +00:00
co-authored by Claude Opus 5.5
parent 3bb5142817
commit 9f815a2bb7
16 changed files with 158 additions and 50 deletions
@@ -6,6 +6,9 @@ import org.junit.Assert.*
import org.junit.Test
class AfterDarkMoviesTest {
// No server is built in: these sign-ins belong to a made-up one.
@org.junit.Before fun server() { EmbyServer.origin = "https://emby.example.com" }
@org.junit.After fun noServer() { EmbyServer.origin = "" }
private fun movie(id: String, genre: String = "Horror") = JSONObject().put("Id", id).put("Type", "Movie")
.put("Name", "Fixture $id").put("ProductionYear", 1999).put("OfficialRating", "18")
.put("Genres", JSONArray().put(genre)).put("Container", "mkv").put("RunTimeTicks", 54_000_000_000L)
@@ -5,6 +5,9 @@ import org.junit.Assert.*
import org.junit.Test
class ChannelPresetsTest {
// No server is built in: these sign-ins belong to a made-up one.
@org.junit.Before fun server() { EmbyServer.origin = "https://emby.example.com" }
@org.junit.After fun noServer() { EmbyServer.origin = "" }
private fun series(id: String, title: String, year: Int? = null) = SeriesCandidate(id, title, year, "")
@Test
@@ -7,6 +7,9 @@ import org.junit.Test
import java.net.InetAddress
class EmbyPlaybackTest {
// No server is built in: these sign-ins belong to a made-up one.
@org.junit.Before fun server() { EmbyServer.origin = "https://emby.example.com" }
@org.junit.After fun noServer() { EmbyServer.origin = "" }
private class Fake : EmbyTransport {
val requests = mutableListOf<EmbyRequest>()
var response = EmbyReply(200, "")
@@ -67,7 +70,7 @@ class EmbyPlaybackTest {
assertFalse(url.contains("api_key")); assertTrue(url.contains("Static=true"))
val cdn = session.mediaUrl("https://media.example.test/file.mkv?signature=fixture-signature")
assertTrue(session.mediaHeaders(cdn).isEmpty())
assertTrue(session.mediaHeaders("https://bk2.appboxmanager.xyz:444/file").isEmpty())
assertTrue(session.mediaHeaders("https://emby.example.com:444/file").isEmpty())
}
@Test fun rejectsInsecureAddressesAndCredentialsInExternalUrls() {
val session = session(Fake())
@@ -6,7 +6,7 @@ import org.junit.Test
import java.net.URI
class EmbyServerTest {
@After fun reset() { EmbyServer.origin = EmbyServer.DEFAULT }
@After fun reset() { EmbyServer.origin = "" }
@Test fun typedAddressesBecomeHttpsOrigins() {
assertEquals("https://emby.example.com", EmbyServer.normalise("emby.example.com"))
@@ -8,7 +8,7 @@ import java.net.URI
/** Home servers over plain HTTP (Paul, 6 November 2026): private addresses only, checked on every connection; HTTPS everywhere else. */
class HomeServerTest {
@After fun reset() { EmbyServer.origin = EmbyServer.DEFAULT }
@After fun reset() { EmbyServer.origin = "" }
private fun ip(text: String) = InetAddress.getByName(text)
@Test fun plainHttpOnlyForAHomeAddress() {
@@ -32,7 +32,7 @@ class HomeServerTest {
assertThrows(EmbyCheckException::class.java) { EmbyServer.checkHomeConnection("http://nas.local:8096") { listOf(ip("93.184.216.34")) } }
assertThrows(EmbyCheckException::class.java) { EmbyServer.checkHomeConnection("http://nas.local:8096") { emptyList() } }
// HTTPS servers aren't touched by this check.
EmbyServer.checkHomeConnection(EmbyServer.DEFAULT) { throw AssertionError("not resolved") }
EmbyServer.checkHomeConnection("https://emby.example.com") { throw AssertionError("not resolved") }
}
@Test fun mediaUsesPlainHttpOnlyToTheHomeServerItself() {
@@ -43,8 +43,8 @@ class HomeServerTest {
assertEquals("$home/emby/Videos/1/stream.mkv", PlaybackUrls.resolve("/emby/Videos/1/stream.mkv?api_key=t", "$home/emby/", "t", home))
// Plain HTTP anywhere else is refused, home server or not.
assertThrows(EmbyCheckException::class.java) { PlaybackUrls.resolve("http://cdn.example.com/v.mkv", "$home/emby/", "t", home) }
assertThrows(EmbyCheckException::class.java) { PlaybackUrls.resolve("http://cdn.example.com/v.mkv", "${EmbyServer.DEFAULT}/emby/", "t", EmbyServer.DEFAULT) }
assertThrows(EmbyCheckException::class.java) { PlaybackUrls.resolve("/emby/v.mkv", "http://192.168.1.20:8096/emby/", "t", EmbyServer.DEFAULT) }
assertThrows(EmbyCheckException::class.java) { PlaybackUrls.resolve("http://cdn.example.com/v.mkv", "${"https://emby.example.com"}/emby/", "t", "https://emby.example.com") }
assertThrows(EmbyCheckException::class.java) { PlaybackUrls.resolve("/emby/v.mkv", "http://192.168.1.20:8096/emby/", "t", "https://emby.example.com") }
// A session on a home server sends its token to that server only.
val session = EmbySampleSession(HttpsEmbyTransport("fixture-device", home), "fixture-token", "fixture-user", EmbySample(emptyList(), 0))
assertEquals(mapOf("X-Emby-Token" to "fixture-token"), session.mediaHeaders("$home/emby/Videos/1/stream.mkv"))
@@ -14,7 +14,7 @@ import java.net.URL
* The same code the box runs: sign-in, the catalogue, a channel read, the Drive-In's curated films and a stream.
*/
class JellyfinLiveTest {
@After fun reset() { CuratedDriveInEvents.list = emptyList(); CuratedDriveInEvents.copies = emptyMap(); EmbyServer.origin = EmbyServer.DEFAULT }
@After fun reset() { CuratedDriveInEvents.list = emptyList(); CuratedDriveInEvents.copies = emptyMap(); EmbyServer.origin = "" }
private class MemoryCatalogue : CatalogueSink {
val records = mutableListOf<CatalogueRecord>(); var next = 0L; var finished = false
@@ -16,6 +16,9 @@ import java.security.MessageDigest
class PortabilityTest {
@get:Rule val folder = TemporaryFolder()
private val other = "https://emby.friend.example:8920"
/** Paul's server under a made-up address: the app holds only a hash of the real one. */
private val paul = "https://paul.example"
@org.junit.Before fun paulsServer() { Workspaces.isPaulsServer = { it == paul } }
@After fun reset() {
Workspaces.reset()
@@ -87,24 +90,30 @@ class PortabilityTest {
@Test fun theOriginalServerIsTodaysDataWhereItIsAndOpeningItWritesNothing() {
val (noBackup, cache) = todaysBox()
val before = digest(noBackup); val cacheBefore = digest(cache)
assertEquals(EmbyServer.DEFAULT, Workspaces.activeOrigin(noBackup))
val original = Workspaces.openIn(noBackup, cache, Workspaces.activeOrigin(noBackup))
// A box from before the note: its saved sign-in names the server, read once.
assertEquals(paul, Workspaces.activeOrigin(noBackup) { paul })
val original = Workspaces.openIn(noBackup, cache, Workspaces.activeOrigin(noBackup) { paul }!!)
assertTrue(original.original)
assertEquals(File(noBackup, "orbit-connection.v1"), original.connectionFile)
assertEquals(File(noBackup, "catalogue.db"), original.catalogueFile)
assertEquals(File(noBackup, "schedule"), original.scheduleDir)
assertEquals(File(cache, "artwork"), original.artworkDir)
assertEquals(before, digest(noBackup)); assertEquals(cacheBefore, digest(cache))
assertEquals(setOf("orbit-connection.v1", "catalogue.db", "schedule"), noBackup.list()!!.toSet())
assertTrue(Workspaces.originalOpen)
// Only the note is added; every file that was there is byte for byte the same.
assertEquals(before, digest(noBackup).filterKeys { it in before }); assertEquals(cacheBefore, digest(cache))
assertEquals(setOf("orbit-connection.v1", "catalogue.db", "schedule", "original-server"), noBackup.list()!!.toSet())
assertEquals(paul, Workspaces.originalOrigin(noBackup)); assertEquals(paul, Workspaces.activeOrigin(noBackup))
assertTrue(Workspaces.paulsServerOpen)
// Opening it again writes nothing at all.
Workspaces.reset(); Workspaces.isPaulsServer = { it == paul }
val once = digest(noBackup); Workspaces.openIn(noBackup, cache, paul); assertEquals(once, digest(noBackup))
}
@Test fun anotherServerGetsItsOwnFolderAndTodaysDataIsNeverTouched() {
val (noBackup, cache) = todaysBox()
val before = digest(noBackup)
Workspaces.openIn(noBackup, cache, EmbyServer.DEFAULT)
Workspaces.openIn(noBackup, cache, paul)
val friend = Workspaces.openIn(noBackup, cache, other)
assertFalse(friend.original); assertFalse(Workspaces.originalOpen)
assertFalse(friend.original); assertFalse(Workspaces.paulsServerOpen)
assertEquals(File(noBackup, "servers/${Workspaces.keyOf(other)}"), friend.root)
assertNotEquals(File(cache, "artwork"), friend.artworkDir)
assertNotEquals("orbit-connection-key-v1", friend.keyAlias)
@@ -112,12 +121,12 @@ class PortabilityTest {
// Only the new folder's note and which server is in use were written; everything that was there is byte for byte the same.
val after = digest(noBackup)
assertEquals(before, after.filterKeys { it in before })
assertEquals(setOf("servers/${Workspaces.keyOf(other)}/server", "active-server"), after.keys - before.keys)
assertEquals(setOf("original-server", "servers/${Workspaces.keyOf(other)}/server", "active-server"), after.keys - before.keys)
// Back to the original server: still the same data, and an older Orbit still finds all of it where it always was.
assertTrue(Workspaces.openIn(noBackup, cache, EmbyServer.DEFAULT).original)
assertTrue(Workspaces.openIn(noBackup, cache, paul).original)
assertEquals(before, digest(noBackup).filterKeys { it in before })
assertEquals(EmbyServer.DEFAULT, Workspaces.activeOrigin(noBackup))
assertEquals(listOf(EmbyServer.DEFAULT), Workspaces.known(noBackup, cache)) // the new server holds nothing yet
assertEquals(paul, Workspaces.activeOrigin(noBackup))
assertEquals(listOf(paul), Workspaces.known(noBackup, cache)) // the new server holds nothing yet
}
@Test fun aFolderNeverOpensForAnotherAddressAndAGarbledChoiceFallsBackToTheOriginal() {
@@ -126,13 +135,16 @@ class PortabilityTest {
File(root, "server").writeText("https://someone.else.example")
assertThrows(IllegalStateException::class.java) { Workspaces.openIn(noBackup, cache, other) }
File(noBackup, "active-server").writeText("http://not-https.example")
assertEquals(EmbyServer.DEFAULT, Workspaces.activeOrigin(noBackup))
assertNull(Workspaces.activeOrigin(noBackup)) // no note, and the sign-in can't be read
Workspaces.openIn(noBackup, cache, paul)
File(noBackup, "active-server").writeText("http://not-https.example")
assertEquals(paul, Workspaces.activeOrigin(noBackup)) // the note
assertThrows(IllegalArgumentException::class.java) { Workspaces.openIn(noBackup, cache, "http://plain.example") }
}
@Test fun switchingServersForgetsWhatTheLastOneShowed() {
val (noBackup, cache) = todaysBox()
Workspaces.openIn(noBackup, cache, EmbyServer.DEFAULT)
Workspaces.openIn(noBackup, cache, paul)
CuratedDriveInEvents.refresh { PaulsEventCopies }
ApprovedDriveInEvents.list = PaulsDriveInEvents.take(1)
PromoBoard.shown[101] = 1L
@@ -142,7 +154,7 @@ class PortabilityTest {
@Test fun paulsOwnDecisionsByItemApplyOnlyOnHisServer() {
val (noBackup, cache) = todaysBox()
Workspaces.openIn(noBackup, cache, EmbyServer.DEFAULT)
Workspaces.openIn(noBackup, cache, paul)
val afterDark = SmartChannels.single { it.number == AFTER_DARK_NUMBER }
assertTrue(afterDark.withdrawn.isNotEmpty()); assertTrue(PremiereCalls.isNotEmpty())
val advent = java.time.LocalDateTime.of(2026, 12, 1, 18, 30).atZone(java.time.ZoneId.of("Europe/London")).toInstant().toEpochMilli()
@@ -154,6 +166,36 @@ class PortabilityTest {
assertFalse(afterDark.signature.contains("#withdrawn"))
}
@Test fun noServerIsBuiltInAndANewBoxsFirstServerBecomesItsOriginal() {
Workspaces.reset()
assertEquals("", EmbyServer.origin)
val noBackup = folder.newFolder("fresh"); val cache = folder.newFolder("fresh-cache")
assertNull(Workspaces.activeOrigin(noBackup)); assertTrue(Workspaces.known(noBackup, cache).isEmpty())
val first = Workspaces.openIn(noBackup, cache, other)
assertTrue(first.original); assertEquals(noBackup, first.root); assertFalse(Workspaces.paulsServerOpen)
assertEquals(other, Workspaces.originalOrigin(noBackup)); assertEquals(other, Workspaces.activeOrigin(noBackup))
// A second server gets its own folder, and Paul's server is just another one here.
val second = Workspaces.openIn(noBackup, cache, paul)
assertFalse(second.original); assertEquals(File(noBackup, "servers/${Workspaces.keyOf(paul)}"), second.root)
}
@Test fun aBoxFromBeforeTheNoteGivesItsDataOnlyToPaulsServer() {
val (noBackup, cache) = todaysBox()
val before = digest(noBackup)
// Its sign-in can't be read, so nothing is open; signing in somewhere else never takes Paul's data.
assertNull(Workspaces.activeOrigin(noBackup))
val friend = Workspaces.openIn(noBackup, cache, other)
assertFalse(friend.original); assertNull(Workspaces.originalOrigin(noBackup))
assertTrue(Workspaces.openIn(noBackup, cache, paul).original)
assertEquals(paul, Workspaces.originalOrigin(noBackup))
assertEquals(before, digest(noBackup).filterKeys { it in before })
}
@Test fun theAppHoldsNoServerAddress() {
val source = File("src/main").walkTopDown().filter { it.isFile && it.extension in setOf("kt", "xml", "html", "js", "json") }
assertTrue(source.none { it.readText().contains("appboxmanager") })
}
@Test fun aSessionStaysWithItsOwnServerAfterTheServerInUseChanges() {
val requests = mutableListOf<String>()
val transport = HttpsEmbyTransport("fixture-device", "https://emby.home.example")
@@ -7,6 +7,9 @@ import org.junit.Test
import javax.crypto.KeyGenerator
class RememberedStateTest {
// No server is built in: these sign-ins belong to a made-up one.
@org.junit.Before fun server() { EmbyServer.origin = "https://emby.example.com" }
@org.junit.After fun noServer() { EmbyServer.origin = "" }
private fun state(): RememberedState {
val series = SeriesCandidate("fixture-series", "Fixture series", 1996, "TV-PG")
val episodes = SeriesEpisodes(series, List(2) { EpisodeCandidate("episode-$it", "Fixture $it", 1, it + 1, 60_000) }, false)
@@ -22,16 +22,21 @@ class WorkspaceSnapshotTest {
val dir = System.getenv("ORBIT_SNAPSHOT_DIR")?.let(::File)
assumeTrue(dir != null && dir.isDirectory)
val noBackup = dir!!; val cache = File(noBackup.parentFile, "cache-for-test").apply { mkdirs() }
// The install snapshot leaves the encrypted sign-in out; a stand-in marks where the box has one.
File(noBackup, "orbit-connection.v1").let { if (!it.exists()) it.writeBytes(byteArrayOf(1)) }
val before = digest(noBackup)
val original = Workspaces.openIn(noBackup, cache, Workspaces.activeOrigin(noBackup))
// Paul's server stands in under a made-up address; the box's own sign-in names the real one.
val paul = "https://paul.example"; Workspaces.isPaulsServer = { it == paul }
val original = Workspaces.openIn(noBackup, cache, Workspaces.activeOrigin(noBackup) { paul }!!)
assertTrue(original.original); assertEquals(File(noBackup, "schedule"), original.scheduleDir)
assertEquals(before, digest(noBackup))
assertEquals(before, digest(noBackup).filterKeys { it in before })
Workspaces.openIn(noBackup, cache, "https://emby.friend.example")
Workspaces.openIn(noBackup, cache, EmbyServer.DEFAULT)
Workspaces.openIn(noBackup, cache, paul)
val after = digest(noBackup)
assertEquals(before, after.filterKeys { it in before })
println("snapshot files=${before.size} unchanged=${before.count { (k, v) -> after[k] == v }} added=${(after.keys - before.keys).sorted()}")
val saved = File(noBackup, "schedule/episodes-300.json").readText().let { Regex("\"signature\":\"(events:[^\"]*)\"").find(it)!!.groupValues[1] }
assertEquals(saved, eventSignature(PaulsDriveInEvents, PaulsEventCopies))
// Paul's built-in events first; events he approved later follow them.
assertTrue(saved, saved.startsWith(eventSignature(PaulsDriveInEvents, PaulsEventCopies)))
}
}