Removals stay removed across rooms (audit A3): Continue watching and Taste resets

What's taken off Continue watching (by hand, or watched to the end) is recorded
in its own gone-continue file for three days and passed on by Rooms sync, so the
other TV's copy can't bring it back; watching it again later does. A Taste reset
in either room wins over older events. Older Orbits ignore the new file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 17:29:11 +00:00
co-authored by Claude Opus 5.5
parent b099bb5175
commit a6d2f2c33c
5 changed files with 113 additions and 8 deletions
@@ -0,0 +1,54 @@
package tv.orbit.classic
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
/** Audit A3 (9 November 2026): what's removed in one room stays removed in the other. */
class RoomRemovalsTest {
@get:Rule val tmp = TemporaryFolder()
private val now = 1_794_300_000_000L
private fun mark(start: Long, at: Long) = ContinueMark(304, start, "4455505", 30 * 60_000L, 90 * 60_000L, at)
private fun list(vararg m: ContinueMark) = JSONArray(m.map { it.toJson() }).toString()
@Test fun aRemovalInTheOtherRoomTakesItOffHere() {
val dir = tmp.root
File(dir, "continue-grown.json").writeText(list(mark(1_000L, now - 60_000)))
// The other room still has it in its list, and also says it was taken off afterwards.
mergeFamilyFiles(dir, JSONObject().put("continue-grown.json", list(mark(1_000L, now - 60_000)))
.put("gone-continue-grown.json", JSONObject().put("304:1000", now - 30_000).toString()), now)
assertEquals(0, JSONArray(File(dir, "continue-grown.json").readText()).length())
}
@Test fun anOlderRoomCantBringItBack() {
val dir = tmp.root
File(dir, "gone-continue-grown.json").writeText(JSONObject().put("304:1000", now - 30_000).toString())
mergeFamilyFiles(dir, JSONObject().put("continue-grown.json", list(mark(1_000L, now - 60_000))), now) // no gone file: an older Orbit
assertEquals(0, JSONArray(File(dir, "continue-grown.json").readText()).length())
}
@Test fun watchingItAgainAfterwardsBringsItBack() {
assertEquals(1, ContinueGone.filter(listOf(mark(1_000L, now)), mapOf("304:1000" to now - 30_000)).size)
}
@Test fun removalsAreKeptThreeDays() {
val merged = ContinueGone.merged(mapOf("304:1" to now - 4 * 86_400_000L), mapOf("304:2" to now - 1_000), now)
assertEquals(setOf("304:2"), merged.keys)
}
@Test fun aTasteResetInTheOtherRoomClearsWhatCameBefore() {
val dir = tmp.root; File(dir, "taste").mkdirs()
val old = """{"v":1,"id":"a1","p":"grown","k":"stayed","i":"4455505","s":null,"t":"Film","c":304,"w":${now - 100_000},"ms":1500000,"src":"watching"}"""
val newer = """{"v":1,"id":"b2","p":"grown","k":"stayed","i":"4455506","s":null,"t":"Film 2","c":304,"w":${now - 1_000},"ms":1500000,"src":"watching"}"""
File(dir, "taste/grown.events.jsonl").writeText(old + "\n")
File(dir, "taste/grown.state.json").writeText(JSONObject().put("v", 1).put("personalise", true).put("suppress", JSONObject()).put("resetAt", 0).toString())
mergeFamilyFiles(dir, JSONObject().put("taste/grown.state.json", JSONObject().put("v", 1).put("personalise", true).put("resetAt", now - 50_000).toString())
.put("taste/grown.events.jsonl", old + "\n" + newer + "\n"), now)
assertEquals(listOf("b2"), File(dir, "taste/grown.events.jsonl").readLines().filter { it.isNotBlank() }.map { JSONObject(it).getString("id") })
assertTrue(JSONObject(File(dir, "taste/grown.state.json").readText()).getBoolean("personalise")) // their own choice stays
}
}