A small module builds preview text for a message and records in audit whether a fallback text was used. After a recent change, the behavior differs from what is expected: for some inputs the wrong text is returned, and the audit marks the fallback path even when it was not needed.
renderPreview method must return the main body value if it is not empty after trim.body is missing or consists only of spaces, fallback must be used.fallback is passed as a by-name computation and must not be evaluated eagerly.Audit.markFallbackUsed must be called only if the fallback text was actually selected.fallback was selected, the result must return the computed fallback exactly, without additional normalization.PreviewRenderer.scala.scala/sbt console:import preview.*
val audit1 = AuditLog()
PreviewRenderer.renderPreview(Some(" Hello ")) {
audit1.markFallbackUsed()
"backup"
}(audit1)
audit1.fallbackMarked
val audit2 = AuditLog()
PreviewRenderer.renderPreview(Some(" ")) {
audit2.markFallbackUsed()
" backup text "
}(audit2)
fallbackMarked.Some(" Hello "), the original body must be returned, fallback must not be evaluated, and audit must not mark the fallback path.Some(" "), fallback must be used, audit must mark the fallback path, and the result must be the fallback value as-is, for example " backup text ".None, behavior must be the same as for an empty body: fallback is used, and audit marks the fallback path.3.3.121sbt 1.9.8previewUse line comments to explain the problem, its impact, the fix and how to test it.