Safety limits after the ban, and four new themes
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 4m18s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 2m50s
release-gate / verify (push) Successful in 15m8s

- Every request this TV makes counts towards 400 in any 60 minutes; at that point background work stops (watching never
  does) and Settings says when. Background budget 200 an hour; channel setup one request a second.
- The guide's picture rests after 10 minutes with no button press; any button brings it back.
- Velvet, Evergreen, Sunset and Frost join the six looks; the picker shows ten, five to a row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 07:22:28 +00:00
co-authored by Claude Opus 5.5
parent e3f8eb5a80
commit 22f018bd82
8 changed files with 119 additions and 16 deletions
@@ -0,0 +1,48 @@
package tv.orbit.classic
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
/** The limits added after the ban (12 November 2026): a 400-an-hour ceiling on everything, 200 in the background. */
class SafetyLimitsTest {
private var now = 1_800_000_000_000L
@Before fun up() { ServerRequests.clearForTest(); ServerRequests.clock = { now }; BackgroundPacing.resetForTest(); BackgroundPacing.clock = { now }; BackgroundPacing.sleep = { now += it } }
@After fun down() { ServerRequests.clearForTest(); ServerRequests.clock = System::currentTimeMillis; BackgroundPacing.resetForTest() }
private fun background(): Boolean = try { BackgroundPacing.run { BackgroundPacing.beforeRequest(); ServerRequests.count(RequestKind.Catalogue, true) }; true } catch (_: PacedOut) { false }
@Test fun backgroundStopsAtTwoHundredAnHour() {
var made = 0
while (background()) made++
assertEquals(200, made)
}
@Test fun watchingNeverStopsButBackgroundYieldsAtTheCeiling() {
// An evening of heavy use: 380 playback requests in the hour, none of them slowed or refused.
repeat(380) { BackgroundPacing.beforeRequest(); ServerRequests.count(RequestKind.Report, true); now += 1_000 }
var made = 0
while (made < 100 && background()) made++
assertEquals("background stops once the TV reaches 400 in all", 20, made)
assertNotNull(BackgroundPacing.ceilingHitMs)
// Playback still goes through at the ceiling.
BackgroundPacing.beforeRequest(); ServerRequests.count(RequestKind.Report, true)
assertEquals(401, ServerRequests.inLastHour())
// An hour on, there's room again.
now += 60 * 60_000L
assertTrue(background())
}
@Test fun setupIsOneRequestASecond() {
val times = mutableListOf<Long>()
BackgroundPacing.setup { repeat(30) { BackgroundPacing.beforeRequest(); times += now } }
assertTrue(times.zipWithNext().all { (a, b) -> b - a >= 1_000 })
}
@Test fun theGuidePictureRestsAfterTenMinutes() {
assertEquals(10 * 60_000L, GUIDE_PICTURE_REST_MS)
// The rest begins exactly ten minutes after the last press (plus the same small margin as a programme's end).
assertEquals(GUIDE_PICTURE_REST_MS + 50, programmeEndDelayMs(1_000L + GUIDE_PICTURE_REST_MS, 1_000L))
}
}