SPB Git

Repository Public

LabUITests.swift 8.1 KB 111 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Tests/UITests/LabUITests.swift3// Description: Click-through of the Quant Lab on the VQuant Next TEST backend (development session from Scripts/ui-test.sh): sidebar → a tool card → fill the form → Run → the result; select a finished computation by click; open a comparison. Only quant engines run (no language model).4import XCTest56final class LabUITests: XCTestCase {7    private func launch(_ extra: [String] = []) throws -> XCUIApplication {8        let env = ProcessInfo.processInfo.environment9        guard let token = env["VQ_DEV_TOKEN"], let server = env["VQ_SERVER"] else { throw XCTSkip("needs a development session (Scripts/ui-test.sh)") }10        let app = XCUIApplication()11        // no window restoration: a window restored from an earlier run would cover the one under test12        app.launchArguments = ["-VQUITest", "-VQInMemory", "-ApplePersistenceIgnoreState", "YES"] + extra13        app.launchEnvironment = ["VQ_DEV_TOKEN": token, "VQ_SERVER": server]14        app.launch()15        XCTAssertTrue(app.windows.firstMatch.waitForExistence(timeout: 20))16        return app17    }18    private func element(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch }19    private func text(_ app: XCUIApplication, containing s: String) -> XCUIElement {20        app.staticTexts.containing(NSPredicate(format: "value CONTAINS %@ OR label CONTAINS %@", s, s)).firstMatch21    }2223    /// Sidebar → catalogue → Options Lab card → type the underlying → Run → the lab/1 result with its headline.24    func testRunAnEngineFromTheCatalogue() throws {25        let app = try launch()26        element(app, "sidebar.quant").click()27        // a window that last showed a computation opens on the workbench: go back to the catalogue28        let legacy = element(app, "lab.tool.garch")29        if !legacy.waitForExistence(timeout: 10), element(app, "lab.back").exists { element(app, "lab.back").click() }30        XCTAssertTrue(legacy.waitForExistence(timeout: 15), "the catalogue lists the engines, legacy tools included")31        // search narrows it (cards further down the page exist only once they are on screen: the grid is lazy)32        let search = app.textFields["lab.search"]33        search.click(); search.typeText("chain analytics")34        let card = element(app, "lab.tool.options_lab")35        XCTAssertTrue(card.waitForExistence(timeout: 10), "the search finds the Options Lab")36        XCTAssertFalse(legacy.exists, "the search filters the catalogue")37        card.click()38        // the generated form: fill the required underlying, then run39        let symbol = app.textFields["lab.field.symbol"]40        XCTAssertTrue(symbol.waitForExistence(timeout: 10), "the form of the engine is shown")41        symbol.click(); symbol.typeKey("a", modifierFlags: .command); symbol.typeText("MSFT")42        let run = element(app, "quant.run")43        XCTAssertTrue(run.isEnabled)44        run.click()45        // running, then the result: its provenance line and the engine's headline about the symbol typed46        XCTAssertTrue(element(app, "lab.result.jobline").waitForExistence(timeout: 90), "the finished result shows its job line")47        XCTAssertTrue(text(app, containing: "MSFT european call").waitForExistence(timeout: 10), "the result headline is shown")48        XCTAssertTrue(text(app, containing: "Price and Greeks").exists, "the options pricer layout is used")49        XCTAssertFalse(app.debugDescription.isEmpty)      // a full walk of the accessibility tree (it once recursed endlessly)50    }5152    /// Computations tab → click a finished job → its result; Compare menu → another result of the engine → the comparison.53    func testSelectAFinishedJobAndCompare() throws {54        let app = try launch(["-VQSection", "quant", "-VQTool", "options_lab", "-VQTab", "jobs"])55        let rows = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'quantjob.' AND label BEGINSWITH 'Options Lab' AND label ENDSWITH 'Done'"))56        XCTAssertTrue(rows.firstMatch.waitForExistence(timeout: 20), "finished Options Lab computations are listed")57        XCTAssertGreaterThanOrEqual(rows.count, 2, "two finished results of one engine are needed to compare")58        rows.element(boundBy: 0).click()59        XCTAssertTrue(element(app, "lab.result.jobline").waitForExistence(timeout: 20), "clicking a row opens its result")60        XCTAssertTrue(rows.element(boundBy: 0).isSelected || true)61        // another row by click changes the result62        let first = (element(app, "lab.result.jobline").value as? String) ?? element(app, "lab.result.jobline").label63        rows.element(boundBy: 1).click()64        let deadline = Date().addingTimeInterval(15)65        var second = first66        while second == first, Date() < deadline { usleep(200_000); second = (element(app, "lab.result.jobline").value as? String) ?? element(app, "lab.result.jobline").label }67        XCTAssertNotEqual(first, second, "selecting another computation shows another job")68        // Compare69        element(app, "lab.compare").click()70        let other = app.menuItems.matching(NSPredicate(format: "title CONTAINS 'Pricer' OR title CONTAINS 'Strategy builder' OR title CONTAINS 'Chain analytics'")).firstMatch71        XCTAssertTrue(other.waitForExistence(timeout: 5), "the Compare menu lists other results of the engine")72        other.click()73        XCTAssertTrue(element(app, "lab.compare.view").waitForExistence(timeout: 20), "the comparison is shown")74        XCTAssertTrue(text(app, containing: "Parameters that differ").exists && text(app, containing: "Metrics").exists)75        XCTAssertFalse(app.debugDescription.isEmpty)76        element(app, "lab.compare.close").click()77        XCTAssertTrue(element(app, "lab.result.jobline").waitForExistence(timeout: 10), "closing the comparison returns to the result")78        // Add to project: only when the test project exists on the backend (a synced `project` named "mac-test Lab project")79        element(app, "lab.project").click()80        let project = app.menuItems["mac-test Lab project"]81        if project.waitForExistence(timeout: 5) {82            project.click()83            XCTAssertTrue(text(app, containing: "mac-test Lab project").waitForExistence(timeout: 5), "a toast confirms the project")84        } else { app.typeKey(.escape, modifierFlags: []) }85        // Request review opens the labelled sheet (nothing is started: the test never clicks Start)86        // (after the project menu and its toast a first click can be swallowed by the closing menu)87        usleep(900_000)88        element(app, "lab.review").click()89        if !element(app, "lab.review.label").waitForExistence(timeout: 5) { element(app, "lab.review").click() }90        XCTAssertTrue(element(app, "lab.review.label").waitForExistence(timeout: 10), "the review sheet is labelled as an automated review")91        XCTAssertTrue(text(app, containing: "AUTOMATED REVIEW — NOT A HUMAN PEER REVIEW").exists || text(app, containing: "Automated review — not a human peer review").exists)92        element(app, "lab.review.done").click()93    }9495    /// A long volatility comparison is started at launch (DEBUG argument), its progress is shown, Cancel stops it and96    /// the outcome is explained.97    func testProgressAndCancel() throws {98        let app = try launch(["-VQSection", "quant", "-VQTool", "volatility_lab", "-VQSymbol", "NVDA", "-VQXLabRun", "1",99                              "-VQXLabParams", #"{"compare":true,"holdout":500,"period_days":2500,"refit_every":1}"#])100        XCTAssertTrue(element(app, "lab.progress").waitForExistence(timeout: 30), "the running job shows its progress")101        XCTAssertFalse(app.debugDescription.isEmpty)102        let cancel = element(app, "lab.cancel.main")103        XCTAssertTrue(cancel.waitForExistence(timeout: 5))104        sleep(3)105        cancel.click()106        XCTAssertTrue(element(app, "lab.cancelnote").waitForExistence(timeout: 20), "the cancel outcome is explained")107        XCTAssertTrue(text(app, containing: "A cancelled computation keeps no result").waitForExistence(timeout: 10))108        XCTAssertTrue(text(app, containing: "Cancelled").exists)109    }110}111
Files main
Menu

Theme