Skip to content

Conversation

xav-ie
Copy link
Contributor

@xav-ie xav-ie commented Aug 24, 2025

Hello, this PR fixes #1322. I also added comprehensive tests verifying we agree on the expected behavior.

I encountered this error a lot randomly from a flaky test during development:

> make test-010
...
./test/gs_helpers.lua:275: status['added'] did not match gitsigns_status_dict
Expected objects to be the same.
Passed in:
(number) 1
Expected:
(number) 0

stack traceback:
        ./test/gs_helpers.lua:275: in function 'check_status'
        ./test/gs_helpers.lua:323: in function 'cond'
        ./test/gs_helpers.lua:125: in function 'expectf'
        ./test/gs_helpers.lua:321: in function 'check'
        test/gitsigns_spec.lua:685: in function <test/gitsigns_spec.lua:669>

I don't think this has anything to do with what I have done and wanted to bring this to your attention because I wasted many hours on this just to find it was just a flaky test :(. Or, maybe I just don't understand how the testing framework works. Either way, it was very difficult to know if I was introducing this error, because on re-run, it would go away!!! I think my tests are reasonable and don't do anything bad, but idk 🫠

It also happens randomly with 011:

> make test-011
...
======== 66 tests from 5 test files ran. (59153.33 ms total)
PASSED   65 tests.
FAILED   1 test, listed below:
FAILED   test/gitsigns_spec.lua @ 735: gitsigns (with screen) diff-ext can stages file with merge conflicts #46#
./test/gs_helpers.lua:269: b:gitsigns_head does not match
Expected objects to be the same.
Passed in:
(string) 'abranch'
Expected:
(string) 'HEAD(rebasing)'

stack traceback:
        ./test/gs_helpers.lua:269: in function 'check_status'
        ./test/gs_helpers.lua:323: in function 'cond'
        ./test/gs_helpers.lua:125: in function 'expectf'
        ./test/gs_helpers.lua:321: in function 'check'
        test/gitsigns_spec.lua:767: in function <test/gitsigns_spec.lua:735>


 1 FAILED TEST
E5113: Error while calling lua chunk:
make[1]: *** [Makefile:39: test] Error 1
make[1]: Leaving directory '/home/x/Projects/gitsigns.nvim'
make: *** [Makefile:55: test-011] Error 2

But then, on re-run, it works for 10 straight reruns or more! I have tried numerous strategies to re-write and refactor my tests but I just don't know what I am doing wrong. My code works and I just wanted to show that with a test, but spent 10x more on the test than the fix.


  • feat(win_width): accept winid param

    This helps ensure we are getting the expected window width.

  • test(handle_blame_info): verify right_align falls back to eol

  • fix(handle_blame_info): do not consider wrap/nowrap for right_align/eol

    When calculating if a line should fall back to eol for very long lines,
    window wrapping should not be considered. This is because when window is
    nowrap, then the blame should still be eol.

    The idea of right_align option is to be nicely right aligned, but fall
    back to eol when there is not enough room. Long lines with nowrap will
    never have extra room, so they should also always fall back to eol
    mode.

@xav-ie xav-ie force-pushed the fix-right-align branch 5 times, most recently from cb17c2f to 4edc6dd Compare August 25, 2025 01:44
@xav-ie xav-ie marked this pull request as ready for review August 25, 2025 01:46
This helps ensure we are getting the expected window width.
…n/eol`

When calculating if a line should fall back to `eol` for very long lines,
window wrapping should not be considered. This is because when window is
`nowrap`, then the blame should still be `eol`.

The idea of `right_align` option is to be nicely right aligned, but fall
back to `eol` when there is not enough room. Long lines with `nowrap` will
*never* have extra room, so they should also always fall back to `eol`
mode.
@lewis6991 lewis6991 merged commit 75879cd into lewis6991:main Sep 30, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch from virt_text_pos right_align to eol on long lines isn't working

2 participants