Cotton code
138 lines · 9.4 KB · SwiftRaw
// Your Claude asks (owner, 23 Nov 2026, from his iPhone in Story; shared/DECISIONS.md "Your Claude asks"): the card// "Let your Claude read your data" in Words, Days, Story and Comms is the app's own sheet from the foot, never the old// paper, every line whole, no table named, Everything by default and Let me choose opening the groups as ticks, the// lengths on a timed card, Not now and Allow fixed at the foot and in the window at the largest text; a tap above puts// it aside until the app is next opened. The card is the core's own for an invented request (`-unlock-card-seed`,// Fixtures/unlock-card-seed.json written by rules/unlock_tests.rs); nothing is sent.import XCTestenum UnlockAskUI {    static func seed(_ which: String) -> [String] { ["-unlock-card-seed", which] }    @MainActor static func id(_ app: XCUIApplication, _ identifier: String) -> XCUIElement {        app.descendants(matching: .any).matching(identifier: identifier).firstMatch    }    /// Not now and Allow stand inside the window, under the words.    @MainActor static func assertFootInSight(_ app: XCUIApplication, file: StaticString = #filePath, line: UInt = #line) {        let window = app.windows.firstMatch.frame        for act in ["unlock-not-now", "unlock-allow"] {            let button = id(app, act)            XCTAssertTrue(button.waitForExistence(timeout: 10), "\(act) stands", file: file, line: line)            XCTAssertTrue(button.isHittable, "\(act) can be touched", file: file, line: line)            XCTAssertTrue(window.contains(button.frame), "\(act) stands inside the window", file: file, line: line)            XCTAssertGreaterThanOrEqual(button.frame.minY, id(app, "unlock-scroll").frame.maxY - 1, "\(act) stands under the words", file: file, line: line)        }    }    /// The card for your Claude, in plain words: who asks, the promise, Everything chosen, Let me choose, how long and    /// where to change it; no table and no switch; Not now answers it and it goes.    @MainActor static func assertPlainWords(_ app: XCUIApplication, file: StaticString = #filePath, line: UInt = #line) {        let sheet = id(app, "unlock-sheet")        XCTAssertTrue(sheet.waitForExistence(timeout: 60), "the card rises in the app's own sheet", file: file, line: line)        for part in ["unlock-title", "unlock-who", "unlock-reason", "unlock-what", "unlock-everything", "unlock-choose", "unlock-how-long-line", "unlock-settings"] {            XCTAssertTrue(id(app, part).exists, "\(part) stands", file: file, line: line)        }        XCTAssertTrue(id(app, "unlock-everything").isSelected, "Everything is chosen at first", file: file, line: line)        XCTAssertFalse(id(app, "unlock-choose").isSelected, file: file, line: line)        XCTAssertFalse(id(app, "unlock-groups").exists, "the groups wait for Let me choose", file: file, line: line)        XCTAssertEqual(sheet.switches.count, 0, "no table is switched on the card", file: file, line: line)        for table in ["note_attachment", "journal_entry", "thread_member", "Runs", "Dev jobs"] {            XCTAssertEqual(app.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", table)).count, 0, "no table is named: \(table)", file: file, line: line)        }        XCTAssertEqual(app.descendants(matching: .any).matching(identifier: "unlock-act-allow").count, 0, "nothing of the paper card stands", file: file, line: line)        assertFootInSight(app, file: file, line: line)        id(app, "unlock-not-now").tap()        XCTAssertTrue(SettingsPartsUI.waitGone(sheet), "Not now answers it and it goes", file: file, line: line)    }    /// Let me choose over long lines: Scripts' line stands on one line, as Photos' beside it does (coordinator, 24 Nov    /// 2026: it broke onto two with room to spare). Default text size.    @MainActor static func assertScriptsOnOneLine(_ app: XCUIApplication, file: StaticString = #filePath, line: UInt = #line) {        let choose = id(app, "unlock-choose")        XCTAssertTrue(choose.waitForExistence(timeout: 30), "Let me choose stands", file: file, line: line)        choose.tap()        let scripts = id(app, "unlock-group-scripts"), photos = id(app, "unlock-group-photos")        XCTAssertTrue(scripts.waitForExistence(timeout: 5) && photos.exists, "Scripts and Photos are offered", file: file, line: line)        SettingsPartsUI.reach(app, scripts)        XCTAssertEqual(scripts.frame.height, photos.frame.height, accuracy: 1, "Scripts stands as tall as Photos: one line", file: file, line: line)        let shot = XCTAttachment(screenshot: app.screenshot())        shot.name = "unlock-groups"        shot.lifetime = .keepAlways        XCTContext.runActivity(named: "the groups") { $0.add(shot) }    }    /// Let me choose opens the groups, all ticked; Allow is off with none ticked and back with one; Allow answers it.    @MainActor static func assertChoosing(_ app: XCUIApplication, file: StaticString = #filePath, line: UInt = #line) {        let choose = id(app, "unlock-choose")        XCTAssertTrue(choose.waitForExistence(timeout: 60), file: file, line: line)        choose.tap()        XCTAssertTrue(id(app, "unlock-groups").waitForExistence(timeout: 5), "the groups open", file: file, line: line)        XCTAssertTrue(choose.isSelected, file: file, line: line)        let groups = ["notes", "calendar", "messages"].map { id(app, "unlock-group-\($0)") }        for group in groups {            SettingsPartsUI.reach(app, group)            XCTAssertTrue(group.isSelected, "each group starts ticked", file: file, line: line)            group.tap()        }        XCTAssertFalse(id(app, "unlock-allow").isEnabled, "Allow is off with nothing ticked", file: file, line: line)        groups[1].tap()        XCTAssertTrue(id(app, "unlock-allow").isEnabled, "Allow is back with one ticked", file: file, line: line)        id(app, "unlock-allow").tap()        XCTAssertTrue(SettingsPartsUI.waitGone(id(app, "unlock-sheet")), "Allow answers it and it goes", file: file, line: line)    }    /// Several of the person's own machines waiting (f1d096c29d): the card names who asks in plain words, never a    /// token's own name ("Lane …"); Allow all stands on its own row with who else waits, hidden while choosing groups;    /// a tap answers them all and the sheet goes.    @MainActor static func assertAllowAll(_ app: XCUIApplication, file: StaticString = #filePath, line: UInt = #line) {        let all = id(app, "unlock-allow-all")        XCTAssertTrue(all.waitForExistence(timeout: 60), "Allow all stands", file: file, line: line)        XCTAssertEqual(all.label, "Allow all 3", file: file, line: line)        let others = id(app, "unlock-all-line")        XCTAssertTrue(others.exists, "who else waits", file: file, line: line)        XCTAssertEqual(others.label, "Also waiting: Claude Code on mac-d and Claude Code on mac-a", file: file, line: line)        XCTAssertGreaterThan(id(app, "unlock-allow").frame.minY, all.frame.maxY - 1, "above the foot", file: file, line: line)        let token = app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS %@", "Lane ")).firstMatch        XCTAssertFalse(token.exists, "no token's own name: \(token.label)", file: file, line: line)        XCTAssertTrue(id(app, "unlock-title").label.contains("Claude Code"), id(app, "unlock-title").label, file: file, line: line)        let choose = id(app, "unlock-choose")        if choose.exists {            SettingsPartsUI.reach(app, choose)            choose.tap()            XCTAssertFalse(id(app, "unlock-allow-all").exists, "hidden while choosing", file: file, line: line)            let everything = id(app, "unlock-everything")            SettingsPartsUI.reach(app, everything)            everything.tap()        }        XCTAssertTrue(all.waitForExistence(timeout: 5), file: file, line: line)        all.tap()        XCTAssertTrue(SettingsPartsUI.waitGone(id(app, "unlock-sheet")), "Allow all answers them and it goes", file: file, line: line)    }    /// A timed card offers its lengths, the suggestion chosen; another can be chosen.    @MainActor static func assertLengths(_ app: XCUIApplication, file: StaticString = #filePath, line: UInt = #line) {        let fifteen = id(app, "unlock-duration-15")        XCTAssertTrue(fifteen.waitForExistence(timeout: 60), "the lengths stand", file: file, line: line)        XCTAssertTrue(fifteen.isSelected, "the suggestion is chosen", file: file, line: line)        let hour = id(app, "unlock-duration-60")        SettingsPartsUI.reach(app, hour)        hour.tap()        XCTAssertTrue(hour.isSelected, "1 hour chosen", file: file, line: line)        XCTAssertFalse(fifteen.isSelected, file: file, line: line)        assertFootInSight(app, file: file, line: line)    }    /// A tap above the sheet puts it aside, nothing answered: the app under it is free; opened again, it rises again.    @MainActor static func assertAside(_ launch: () -> XCUIApplication, file: StaticString = #filePath, line: UInt = #line) {        let app = launch()        let sheet = id(app, "unlock-sheet")        XCTAssertTrue(sheet.waitForExistence(timeout: 60), file: file, line: line)        app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.08)).tap()        XCTAssertTrue(SettingsPartsUI.waitGone(sheet), "a tap above puts it aside", file: file, line: line)        app.terminate()        let again = launch()        XCTAssertTrue(id(again, "unlock-sheet").waitForExistence(timeout: 60), "opened again, it rises again", file: file, line: line)    }}