Ariver
2026-07-13 14a1efc86d0295be3a0d3fe1ebe7b8080266da2d
C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift
@@ -6,7 +6,7 @@
    func testAppIdentity() {
        XCTAssertEqual(AlignerAppInfo.name, "Aligner")
        XCTAssertEqual(AlignerAppInfo.bundleIdentifier, "com.ar.Aligner")
        XCTAssertEqual(AlignerAppInfo.minimumMacOSVersion, "26.0")
        XCTAssertEqual(AlignerAppInfo.minimumMacOSVersion, "14.0")
    }
    func testRound0OnlyDefinesQuickSwitchEntryPoint() {
@@ -171,6 +171,33 @@
                subroleDescription: "standard"
            )
        )
    }
    func testWindowEnumerationPolicyRejectsLowConfidenceAXOnlyRegularWindows() {
        XCTAssertFalse(WindowEnumerationPolicy.shouldIncludeAXOnlyRecord(
            identifierSource: .cgWindow,
            isMinimized: false,
            isFullscreen: false,
            spaceIDs: []
        ))
        XCTAssertTrue(WindowEnumerationPolicy.shouldIncludeAXOnlyRecord(
            identifierSource: .cgWindow,
            isMinimized: true,
            isFullscreen: false,
            spaceIDs: []
        ))
        XCTAssertTrue(WindowEnumerationPolicy.shouldIncludeAXOnlyRecord(
            identifierSource: .cgWindow,
            isMinimized: false,
            isFullscreen: true,
            spaceIDs: [42]
        ))
        XCTAssertFalse(WindowEnumerationPolicy.shouldIncludeAXOnlyRecord(
            identifierSource: .syntheticAX,
            isMinimized: false,
            isFullscreen: false,
            spaceIDs: []
        ))
    }
    func testMinimizedWindowFallbackPolicyAvoidsOccupiedSyntheticIDCollisions() {
@@ -377,6 +404,214 @@
        XCTAssertNil(WindowEnumerationPolicy.window(from: tinyRecord))
    }
    func testFinderTabSpaceAttributionInheritsFullscreenHostSpaceForMatchingFrame() {
        let finderApp = AlignerApp(
            bundleIdentifier: "com.apple.finder",
            name: "访达",
            category: .finder,
            processIdentifier: 74678
        )
        let frame = CGRect(x: 0, y: 0, width: 960, height: 1080)
        let host = WindowEnumerationRecord(
            id: 33112,
            app: finderApp,
            title: "下载",
            size: frame.size,
            frame: frame,
            subrole: .standard,
            isFullscreen: true,
            hasAXBacking: true,
            spaceIDs: [843]
        )
        let inactiveTab = WindowEnumerationRecord(
            id: 42286,
            app: finderApp,
            title: "Appcache",
            size: frame.size,
            frame: frame,
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        let attributed = FinderTabSpaceAttributionPolicy.attributedRecords([inactiveTab, host])
        XCTAssertEqual(attributed[0].spaceIDs, [843])
        XCTAssertTrue(attributed[0].isFullscreen)
    }
    func testFinderTabSpaceAttributionDoesNotGuessNoSpaceWindowsWithoutHostOverlap() {
        let finderApp = AlignerApp(
            bundleIdentifier: "com.apple.finder",
            name: "访达",
            category: .finder,
            processIdentifier: 74678
        )
        let otherApp = AlignerApp(
            bundleIdentifier: "com.example.Other",
            name: "Other",
            category: .generic,
            processIdentifier: 74678
        )
        let hostFrame = CGRect(x: 0, y: 0, width: 960, height: 1080)
        let farFrame = CGRect(x: 1200, y: 0, width: 500, height: 600)
        let host = WindowEnumerationRecord(
            id: 33112,
            app: finderApp,
            title: "下载",
            size: hostFrame.size,
            frame: hostFrame,
            subrole: .standard,
            isFullscreen: true,
            hasAXBacking: true,
            spaceIDs: [843]
        )
        let farFinderTab = WindowEnumerationRecord(
            id: 42286,
            app: finderApp,
            title: "Appcache",
            size: farFrame.size,
            frame: farFrame,
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        let nonFinderWindow = WindowEnumerationRecord(
            id: 50222,
            app: otherApp,
            title: "Appcache",
            size: hostFrame.size,
            frame: hostFrame,
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        let attributed = FinderTabSpaceAttributionPolicy.attributedRecords([farFinderTab, nonFinderWindow, host])
        XCTAssertEqual(attributed[0].spaceIDs, [])
        XCTAssertFalse(attributed[0].isFullscreen)
        XCTAssertEqual(attributed[1].spaceIDs, [])
        XCTAssertFalse(attributed[1].isFullscreen)
    }
    func testFinderTabSpaceAttributionHandlesFinderSplitViewHostsByFrame() {
        let finderApp = AlignerApp(
            bundleIdentifier: "com.apple.finder",
            name: "访达",
            category: .finder,
            processIdentifier: 74678
        )
        let leftFrame = CGRect(x: 0, y: 0, width: 960, height: 1080)
        let rightFrame = CGRect(x: 960, y: 0, width: 960, height: 1080)
        let leftHost = WindowEnumerationRecord(
            id: 33112,
            app: finderApp,
            title: "下载",
            size: leftFrame.size,
            frame: leftFrame,
            subrole: .standard,
            isFullscreen: true,
            hasAXBacking: true,
            spaceIDs: [843]
        )
        let rightHost = WindowEnumerationRecord(
            id: 41557,
            app: finderApp,
            title: "应用程序",
            size: rightFrame.size,
            frame: rightFrame,
            subrole: .standard,
            isFullscreen: true,
            hasAXBacking: true,
            spaceIDs: [843]
        )
        let leftInactiveTab = WindowEnumerationRecord(
            id: 42286,
            app: finderApp,
            title: "Appcache",
            size: leftFrame.size,
            frame: leftFrame,
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        let rightInactiveTab = WindowEnumerationRecord(
            id: 61385,
            app: finderApp,
            title: "build",
            size: rightFrame.size,
            frame: rightFrame,
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        let attributed = FinderTabSpaceAttributionPolicy.attributedRecords([
            leftInactiveTab,
            rightInactiveTab,
            leftHost,
            rightHost
        ])
        XCTAssertEqual(attributed[0].spaceIDs, [843])
        XCTAssertEqual(attributed[1].spaceIDs, [843])
        XCTAssertTrue(attributed[0].isFullscreen)
        XCTAssertTrue(attributed[1].isFullscreen)
    }
    func testFinderTabSpaceAttributionRejectsContainingHostsWithDifferentSize() {
        let finderApp = AlignerApp(
            bundleIdentifier: "com.apple.finder",
            name: "访达",
            category: .finder,
            processIdentifier: 74678
        )
        let splitRightFrame = CGRect(x: 960, y: 0, width: 960, height: 1080)
        let fullDisplayFrame = CGRect(x: 0, y: 0, width: 1920, height: 1080)
        let splitHost = WindowEnumerationRecord(
            id: 33112,
            app: finderApp,
            title: "下载",
            size: splitRightFrame.size,
            frame: splitRightFrame,
            subrole: .standard,
            isFullscreen: true,
            hasAXBacking: true,
            spaceIDs: [843]
        )
        let containingHost = WindowEnumerationRecord(
            id: 41557,
            app: finderApp,
            title: "应用程序",
            size: fullDisplayFrame.size,
            frame: fullDisplayFrame,
            subrole: .standard,
            isFullscreen: true,
            hasAXBacking: true,
            spaceIDs: [1112]
        )
        let inactiveTab = WindowEnumerationRecord(
            id: 42286,
            app: finderApp,
            title: "Appcache",
            size: splitRightFrame.size,
            frame: splitRightFrame,
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        let attributed = FinderTabSpaceAttributionPolicy.attributedRecords([
            inactiveTab,
            containingHost,
            splitHost
        ])
        XCTAssertEqual(attributed[0].spaceIDs, [843])
        XCTAssertTrue(attributed[0].isFullscreen)
    }
    func testWindowEnumerationPolicyKeepsMinimizedAndFullscreenCGOnlyOffscreenWindows() {
        let minimized = makeWindowRecord(
            title: "Minimized Document.md",
@@ -497,6 +732,13 @@
        XCTAssertEqual(templates.map(\.category), categories)
        XCTAssertTrue(templates.allSatisfy { $0.headerHeight > 0 })
        XCTAssertTrue(templates.allSatisfy { $0.contentRows > 0 })
    }
    func testSkeletonThumbnailPaletteStaysQuietForFallbackState() {
        XCTAssertLessThanOrEqual(SkeletonThumbnailPalette.headerAlpha, 0.10)
        XCTAssertLessThanOrEqual(SkeletonThumbnailPalette.contentRowAlpha, 0.08)
        XCTAssertLessThanOrEqual(SkeletonThumbnailPalette.accentStripeAlpha, 0.30)
        XCTAssertGreaterThanOrEqual(SkeletonThumbnailPalette.titleBandAlpha, 0.80)
    }
    @MainActor
@@ -1441,6 +1683,87 @@
        XCTAssertNil(QuickSwitchSpaceFilterPolicy.singleFullscreenSelection(inSpaceID: 12, viewModel: viewModel))
    }
    func testQuickSwitchViewModelOrdersSplitViewAppNamesByWindowFrame() {
        let leftApp = AlignerApp(bundleIdentifier: "com.example.Left", name: "Left App", category: .generic)
        let rightApp = AlignerApp(bundleIdentifier: "com.example.Right", name: "Right App", category: .generic)
        let displayUUID = "display-a"
        let snapshot = QuickSwitchSnapshotBuilder.snapshot(
            displays: [
                AlignerDisplay(
                    uuid: displayUUID,
                    physical: true,
                    spaces: [
                        AlignerSpace(id: 20, type: .fullscreen, displayUUID: displayUUID, index: 1)
                    ]
                )
            ],
            windows: [
                AlignerWindow(
                    id: 2,
                    app: rightApp,
                    title: "Right",
                    isFullscreen: true,
                    frame: CGRect(x: 960, y: 0, width: 960, height: 1080),
                    spaceIDs: [20]
                ),
                AlignerWindow(
                    id: 1,
                    app: leftApp,
                    title: "Left",
                    isFullscreen: true,
                    frame: CGRect(x: 0, y: 0, width: 960, height: 1080),
                    spaceIDs: [20]
                )
            ]
        )
        let viewModel = QuickSwitchViewModelBuilder.viewModel(from: snapshot)
        let space = viewModel.displays.single?.spaces.single
        XCTAssertEqual(space?.splitViewAppNames, ["Left App", "Right App"])
        XCTAssertEqual(space?.appNames, ["Left App", "Right App"])
    }
    func testQuickSwitchViewModelKeepsDuplicateAppNamesForSameAppSplitView() {
        let finder = AlignerApp(bundleIdentifier: "com.apple.finder", name: "访达", category: .finder)
        let displayUUID = "display-a"
        let snapshot = QuickSwitchSnapshotBuilder.snapshot(
            displays: [
                AlignerDisplay(
                    uuid: displayUUID,
                    physical: true,
                    spaces: [
                        AlignerSpace(id: 21, type: .fullscreen, displayUUID: displayUUID, index: 1)
                    ]
                )
            ],
            windows: [
                AlignerWindow(
                    id: 12,
                    app: finder,
                    title: "右侧访达",
                    isFullscreen: true,
                    frame: CGRect(x: 900, y: 0, width: 900, height: 1000),
                    spaceIDs: [21]
                ),
                AlignerWindow(
                    id: 11,
                    app: finder,
                    title: "左侧访达",
                    isFullscreen: true,
                    frame: CGRect(x: 0, y: 0, width: 900, height: 1000),
                    spaceIDs: [21]
                )
            ]
        )
        let viewModel = QuickSwitchViewModelBuilder.viewModel(from: snapshot)
        let space = viewModel.displays.single?.spaces.single
        XCTAssertEqual(space?.splitViewAppNames, ["访达", "访达"])
        XCTAssertEqual(space?.appNames, ["访达"])
    }
    func testQuickSwitchFocusPolicySelectsFirstStableWindowInitially() {
        let app = makeApp()
        let snapshot = QuickSwitchSnapshotBuilder.snapshot(