Ariver
2026-06-04 933e0a66306b7bd53d67f48834cb7f56f5cd8d1b
C1.source/Tests/AlignerCoreTests/AlignerCoreTests.swift
@@ -244,6 +244,76 @@
        XCTAssertEqual(window?.title, "Visible Document.md")
    }
    func testWindowEnumerationPolicyKeepsKnownCGOnlyOffscreenMainWindows() {
        let hbuilderApp = AlignerApp(
            bundleIdentifier: "io.dcloud.HBuilderX",
            name: "HBuilderX",
            category: .editorIDE
        )
        let record = WindowEnumerationRecord(
            id: 55_388,
            app: hbuilderApp,
            title: "lm-app - HBuilder X 5.07",
            size: CGSize(width: 1048, height: 796),
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        let emptyTitleRecord = WindowEnumerationRecord(
            id: 55_389,
            app: hbuilderApp,
            title: "",
            size: CGSize(width: 1048, height: 796),
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        let tinyRecord = WindowEnumerationRecord(
            id: 55_390,
            app: hbuilderApp,
            title: "HBuilderX Utility",
            size: CGSize(width: 80, height: 40),
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        XCTAssertEqual(WindowEnumerationPolicy.window(from: record)?.title, "lm-app - HBuilder X 5.07")
        XCTAssertNil(WindowEnumerationPolicy.window(from: emptyTitleRecord))
        XCTAssertNil(WindowEnumerationPolicy.window(from: tinyRecord))
    }
    func testWindowEnumerationPolicyKeepsShottrCGOnlyAnnotationWindow() {
        let shottrApp = AlignerApp(
            bundleIdentifier: "cc.ffitch.shottr",
            name: "Shottr",
            category: .generic
        )
        let annotationRecord = WindowEnumerationRecord(
            id: 78,
            app: shottrApp,
            activationPolicy: .accessory,
            title: "Shottr",
            size: CGSize(width: 1710, height: 997),
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        let utilityRecord = WindowEnumerationRecord(
            id: 102,
            app: shottrApp,
            activationPolicy: .accessory,
            title: "Colors",
            size: CGSize(width: 250, height: 397),
            subrole: .standard,
            hasAXBacking: false,
            isOnscreen: false
        )
        XCTAssertEqual(WindowEnumerationPolicy.window(from: annotationRecord)?.title, "Shottr")
        XCTAssertNil(WindowEnumerationPolicy.window(from: utilityRecord))
    }
    func testWindowEnumerationPolicyKeepsMinimizedAndFullscreenCGOnlyOffscreenWindows() {
        let minimized = makeWindowRecord(
            title: "Minimized Document.md",
@@ -1085,6 +1155,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(