jabref icon indicating copy to clipboard operation
jabref copied to clipboard

KeyBindingsTabModelTest.randomNewKeyKeyBindingInRepository fails on macOS

Open MarkOmelyanenko opened this issue 4 months ago • 6 comments

JabRef version

5.15 (latest release)

Operating system

macOS

Details on version and operating system

macOS 26.5.1

Checked with the latest development build (copy version output from About dialog)

  • [x] I made a backup of my libraries before testing the latest development version.
  • [x] I have tested the latest development version and the problem persists

Steps to reproduce the behaviour

  1. On macOS, use a current checkout of the JabRef development branch.

  2. Run the following test individually:

    ./gradlew :jabgui:test \
      --tests "org.jabref.gui.keyboard.KeyBindingsTabModelTest.randomNewKeyKeyBindingInRepository" \
      --rerun-tasks
    
    

Appendix

The test creates a synthetic KeyEvent with control = true and meta = false.

KeyEvent shortcutKeyEvent = new KeyEvent(KeyEvent.KEY_PRESSED, "K", "K", KeyCode.K, true, true, true, false);

While the key-binding logic in KeyBindingViewModel.setNewBinding(KeyEvent evt) uses evt.isShortcutDown().

if (evt.isShortcutDown()) {
    modifiers = "shortcut+";
}

On macOS, the platform shortcut modifier is Meta/Command rather than Control, so this may cause the synthetic event not to match the generated key combination.

I also noticed that neighboring tests in the same test class already use assumeFalse(OS.OS_X), while randomNewKeyKeyBindingInRepository() does not.

Failure output
org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at [email protected]/org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:190)
	at org.jabref/org.jabref.gui.keyboard.KeyBindingsTabModelTest.randomNewKeyKeyBindingInRepository(KeyBindingsTabModelTest.java:89)
Image

MarkOmelyanenko avatar Jul 08 '26 14:07 MarkOmelyanenko

Yeah, the test needs to be updated with assumeFalse or DisabledOnOS(MacOS)

Siedlerchr avatar Jul 08 '26 16:07 Siedlerchr

Yeah, the test needs to be updated with assumeFalse or DisabledOnOS(MacOS)

I propose not disabling these tests on macOS and instead making the synthetic KeyEvents platform-aware.

Since KeyBindingViewModel.setNewBinding() relies on evt.isShortcutDown(), I changed the synthetic test events to use the platform-specific shortcut modifier: Control on non-macOS platforms and Meta/Command on macOS.

I wrote a helper:

private KeyEvent createShortcutKeyEvent(String character, KeyCode keyCode) {
    boolean controlDown = !OS.OS_X;
    boolean metaDown = OS.OS_X;

    return new KeyEvent(
            KeyEvent.KEY_PRESSED,
            character,
            character,
            keyCode,
            true,
            controlDown,
            true,
            metaDown
    );
}

Then the failing test can use:

KeyEvent shortcutKeyEvent = createShortcutKeyEvent("K", KeyCode.K);

I also applied the same approach to the neighboring tests that were previously skipped on macOS.

With this change, I removed the existing:

assumeFalse(OS.OS_X);

from those tests.

I tested this locally on macOS:

  • the originally failing randomNewKeyKeyBindingInRepository() test passes;
  • the previously skipped macOS tests pass;
  • the full KeyBindingsTabModelTest class passes.

Would you be open to this approach? I already have the changes working locally.

MarkOmelyanenko avatar Jul 08 '26 22:07 MarkOmelyanenko

Yeah that's a valid approach. Go ahead

Mark Omelyanenko @.***> schrieb am Do., 9. Juli 2026, 00:54:

MarkOmelyanenko left a comment (JabRef/jabref#16208) https://github.com/JabRef/jabref/issues/16208#issuecomment-4919912464

Yeah, the test needs to be updated with assumeFalse or DisabledOnOS(MacOS)

I propose not disabling these tests on macOS and instead making the synthetic KeyEvents platform-aware.

Since KeyBindingViewModel.setNewBinding() relies on evt.isShortcutDown(), I changed the synthetic test events to use the platform-specific shortcut modifier: Control on non-macOS platforms and Meta/Command on macOS.

I wrote a helper:

private KeyEvent createShortcutKeyEvent(String character, KeyCode keyCode) { boolean controlDown = !OS.OS_X; boolean metaDown = OS.OS_X;

return new KeyEvent(
        KeyEvent.KEY_PRESSED,
        character,
        character,
        keyCode,
        true,
        controlDown,
        true,
        metaDown
);

}

Then the failing test can use:

KeyEvent shortcutKeyEvent = createShortcutKeyEvent("K", KeyCode.K);

I also applied the same approach to the neighboring tests that were previously skipped on macOS.

With this change, I removed the existing:

assumeFalse(OS.OS_X);

from those tests.

I tested this locally on macOS:

  • the originally failing randomNewKeyKeyBindingInRepository() test passes;
  • the previously skipped macOS tests pass;
  • the full KeyBindingsTabModelTest class passes.

Would you be open to this approach? I already have the changes working locally.

— Reply to this email directly, view it on GitHub https://github.com/JabRef/jabref/issues/16208?email_source=notifications&email_token=AACOFZABMRSLRKTOY3STZE35D3GMBA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOJRHE4TCMRUGY2KM4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4919912464, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACOFZFBTUU7D3QOVCTU7ND5D3GMBAVCNFSNUABEKJSXA33TNF2G64TZHMYTONRTGQYDOMJ3JFZXG5LFHM2DQMZYGU3DAOJSG6QXMAQ . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS https://github.com/notifications/mobile/ios/AACOFZGUG2OXEWHQDCSI6TD5D3GMBA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOJRHE4TCMRUGY2KM4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJKTGN5XXIZLSL5UW64Y and Android https://github.com/notifications/mobile/android/AACOFZAPRFMDKVZWBWETBKL5D3GMBA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOJRHE4TCMRUGY2KM4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI. Download it today! You are receiving this because you commented.Message ID: @.***>

Siedlerchr avatar Jul 09 '26 06:07 Siedlerchr

/assign-me

MarkOmelyanenko avatar Jul 09 '26 10:07 MarkOmelyanenko

⚠️ Self-Assignment Not Allowed

Hi @MarkOmelyanenko, you cannot self-assign an issue you created.

[!NOTE] This project requires maintainer approval before working on self-created issues to ensure alignment with the project roadmap.

What you can do
  • Wait for a maintainer to review and approve your issue
  • Ask a maintainer to assign you if the issue is approved
  • Look for other existing issues to contribute to

jabref-machine avatar Jul 09 '26 10:07 jabref-machine

We think that this issue was fixed. Please head to https://builds.jabref.org/main to download a development build and try it out.

For any feedback, add a comment to the pull request at https://github.com/JabRef/jabref/pull/16218.

github-actions[bot] avatar Jul 09 '26 18:07 github-actions[bot]