Cotton code
75 lines · 4.8 KB · SwiftRaw
// Every app is Cotton's frame with its manifest's say: one database means no// caps and no Databases screen, and the fan holds exactly the manifest's tools// and Home. Cotton's own manifest (`App/CottonManifest`) names Personal alone;// a bundle with none (the Mac app) keeps its caps and every installed tool.import CottonKitimport XCTest@testable import CottonUIfinal class BusinessFlavourDialTests: XCTestCase {    private let sharmila = FlavourManifest(        flavour: "sharmila", name: "Sharmila's Yoga Zone", databases: .single, home: .object(["id": .string("home"), "parts": .array([.object(["kind": .string("today")])])]))    private let installed = ["calendar", "email", "money", "notes", "people", "todos", "tools"]    /// RULE: a business app that shows one database draws no caps arc on its root, and has no Databases screen to open — there is nothing to switch to.    func testASingleDatabaseAppHasNoCapsAndNoDatabasesScreen() {        XCTAssertFalse(DialFrame.drawsCaps(fan: true, manifest: sharmila))        XCTAssertFalse(DialFrame.drawsCaps(fan: false, manifest: sharmila))        XCTAssertFalse(DatabaseScene.hasDatabasesScreen(sharmila))    }    /// RULE: a bundle with no manifest (the Mac app) keeps its caps arc with the fan, its Databases screen, and every installed tool on its fan.    func testNoManifestKeepsItsCapsAndEveryInstalledTool() {        XCTAssertTrue(DialFrame.drawsCaps(fan: true, manifest: nil))        XCTAssertFalse(DialFrame.drawsCaps(fan: false, manifest: nil))        XCTAssertTrue(DatabaseScene.hasDatabasesScreen(nil))        let many = FlavourManifest(flavour: "x", name: "X", databases: .many, home: .object(["id": .string("home"), "parts": .array([])]))        XCTAssertTrue(DialFrame.drawsCaps(fan: true, manifest: many))    }    /// RULE: the board's caps and fan read the manifest through `DialFrame` — the home's `caps:` is `drawsCaps` and the fan deals every placed tile — so the pure rules above are the ones drawn.    func testTheBoardDrawsTheRulesAbove() throws {        let source = SourceSweep.withoutComments(            try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/BoardSurface.swift", ownedBy: "shell"))            .filter { !$0.isWhitespace }        XCTAssertTrue(source.contains("DialFrame.drawsCaps(fan:drawsFan,manifest:FlavourManifest.current)"))        XCTAssertTrue(source.contains("caps:drawsCaps,"))    }    /// RULE: every manifest the project builds crosses to the core whole — what `CottonConfig` sends (the decoded manifest, encoded again) holds every key of the file with the same value. A key the struct did not carry (`database`, 19 Oct 2026) never reached the core, so Cotton Development opened on Personal (walk). A business server named per side crosses as this build's side's one address (`BusinessAddress`).    func testEveryManifestCrossesToTheCoreWhole() throws {        let root = SourceSweep.repoRoot.appendingPathComponent("apps/cotton/App")        let flavours = try FileManager.default.contentsOfDirectory(atPath: root.appendingPathComponent("Flavours").path)            .filter { !$0.hasPrefix(".") }.map { "Flavours/\($0)/flavour.json" }        for path in flavours + ["CottonManifest/flavour.json"] {            let data = try Data(contentsOf: root.appendingPathComponent(path))            var file = try JSONDecoder().decode(JSONValue.self, from: data)            if case .object(var whole) = file, case .object(var business)? = whole["business"], case .object(let sides)? = business["server"] {                business["server"] = sides[AppFlavor.current.rawValue]                whole["business"] = .object(business)                file = .object(whole)            }            let sent = try JSONDecoder().decode(JSONValue.self, from: JSONEncoder().encode(JSONDecoder().decode(FlavourManifest.self, from: data)))            XCTAssertEqual(sent, file, path)        }    }    /// RULE: a bundle with no `flavour.json` reads as no manifest — a test bundle carries none.    func testNoManifestReadsAsNone() {        XCTAssertNil(FlavourManifest.of(Bundle(for: Self.self)))    }    @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")    }}