test(level-guesser): guard colon-prefix against false positives

Require a word char before the colon so the tagged form only fires on
"<tag>:<level> " (z2m) and not on bare ":level" in URLs. Add negative
tests covering level words embedded in prose and URLs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Amir Raminfar
2026-05-23 13:56:45 -07:00
parent 54cecbb5d8
commit c7ef0b1121
2 changed files with 6 additions and 2 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ var aliasToCanonical = map[string]string{}
// (?i:^<alt>[^a-z] // plain prefix: "error: ..."
// |\[ ?<alt> ?\] // bracketed: "[ERROR]" / "[ error ]"
// | <alt>[/|:-] // separator: " error|", " info:" (z2m)
// |:<alt>\s) // colon prefix: "Tag:info " (z2m)
// |\w:<alt>\s) // tagged: "Zigbee2MQTT:info " (z2m)
// |"<UPPER>" // quoted: "\"ERROR\""
// |\s<UPPER>\s // spaced: " ERROR "
//
@@ -62,7 +62,7 @@ func init() {
`(?i:^` + alt + `[^a-z]` +
`|\[ ?` + alt + ` ?\]` +
`| ` + alt + `[/|:-]` +
`|:` + alt + `\s)` +
`|\w:` + alt + `\s)` +
`|"` + upper + `"` +
`|\s` + upper + `\s`,
)
+4
View File
@@ -94,6 +94,10 @@ func TestGuessLogLevel(t *testing.T) {
{"Zigbee2MQTT:info 2025-12-22 12:00:00: started", "info"},
{"Zigbee2MQTT:warn 2025-12-22 12:00:00: queue full", "warn"},
{"Zigbee2MQTT:error 2025-12-22 12:00:00: failure", "error"},
// False-positive guards: level words embedded in prose or URLs must not match.
{"there was an error in the connection info report", "unknown"},
{"user information saved successfully", "unknown"},
{"GET https://example.com/info returned 200", "unknown"},
// Pipe-delimited
{"2024-01-01 12:00:00 | ERROR | something went wrong", "error"},
{"2024-01-01 12:00:00 | INFO | starting up", "info"},