Harden diagnostic handling and warning presentation

This commit is contained in:
2026-08-27 18:41:59 +00:00
parent 1025001f20
commit 079d5af337
67 changed files with 518 additions and 318 deletions

View File

@@ -63,11 +63,11 @@ func (n *Normalizer) Normalize(ctx context.Context, req contracts.TypedNormalize
if err := ctx.Err(); err != nil {
return contracts.TypedNormalizeResult[dnd.SceneDescriptionList]{}, normalizerErrorf("context error before normalize: %w", err)
}
value, warnings, err := normalizeList(req.MergeOutput.Value, req.Source)
value, findings, err := normalizeList(req.MergeOutput.Value, req.Source)
if err != nil {
return contracts.TypedNormalizeResult[dnd.SceneDescriptionList]{}, normalizerErrorf("normalize scenes: %w", err)
}
diagnosticGroups, err := diagnostics.NormalizationDiagnostics(warnings)
diagnosticGroups, err := diagnostics.NormalizationDiagnostics(findings)
if err != nil {
return contracts.TypedNormalizeResult[dnd.SceneDescriptionList]{}, normalizerErrorf("collect diagnostics: %w", err)
}
@@ -92,7 +92,7 @@ func normalizeList(input dnd.SceneDescriptionList, doc *source.SourceDocument) (
documentIndex := source.NewDocumentIndex(doc)
records := make([]normalizedScene, len(input.Scenes))
warnings := make([]diagnostics.Finding, 0)
findings := make([]diagnostics.Finding, 0)
for sceneIndex, scene := range input.Scenes {
originalTitle, originalSummary := scene.Title, scene.Summary
scene.Title = strings.TrimSpace(scene.Title)
@@ -104,7 +104,7 @@ func normalizeList(input dnd.SceneDescriptionList, doc *source.SourceDocument) (
return dnd.SceneDescriptionList{}, nil, fmt.Errorf("scenes[%d].source_ref: %s", sceneIndex, diagnostics.Truncate(err.Error()))
}
if originalTitle != scene.Title || originalSummary != scene.Summary {
warnings = append(warnings, diagnostics.Finding{
findings = append(findings, diagnostics.Finding{
Scope: sceneScope(sceneIndex),
ReasonCode: ReasonCodeProseNormalized,
Message: fmt.Sprintf("input index %d: title and/or summary whitespace normalized", sceneIndex),
@@ -125,7 +125,7 @@ func normalizeList(input dnd.SceneDescriptionList, doc *source.SourceDocument) (
if position == record.inputIndex {
continue
}
warnings = append(warnings, diagnostics.Finding{
findings = append(findings, diagnostics.Finding{
Scope: sceneScope(record.inputIndex),
ReasonCode: ReasonCodeOrderNormalized,
Message: fmt.Sprintf("input index %d moved to normalized position %d by canonical scene order",
@@ -146,7 +146,7 @@ func normalizeList(input dnd.SceneDescriptionList, doc *source.SourceDocument) (
return dnd.SceneDescriptionList{}, nil, fmt.Errorf("source range %s has conflicting records", sourceRefLabel(scene.SourceRef))
}
if retainedIndex, ok := seen[scene]; ok {
warnings = append(warnings, diagnostics.Finding{
findings = append(findings, diagnostics.Finding{
Scope: sceneScope(record.inputIndex),
ReasonCode: ReasonCodeDuplicateCollapsed,
Message: fmt.Sprintf("input index %d: exact duplicate scene collapsed; retained input index %d",
@@ -159,7 +159,7 @@ func normalizeList(input dnd.SceneDescriptionList, doc *source.SourceDocument) (
seen[scene] = record.inputIndex
unique = append(unique, scene)
}
return dnd.SceneDescriptionList{Scenes: unique}, warnings, nil
return dnd.SceneDescriptionList{Scenes: unique}, findings, nil
}
func sceneScope(index int) string { return fmt.Sprintf("scenes[%d]", index) }

View File

@@ -53,7 +53,7 @@ func TestNormalizeTrimsOrdersDeduplicatesAndOwnsOutput(t *testing.T) {
}
}
func TestNormalizeLimitsCombinedSceneMutationWarnings(t *testing.T) {
func TestNormalizeLimitsCombinedSceneMutationFindings(t *testing.T) {
count := contracts.MaxDiagnosticSamples + 1
doc := &source.SourceDocument{ID: "session", Units: make([]source.SourceUnit, count)}
input := dnd.SceneDescriptionList{Scenes: make([]dnd.SceneDescription, count)}