Cotton code
101 lines · 5.8 KB · SwiftRaw
// The dial is chrome (owner with the architect, 16 Oct 2026): the fan, the// caps arc and the record button are the app's ONE frame, written in code and// drawn on every page of every database. On the owner's phone (build 288) the// stored per-database Home board decided what the dial drew, and after a// database switch it drew only Me and Tools on every database.import CottonKitimport XCTest@testable import CottonUIfinal class DialFrameTests: XCTestCase {    private func boardSurface() throws -> String {        SourceSweep.withoutComments(            try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/BoardSurface.swift", ownedBy: "dialchrome"))    }    /// The text of one `private var <name>: Bool { … }` declaration.    private func declaration(_ name: String, in source: String) throws -> String {        let head = try XCTUnwrap(source.range(of: "private var \(name): Bool {"), "\(name) is declared")        let rest = source[head.upperBound...]        var depth = 1        var end = rest.startIndex        for index in rest.indices {            switch rest[index] {            case "{": depth += 1            case "}": depth -= 1            default: break            }            if depth == 0 { end = index; break }        }        return String(rest[..<end])    }    /// RULE: The frame — fan, caps arc and record button — is drawn in code on the phone's root whatever the board says: `drawsFan` is `DialFrame.draws(root:)` and `drawsCaps` is the fan's, and neither reads the board or its parts; a board with no parts still draws the dial, and a stored board only decides which cards are on it (owner's phone, build 288: a stored Home board drew only Me and Tools after a switch).    func testTheFrameIsDrawnInCodeAndNoBoardPartDecidesIt() throws {        let source = try boardSurface()        for name in ["drawsFan", "drawsCaps"] {            let body = try declaration(name, in: source)            for board in ["parts", "board", "arrangement", ".tools(", ".databases"] {                XCTAssertFalse(body.contains(board), "\(name) reads \(board): the frame is code, never a board part")            }        }        XCTAssertTrue(try declaration("drawsFan", in: source).contains("DialFrame.draws(root: root)"))        XCTAssertTrue(try declaration("drawsCaps", in: source).contains("drawsFan"), "the caps arc stands with the fan")        // The record button is placed by the frame on the root, with the fan.        let squeezed = source.filter { !$0.isWhitespace }        XCTAssertTrue(squeezed.contains(".voiced(drawsFan,"), "the record button is voiced by the frame's own predicate")    }    /// RULE: No board part draws the frame: the `databases` part and the `tools` part's `fan` face are gone from the closed set, and the head carries no database cap — a stored board that still names them draws nothing for them, never the dial.    func testNoBoardPartNamesTheFrame() {        XCTAssertNil(BoardToolsFace(rawValue: "fan"))    }    /// RULE: The frame stands on the phone's root and nowhere else: a pushed board is a page under it, and the Mac draws no fan.    func testTheFrameStandsOnTheRoot() {        XCTAssertFalse(DialFrame.draws(root: false))        #if os(iOS)        XCTAssertTrue(DialFrame.draws(root: true))        #else        XCTAssertFalse(DialFrame.draws(root: true))        #endif    }    /// RULE: Every page host folds the dial and wears its X: a page pushed on the shown tile's stack and a layer a screen opens on the tile's own root page (a row of a fan card's Outages, Feedback or Bin list) are both pages over the root, so the dial folds while either stands (`Navigator.pageOpen`), and a layer is never a column's root, so its X is drawn (walker pass 5: those pages opened under the risen fan with no Close and the only way out was the centre card).    @MainActor    func testEveryPageHostFoldsTheDialAndWearsItsX() throws {        let navigator = Navigator()        navigator.arrival = .stack        navigator.tile = "outages"        XCTAssertFalse(navigator.pageOpen, "the tile's own page is the root: the dial stands")        navigator.layeredRoots.insert("outages")        XCTAssertTrue(navigator.pageOpen, "a layer on the root page folds the dial")        navigator.tile = "notes"        XCTAssertFalse(navigator.pageOpen, "another tile's layer is that tile's")        let source = try boardSurface().filter { !$0.isWhitespace }        XCTAssertTrue(source.contains("pageOpen:navigator?.pageOpen==true"), "the fan folds on the navigator's one answer")        let tiles = SourceSweep.withoutComments(            try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/Board/TilePage.swift", ownedBy: "dialchrome"))        XCTAssertTrue(tiles.contains("navigator?.layeredRoots.insert(key)"), "the tile's root page says when a layer stands on it")        let layers = SourceSweep.withoutComments(            try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/Board/PageDestination.swift", ownedBy: "dialchrome"))        XCTAssertTrue(layers.contains("environment.cottonAtColumnRoot = false"), "a layer wears its X")    }    @MainActor func testViewsUseTheToolsArcAndNeverReserveARingBand() throws {        let source = SourceSweep.withoutComments(try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/Board/FanSurface.swift", ownedBy: "fan"))        XCTAssertFalse(source.contains("ViewRingArc"))        XCTAssertFalse(source.contains("ringHeight"))        XCTAssertTrue(source.contains("FanTierArc(tier: open, geometry: geometry,"))        let views = [ToolView(id: "all", label: "All", count: 9, isDefault: true, read: .init(table: "synthetic"))]        let tier = ViewTier.make(tool: "synthetic", views: views, current: "all")        XCTAssertEqual(tier.cards.map(\.id), ["all"])        XCTAssertEqual(tier.cards.map(\.count), [9])        XCTAssertEqual(tier.raised, "all")    }}