// The seven Settings tables: their definitions in the shared format, and the // sources that answer the Records verbs from the app's own reads (rebuild note // 7b95efa4, "Settings are lists and pages drawn by the same interpreter"). // // Every source is driven through `ScriptedCore`, so what is asserted is what a // read's answer becomes as records and which method a write calls with which // body. Every id, name and number here is invented. import CottonKit import Foundation import XCTest @testable import CottonUI final class SettingsTablesTests: XCTestCase { /// The resources as the source tree holds them (`TableDefinitionTests`). private static var resources: Bundle? { Bundle(url: SourceSweep.iosSources.appendingPathComponent("CottonUI/Resources")) } private func definitions() throws -> [TableDefinition] { let loaded = FixtureDefinitions.load(from: try XCTUnwrap(Self.resources)) XCTAssertEqual(loaded.failures, []) return loaded.definitions } private func records(_ replies: [String: ScriptedCore.Reply]) throws -> (SettingsRecords, ScriptedCore) { var replies = replies replies["tools.list"] = replies["tools.list"] ?? .ok(#"{"tools":[],"table_definitions":[]}"#) let core = ScriptedCore(replies) return (SettingsRecords(core: core, definitions: try definitions()), core) } /// The body a method was sent, read back off the wire. private func sent(_ core: ScriptedCore, _ method: String) async throws -> [String: Any] { let calls = await core.calls let call = try XCTUnwrap(calls.last { $0.method == method }, "\(method) was never called") return try XCTUnwrap(JSONSerialization.jsonObject(with: Data(call.requestJSON.utf8)) as? [String: Any]) } private func refusal(_ act: () async throws -> T) async -> Error? { await Self.refusal(act) } /// Static, so an `async let` can run it without capturing the test case. private static func refusal(_ act: () async throws -> T) async -> Error? { do { _ = try await act() return nil } catch { return error } } // ── The guard ────────────────────────────────────────────────────────── // ── The definitions ──────────────────────────────────────────────────── // ── Sessions ─────────────────────────────────────────────────────────── /// RULE: A Settings table that became a tool (Spec 9.3) has no Settings row and opens from its Home tool's route, because a list with acts is a tool. func testATableThatBecameAToolHasNoSettingsRowAndOpensFromHome() { let rows = Set(SettingsTables.entries.map(\.table)) for tool in SettingsTables.tools { XCTAssertFalse(rows.contains(tool.table), "\(tool.table) is a tool and a Settings row as well") // The Mac board opens a card through this; without it the card // falls to the plain list, which has no verbs for the table. XCTAssertNotNil(SettingsTables.route(forTable: tool.table), "\(tool.table) has no route for its card") } } // ── Voice words ──────────────────────────────────────────────────────── /// `settings.voiceTerm` for a NEW word, as the core answers it (Spec 9.3). // ── Storage ──────────────────────────────────────────────────────────── /// RULE: Storage and Devices are read on this device, so they take the local deadline and, overrun, say the phone is busy, never that the Mac is asleep (13 Oct 2026, build 269: Devices blamed a Mac it never asked, mid catch-up). // ── Everything ───────────────────────────────────────────────────────── // RULE: Native Everything reads/count refusals are guarded in its engine, not by a retired Swift adapter. func testATableSettingsDoesNotOpenIsUnknown() async throws { let (records, _) = try records([:]) let refused = await refusal { try await records.list(table: "todo", project: nil, query: nil, page: 0) } XCTAssertEqual(refused as? RecordsError, .unknownTable("todo")) } }