Finalize structured diagnostic aggregation

This commit is contained in:
2026-08-27 16:40:17 +00:00
parent 480680b257
commit 4dbbf68051
112 changed files with 656 additions and 893 deletions

View File

@@ -132,13 +132,13 @@ type actorCanonicalization struct {
to string
}
func normalizeList(input dnd.CombatTurnList, documentIndex source.DocumentIndex, order shared.SourceRefOrder, registry *npcregistry.Registry) (dnd.CombatTurnList, []contracts.Warning) {
func normalizeList(input dnd.CombatTurnList, documentIndex source.DocumentIndex, order shared.SourceRefOrder, registry *npcregistry.Registry) (dnd.CombatTurnList, []diagnostics.Finding) {
if input.CombatTurns == nil {
return dnd.CombatTurnList{}, nil
}
records := make([]normalizedRecord, len(input.CombatTurns))
warnings := make([]contracts.Warning, 0)
warnings := make([]diagnostics.Finding, 0)
for index, inputTurn := range input.CombatTurns {
turn, actorChange, refsChanged := normalizeTurn(inputTurn, order, registry)
earliest, hasEvidence := order.EarliestValid(turn.SourceRefs)
@@ -149,7 +149,7 @@ func normalizeList(input dnd.CombatTurnList, documentIndex source.DocumentIndex,
hasEvidence: hasEvidence,
}
if actorChange != nil {
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: turnScope(index),
ReasonCode: ReasonCodeActorCanonicalized,
Message: fmt.Sprintf("input index %d: actor canonicalized from %s to %s",
@@ -157,7 +157,7 @@ func normalizeList(input dnd.CombatTurnList, documentIndex source.DocumentIndex,
})
}
if refsChanged {
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: turnScope(index),
ReasonCode: ReasonCodeSourceRefsNormalized,
Message: fmt.Sprintf("input index %d: source references normalized (original count %d, final count %d)",
@@ -179,7 +179,7 @@ func normalizeList(input dnd.CombatTurnList, documentIndex source.DocumentIndex,
if position == record.inputIndex {
continue
}
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: turnScope(record.inputIndex),
ReasonCode: ReasonCodeTurnsReordered,
Message: fmt.Sprintf("input index %d moved to normalized position %d by source chronology",
@@ -236,7 +236,7 @@ type duplicateGroup struct {
removed []int
}
func collapseDuplicates(records []normalizedRecord, documentIndex source.DocumentIndex) ([]dnd.CombatTurn, []contracts.Warning) {
func collapseDuplicates(records []normalizedRecord, documentIndex source.DocumentIndex) ([]dnd.CombatTurn, []diagnostics.Finding) {
if len(records) == 0 {
return make([]dnd.CombatTurn, 0), nil
}
@@ -267,7 +267,7 @@ func collapseDuplicates(records []normalizedRecord, documentIndex source.Documen
}
}
warnings := make([]contracts.Warning, 0)
warnings := make([]diagnostics.Finding, 0)
for _, group := range groups {
if len(group.removed) == 0 {
continue
@@ -309,12 +309,12 @@ func writeKeyInt(builder *strings.Builder, value int) {
builder.WriteByte(';')
}
func duplicateWarning(retainedIndex int, removed []int) contracts.Warning {
func duplicateWarning(retainedIndex int, removed []int) diagnostics.Finding {
issues := make([]string, len(removed))
for index, removedIndex := range removed {
issues[index] = fmt.Sprintf("removed input index %d", removedIndex)
}
return contracts.Warning{
return diagnostics.Finding{
Scope: turnScope(retainedIndex),
ReasonCode: ReasonCodeDuplicateCollapsed,
Message: diagnostics.Aggregate(