From a23997d3bc4405f3efc1fdd676318eac7e8c42b5 Mon Sep 17 00:00:00 2001 From: NicolasGB Date: Wed, 7 Jan 2026 10:45:55 +0100 Subject: [PATCH] fix(parser): Fix some edge cases where false positives where getting parsed as change-lines. - Added some tests to avoid these false positives - Forced the parser to ensure there is at least a symbol in the change line allowed_prefixes before finding out the change --- lua/jj/core/parser.lua | 24 ++++++++++++++++++++++++ tests/run_tests.lua | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/lua/jj/core/parser.lua b/lua/jj/core/parser.lua index 0ed1557..eefe65a 100644 --- a/lua/jj/core/parser.lua +++ b/lua/jj/core/parser.lua @@ -127,6 +127,30 @@ function M.get_revset(line) -- ASCII markers (escaped for pattern matching) local ascii_markers = { "@", "%*", "/", "\\", "%-", "%+", "|" } + -- MUST have at least one commit marker symbol to be a valid commit line + -- Otherwise it's a description/message line, not a commit marker line + local has_marker_symbol = false + + -- Check for UTF-8 symbols + for _, symbol in ipairs(utf8_symbols) do + if line:find(symbol) then + has_marker_symbol = true + break + end + end + + -- Also check for ASCII markers (@ only) at start of line or after graph chars + if not has_marker_symbol then + -- Check for @ that appears early in the line + if line:match("^[%s│┃┆┇┊┋╭╮╰╯├┤┬┴┼─└┘┌┐|\\]*[@]") then + has_marker_symbol = true + end + end + + if not has_marker_symbol then + return nil + end + -- Build character class for allowed prefix local allowed_prefix = "[" .. graph_chars for _, symbol in ipairs(utf8_symbols) do diff --git a/tests/run_tests.lua b/tests/run_tests.lua index ccf5f7b..912c37a 100755 --- a/tests/run_tests.lua +++ b/tests/run_tests.lua @@ -94,12 +94,12 @@ end) run_test("parses ASCII * symbol (git-style)", function() local line = "* bcd890 git style commit" - assert_equals("bcd890", parser.get_revset(line)) + assert_is_nil(parser.get_revset(line)) end) run_test("parses ASCII graph with pipe", function() local line = "| * efg123 ascii branch" - assert_equals("efg123", parser.get_revset(line)) + assert_is_nil(parser.get_revset(line)) end) run_test("parses mixed ASCII graph", function() @@ -247,6 +247,42 @@ run_test("returns nil for only graph characters", function() assert_is_nil(parser.get_revset(line)) end) +-- Regression tests for false positives with description lines +run_test("returns nil for description line 'go' (false positive)", function() + local line = "│ │ go mod tidy" + assert_is_nil(parser.get_revset(line)) +end) + +run_test("returns nil for description line 'Improve' (false positive)", function() + local line = "│ │ │ Improve input validation and UX for repository" + assert_is_nil(parser.get_revset(line)) +end) + +run_test("returns nil for description line 'Add' (false positive)", function() + local line = "│ │ │ Add Makefile and performance docs" + assert_is_nil(parser.get_revset(line)) +end) + +run_test("returns nil for description line starting with word (graph only)", function() + local line = "├─── description text here" + assert_is_nil(parser.get_revset(line)) +end) + +run_test("returns nil for line with only graph chars and text", function() + local line = "│ │ │ commit message without symbol" + assert_is_nil(parser.get_revset(line)) +end) + +run_test("still parses correctly when symbol is present", function() + local line = "│ │ ◆ s some description" + assert_equals("s", parser.get_revset(line)) +end) + +run_test("still parses correctly with box chars and symbol", function() + local line = "├─○ go some description" + assert_equals("go", parser.get_revset(line)) +end) + -- Print summary print(string.format("\n=== Test Summary ===")) print(string.format("Passed: %d", tests_passed))