Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Astra9// File : UITests/AstraUITests.swift10// Module : UITests11// Repository : https://git.spboucher.ai/orix-astra12// Created : 2026-11-2113// Last Modified : 2026-11-2214//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : Proprietary, all rights reserved (see license file)80// License File : LICENSE81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import XCTest8990/// End-to-end checks that need no network and no key: first launch, navigation, provider key sheet, custom endpoint91/// validation. Live cloud and on-device flows are covered by the provider smoke tests and the MLX verification run.92@MainActor93final class AstraUITests: XCTestCase {94 private var app: XCUIApplication!9596 override func setUp() async throws {97 continueAfterFailure = false98 app = XCUIApplication()99 }100101 private func launch(_ arguments: [String]) {102 app.launchArguments = arguments103 app.launch()104 }105106 func testFirstLaunchOnboardingLeadsToTheApp() {107 launch(["-ORIXReset", "YES", "-ORIXInMemory", "YES"])108 XCTAssertTrue(app.staticTexts["ORIX Astra"].waitForExistence(timeout: 30))109 let next = app.buttons["onboarding-continue"]110 XCTAssertTrue(next.exists)111 next.tap()112 XCTAssertTrue(app.staticTexts["Yours, on your device"].waitForExistence(timeout: 5))113 next.tap()114 XCTAssertTrue(app.staticTexts["Your first model"].waitForExistence(timeout: 5))115 next.tap()116 XCTAssertTrue(app.tabBars.buttons["Chat"].waitForExistence(timeout: 10))117 }118119 func testSkipGoesStraightToTheApp() {120 launch(["-ORIXReset", "YES", "-ORIXInMemory", "YES"])121 let skip = app.buttons["onboarding-skip"]122 XCTAssertTrue(skip.waitForExistence(timeout: 30))123 skip.tap()124 XCTAssertTrue(app.tabBars.buttons["Models"].waitForExistence(timeout: 10))125 }126127 func testEveryTabOpens() {128 launch(["-ORIXReset", "YES", "-ORIXInMemory", "YES", "-ORIXSkipOnboarding", "YES"])129 XCTAssertTrue(app.tabBars.buttons["Chat"].waitForExistence(timeout: 30))130 for tab in ["Models", "Arena", "Agents", "Lab", "Chat"] {131 app.tabBars.buttons[tab].tap()132 XCTAssertTrue(app.navigationBars[tab].waitForExistence(timeout: 10), "\(tab) did not open")133 }134 }135136 func testWithoutAModelTheChatTabPointsToModels() {137 launch(["-ORIXReset", "YES", "-ORIXInMemory", "YES", "-ORIXSkipOnboarding", "YES"])138 let open = app.buttons["empty-open-models"]139 // On a device with Apple Intelligence available a model exists already; the test only applies when none does.140 guard open.waitForExistence(timeout: 20) else { return }141 open.tap()142 XCTAssertTrue(app.navigationBars["Models"].waitForExistence(timeout: 10))143 }144145 func testProviderKeySheetNeverKeepsTheKeyOnScreen() {146 launch(["-ORIXReset", "YES", "-ORIXInMemory", "YES", "-ORIXSkipOnboarding", "YES", "-ORIXTab", "models"])147 let provider = app.buttons["provider-anthropic"]148 XCTAssertTrue(provider.waitForExistence(timeout: 30))149 provider.tap()150 let field = app.secureTextFields["key-field"]151 XCTAssertTrue(field.waitForExistence(timeout: 10))152 XCTAssertFalse(app.buttons["key-save"].isEnabled, "saving must be disabled for an empty key")153 field.tap()154 field.typeText("sk-ant-not-a-real-key-000000")155 XCTAssertTrue(app.buttons["key-save"].isEnabled)156 app.buttons["key-save"].tap()157 // The provider rejects the key (or the device is offline): either way the sheet must report a failure, the field158 // must be empty again and the typed value must not be readable anywhere on screen.159 XCTAssertTrue(app.staticTexts["Connection failed"].waitForExistence(timeout: 40))160 XCTAssertFalse(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "not-a-real-key")).firstMatch.exists)161 XCTAssertTrue(app.buttons["key-remove"].exists)162 }163164 func testCustomEndpointRefusesPlainHTTPToAPublicHost() {165 launch(["-ORIXReset", "YES", "-ORIXInMemory", "YES", "-ORIXSkipOnboarding", "YES", "-ORIXTab", "models"])166 let add = app.buttons["add-endpoint"]167 XCTAssertTrue(app.navigationBars["Models"].waitForExistence(timeout: 30))168 // the button sits at the end of a long page: scroll until it can be tapped169 var swipes = 0170 while !(add.exists && add.isHittable), swipes < 8 { app.swipeUp(velocity: .slow); swipes += 1 }171 XCTAssertTrue(add.exists && add.isHittable, "the add-endpoint button never became reachable")172 add.tap()173 let name = app.textFields["endpoint-name"]174 XCTAssertTrue(name.waitForExistence(timeout: 10))175 name.tap(); name.typeText("Lab")176 let url = app.textFields["endpoint-url"]177 url.tap()178 url.press(forDuration: 1.2)179 if app.menuItems["Select All"].waitForExistence(timeout: 2) { app.menuItems["Select All"].tap() }180 url.typeText("http://example.com/v1")181 app.buttons["endpoint-save"].tap()182 XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] %@", "Plain HTTP")).firstMatch.waitForExistence(timeout: 10))183 }184185 /// Real end to end on the iOS runtime: downloads the smallest catalogued model from the mirror, lets the app verify the186 /// SHA-256 of every file, sees it listed as downloaded, then removes it. Needs the network (about 150 MB).187 func testDownloadVerifyAndRemoveTheSmallestModel() {188 launch(["-ORIXReset", "YES", "-ORIXSkipOnboarding", "YES", "-ORIXTab", "models"])189 XCTAssertTrue(app.navigationBars["Models"].waitForExistence(timeout: 30))190 let download = app.buttons["download-SmolLM2-135M-Instruct-8bit"]191 var swipes = 0192 while !(download.exists && download.isHittable), swipes < 10 { app.swipeUp(velocity: .slow); swipes += 1 }193 XCTAssertTrue(download.exists && download.isHittable, "the smallest model's download button was not found")194 download.tap()195 // while it runs, the cell offers Pause; when every file is verified the badge reads "Downloaded"196 let remove = app.buttons["Remove SmolLM2 135M Instruct (8-bit)"].exists ? app.buttons["Remove SmolLM2 135M Instruct (8-bit)"]197 : app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Remove SmolLM2")).firstMatch198 XCTAssertTrue(remove.waitForExistence(timeout: 300), "the model was not installed within five minutes")199 XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", "Downloaded")).firstMatch.exists)200 remove.tap()201 let confirm = app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Remove and free")).firstMatch202 XCTAssertTrue(confirm.waitForExistence(timeout: 10))203 confirm.tap()204 XCTAssertTrue(download.waitForExistence(timeout: 30), "after removal the model should be downloadable again")205 }206}207