import XCTest@testable importCottonKitfinalclassFlavourOverrideTests: XCTestCase {privatelet manifest = FlavourManifest( flavour: "sharmila", name: "Synthetic Studio", databases: .single, home: nil, business: BusinessAddress(server: "https://cotton-business.synthetic.workers.dev", slug: "synthetic-studio"))/// RULE: A device build never takes the simulator's business override: the launch arguments that point a walk at a synthetic business served on the Mac are read only inside `#if targetEnvironment(simulator)`, in `FlavourManifest.swift` alone, and the device branch returns the bundle's manifest unchanged — a phone in a person's hand reaches only the object the business's manifest names.func testADeviceBuildNeverTakesTheSimulatorOverride() throws {let source = SourceSweep.withoutComments(trySourceSweep.mustRead("apps/cotton/Sources/CottonKit/FlavourManifest.swift", ownedBy: "shell3"))letopen = try XCTUnwrap(source.range(of: "#if targetEnvironment(simulator)"), "the override is not simulator-only")let otherwise = try XCTUnwrap(source.range(of: "#else", range: open.upperBound..<source.endIndex))let close = try XCTUnwrap(source.range(of: "#endif", range: otherwise.upperBound..<source.endIndex))let simulator = source[open.upperBound..<otherwise.lowerBound]let device = source[otherwise.upperBound..<close.lowerBound] XCTAssertTrue(simulator.contains("businessServerArgument") && simulator.contains("businessSlugArgument")) XCTAssertEqual(device.trimmingCharacters(in: .whitespacesAndNewlines), "return manifest", "the device branch changes nothing")let outside = source[..<open.lowerBound] + source[close.upperBound...] XCTAssertFalse(outside.contains("UserDefaults"), "the arguments are read outside the simulator branch") XCTAssertEqual(FlavourManifest.businessServerArgument, "businessServer") XCTAssertEqual(FlavourManifest.businessSlugArgument, "businessSlug")for (name, text) intrySourceSweep.swiftSources() where !name.hasSuffix("FlavourManifest.swift") {let code = SourceSweep.withoutComments(text)for key in ["businessServerArgument", "businessSlugArgument", "\"businessServer\"", "\"businessSlug\"", "customersServer", "customersDatabase"] { XCTAssertFalse(code.contains(key), "\(name) reads the simulator's business override") } } }/// RULE: The override replaces the business's server and slug only when both are named and the manifest names a business at all; anything less leaves the manifest as the bundle carries it — the override never makes Cotton a business.func testTheOverrideNeedsBothHalves() { XCTAssertEqual(manifest.servingBusiness(server: "http://127.0.0.1:8787", slug: nil), manifest) XCTAssertEqual(manifest.servingBusiness(server: "", slug: "studio"), manifest)let served = manifest.servingBusiness(server: "http://127.0.0.1:8787", slug: "studio") XCTAssertEqual(served.business, BusinessAddress(server: "http://127.0.0.1:8787", slug: "studio"))var none = manifest none.business = nil XCTAssertEqual(none.servingBusiness(server: "http://127.0.0.1:8787", slug: "studio"), none)varopen = manifestopen.business = BusinessAddress(server: "https://cottondb.com", window: ["message": 90]) XCTAssertEqual(open.servingBusiness(server: "http://127.0.0.1:8787", slug: "studio").business,BusinessAddress(server: "http://127.0.0.1:8787", window: ["message": 90]),"at the open host the server alone moves: a slug never makes Cotton a business") XCTAssertEqual(open.servingBusiness(server: nil, slug: nil), open) }/// RULE: The manifest's `business` is `{server, slug}` and crosses to the core as written; the relay's `customers` block is not read.func testTheBusinessBlockReadsAsServerAndSlug() throws {let bundled = try JSONDecoder().decode(FlavourManifest.self, from: Data(""" {"flavour": "sharmila", "name": "Synthetic Studio", "databases": "single", "tools": ["yoga"], "business": {"server": "https://cotton-business.synthetic.workers.dev", "slug": "studio"}} """.utf8)) XCTAssertEqual(bundled.business, BusinessAddress(server: "https://cotton-business.synthetic.workers.dev", slug: "studio"))let crossed = try JSONDecoder().decode(JSONValue.self, from: JSONEncoder().encode(bundled.servingBusiness(server: "http://127.0.0.1:8787", slug: "walk"))) XCTAssertEqual(crossed["business"], .object(["server": .string("http://127.0.0.1:8787"), "slug": .string("walk")]))let source = SourceSweep.withoutComments(trySourceSweep.mustRead("apps/cotton/Sources/CottonKit/FlavourManifest.swift", ownedBy: "business")) XCTAssertFalse(source.contains("customers"), "the manifest still reads the relay's customers") }}