From 270f3febb94d64e84c2d99af48ff49733c5c7bc6 Mon Sep 17 00:00:00 2001 From: Oliver Kieselbach Date: Wed, 8 Jul 2026 13:33:46 +0200 Subject: [PATCH] =?UTF-8?q?test(agent):=20fix=20CmTraceLogParser=20BOM=20e?= =?UTF-8?q?xpectation=20=E2=80=94=20parser=20is=20BOM-tolerant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The malformed-input theory asserted a BOM-prefixed CMTrace line yields false, assuming a leading U+FEFF breaks the StartsWith gate. It doesn't: culture- sensitive string.StartsWith treats U+FEFF as ignorable so the gate passes, and the unanchored regex matches the " --- .../Monitoring/Ime/CmTraceLogParserTests.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Agent/AutopilotMonitor.Agent.V2.Core.Tests/Monitoring/Ime/CmTraceLogParserTests.cs b/src/Agent/AutopilotMonitor.Agent.V2.Core.Tests/Monitoring/Ime/CmTraceLogParserTests.cs index edbc885b..5af372fb 100644 --- a/src/Agent/AutopilotMonitor.Agent.V2.Core.Tests/Monitoring/Ime/CmTraceLogParserTests.cs +++ b/src/Agent/AutopilotMonitor.Agent.V2.Core.Tests/Monitoring/Ime/CmTraceLogParserTests.cs @@ -26,8 +26,7 @@ namespace AutopilotMonitor.Agent.V2.Core.Tests.Monitoring.Ime [InlineData("")] // empty [InlineData(" ")] // whitespace only [InlineData("")] // leading BOM breaks the StartsWith gate - [InlineData("garbage prefix ")] // leading junk + [InlineData("garbage prefix ")] // leading junk (non-ignorable) fails the StartsWith gate public void TryParseLine_returns_false_without_throwing_for_malformed_input(string line) { var ok = CmTraceLogParser.TryParseLine(line, out var entry); @@ -36,6 +35,24 @@ namespace AutopilotMonitor.Agent.V2.Core.Tests.Monitoring.Ime Assert.Null(entry); } + // ── Leading BOM → still parses (BOM-tolerant) ──────────────────────── + + [Fact] + public void TryParseLine_parses_bom_prefixed_line() + { + // A U+FEFF BOM can prefix the first line of a freshly-opened log. It does NOT break + // parsing: string.StartsWith (culture-sensitive) treats U+FEFF as an ignorable + // character so the gate passes, and the unanchored regex matches the "