Chair learning: specific reasons only, and nothing used until you confirm it
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m13s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m33s

Paul, 5 November 2026: two Ring X rejections (UFC 332, The Arena) taught
'fewer Action titles for Ring X', a broad conclusion from the one genre they
shared. Lessons now come from what decisions specifically share: a named
editorial concept (MMA, boxing, professional wrestling, made-for-TV
romance...) from two, or a genre that isn't one of the channel's own from
three; a channel's defining genres never make a lesson, and a concept beats
a genre for the same decisions. Every lesson is a proposal until confirmed
on the Chair (confirm, dismiss, or stop using it); only confirmed lessons
apply, and only while learning is on.

Also a read-only check of the proposed Ring X correction (wrestling first,
MMA events out); the channel's brief is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-05 16:02:23 +00:00
co-authored by Claude Opus 5.5
parent 848c674546
commit 0d6d7ccf0c
6 changed files with 201 additions and 66 deletions
@@ -6,40 +6,56 @@ import org.junit.Assert.*
import org.junit.Test
import java.io.File
/** The Chair learning from your decisions: patterns of two or more, explained, used only while learning is on. */
/** The Chair learning from your decisions: specific shared reasons, never a channel's own genre, used only once you confirm them. */
class ChairLearningTest {
private fun ev(id: String, title: String, genres: List<String>) = TitleEvidence(id, "Movie", title, 2026, "A story.", genres, null, null, null, null)
private fun ev(id: String, title: String, genres: List<String>, overview: String = "A story.", studios: List<String>? = null, type: String = "Movie") =
TitleEvidence(id, type, title, 2026, overview, genres, studios, null, null, null)
private fun placed(id: String, title: String, channel: Int, suggested: Int) = ChairDecision(id, title, "Movie", true, channel, suggested, 1)
private fun dropped(id: String, title: String, suggested: Int) = ChairDecision(id, title, "Movie", false, null, suggested, 1)
@Test fun twoMatchingDecisionsMakeALessonOneDoesNot() {
val evidence = mapOf("1" to ev("1", "Gore Night", listOf("Horror")), "2" to ev("2", "Splatter Party", listOf("Horror")), "3" to ev("3", "Wedding", listOf("Romance")),
"4" to ev("4", "Big Day", listOf("Romance")), "5" to ev("5", "Lone Shark", listOf("Horror")))
val lessons = chairLessons(listOf(placed("1", "Gore Night", 305, 304), placed("2", "Splatter Party", 305, 304), dropped("3", "Wedding", 307), dropped("4", "Big Day", 307),
placed("5", "Lone Shark", 304, 304)), evidence)
assertEquals(5, lessons.decisions); assertEquals(1, lessons.agreed); assertEquals(2, lessons.changed); assertEquals(2, lessons.dropped)
assertEquals(305, lessons.redirectFor(304, setOf("Horror"))!!.to)
assertNotNull(lessons.holdBackFor(307, setOf("Romance")))
assertNull(lessons.redirectFor(304, setOf("Comedy")))
assertTrue(lessons.lessons.first { it.kind == ChairLesson.Kind.Redirect }.text().contains("Gore Night")) // explained by its own decisions
// One decision alone is no pattern.
assertTrue(chairLessons(listOf(placed("1", "Gore Night", 305, 304)), evidence).lessons.isEmpty())
// Paul's two Ring X rejections, as the library has them.
private val ufc = ev("u", "UFC 332: Silva vs. Wang", listOf("Action", "Drama"), "UFC 332 was a mixed martial arts event produced by the Ultimate Fighting Championship.", listOf("Ultimate Fighting Championship"))
private val arena = ev("a", "The Arena (2026)", listOf("Game Show", "Martial Arts", "Reality", "Sport"), "Fighters face brutal tests and cage bouts for a shot at a pro MMA contract.", listOf("Netflix"), "Series")
@Test fun twoMmaRejectionsTeachMmaNotAction() {
val lessons = chairLessons(listOf(dropped("u", ufc.name, 401), dropped("a", arena.name, 401)), mapOf("u" to ufc, "a" to arena))
val lesson = lessons.lessons.single()
assertEquals("MMA", lesson.feature); assertTrue(lesson.concept); assertEquals(401, lesson.from)
assertTrue(lessons.lessons.none { it.feature == "Action" }) // Ring X's own genre is never the lesson
assertTrue(lesson.text().contains("UFC 332") && lesson.text().contains("The Arena"))
// Confirmed, it holds back MMA for Ring X, and not professional wrestling, though both are Action.
val wrestling = ev("w", "WWE Survivor Series 2026", listOf("Action", "Sport"), "WWE's annual pay-per-view wrestling event.")
val mma = ev("m", "UFC 333", listOf("Action"), "A UFC mixed martial arts event.")
assertNull(lessons.holdBackFor(401, mma, emptySet())) // a proposal does nothing
assertNotNull(lessons.holdBackFor(401, mma, setOf(lesson.key)))
assertNull(lessons.holdBackFor(401, wrestling, setOf(lesson.key)))
}
@Test fun lessonsChangeSuggestionsOnlyWhileLearningIsOn() {
val horror = { id: String, name: String -> JSONObject().put("id", id).put("type", "Movie").put("name", name).put("year", 2026)
.put("overview", "A haunted house, a demon and a curse: terror for a family in the night.").put("genres", JSONArray(listOf("Horror"))).put("studios", JSONObject.NULL)
@Test fun aBroadGenreNeedsThreeAndASpecificReasonWins() {
val e = mapOf("1" to ev("1", "Wedding One", listOf("Romance", "Musical")), "2" to ev("2", "Wedding Two", listOf("Romance", "Musical")), "3" to ev("3", "Wedding Three", listOf("Romance", "Musical")))
assertTrue(chairLessons(listOf(dropped("1", "Wedding One", 307), dropped("2", "Wedding Two", 307)), e).lessons.isEmpty()) // two by genre: not enough
assertEquals("Musical", chairLessons(listOf(dropped("1", "Wedding One", 307), dropped("2", "Wedding Two", 307), dropped("3", "Wedding Three", 307)), e).lessons.single().feature)
// Redirects work the same way: two horror-comedies with gore both moved to After Dark.
val g = mapOf("4" to ev("4", "Gore Night", listOf("Horror", "Comedy"), "A splatter party."), "5" to ev("5", "Blood Bath", listOf("Horror", "Comedy"), "A gross-out splatter romp."))
assertTrue(chairLessons(listOf(placed("4", "Gore Night", 305, 304), placed("5", "Blood Bath", 305, 304)), g).lessons.none { it.feature == "Horror" })
}
@Test fun lessonsChangeSuggestionsOnlyOnceConfirmedAndLearningIsOn() {
val line = { id: String, name: String, ov: String -> JSONObject().put("id", id).put("type", "Movie").put("name", name).put("year", 2026)
.put("overview", ov).put("genres", JSONArray(listOf("Action", "Sport"))).put("studios", JSONObject.NULL)
.put("rating", JSONObject.NULL).put("countries", JSONArray(listOf("United States"))).put("taglines", JSONObject.NULL) }
val evidence = File.createTempFile("evidence", ".jsonl").apply { deleteOnExit(); writeText(listOf(horror("1", "Gore Night"), horror("2", "Splatter Party"), horror("9", "The Haunting"), horror("10", "The Curse")).joinToString("") { "$it\n" }) }
val evidence = File.createTempFile("evidence", ".jsonl").apply { deleteOnExit(); writeText(listOf(line("1", "UFC 330", "A UFC mixed martial arts pay-per-view event with a title bout."),
line("2", "UFC 331", "A UFC mixed martial arts pay-per-view event with a title bout."), line("9", "UFC 334", "A UFC mixed martial arts pay-per-view event with a title bout.")).joinToString("") { "$it\n" }) }
val sets = File.createTempFile("collections", ".jsonl").apply { delete(); deleteOnExit() }
val history = listOf(placed("1", "Gore Night", 305, 304), placed("2", "Splatter Party", 305, 304))
fun report(learning: Boolean) = buildDeskReport(evidence, sets, emptyMap(), listOf(Arrival("9", "Movie", "The Haunting", 2026, "2026-10-30", "tmdb:9", 0)),
emptySet(), emptyMap(), 1, true, DirectorMode.Balanced, 1_793_800_000_000, decided = setOf("1", "2"), history = history, learning = learning)
val off = report(false); val on = report(true)
assertEquals(1, off.lessons.size); assertFalse(off.learningOn)
val offFirst = (off.picks.map { it.options } + off.asks.map { it.options }).single().first()
val onFirst = (on.picks.map { it.options } + on.asks.map { it.options }).single().first()
assertEquals(304, offFirst.number) // off: the brief's own suggestion
assertEquals(305, onFirst.number); assertTrue(onFirst.reason.startsWith("learned from you"))
val history = listOf(dropped("1", "UFC 330", 401), dropped("2", "UFC 331", 401))
fun report(state: LearningState) = buildDeskReport(evidence, sets, emptyMap(), listOf(Arrival("9", "Movie", "UFC 334", 2026, "2026-10-30", "tmdb:9", 0)),
emptySet(), emptyMap(), 1, true, DirectorMode.Balanced, 1_793_800_000_000, decided = setOf("1", "2"), history = history, learning = state)
fun shown(r: DeskReport) = (r.picks.map { it.id } + r.asks.map { it.id }).contains("9")
val proposed = report(LearningState(on = true))
assertEquals("proposed", proposed.lessons.single().state); assertTrue(shown(proposed)) // on, but not confirmed: nothing changes
val key = proposed.lessons.single().key
assertFalse(shown(report(LearningState(on = true, confirmed = setOf(key))))) // confirmed and on: held back
assertTrue(shown(report(LearningState(on = false, confirmed = setOf(key))))) // off undoes it
assertTrue(report(LearningState(on = true, dismissed = setOf(key))).lessons.isEmpty()) // dismissed: gone
}
}