importFoundationimport XCTest@testable importCottonKitfinalclassGenesisTests: XCTestCase {// RULE: the app must preserve the manifest's closed genesis choice; null or a misspelling cannot become permission to found Personal.func testGenesisIsAClosedManifestChoice() throws {func decode(_ value: Any) throws -> FlavourManifest {let data = try JSONSerialization.data(withJSONObject: ["flavour": "synthetic-business", "name": "Synthetic studio","databases": "single", "tools": [], "genesis": value ])returntry JSONDecoder().decode(FlavourManifest.self, from: data) } XCTAssertEqual(try decode("personal").genesis, .personal) XCTAssertEqual(try decode("none").genesis, .none) XCTAssertThrowsError(try decode(NSNull())) XCTAssertThrowsError(try decode("no")) XCTAssertThrowsError(try decode(false)) }// RULE (12 Nov 2026): an app's ground is its manifest's `ground`, read and written back as the file says it; Cotton's and a business app's name none, and every Cotton app stands on one but Messages, whose chats lie on the shell's paper and which launches flat on its own colour with its Quote mark (`flat`; owner, 22 Nov 2026: the pegboard launch is retired).func testEachAppsGroundIsItsManifests() throws {let app = URL(fileURLWithPath: #filePath).deletingLastPathComponent() .deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("App")func manifest(_ path: String) throws -> FlavourManifest {try JSONDecoder().decode(FlavourManifest.self, from: Data(contentsOf: app.appendingPathComponent(path))) } XCTAssertNil(try manifest("CottonManifest/flavour.json").ground) XCTAssertNil(try manifest("../Tests/Fixtures/Flavours/rigby.json").ground)let books = try manifest("Flavours/books/flavour.json") XCTAssertEqual(books.ground, "feltNavy")let written = try JSONSerialization.jsonObject(with: JSONEncoder().encode(books)) as? [String: Any] XCTAssertEqual(written?["ground"] as? String, "feltNavy", "the ground is written back as the file says it")for name in ["books", "cinemas", "developer", "downloads", "keys", "money", "music", "notes", "people"] { XCTAssertNotNil(try manifest("Flavours/\(name)/flavour.json").ground, name) }let messages = try manifest("Flavours/messages/flavour.json") XCTAssertNil(messages.ground, "Messages' chats lie on the shell's paper") XCTAssertNil(messages.launch, "Comms launches flat, on no painted ground") XCTAssertTrue(messages.flat) }// RULE: `"databases": "only"` is add-only (architect, 22 Oct 2026: one meaning per key): exactly one database ever, which every single-database path treats as `single`; Rigby says it, and every other shipped manifest keeps `single`, one shown at a time.func testOnlyRigbyHoldsOneDatabaseEver() throws {let app = URL(fileURLWithPath: #filePath).deletingLastPathComponent() .deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("App")func manifest(_ path: String) throws -> FlavourManifest {try JSONDecoder().decode(FlavourManifest.self, from: Data(contentsOf: app.appendingPathComponent(path))) }let rigby = try manifest("../Tests/Fixtures/Flavours/rigby.json") XCTAssertEqual(rigby.databases, .only) XCTAssertTrue(rigby.isSingleDatabase) XCTAssertEqual(try manifest("CottonManifest/flavour.json").databases, .single)let flavours = tryFileManager.default.contentsOfDirectory(atPath: app.appendingPathComponent("Flavours").path).filter { !$0.hasPrefix(".") }for name in flavours where name != "rigby" { XCTAssertNotEqual(try manifest("Flavours/\(name)/flavour.json").databases, .only, name) } }// RULE: the manifest's `fan` is add-only (owner and architect, 22 Oct 2026): absent, Home and Tools and no Settings card, and it stays unsaid when written back; Rigby's names no Home, no Tools, a Settings card and Todos to open on; Cotton's keeps Home and Tools and carries the same Settings card Rigby's does, so the owner exports from Cotton (the owner, 23 Oct 2026); Nancy's holds no Tools card and Sharmila's is Rigby's shape opening on yoga; every other shipped flavour says no `fan`, and each is written back as its file says it.func testEachFlavoursDialIsItsManifests() throws {let app = URL(fileURLWithPath: #filePath).deletingLastPathComponent() .deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("App")func manifest(_ path: String) throws -> FlavourManifest {try JSONDecoder().decode(FlavourManifest.self, from: Data(contentsOf: app.appendingPathComponent(path))) }let rigby = try manifest("../Tests/Fixtures/Flavours/rigby.json") XCTAssertEqual(rigby.fan, FlavourManifest.Fan(home: false, tools: false, settings: true, opens: "todos"))let cotton = try manifest("CottonManifest/flavour.json") XCTAssertEqual(cotton.fan, FlavourManifest.Fan(home: true, tools: true, settings: true, opens: nil)) XCTAssertTrue(cotton.fan.settings && rigby.fan.settings, "Cotton's fan carries the Settings card Rigby's does")let cottonWritten = try JSONSerialization.jsonObject(with: JSONEncoder().encode(cotton)) as? [String: Any] XCTAssertEqual((cottonWritten?["fan"] as? [String: Any])?["settings"] as? Bool, true, "the core is handed Cotton's Settings card")// Cotton Books opens on the Books tool's Reading deck, and its dial is// that tool alone: no sync card, no Settings (owner, 4 Nov 2026). XCTAssertEqual(try manifest("Flavours/books/flavour.json").fan,FlavourManifest.Fan(home: false, tools: false, settings: false, opens: "books"))// Cotton Music and Cotton Cinemas open without Home, as Books does: a// one-tool app's fan is its views (bcaf8f49dc), on the Listening and// Films decks. XCTAssertEqual(try manifest("Flavours/music/flavour.json").fan,FlavourManifest.Fan(home: false, tools: false, settings: false, opens: "music")) XCTAssertEqual(try manifest("Flavours/cinemas/flavour.json").fan,FlavourManifest.Fan(home: false, tools: false, settings: false, opens: "cinemas"))let plain = try manifest("../Tests/Fixtures/Flavours/development.json") XCTAssertEqual(plain.fan, .cottons)let written = try JSONSerialization.jsonObject(with: JSONEncoder().encode(plain)) as? [String: Any] XCTAssertNil(written?["fan"], "a manifest with Cotton's own dial says no fan") }// RULE: the manifest's `sync` is add-only (architect, 22 Oct 2026): absent, the app syncs as Cotton does and it stays unsaid when written back; Rigby's says false, and every other shipped flavour syncs.func testOnlyRigbyNeverSyncs() throws {let app = URL(fileURLWithPath: #filePath).deletingLastPathComponent() .deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("App")func manifest(_ path: String) throws -> FlavourManifest {try JSONDecoder().decode(FlavourManifest.self, from: Data(contentsOf: app.appendingPathComponent(path))) }let cotton = try manifest("CottonManifest/flavour.json") XCTAssertTrue(cotton.sync)let written = try JSONSerialization.jsonObject(with: JSONEncoder().encode(cotton)) as? [String: Any] XCTAssertNil(written?["sync"])let flavours = tryFileManager.default.contentsOfDirectory(atPath: app.appendingPathComponent("Flavours").path).filter { !$0.hasPrefix(".") }for name in flavours where name != "rigby" { XCTAssertTrue(try manifest("Flavours/\(name)/flavour.json").sync, name) }let rigby = try manifest("../Tests/Fixtures/Flavours/rigby.json") XCTAssertFalse(rigby.sync)let rigbyWritten = try JSONSerialization.jsonObject(with: JSONEncoder().encode(rigby)) as? [String: Any] XCTAssertEqual(rigbyWritten?["sync"] as? Bool, false) }// RULE: there is no first-open choice anywhere (owner, 6 Nov 2026: Cotton is local-first, an app opens and works on its own database at once, and Sign in merges it into the object later): no shipped manifest names `first_open`, Cotton keeps the server Backup signs in at, and every one of Cotton's own apps founds Personal, so its first open starts its own database.func testNoManifestAsksOnFirstOpen() throws {let app = URL(fileURLWithPath: #filePath).deletingLastPathComponent() .deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("App")func raw(_ path: String) throws -> [String: Any] {try XCTUnwrap(JSONSerialization.jsonObject(with: Data(contentsOf: app.appendingPathComponent(path))) as? [String: Any]) }let cotton = try JSONDecoder().decode(FlavourManifest.self, from: Data(contentsOf: app.appendingPathComponent("CottonManifest/flavour.json"))) XCTAssertEqual(cotton.genesis, .personal) XCTAssertNotNil(cotton.personalObject, "and still names the server Backup signs in at") XCTAssertNil(try raw("CottonManifest/flavour.json")["first_open"])let flavours = tryFileManager.default.contentsOfDirectory(atPath: app.appendingPathComponent("Flavours").path).filter { !$0.hasPrefix(".") } XCTAssertTrue(flavours.contains("books"))for name in flavours {let manifest = try raw("Flavours/\(name)/flavour.json") XCTAssertNil(manifest["first_open"], name)// Which apps found Personal is read from apps/registry.json and the kits by shipped-genesis.test.ts, never listed here. } }}