Преглед изворни кода

chore(deps): upgrade armature-health to v2.0.2

v2.0.2 bounds stored issue fields: keys over 191 bytes are shortened with a
hash, and titles over 512 characters are cut. Configuration issue keys
included the whole message, so a long message no longer matched its stored
key. Such issues were logged again on every rebuild and lost their list
order.

Issue keys are now a SHA-256 hash of the identifying fields, which always
fits and is stored unchanged, and the cached list is keyed by the stored key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jamesread пре 2 дана
родитељ
комит
67d7ea23ca

+ 1 - 1
service/go.mod

@@ -21,7 +21,7 @@ require (
 	github.com/golang-jwt/jwt/v5 v5.3.1
 	github.com/golangci/golangci-lint/v2 v2.15.0
 	github.com/google/uuid v1.6.0
-	github.com/jamesread/armature-health/v2 v2.0.0
+	github.com/jamesread/armature-health/v2 v2.0.2
 	github.com/jamesread/golure v0.0.0-20261111213547-dc225fc15a30
 	github.com/knadh/koanf/parsers/yaml v1.1.1
 	github.com/knadh/koanf/providers/env v1.1.0

+ 2 - 2
service/go.sum

@@ -343,8 +343,8 @@ github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUq
 github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
 github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
-github.com/jamesread/armature-health/v2 v2.0.0 h1:rJO1zFqPKL6Ji5OeyEWlAeL5qYjdIyLpKgntMAGgcr8=
-github.com/jamesread/armature-health/v2 v2.0.0/go.mod h1:PqpA8CV9tJvwjjXaiNBhOVKZHPaeJs4Krga4DngYsKI=
+github.com/jamesread/armature-health/v2 v2.0.2 h1:51yxUwXR3WPEj3IpXE2EW2yIGN58ieNjYv49n/K4zNM=
+github.com/jamesread/armature-health/v2 v2.0.2/go.mod h1:PqpA8CV9tJvwjjXaiNBhOVKZHPaeJs4Krga4DngYsKI=
 github.com/jamesread/golure v0.0.0-20261111213547-dc225fc15a30 h1:OH3LW5inwllequ0Saiv/y7mvfGWSmEE0rLROIEW5IBs=
 github.com/jamesread/golure v0.0.0-20261111213547-dc225fc15a30/go.mod h1:eanAcCk4sl2dM5bax4jeSCexnVYRF2IhhtQ4B+Wx8DU=
 github.com/jdx/go-netrc v1.0.0 h1:QbLMLyCZGj0NA8glAhxUpf1zDg6cxnWgMBbjq40W0gQ=

+ 17 - 8
service/internal/configissues/health.go

@@ -1,6 +1,8 @@
 package configissues
 
 import (
+	"crypto/sha256"
+	"encoding/hex"
 	"slices"
 	"sort"
 	"strings"
@@ -27,8 +29,10 @@ var (
 
 // issueKey identifies the same problem across rebuilds. Severity is left out
 // so that a change in severity updates the issue rather than raising a new one.
+// It is a hash so that it always fits armature-health's key limit and is stored
+// unchanged; a longer key would be shortened, and stop matching.
 func issueKey(issue Issue) string {
-	return strings.Join([]string{
+	sum := sha256.Sum256([]byte(strings.Join([]string{
 		issue.Code,
 		issue.ActionID,
 		issue.ActionTitle,
@@ -36,7 +40,8 @@ func issueKey(issue Issue) string {
 		issue.Source,
 		issue.ConfigFile,
 		issue.Message,
-	}, "\x00")
+	}, "\x00")))
+	return hex.EncodeToString(sum[:])
 }
 
 // armature-health treats anything that is not a warning or an error as info.
@@ -110,6 +115,15 @@ func rememberOrder(sourceID string, issues []Issue) {
 // Within a source, issues keep the order they were collected in, and issues
 // reported between rebuilds follow in the order they were reported.
 func orderedIssues(stored []health.IssueView) []Issue {
+	views := orderedIssueViews(stored)
+	out := make([]Issue, 0, len(views))
+	for _, view := range views {
+		out = append(out, fromHealthIssue(view))
+	}
+	return out
+}
+
+func orderedIssueViews(stored []health.IssueView) []health.IssueView {
 	views := uniqueIssueViews(stored)
 
 	orderMu.Lock()
@@ -118,12 +132,7 @@ func orderedIssues(stored []health.IssueView) []Issue {
 	sort.SliceStable(views, func(left, right int) bool {
 		return issueSortsBefore(views[left], views[right])
 	})
-
-	out := make([]Issue, 0, len(views))
-	for _, view := range views {
-		out = append(out, fromHealthIssue(view))
-	}
-	return out
+	return views
 }
 
 func uniqueIssueViews(stored []health.IssueView) []health.IssueView {

+ 23 - 0
service/internal/configissues/health_test.go

@@ -2,6 +2,7 @@ package configissues
 
 import (
 	"context"
+	"strings"
 	"testing"
 
 	log "github.com/sirupsen/logrus"
@@ -166,3 +167,25 @@ func TestListKeepsCollectionOrder(t *testing.T) {
 
 	assert.Equal(t, []string{"load", "runtime", "config a", "config c", "config b"}, messages(List()))
 }
+
+func TestLongIssuesKeepOrderAndAreNotLoggedAgain(t *testing.T) {
+	resetIssues(t)
+	hook := captureLogs(t)
+
+	long := strings.Repeat("x", 600)
+	issues := []Issue{
+		testIssue(CodeConfigDecode, "b "+long),
+		testIssue(CodeConfigDecode, "a "+long),
+	}
+	Replace(issues)
+	Replace(issues)
+	ReportRuntime(testIssue(CodeDeprecatedAPICall, long))
+	ReportRuntime(testIssue(CodeDeprecatedAPICall, long))
+
+	assert.Len(t, issueLogEntries(hook), 3, "an unchanged long issue must not be logged again")
+
+	listed := List()
+	require.Len(t, listed, 3)
+	assert.True(t, strings.HasPrefix(listed[1].Message, "b "), "long issues must keep collection order")
+	assert.True(t, strings.HasPrefix(listed[2].Message, "a "), "long issues must keep collection order")
+}

+ 8 - 4
service/internal/configissues/store.go

@@ -155,10 +155,14 @@ func refreshSnapshot() {
 		return
 	}
 
-	ordered := orderedIssues(stored)
-	severities := make(map[string]string, len(ordered))
-	for _, issue := range ordered {
-		severities[issueKey(issue)] = issue.Severity
+	// Severities are keyed by the stored key rather than one worked out again from
+	// the listed issue, because armature-health shortens long titles and attributes.
+	views := orderedIssueViews(stored)
+	ordered := make([]Issue, 0, len(views))
+	severities := make(map[string]string, len(views))
+	for _, view := range views {
+		ordered = append(ordered, fromHealthIssue(view))
+		severities[view.IssueKey] = view.Severity
 	}
 
 	snapshotMu.Lock()