import Foundation import XCTest @testable import CottonUI /// Scan guards over the record page's cards and tray (`CottonUI/Cards/`), and /// the no-literal guard over every generic surface. final class CardGuardTests: XCTestCase { private static let cards = "CottonUI/Cards/" private func cardSources() throws -> [(name: String, text: String)] { let files = try SourceSweep.swiftSources().filter { $0.name.hasPrefix(Self.cards) } XCTAssertGreaterThan(files.count, 5, "the sweep found no card sources — did Cards/ move?") return files.map { ($0.name, SourceSweep.withoutComments($0.text)) } } /// RULE: nothing in CottonUI raises a system alert or confirmation dialog, and nothing under Cards/ presents a sheet, cover, popover or confirm — an act is a card (tap fires, tap asks, hold confirms) and a pick is the pick sheet, so a popup is a second way to act (owner, 12 Oct 2026; architect, 13 Oct 2026). func testNoAlertAnywhereAndNoModalInTheCardsOrTheTray() throws { let everywhere = try SourceSweep.swiftSources().filter { $0.name.hasPrefix("CottonUI/") } XCTAssertFalse(everywhere.isEmpty) for file in everywhere { let hits = try SourceSweep.matches(#"\.(alert|confirmationDialog)\s*\("#, in: SourceSweep.withoutComments(file.text)) XCTAssertTrue(hits.isEmpty, "\(file.name) raises \(hits)") } // A presentation is told by its binding: `theme.sheet(.cream)` is a paper's colour, not a sheet. let modal = #"\.(sheet|fullScreenCover|popover|cottonSheet|confirmDecision)\s*\(\s*(isPresented|item)\s*:"# XCTAssertFalse(try SourceSweep.matches(modal, in: "x.sheet(isPresented: $on) {}").isEmpty) XCTAssertFalse(try SourceSweep.matches(modal, in: "x.confirmDecision(\n item: $it)").isEmpty) for file in try cardSources() { let hits = try SourceSweep.matches(modal, in: file.text) XCTAssertTrue(hits.isEmpty, "\(file.name) presents \(hits) — the pick sheet is the only place a card asks") } } /// The generic surfaces: everything a definition draws through. private static let generic = ["CottonUI/Cards/", "CottonUI/Surfaces/", "CottonUI/Faces/", "CottonUI/Definitions/", "CottonUI/Editors/"] /// RULE: no generic surface (Cards/, Surfaces/, Faces/, Definitions/, Editors/) reads a definition's `builtin` flag or branches on a table's identity — a table id, a record's table or kind, an engine compared to a literal, switched over, looked up in a literal list, or turned into a `RecordKind` — so a shipped tool and an imported one are the same thing to everything a person sees, and what differs is a definition key (owner's amendment, 12 Oct 2026; the no-literal guard, architect 14 Oct 2026). No allow-list: a table that needs its own behaviour names it in its definition. func testNoGenericSurfaceReadsBuiltinOrNamesATable() throws { let patterns = [ #"(?