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

@@ -124,13 +124,13 @@ type normalizedRecord struct {
inputIndex int
}
func normalizeList(input dnd.NPCOccurrenceList, documentIndex source.DocumentIndex, order shared.SourceRefOrder, registry *npcregistry.Registry) (dnd.NPCOccurrenceList, []contracts.Warning, error) {
func normalizeList(input dnd.NPCOccurrenceList, documentIndex source.DocumentIndex, order shared.SourceRefOrder, registry *npcregistry.Registry) (dnd.NPCOccurrenceList, []diagnostics.Finding, error) {
if input.Occurrences == nil {
return dnd.NPCOccurrenceList{}, nil, nil
}
records := make([]normalizedRecord, len(input.Occurrences))
warnings := make([]contracts.Warning, 0)
warnings := make([]diagnostics.Finding, 0)
for index, inputOccurrence := range input.Occurrences {
occurrence, refsChanged, err := normalizeOccurrence(inputOccurrence, order, registry)
if err != nil {
@@ -138,7 +138,7 @@ func normalizeList(input dnd.NPCOccurrenceList, documentIndex source.DocumentInd
}
records[index] = normalizedRecord{occurrence: occurrence, inputIndex: index}
if refsChanged {
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: occurrenceScope(index),
ReasonCode: ReasonCodeSourceRefsNormalized,
Message: fmt.Sprintf("input index %d: source references normalized (original count %d, final count %d)",
@@ -154,7 +154,7 @@ func normalizeList(input dnd.NPCOccurrenceList, documentIndex source.DocumentInd
if position == record.inputIndex {
continue
}
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: occurrenceScope(record.inputIndex),
ReasonCode: ReasonCodeOccurrencesReordered,
Message: fmt.Sprintf("input index %d moved to normalized position %d by source chronology", record.inputIndex, position),
@@ -192,7 +192,7 @@ type duplicateGroup struct {
removed []int
}
func collapseDuplicates(records []normalizedRecord, documentIndex source.DocumentIndex) ([]dnd.NPCOccurrence, []contracts.Warning) {
func collapseDuplicates(records []normalizedRecord, documentIndex source.DocumentIndex) ([]dnd.NPCOccurrence, []diagnostics.Finding) {
if len(records) == 0 {
return make([]dnd.NPCOccurrence, 0), nil
}
@@ -220,7 +220,7 @@ func collapseDuplicates(records []normalizedRecord, documentIndex source.Documen
output = append(output, cloneOccurrence(record.occurrence))
}
}
warnings := make([]contracts.Warning, 0)
warnings := make([]diagnostics.Finding, 0)
for _, group := range groups {
if len(group.removed) != 0 {
warnings = append(warnings, duplicateWarning(group.retainedIndex, group.removed))
@@ -229,12 +229,12 @@ func collapseDuplicates(records []normalizedRecord, documentIndex source.Documen
return output, warnings
}
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: occurrenceScope(retainedIndex),
ReasonCode: ReasonCodeDuplicateCollapsed,
Message: diagnostics.Aggregate(