Ariver
2026-06-09 146fbcf6430d2513df7fb536c7e9ace81f1e57b9
C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift
@@ -212,12 +212,25 @@
        let record = makeWindowRecord(
            title: "Closed Document.md",
            hasAXBacking: false,
            isOnscreen: false,
            spaceIDs: [5]
            isOnscreen: false
        )
        XCTAssertFalse(WindowEnumerationPolicy.shouldInclude(record))
        XCTAssertNil(WindowEnumerationPolicy.window(from: record))
    }
    func testWindowEnumerationPolicyKeepsCGOnlyOffscreenWindowsWithKnownSpaceIDs() {
        let record = makeWindowRecord(
            title: "Other Space Document.md",
            hasAXBacking: false,
            isOnscreen: false,
            spaceIDs: [5]
        )
        let window = WindowEnumerationPolicy.window(from: record)
        XCTAssertEqual(window?.title, "Other Space Document.md")
        XCTAssertEqual(window?.spaceIDs, [5])
    }
    func testWindowEnumerationPolicyKeepsAXBackedOffscreenWindows() {
@@ -283,13 +296,13 @@
        XCTAssertNil(WindowEnumerationPolicy.window(from: tinyRecord))
    }
    func testWindowEnumerationPolicyKeepsShottrCGOnlyAnnotationWindow() {
    func testWindowEnumerationPolicyExcludesClosedShottrCGPlaceholderButKeepsVisibleWindow() {
        let shottrApp = AlignerApp(
            bundleIdentifier: "cc.ffitch.shottr",
            name: "Shottr",
            category: .generic
        )
        let annotationRecord = WindowEnumerationRecord(
        let closedPlaceholderRecord = WindowEnumerationRecord(
            id: 78,
            app: shottrApp,
            activationPolicy: .accessory,
@@ -298,6 +311,16 @@
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        let visibleRecord = WindowEnumerationRecord(
            id: 79,
            app: shottrApp,
            activationPolicy: .accessory,
            title: "Shottr",
            size: CGSize(width: 1710, height: 997),
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: true
        )
        let utilityRecord = WindowEnumerationRecord(
            id: 102,
@@ -310,8 +333,48 @@
            isOnscreen: false
        )
        XCTAssertEqual(WindowEnumerationPolicy.window(from: annotationRecord)?.title, "Shottr")
        XCTAssertNil(WindowEnumerationPolicy.window(from: closedPlaceholderRecord))
        XCTAssertEqual(WindowEnumerationPolicy.window(from: visibleRecord)?.title, "Shottr")
        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() {
@@ -1155,6 +1218,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(