Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Tests/UITests/ResearchUITests.swift3// Description: UI tests of Research 2.0 by CLICKS on the VQuant Next test backend (5058, development session): the Studies scope and a study's six inspector tabs, the model picker (Auto), the Research mode, a stored conversation and its trace sheet. No test sends a question: no model is called.4import XCTest56final class ResearchUITests: 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 app.launchArguments = ["-VQUITest", "-VQInMemory", "-ApplePersistenceIgnoreState", "YES"] + extra12 app.launchEnvironment = ["VQ_DEV_TOKEN": token, "VQ_SERVER": server]13 app.launch()14 XCTAssertTrue(app.windows.firstMatch.waitForExistence(timeout: 20))15 return app16 }17 private func el(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch }18 private func text(_ e: XCUIElement) -> String { (e.value as? String).flatMap { $0.isEmpty ? nil : $0 } ?? e.label }1920 /// Sidebar → Research → Studies → a study row → the cockpit's inspector, tab by tab.21 func testStudiesScopeAndInspectorTabs() throws {22 let app = try launch()23 el(app, "sidebar.research").click()24 let studies = el(app, "scope.studies")25 XCTAssertTrue(studies.waitForExistence(timeout: 10))26 studies.click()27 let row = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'study.'")).firstMatch28 guard row.waitForExistence(timeout: 15) else { throw XCTSkip("the test backend holds no research workspace yet (run the integration tests once: they create one)") }29 row.click()30 XCTAssertTrue(el(app, "inspector.tab.activite").waitForExistence(timeout: 15), "clicking a study shows the research cockpit")31 for tab in ["code", "experiences", "figures", "fichiers", "environnement", "activite"] {32 let t = el(app, "inspector.tab.\(tab)")33 XCTAssertTrue(t.waitForExistence(timeout: 5), "tab \(tab) exists")34 t.click()35 let deadline = Date().addingTimeInterval(4)36 while !t.isSelected, Date() < deadline { usleep(150_000) }37 XCTAssertTrue(t.isSelected, "clicking \(tab) selects it")38 }39 // the inspector can be folded away and brought back40 el(app, "conversation.inspector").click()41 XCTAssertFalse(el(app, "inspector.tab.activite").waitForExistence(timeout: 2))42 el(app, "conversation.inspector").click()43 XCTAssertTrue(el(app, "inspector.tab.activite").waitForExistence(timeout: 5))44 }4546 /// The composer: the model picker reads the server registry and Auto can be chosen; the Research mode explains itself.47 func testModelPickerAutoAndResearchMode() throws {48 let app = try launch()49 el(app, "sidebar.research").click()50 let model = el(app, "composer.model")51 XCTAssertTrue(model.waitForExistence(timeout: 10))52 // a popover closes when another process takes the screen (several UI test suites share it): a few attempts53 var picked = false, listedRegistry = false, fallback = false54 for _ in 0..<4 where !picked {55 app.activate()56 if !el(app, "model.auto").exists { model.click() }57 let auto = el(app, "model.auto")58 guard auto.waitForExistence(timeout: 8) else { continue }59 guard el(app, "model.claude-sonnet-5-5").waitForExistence(timeout: 8) else { continue }60 listedRegistry = true; fallback = el(app, "model.notice").exists61 guard auto.exists else { continue }62 auto.click(); picked = true63 }64 XCTAssertTrue(listedRegistry, "the picker lists Auto first, then the models of the server registry")65 XCTAssertFalse(fallback, "the registry was read (no fallback notice)")66 XCTAssertTrue(picked, "Auto was clicked")67 let deadline = Date().addingTimeInterval(5)68 while !(model.label.contains("Auto") || app.staticTexts["Auto"].exists), Date() < deadline { usleep(150_000) }69 XCTAssertTrue(model.label.contains("Auto") || app.staticTexts["Auto"].exists, "Auto is now the composer's model")70 let research = el(app, "mode.research")71 XCTAssertTrue(research.waitForExistence(timeout: 5))72 research.click()73 let detail = el(app, "composer.modeDetail")74 XCTAssertTrue(detail.waitForExistence(timeout: 5))75 XCTAssertTrue(text(detail).hasPrefix("Research"), "the Research mode is explained in one line (\(text(detail)))")76 // back to the defaults the other tests expect (mode and model are synced preferences of the test account)77 el(app, "mode.standard").click()78 model.click()79 let fable = el(app, "model.claude-fable-5-2")80 if fable.waitForExistence(timeout: 8) { fable.click() }81 }8283 /// A stored conversation opens by click and its trace sheet opens and closes.84 func testStoredConversationAndTraceSheet() throws {85 let app = try launch()86 el(app, "sidebar.research").click()87 let row = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'session.'")).firstMatch88 XCTAssertTrue(row.waitForExistence(timeout: 15), "the conversation list is filled")89 row.click()90 let trace = el(app, "conversation.trace")91 XCTAssertTrue(trace.waitForExistence(timeout: 15), "the conversation opened (its header offers the trace)")92 trace.click()93 let done = el(app, "trace.done")94 XCTAssertTrue(done.waitForExistence(timeout: 10), "the trace sheet is shown")95 done.click()96 XCTAssertFalse(el(app, "trace.done").waitForExistence(timeout: 2))97 }98}99