SPB Git

Repository Public

SPChatUITests.swift 8.4 KB 131 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: SPChat/Tests/UITests/SPChatUITests.swift3// Description: End-to-end UI tests on the real app against the DEVELOPMENT backend: history, sending with live streaming, palette, settings, windows, offline.4import XCTest56/// Needs `SPCHAT_SERVER` (loopback) and `SPCHAT_SESSION_COOKIE` in the runner environment — see Scripts/ui-test.sh.7final class SPChatUITests: XCTestCase {8    private var server: String { ProcessInfo.processInfo.environment["SPCHAT_SERVER"] ?? "" }9    private var cookie: String { ProcessInfo.processInfo.environment["SPCHAT_SESSION_COOKIE"] ?? "" }1011    override func setUpWithError() throws {12        continueAfterFailure = false13        try XCTSkipIf(server.isEmpty || cookie.isEmpty, "development backend not configured (run Scripts/ui-test.sh)")14    }1516    @MainActor private func launch(server: String? = nil, extra: [String] = []) -> XCUIApplication {17        let app = XCUIApplication()18        app.launchArguments = ["-SPChatUITest", "-SPChatInMemory", "-ApplePersistenceIgnoreState", "YES"] + extra19        app.launchEnvironment = ["SPCHAT_SERVER": server ?? self.server, "SPCHAT_SESSION_COOKIE": cookie]20        app.launch()21        return app22    }2324    @MainActor func testHistorySendStreamPaletteSettingsAndWindows() throws {25        let app = launch()26        // signed in with the injected development session: the shared history is listed27        let list = app.outlines["sidebar-list"].firstMatch28        XCTAssertTrue(list.waitForExistence(timeout: 20), "sidebar")29        XCTAssertTrue(app.staticTexts["Espace de travail"].waitForExistence(timeout: 10))30        XCTAssertTrue(app.descendants(matching: .any)["welcome"].waitForExistence(timeout: 10), "empty conversation shows the welcome screen")3132        // type and send with Return; the answer streams in and settles33        let composer = app.textViews["composer-text"].firstMatch34        XCTAssertTrue(composer.waitForExistence(timeout: 10))35        composer.click(); composer.typeText("Reponds uniquement par le mot OK.\n")36        let answer = app.descendants(matching: .any).matching(identifier: "message-assistant").firstMatch37        XCTAssertTrue(answer.waitForExistence(timeout: 60), "assistant answer appears")38        let done = NSPredicate { _, _ in !app.buttons["stop"].exists && app.buttons["send"].exists }39        wait(for: [expectation(for: done, evaluatedWith: nil)], timeout: 90)40        XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "value CONTAINS[c] 'OK' OR label CONTAINS[c] 'OK'")).firstMatch.exists, "the answer text is on screen")41        XCTAssertFalse(app.descendants(matching: .any)["chat-error"].exists)4243        // menu state follows the focused conversation44        XCTAssertTrue(app.menuBars.menuItems["Régénérer la dernière réponse"].isEnabled, "conversation commands are enabled for the frontmost chat")45        XCTAssertFalse(app.menuBars.menuItems["Arrêter la génération"].isEnabled)4647        // ⌘K palette → Utilisation48        app.typeKey("k", modifierFlags: .command)49        let field = app.textFields["palette-field"].firstMatch50        XCTAssertTrue(field.waitForExistence(timeout: 5), "command palette opens with ⌘K")51        field.typeText("Utilisation\n")52        XCTAssertTrue(app.descendants(matching: .any)["usage-screen"].waitForExistence(timeout: 15), "palette navigates to the usage dashboard")5354        // ⌘N → new conversation ; ⌘F → search field focused55        app.typeKey("n", modifierFlags: .command)56        XCTAssertTrue(app.descendants(matching: .any)["welcome"].waitForExistence(timeout: 10), "⌘N opens a new conversation")57        app.typeKey("f", modifierFlags: .command)58        app.typeText("OK")59        XCTAssertEqual(app.textFields["sidebar-search"].firstMatch.value as? String, "OK", "⌘F puts the cursor in the search field")60        app.textFields["sidebar-search"].firstMatch.typeKey("a", modifierFlags: .command); app.typeKey(.delete, modifierFlags: [])6162        // ⌘, → native settings window ; ⇧⌘N → a second main window63        app.typeKey(",", modifierFlags: .command)64        XCTAssertTrue(app.staticTexts["Apparence"].waitForExistence(timeout: 8), "settings window")65        app.typeKey("w", modifierFlags: .command)66        let before = app.windows.count67        app.typeKey("n", modifierFlags: [.command, .shift])68        let more = NSPredicate { _, _ in app.windows.count > before }69        wait(for: [expectation(for: more, evaluatedWith: nil)], timeout: 8)70        app.terminate()71    }7273    /// 2.0 surfaces on the real app and the real development backend: slash commands, model picker over the whole74    /// catalogue, web toggle, Command Center, Explorer, Arena, Constellation, contextual panel. No model is called.75    @MainActor func testNextGenSurfaces() throws {76        let app = launch()77        let composer = app.textViews["composer-text"].firstMatch78        XCTAssertTrue(composer.waitForExistence(timeout: 20))79        // « / » opens the commands above the capsule; Escape clears the command line80        composer.click(); composer.typeText("/")81        XCTAssertTrue(app.descendants(matching: .any)["command-list"].waitForExistence(timeout: 8), "slash commands")82        XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "command-item").firstMatch.exists)83        composer.typeKey(.escape, modifierFlags: [])84        XCTAssertEqual(composer.value as? String, "", "Escape leaves the command mode")8586        // model picker: instant search over the whole catalogue, OpenRouter models included87        app.typeKey("m", modifierFlags: [.command, .shift])88        let search = app.textFields["model-search"].firstMatch89        XCTAssertTrue(search.waitForExistence(timeout: 8), "⇧⌘M opens the model picker")90        search.typeText("gemini")91        let row = app.descendants(matching: .any).matching(identifier: "model-row").firstMatch92        XCTAssertTrue(row.waitForExistence(timeout: 8), "catalogue models are listed")93        search.typeKey(.escape, modifierFlags: [])9495        // web search toggle of the next turn96        let web = app.buttons["web-toggle"].firstMatch97        XCTAssertTrue(web.waitForExistence(timeout: 5)); web.click()98        XCTAssertEqual(web.value as? String, "activée"); web.click()99100        // Command Center → Explorer ; menu shortcuts → Arena, Constellation101        app.typeKey("k", modifierFlags: .command)102        let field = app.textFields["palette-field"].firstMatch103        XCTAssertTrue(field.waitForExistence(timeout: 5)); field.typeText("Explorer le catalogue\n")104        XCTAssertTrue(app.descendants(matching: .any)["explorer-search"].waitForExistence(timeout: 15), "Explorer")105        app.typeKey("a", modifierFlags: [.command, .option])106        XCTAssertTrue(app.descendants(matching: .any)["arena-history"].waitForExistence(timeout: 10), "Arena")107        app.typeKey("g", modifierFlags: [.command, .option])108        XCTAssertTrue(app.descendants(matching: .any)["constellation-limit"].waitForExistence(timeout: 15), "Constellation")109110        // back to a conversation: the contextual panel opens on its tabs111        app.typeKey("n", modifierFlags: .command)112        XCTAssertTrue(app.descendants(matching: .any)["welcome"].waitForExistence(timeout: 10))113        app.typeKey("t", modifierFlags: [.command, .option])114        XCTAssertTrue(app.descendants(matching: .any)["context-panel"].waitForExistence(timeout: 8), "contextual panel")115        app.terminate()116    }117118    @MainActor func testOfflineLaunchKeepsTheAppUsableAndSaysSo() throws {119        // nothing listens on this loopback port: the server is unreachable120        let app = launch(server: "http://localhost:9")121        XCTAssertTrue(app.outlines["sidebar-list"].firstMatch.waitForExistence(timeout: 20), "the app opens with its stored session even when the server is unreachable")122        XCTAssertTrue(app.descendants(matching: .any)["offline-indicator"].waitForExistence(timeout: 15), "the sidebar says the list comes from the local cache")123        let composer = app.textViews["composer-text"].firstMatch124        XCTAssertTrue(composer.waitForExistence(timeout: 10))125        composer.click(); composer.typeText("Message hors ligne\n")126        XCTAssertTrue(app.descendants(matching: .any)["chat-error"].waitForExistence(timeout: 40), "the failure is explained")127        XCTAssertEqual(composer.value as? String, "Message hors ligne", "the text went back to the composer: nothing lost")128        app.terminate()129    }130}131
Files main
Menu

Theme