From 00d2b19bf0cb14255e21ecd2f6aba8555eef625d Mon Sep 17 00:00:00 2001 From: Konrad Neitzel Date: Sat, 14 Nov 2026 07:41:58 +0100 Subject: [PATCH] Avoid title substring false positives in native desktop smoke test --- .../core/desktop/ForegroundDetectorTest.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/de/neitzel/core/desktop/ForegroundDetectorTest.java b/core/src/test/java/de/neitzel/core/desktop/ForegroundDetectorTest.java index 5a38635..c98f7ab 100644 --- a/core/src/test/java/de/neitzel/core/desktop/ForegroundDetectorTest.java +++ b/core/src/test/java/de/neitzel/core/desktop/ForegroundDetectorTest.java @@ -37,6 +37,17 @@ class ForegroundDetectorTest { } } + @Test void windowDiagnosticsIgnoreTitlesEvenWhenTheyMatchApplicationMetadata() { + var application = new ForegroundDetector.Application("test", "example.editor", "Editor", 42); + var withoutTitle = new ForegroundDetector.Window("window-1", application, null); + // A title can coincide with application metadata that diagnostics legitimately include. + assertTrue(withoutTitle.toString().contains("Editor")); + for (String title : new String[] {"Editor", "private-document-title"}) { + var window = new ForegroundDetector.Window("window-1", application, title); + assertEquals(withoutTitle.toString(), window.toString()); + } + } + @Test @EnabledIfSystemProperty(named = "desktop.native.tests", matches = "true") void nativeForegroundAndInventoryAreObservableWithoutLoggingTitles() { try (var detector = ForegroundDetector.system()) { @@ -47,8 +58,14 @@ class ForegroundDetectorTest { var inventory = detector.inventory(); assertTrue(inventory.available(), inventory.limitation()); assertFalse(inventory.applications().isEmpty()); - if (snapshot.window() != null && snapshot.window().title() != null && !snapshot.window().title().isEmpty()) - assertFalse(snapshot.window().toString().contains(snapshot.window().title())); + if (snapshot.window() != null) { + var window = snapshot.window(); + var withoutTitle = new ForegroundDetector.Window(window.id(), window.application(), null); + // Compare independence from the title, not accidental substring overlap. + // A boolean assertion keeps real desktop metadata out of failure messages. + assertTrue(withoutTitle.toString().equals(window.toString()), + "Window diagnostics must not depend on the title"); + } System.out.println("Native desktop smoke: namespace=" + snapshot.application().namespace() + ", appCount=" + inventory.applications().size() + ", windowCount=" + inventory.windows().size() + ", titleAvailable=" + (snapshot.window() != null && snapshot.window().title() != null));