SPB Git

Repository Public

ORIXDJUITests.swift 12.5 KB 256 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX DJ9// File             : UITests/ORIXDJUITests.swift10// Description      : End-to-end interface tests on an isolated, silent instance11//                    (real engine rendering, no audio device, synthesised demo12//                    tracks): navigation, transport, mixer, effects, console,13//                    simulator, documentation, recording, live-run confirmation14//                    and emergency stop.15// Module           : UITests16// Repository       : https://git.spboucher.ai/orix-dj17// Created          : 2026-11-2118// Last Modified    : 2026-11-2119//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author           : Simon-Pierre Boucher25// Position         : Professor of Finance26// Institution      : Université du Québec en Outaouais (UQO)27// Department       : Département des sciences administratives28// Organization     : SP Boucher29//30// Website          : https://spboucher.ai31// Git              : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General          : info@spboucher.ai38// Professional     : contact@spboucher.ai39// Direct           : simon@spboucher.ai40// Research         : research@spboucher.ai41// Development      : dev@spboucher.ai42// Support          : support@spboucher.ai43// Security/Admin   : admin@spboucher.ai44// Notifications    : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification   : Public71// Distribution     : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License          : None specified (no license file in this repository)85// Maintainer       : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import XCTest9394@MainActor95final class ORIXDJUITests: XCTestCase {96    var app: XCUIApplication!9798    override func setUp() async throws {99        continueAfterFailure = false100        app = XCUIApplication()101        let data = "/tmp/orixdj-uitest-\(UUID().uuidString)"102        app.launchArguments = ["-ORIXDataDir", data, "-ORIXSilent", "YES", "-ORIXDemo", "YES", "-AppleLanguages", "(en)", "-AppleLocale", "en_US", "-ApplePersistenceIgnoreState", "YES", "-ORIXStderr", "/tmp/orixdj-uitest-stderr.log"]103    }104105    override func tearDown() async throws { app?.terminate() }106107    private func launch(_ extra: [String] = []) {108        app.launchArguments += extra109        app.launch()110        XCTAssertTrue(app.windows.firstMatch.waitForExistence(timeout: 20))111    }112113    /// Polls a condition without XCTest expectations (which are not concurrency-safe under Swift 6).114    private func waitUntil(_ timeout: TimeInterval, _ what: String, _ condition: () -> Bool, file: StaticString = #filePath, line: UInt = #line) {115        let end = Date().addingTimeInterval(timeout)116        while Date() < end { if condition() { return }; usleep(150_000) }117        XCTFail("timed out waiting for: \(what)", file: file, line: line)118    }119120    private func element(_ id: String) -> XCUIElement { app.descendants(matching: .any).matching(identifier: id).firstMatch }121122    private func open(_ section: String) { let b = app.buttons["section-\(section)"]; XCTAssertTrue(b.waitForExistence(timeout: 10), section); b.click() }123124    /// Diagnostic: prints the accessibility tree of every section (run on demand with -only-testing).125    func testZDumpAccessibilityTree() throws {126        try XCTSkipUnless(ProcessInfo.processInfo.environment["ORIX_AX_DUMP"] == "1", "diagnostic only")127        launch()128        for section in ["studio", "library", "effects", "autoDJ", "automation", "docs", "claude", "recording", "midi", "performance"] {129            open(section); sleep(3)130            print("AXDUMP-BEGIN \(section)\n" + app.windows.firstMatch.debugDescription + "\nAXDUMP-END")131        }132        // Sub-panels of the Automation Studio.133        open("automation")134        for tab in ["simulator", "debugger", "problems", "log", "monitor", "console"] {135            let b = element("automation-tab-\(tab)")136            if b.waitForExistence(timeout: 5) { b.click(); sleep(2); print("AXDUMP-BEGIN automation_\(tab)\n" + app.windows.firstMatch.debugDescription + "\nAXDUMP-END") }137        }138        for mode in ["Presets", "Visual Builder", "Editor"] {139            let b = app.radioButtons[mode].firstMatch140            if b.waitForExistence(timeout: 3) { b.click(); sleep(2); print("AXDUMP-BEGIN automation_mode_\(mode.replacingOccurrences(of: " ", with: ""))\n" + app.windows.firstMatch.debugDescription + "\nAXDUMP-END") }141        }142    }143144    func testEverySectionOpens() {145        launch()146        for (section, root) in [("library", "library-root"), ("effects", "effects-rack"), ("autoDJ", "autodj-root"), ("automation", "automation-studio"), ("docs", "docs-root"),147                                ("claude", "claude-root"), ("recording", "recording-root"), ("midi", "midi-root"), ("performance", "performance"), ("studio", "studio")] {148            open(section)149            XCTAssertTrue(element(root).waitForExistence(timeout: 10), "\(section) did not show \(root)")150        }151    }152153    func testTransportDrivesTheEngine() {154        launch()155        // The demo loads deck B paused; wait until its play button is enabled.156        let play = app.buttons["play-B"]157        XCTAssertTrue(play.waitForExistence(timeout: 20))158        waitUntil(30, "deck B loaded") { play.isEnabled }159        XCTAssertEqual(play.label, "Play deck B")160        play.click()161        waitUntil(5, "deck B playing") { play.label == "Pause deck B" }162        // Sync and key lock latch.163        let sync = app.buttons["sync-B"]164        sync.click()165        XCTAssertEqual(sync.value as? String, "on")166        app.buttons["cue-B"].click()167        waitUntil(5, "deck B paused by cue") { play.label == "Play deck B" }168        // Deck A was started by the demo.169        XCTAssertEqual(app.buttons["play-A"].label, "Pause deck A")170    }171172    func testConsoleExecutesRealCommands() {173        launch(["-ORIXSection", "automation", "-ORIXAutomationTab", "console"])174        let input = element("automation-console-input")175        XCTAssertTrue(input.waitForExistence(timeout: 15))176        input.click()177        input.typeText("deck.B.volume = -8dB\n")178        input.typeText("deck.B.volume\n")179        let output = element("automation-console-output")180        XCTAssertTrue(output.waitForExistence(timeout: 5))181        XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "value CONTAINS '-8 dB' OR label CONTAINS '-8 dB'")).firstMatch.waitForExistence(timeout: 5), "the console did not print the value read back from the engine")182        input.typeText("deck.Z.play()\n")183        XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "value CONTAINS 'E-DECK' OR label CONTAINS 'E-DECK'")).firstMatch.waitForExistence(timeout: 5))184    }185186    func testSimulatorRunsAPreset() {187        launch(["-ORIXSection", "automation", "-ORIXAutomationTab", "simulator", "-ORIXAutomationPreset", "Eight Bar Transition"])188        XCTAssertTrue(element("automation-simulator").waitForExistence(timeout: 20))189        // The preset was simulated at launch: the outcome line reports a finished run.190        XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "value CONTAINS[c] 'finished' OR label CONTAINS[c] 'finished'")).firstMatch.waitForExistence(timeout: 15), "no simulation outcome shown")191    }192193    func testLiveRunAsksBeforeTouchingAPlayingMix() {194        launch(["-ORIXSection", "automation", "-ORIXAutomationPreset", "Filter Sweep"])195        // Deck A is playing: Run must ask first.196        let run = element("automation-run")197        XCTAssertTrue(run.waitForExistence(timeout: 20))198        sleep(6)199        run.click()200        let confirm = app.buttons["Run on the Live Mix"]201        XCTAssertTrue(confirm.waitForExistence(timeout: 10), "no confirmation before running on a playing mix")202        confirm.click()203        XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "(label CONTAINS 'automation' AND label CONTAINS 'running') OR (value CONTAINS 'automation' AND value CONTAINS 'running')")).firstMatch.waitForExistence(timeout: 8), "the status strip does not report the running automation")204        element("emergency-stop").click()205        XCTAssertTrue(element("notice").waitForExistence(timeout: 5))206    }207208    func testDocumentationSearch() {209        launch(["-ORIXSection", "docs"])210        let search = element("docs-search")211        XCTAssertTrue(search.waitForExistence(timeout: 15))212        search.click()213        search.typeText("crossfader")214        XCTAssertTrue(element("docs-search-results").waitForExistence(timeout: 8))215        XCTAssertTrue(element("docs-search-hit").waitForExistence(timeout: 8))216    }217218    func testRecordingShowsAnIndicatorAndStops() {219        launch(["-ORIXSection", "recording"])220        let toggle = element("recording-toggle")221        XCTAssertTrue(toggle.waitForExistence(timeout: 15))222        XCTAssertFalse(element("record-indicator").exists, "the recording indicator is visible while nothing is recorded")223        toggle.click()224        XCTAssertTrue(element("record-indicator").waitForExistence(timeout: 5), "recording started without the indicator")225        sleep(3)226        toggle.click()227        waitUntil(8, "recording indicator gone") { !element("record-indicator").exists }228        XCTAssertTrue(element("recording-takes").waitForExistence(timeout: 5))229    }230231    func testEffectsRack() {232        launch(["-ORIXSection", "effects"])233        let add = element("effects-add")234        XCTAssertTrue(add.waitForExistence(timeout: 15))235        add.click()236        app.menuItems["Echo"].click()237        let power = element("effect-power-echo")238        XCTAssertTrue(power.waitForExistence(timeout: 5))239        XCTAssertEqual(power.value as? String, "off")240        power.click()241        waitUntil(5, "echo on") { power.value as? String == "on" }242        // Emergency stop bypasses it again.243        element("emergency-stop").click()244        waitUntil(5, "echo bypassed") { power.value as? String == "off" }245    }246247    func testClaudeStudioWithoutAKeyExplainsItself() {248        launch(["-ORIXSection", "claude"])249        XCTAssertTrue(element("claude-open-settings").waitForExistence(timeout: 15), "without a key Claude Studio must show its setup state")250        XCTAssertFalse(element("claude-send").exists, "the request form must not be offered without a key")251        // Everything else still works without a key.252        open("studio")253        XCTAssertTrue(app.buttons["play-A"].waitForExistence(timeout: 10))254    }255}256
Files main
Menu

Theme