Tighten NPC interaction validation and consistency
This commit is contained in:
@@ -6,10 +6,13 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxIssues = 20
|
||||
MaxWarnings = 20
|
||||
MaxDisplayedRunes = 128
|
||||
MaxMessageBytes = 4096
|
||||
)
|
||||
@@ -37,6 +40,28 @@ func Aggregate(prefix string, issues []string) string {
|
||||
return aggregateMessage(prefix, displayed, len(issues)-len(displayed))
|
||||
}
|
||||
|
||||
// LimitWarnings returns at most MaxWarnings warnings, reserving the final
|
||||
// position for a deterministic omission summary when truncation is required.
|
||||
func LimitWarnings(warnings []contracts.Warning, scope, reasonCode string) []contracts.Warning {
|
||||
if warnings == nil {
|
||||
return nil
|
||||
}
|
||||
if len(warnings) <= MaxWarnings {
|
||||
bounded := make([]contracts.Warning, len(warnings))
|
||||
copy(bounded, warnings)
|
||||
return bounded
|
||||
}
|
||||
displayed := MaxWarnings - 1
|
||||
bounded := make([]contracts.Warning, displayed, MaxWarnings)
|
||||
copy(bounded, warnings[:displayed])
|
||||
bounded = append(bounded, contracts.Warning{
|
||||
Scope: scope,
|
||||
ReasonCode: reasonCode,
|
||||
Message: fmt.Sprintf("%d additional warning(s) omitted", len(warnings)-displayed),
|
||||
})
|
||||
return bounded
|
||||
}
|
||||
|
||||
func aggregateMessage(prefix string, issues []string, omitted int) string {
|
||||
message := prefix + ": " + strings.Join(issues, ", ")
|
||||
if omitted > 0 {
|
||||
|
||||
Reference in New Issue
Block a user