From 247c82b195be7cb7311ba6c5b9aca358fb91e0dc Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Thu, 04 Jun 2026 17:37:59 +0800
Subject: [PATCH] fix finder cg-only window enumeration

---
 C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift b/C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift
index 66709a1..2dcabd3 100644
--- a/C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift
+++ b/C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift
@@ -314,6 +314,45 @@
         XCTAssertNil(WindowEnumerationPolicy.window(from: utilityRecord))
     }
 
+    func testWindowEnumerationPolicyKeepsFinderCGOnlyOffscreenMainWindows() {
+        let finderApp = AlignerApp(
+            bundleIdentifier: "com.apple.finder",
+            name: "访达",
+            category: .finder
+        )
+        let record = WindowEnumerationRecord(
+            id: 83_664,
+            app: finderApp,
+            title: "Screencapture",
+            size: CGSize(width: 920, height: 436),
+            subrole: .standard,
+            hasAXBacking: false,
+            isOnscreen: false
+        )
+        let emptyTitleRecord = WindowEnumerationRecord(
+            id: 83_665,
+            app: finderApp,
+            title: "",
+            size: CGSize(width: 920, height: 436),
+            subrole: .standard,
+            hasAXBacking: false,
+            isOnscreen: false
+        )
+        let tinyRecord = WindowEnumerationRecord(
+            id: 83_666,
+            app: finderApp,
+            title: "Finder Utility",
+            size: CGSize(width: 80, height: 40),
+            subrole: .standard,
+            hasAXBacking: false,
+            isOnscreen: false
+        )
+
+        XCTAssertEqual(WindowEnumerationPolicy.window(from: record)?.title, "Screencapture")
+        XCTAssertNil(WindowEnumerationPolicy.window(from: emptyTitleRecord))
+        XCTAssertNil(WindowEnumerationPolicy.window(from: tinyRecord))
+    }
+
     func testWindowEnumerationPolicyKeepsMinimizedAndFullscreenCGOnlyOffscreenWindows() {
         let minimized = makeWindowRecord(
             title: "Minimized Document.md",
@@ -1155,6 +1194,23 @@
         XCTAssertEqual(viewModel.initialSelection, QuickSwitchSelection(appGroupIndex: 0, windowIndex: 0, windowID: 1))
     }
 
+    func testQuickSwitchViewModelBuilderUsesNumericSpaceLabelsForSingleDisplay() {
+        let app = AlignerApp(bundleIdentifier: "com.example.Alpha", name: "Alpha", category: .generic)
+        let snapshot = QuickSwitchSnapshotBuilder.snapshot(
+            displays: [makeDisplay(spaceIDs: [10, 11, 12])],
+            windows: [
+                AlignerWindow(id: 1, app: app, title: "A1", spaceIDs: [10]),
+                AlignerWindow(id: 2, app: app, title: "A2", spaceIDs: [11])
+            ]
+        )
+
+        let viewModel = QuickSwitchViewModelBuilder.viewModel(from: snapshot, currentSpaceIDs: [11])
+
+        XCTAssertEqual(viewModel.displays.flatMap { $0.spaces.map(\.label) }, ["01", "02", "03"])
+        XCTAssertEqual(viewModel.displays.flatMap { $0.spaces.filter(\.isCurrent).map(\.label) }, ["02"])
+        XCTAssertEqual(viewModel.waterfallColumns.flatMap { $0.windows.map(\.primarySpaceLabel) }, ["01", "02"])
+    }
+
     func testQuickSwitchFocusPolicySelectsFirstStableWindowInitially() {
         let app = makeApp()
         let snapshot = QuickSwitchSnapshotBuilder.snapshot(

--
Gitblit v1.9.3