From 73ef2c6083dd1b28628a6bb55bb899833f312a9f Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Wed, 11 Nov 2026 12:31:44 +0000 Subject: [PATCH] Select protected spelling findings without sorting --- docs/roadmap/remediation.md | 4 ++- .../framework/validators/protected_terms.go | 25 +++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 1d4eab7..e166a04 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -2,7 +2,7 @@ **Updated:** 2026-11-11 -**Status:** 7 of nine findings resolved. Findings refer to implementation revision +**Status:** 8 of nine findings resolved. Findings refer to implementation revision `aa8073c`. See the [implementation plan](implementation.md). ## Review Result @@ -275,6 +275,8 @@ and available artifact paths on success and interruption. ### R8 — Select a Protected-Spelling Finding in One Pass (P3) +**Completed.** Protection checks select a deterministic spelling in one pass without sorting. Validator and runner tests pass. + **Affected plan:** Stage 5, item 4. **Evidence:** The [protection checks](../../internal/framework/validators/protected_terms.go#L98) diff --git a/internal/framework/validators/protected_terms.go b/internal/framework/validators/protected_terms.go index 11342e0..d9ffd0f 100644 --- a/internal/framework/validators/protected_terms.go +++ b/internal/framework/validators/protected_terms.go @@ -96,35 +96,40 @@ func (v ProtectedVocabulary) occurrences(text string) []protectedOccurrence { } func validateIdentityPreservation(beforeByID, afterByID map[glossary.Identity][]protectedOccurrence) string { - var spellings []string + var selected string + found := false for identity, beforeItems := range beforeByID { if len(afterByID[identity]) < len(beforeItems) && len(beforeItems) > 0 { - spellings = append(spellings, beforeItems[0].canonical) + if spelling := beforeItems[0].canonical; !found || spelling < selected { + selected, found = spelling, true + } } } - return protectedSpellingMessage(spellings) + return protectedSpellingMessage(selected, found) } func validateCapitalizationTransitions(beforeByID, afterByID map[glossary.Identity][]protectedOccurrence) string { - var spellings []string + var selected string + found := false for identity, afterItems := range afterByID { beforeItems := beforeByID[identity] for i, afterItem := range afterItems { if i >= len(beforeItems) || afterItem.text == beforeItems[i].text || afterItem.text == afterItem.canonical { continue } - spellings = append(spellings, afterItem.canonical) + if !found || afterItem.canonical < selected { + selected, found = afterItem.canonical, true + } } } - return protectedSpellingMessage(spellings) + return protectedSpellingMessage(selected, found) } -func protectedSpellingMessage(spellings []string) string { - if len(spellings) == 0 { +func protectedSpellingMessage(spelling string, found bool) string { + if !found { return "" } - sort.Strings(spellings) - return fmt.Sprintf("proposal may alter protected glossary spelling %q", spellings[0]) + return fmt.Sprintf("proposal may alter protected glossary spelling %q", spelling) } // preservesRepeatedIdentities permits a spoken-word proposal to reduce repeated