In a small notes module, after a recent refactor, odd behavior appeared when working with tags. Users notice that seemingly identical notes are no longer found correctly in collections, and filtering by tag sometimes returns extra results.
NoteIndex.contains must return true for a note with the same id and title as one that is already saved.NoteIndex.addIfMissing must not add a duplicate note if an equivalent note is already present in the list.NoteFilter.hasTag must treat only an exact tag name as a match."" must not match tags such as "work" or "home".main:import notes.*
val existing = Note("n-1", "Plan")
val sameData = Note("n-1", "Plan")
val index = NoteIndex(List(existing))
println(index.contains(sameData))
println(index.addIfMissing(sameData).size)
val tagged = NoteWithTags(existing, List("work", "urgent"))
println(NoteFilter.hasTag(tagged, "work"))
println(NoteFilter.hasTag(tagged, "or"))
println(NoteFilter.hasTag(tagged, ""))
contains for two logically identical notes should return true.addIfMissing, the list size should remain 1 if an equivalent note is already present.true only for an exact match, for example "work"."or" and the empty string, the result should be false.main or checking through the Scala REPLnotesUse line comments to explain the problem, its impact, the fix and how to test it.