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

@@ -123,17 +123,17 @@ type nameCanonicalization struct {
to string
}
func normalizeList(input dnd.EnemyEventList, order shared.SourceRefOrder, registry *npcregistry.Registry) (dnd.EnemyEventList, []contracts.Warning) {
func normalizeList(input dnd.EnemyEventList, order shared.SourceRefOrder, registry *npcregistry.Registry) (dnd.EnemyEventList, []diagnostics.Finding) {
if input.Events == nil {
return dnd.EnemyEventList{}, nil
}
records := make([]normalizedRecord, len(input.Events))
warnings := make([]contracts.Warning, 0)
warnings := make([]diagnostics.Finding, 0)
for index, inputEvent := range input.Events {
event, nameChange, refsChanged := normalizeEvent(inputEvent, order, registry)
records[index] = normalizedRecord{event: event, identity: enemyeventmodel.CanonicalIdentity(event), inputIndex: index}
if nameChange != nil {
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: eventScope(index),
ReasonCode: ReasonCodeNameCanonicalized,
Message: fmt.Sprintf("input index %d: subject canonicalized from %s to %s",
@@ -141,7 +141,7 @@ func normalizeList(input dnd.EnemyEventList, order shared.SourceRefOrder, regist
})
}
if refsChanged {
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: eventScope(index),
ReasonCode: ReasonCodeSourceRefsNormalized,
Message: fmt.Sprintf("input index %d: source references normalized (original count %d, final count %d)",
@@ -157,7 +157,7 @@ func normalizeList(input dnd.EnemyEventList, order shared.SourceRefOrder, regist
if position == record.inputIndex {
continue
}
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: eventScope(record.inputIndex),
ReasonCode: ReasonCodeEventsReordered,
Message: fmt.Sprintf("input index %d moved to normalized position %d", record.inputIndex, position),
@@ -208,7 +208,7 @@ type duplicateGroup struct {
removed []int
}
func collapseDuplicates(records []normalizedRecord) ([]dnd.EnemyEvent, []contracts.Warning) {
func collapseDuplicates(records []normalizedRecord) ([]dnd.EnemyEvent, []diagnostics.Finding) {
if len(records) == 0 {
return make([]dnd.EnemyEvent, 0), nil
}
@@ -235,7 +235,7 @@ func collapseDuplicates(records []normalizedRecord) ([]dnd.EnemyEvent, []contrac
for index, record := range kept {
output[index] = cloneEvent(record.event)
}
warnings := make([]contracts.Warning, 0)
warnings := make([]diagnostics.Finding, 0)
for _, group := range groups {
if len(group.removed) == 0 {
continue
@@ -244,7 +244,7 @@ func collapseDuplicates(records []normalizedRecord) ([]dnd.EnemyEvent, []contrac
for index, removed := range group.removed {
issues[index] = fmt.Sprintf("removed input index %d", removed)
}
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: eventScope(group.retainedIndex),
ReasonCode: ReasonCodeDuplicateCollapsed,
Message: diagnostics.Aggregate(

View File

@@ -13,7 +13,6 @@ import (
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
npccodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/npcregistry"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/npcs/identity"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared/diagnostics"
)
func TestNormalizeCanonicalizesSubjectsEvidenceOrderAndDuplicates(t *testing.T) {
@@ -162,7 +161,7 @@ func TestNormalizerContractAndWarningBound(t *testing.T) {
t.Fatalf("unsafe metadata = %s, %v", encoded, err)
}
count := diagnostics.MaxWarnings + 5
count := contracts.MaxDiagnosticSamples + 5
document := &source.SourceDocument{ID: "session", Units: make([]source.SourceUnit, count)}
input := dnd.EnemyEventList{Events: make([]dnd.EnemyEvent, count)}
for index := range document.Units {
@@ -170,7 +169,7 @@ func TestNormalizerContractAndWarningBound(t *testing.T) {
input.Events[index] = dnd.EnemyEvent{Name: " ÁRIA ", Kind: dnd.EnemyEventKindEngaged, SourceRefs: []source.SourceRef{{SourceID: document.ID, StartUnitID: count - index, EndUnitID: count - index}}}
}
result, err := normalizer.Normalize(context.Background(), normalizeRequest(document, input, contracts.ReferenceSet{}))
if err != nil || len(result.Warnings) != 0 || len(result.Diagnostics) == 0 {
if err != nil || len(result.Diagnostics) == 0 {
t.Fatalf("diagnostics = %#v, %v", result.Diagnostics, err)
}
}