// An agent in a chat on iPhone (chat CONTRACT.md "An agent in a chat", "The iPhone's half"), on Comms Dev's seed:// Hill trip holds Bimal's Claude. The group's page offers Add an agent under Add people, lists the agents after the// people with whose agent each is, adds his own Claude from the core's choices and removes it again; with no// assistant connected, Add an agent says to connect one; an agent's words stand on the left under the agent mark,// with whose agent wrote them.import XCTestfinalclassChatAgentTests: XCTestCase {privatelet hillTrip = "11111111-1111-4111-8111-0000000000b1"overridefunc setUp() { continueAfterFailure = false } @MainActor privatefunc launched(_ extra: [String]) -> XCUIApplication {let app = XCUIApplication() app.launchArguments += ["-chat-warm-seed", "YES"] + extra app.launch()return app } @MainActor privatefunc id(_ app: XCUIApplication, _ identifier: String) -> XCUIElement { app.descendants(matching: .any).matching(identifier: identifier).firstMatch }/// Scrolls the page until `element` is on screen. @MainActor privatefunc reach(_ app: XCUIApplication, _ element: XCUIElement) {var left = 10while left > 0, !(element.exists && element.isHittable) { app.swipeUp(velocity: .slow) left -= 1 } }// RULE: the group's page lists its agents after the people, each with whose agent it is; Add an agent stands under// Add people and offers his own Claude; added, it stands first ("Your agent"); tapped, Remove takes it out. @MainActor func testAddAndRemoveYourClaude() {let app = launched(["-chat-warm-open", hillTrip, "-chat-warm-person", "YES"])let add = app.buttons["chat-group-add-agent"] XCTAssertTrue(add.waitForExistence(timeout: 30), "Add an agent stands on the group's page") XCTAssertEqual(add.label, "Add an agent")let people = app.buttons["chat-group-add"] XCTAssertTrue(people.exists) XCTAssertGreaterThan(add.frame.minY, people.frame.maxY - 1, "under Add people")let bimals = id(app, "chat-group-agent-agent-bimal") reach(app, bimals) XCTAssertTrue(bimals.exists, "Bimal's Claude is in the list") XCTAssertTrue(bimals.label.contains("Claude") && bimals.label.contains("Bimal Rao's agent"), bimals.label) XCTAssertGreaterThan(bimals.frame.minY, app.buttons["chat-group-member-+15550100123"].frame.maxY - 1, "after the people") app.swipeDown(velocity: .fast) add.tap()let mine = id(app, "chat-group-agent-choice-agent-mine") XCTAssertTrue(mine.waitForExistence(timeout: 10), "his own Claude is offered") mine.tap()let added = id(app, "chat-group-agent-agent-mine") XCTAssertTrue(added.waitForExistence(timeout: 10), "added, it is in the list") reach(app, added) XCTAssertTrue(added.label.contains("Your agent"), added.label) XCTAssertLessThan(added.frame.minY, bimals.frame.minY, "his own first") added.tap()let remove = id(app, "look-ask-chat-group-agent-remove") XCTAssertTrue(remove.waitForExistence(timeout: 5), "Remove from chat is offered") XCTAssertEqual(remove.label, "Remove from chat") remove.tap() XCTAssertTrue(added.waitForNonExistence(timeout: 10), "removed, it is gone from the list") XCTAssertTrue(bimals.exists, "and Bimal's stays") }// RULE: with no assistant connected, Add an agent says to connect one first, in the core's words. @MainActor func testAddAnAgentSaysToConnectOneFirst() {let app = launched(["-chat-warm-open", hillTrip, "-chat-warm-person", "YES", "-chat-warm-agent", "connect"])let add = app.buttons["chat-group-add-agent"] XCTAssertTrue(add.waitForExistence(timeout: 30)) add.tap()let line = id(app, "chat-group-agent-connect") XCTAssertTrue(line.waitForExistence(timeout: 10), "the line to connect one") XCTAssertEqual(line.label, "Connect Claude first, under You → Your Claude.") }// RULE: an agent's words stand on the left, under the agent mark (seen in the kept picture), never as his own, and// are heard with its name and whose agent it is. @MainActor func testAnAgentsWordsWearTheMark() {let app = launched(["-chat-warm-open", hillTrip])let words = app.descendants(matching: .any)["chat-bubble-m-w12"].firstMatch XCTAssertTrue(words.waitForExistence(timeout: 30), "the agent's words stand in the chat") XCTAssertTrue(words.label.hasPrefix("Claude, Bimal Rao's agent"), words.label) XCTAssertTrue(words.label.contains("Packing list for Saturday"), words.label) XCTAssertLessThan(words.frame.minX, app.frame.width * 0.2, "on the left, where theirs stand")let shot = XCTAttachment(screenshot: app.screenshot()) shot.name = "agent-words" shot.lifetime = .keepAlways add(shot) }}