import XCTest@testable importCottonUIfinalclassNoTableInGenericSurfacesTests: XCTestCase {/// RULE: The app never decides behaviour by whether a table shipped: `builtin` is decoded and read nowhere — whether a record's commands run comes from its engine commands or typed package acts, so an imported tool's records behave as a built-in's (architect, 13 Oct 2026).func testNothingReadsBuiltin() throws {let root = SourceSweep.iosSources.appendingPathComponent("CottonUI")let files = tryFileManager.default.subpathsOfDirectory(atPath: root.path).filter { $0.hasSuffix(".swift") }let read = try NSRegularExpression(pattern: #"(?<!")\bbuiltin\b(?!")"#)var readers: [String] = []for path in files where path != "Definitions/TableDefinition.swift" {let code = SourceSweep.withoutComments(tryString(contentsOf: root.appendingPathComponent(path), encoding: .utf8))if read.firstMatch(in: code, range: NSRange(code.startIndex..., in: code)) != nil { readers.append(path) } } XCTAssertEqual(readers, [], "read whether a table shipped")let commanded = TableDefinition( id: "imported", name: "Imported", plural: "Imported", builtin: false, engine: "an-engine", columns: [ColumnDefinition(key: "title", type: .text)], title: "title", slip: SlipLayout(title: "title"), tile: TileLayout(face: .slipList), page: []) XCTAssertFalse(commanded.canRunCommands, "an engine with no commands runs none") }/// RULE: A package's typed acts need no native engine, and filtering commands must remove those acts too, so the tray can offer them and the Bin can suppress them.func testPackageActsNeedNoNativeEngine() throws {var table = TableDefinition( id: "synthetic_package", name: "Package", plural: "Packages", builtin: false, engine: nil, columns: [ColumnDefinition(key: "title", type: .text)], title: "title", slip: SlipLayout(title: "title"), tile: TileLayout(face: .slipList), page: [])let data = Data(#"{"id":"attend","label":"Attend","kind":"update","verb":"set","data":{"column":"title","value":"Attended"}}"#.utf8) table.acts = [try JSONDecoder().decode(RecordCommand.self, from: data)] XCTAssertTrue(table.canRunCommands) XCTAssertEqual(table.commands?.first?.id, "attend") table.commands = [] XCTAssertFalse(table.canRunCommands) XCTAssertNil(table.acts) }/// RULE: No generic surface names a table or an engine: Surfaces/, Faces/, Definitions/ and Editors/ never compare a table, an id, a link or an engine with a shipped table's or engine's name, index the definitions by one, pass one as a `table:`, list several, or key a map by one — what a table does is a definition key (`role`, `record_route`, `sealed`, `binned`…), so an imported tool behaves as a shipped one. No allow-list (architect ruling 3, 13 Oct 2026).func testNoGenericSurfaceNamesATable() throws {let definitions = FixtureDefinitions.load().definitionslet tables = Set(definitions.map(\.id))let engines = Set(definitions.compactMap(\.engine)) XCTAssertFalse(tables.isEmpty, "the built-in definitions are bundled")let word = #""([a-z_]+)""#let named: [(NSRegularExpression, Set<String>)] = [ (try NSRegularExpression(pattern: #"(?:\btable|\.id|\blinkTo|\bto)\s*[!=]=\s*"# + word), tables), (try NSRegularExpression(pattern: #"\bengine\s*[!=]=\s*"# + word), engines), (try NSRegularExpression(pattern: #"definitions\[\s*"# + word + #"\s*\]"#), tables), (try NSRegularExpression(pattern: #"\btable:\s*"# + word), tables), (try NSRegularExpression(pattern: #"^\s*"# + word + #":\s*(?:\.[a-z]|[A-Z])"#, options: .anchorsMatchLines), tables), ]let list = try NSRegularExpression(pattern: #"\[\s*"[a-z_]+"(?:\s*,\s*"[a-z_]+")+\s*\]"#)let quoted = try NSRegularExpression(pattern: word)// A multi-line string is data a sampler or a preview decodes, not code.let block = try NSRegularExpression(pattern: #"""(?s).*?""""#)let folders = ["CottonUI/Surfaces/", "CottonUI/Faces/", "CottonUI/Definitions/", "CottonUI/Editors/"]var found: [String] = []for source intrySourceSweep.swiftSources() where folders.contains(where: source.name.hasPrefix) {let stripped = SourceSweep.withoutComments(source.text)let code = block.stringByReplacingMatches(in: stripped, range: NSRange(stripped.startIndex..., in: stripped), withTemplate: "\"\"") as NSStringlet all = NSRange(location: 0, length: code.length)for (pattern, words) in named {for match in pattern.matches(in: code asString, range: all) where words.contains(code.substring(with: match.range(at: 1))) { found.append("\(source.name): \(code.substring(with: match.range))") } }for match in list.matches(in: code asString, range: all) {let inside = code.substring(with: match.range) as NSStringlet ids = quoted.matches(in: inside asString, range: NSRange(location: 0, length: inside.length)) .map { inside.substring(with: $0.range(at: 1)) }.filter(tables.contains)if ids.count >= 2 { found.append("\(source.name): \(inside)") } } } XCTAssertEqual(found, [], "a generic surface reads what a table does from its definition, never from its name") }}