Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(threatrules): compare FIELDS.md by content, not by line-ending representation

shukieshah62d4bb0b0cbb
diff --git a/pkg/asymptoteobserve/threatrules/fields_test.go b/pkg/asymptoteobserve/threatrules/fields_test.go
index ba384576..38b7180a 100644
--- a/pkg/asymptoteobserve/threatrules/fields_test.go
+++ b/pkg/asymptoteobserve/threatrules/fields_test.go
@@ -3,6 +3,7 @@ package threatrules
import (
"os"
"path/filepath"
+ "strings"
"testing"
)
@@ -40,7 +41,20 @@ func TestFieldsDocInSync(t *testing.T) {
if err != nil {
t.Fatalf("read FIELDS.md (regenerate: beacon rules fields --markdown > spec/threat-rules/FIELDS.md): %v", err)
}
- if string(got) != want {
+ // Compared after normalizing line endings, because the contract is which fields the document
+ // lists -- not how the checkout happens to represent newlines. The file is committed with LF,
+ // but Git for Windows converts text files to CRLF on checkout by default, so a byte comparison
+ // reported a perfectly current document as stale on Windows and sent the reader off to
+ // regenerate a file that needed nothing.
+ //
+ // This does not weaken the check: a field added, removed or retyped still changes the content
+ // and still fails.
+ if normalizeNewlines(string(got)) != normalizeNewlines(want) {
t.Fatalf("FIELDS.md is stale; regenerate with: beacon rules fields --markdown > spec/threat-rules/FIELDS.md")
}
}
+
+// normalizeNewlines makes a comparison insensitive to checkout line-ending conversion.
+func normalizeNewlines(s string) string {
+ return strings.ReplaceAll(s, "\r\n", "\n")
+}