Cotton code
55 lines · 3.1 KB · SwiftRaw
// The Bin's database rows on the phone's list (sharing2 walk, 16 Oct 2026):// the core answered a removed member's "Sharing test · removed by Asha" row// and the list dropped it, because a row whose state the Bin's Restore answer// does not wait on (`database_binned`) read as already answered and left.// Every record is invented.import CottonKitimport CottonValuesimport Foundationimport XCTest@testable import CottonUI@MainActorfinal class BinDatabaseRowsTests: XCTestCase {    private static var resources: Bundle? {        Bundle(url: SourceSweep.iosSources.appendingPathComponent("CottonUI/Resources"))    }    private func bin() throws -> TableDefinition {        let loaded = FixtureDefinitions.load(from: try XCTUnwrap(Self.resources))        return try XCTUnwrap(loaded.definitions.first { $0.id == "bin" })    }    /// GUARD: a database row is the Bin's own record, never its table's — it is a file the core holds, not a record of `database`, and its Restore is the bin's `restore_database` act (`databases.restore`), the creator's alone (walk 06, 16 Oct 2026: the creator's deleted database opened "This database could not be read" and its Restore answered "That binned record is no longer here").    func testADatabaseRowIsTheBinsOwnRecord() throws {        let definition = try bin()        let restore = try XCTUnwrap(definition.commands?.first { $0.method == "databases.restore" })        XCTAssertEqual(restore.when?["can_restore"], .bool(true), "Restore is the creator's alone")        // Drawn from the Bin row alone — name, who, when, until when —        // never a read of the deleted copy (architect, 16 Oct 2026).        let head = try XCTUnwrap(definition.parts?.head.facts)        // The core draws a head fact only from a column marked `fact` with a        // reading, and never a stamp (cotton-core `parts::STAMPS`); any other        // key is dropped silently (walk 06c: the page drew its title over an        // empty body, and `trashed_at` as a fact still drew nothing).        for key in head {            XCTAssertFalse(["created_at", "updated_at", "trashed_at"].contains(key), "\(key) is a stamp")            let column = try XCTUnwrap(definition.column(key), key)            XCTAssertEqual(column.fact, true, "\(key) draws as a fact")            XCTAssertNotNil(column.reading, "\(key) has words to draw")        }    }    /// GUARD: a Restore's answer names the database it brought back (`shows_database`), so the Bin closes onto that database wearing its receipt — never a card left saying "This binned record is gone" under "Restored" (architect, 16 Oct 2026, walk 06c).    func testARestoreShowsTheDatabaseItBroughtBack() throws {        let wire = #"{"command":"restore_database","kind":"update","receipt":"Restored","answer":{"ok":true,"shows_database":"invented-garden"}}"#        let outcome = try JSONDecoder().decode(CommandOutcome.self, from: Data(wire.utf8))        let change = try outcome.change(table: "bin", record: "database:invented-garden")        XCTAssertEqual(change.opened, .database("invented-garden"))        XCTAssertEqual(change.said?.said, "Restored")    }}