Cotton code
48 lines · 2.6 KB · SwiftRaw
import XCTest/// The microphone and speech-recognition usage strings, on every target that/// can reach the code asking for them (coordinator, 14 Oct 2026: the Home/// preview's first tap on the fan's record button died in TCC — a request/// without its string is a SIGABRT, not a prompt).final class UsageDescriptionTests: XCTestCase {    private static let keys = ["NSMicrophoneUsageDescription", "NSSpeechRecognitionUsageDescription"]    /// RULE: every app or extension target that links CottonUI — which holds the dictation, recording and record-button code that asks for the microphone and speech recognition — carries NSMicrophoneUsageDescription and NSSpeechRecognitionUsageDescription in its Info.plist as does the Home preview's; without them the first tap that reaches the microphone kills the app (TCC, 14 Oct 2026, the preview's record button).    func testEveryTargetThatCanAskForTheMicrophoneSaysWhy() throws {        let project = try SourceSweep.mustRead("apps/cotton/project.yml", ownedBy: "the app's packaging")        let blocks = Self.targets(in: project)        XCTAssertFalse(blocks.isEmpty, "no targets read from project.yml — did its shape change?")        for (name, block) in blocks where block.contains("product: CottonUI") && !block.contains("bundle.unit-test")            && !block.contains("bundle.ui-testing") {            for key in Self.keys {                XCTAssertTrue(block.contains("\(key):"), "\(name) links CottonUI but its Info.plist has no \(key)")            }        }    }    /// Each target's block under `targets:`, by name.    static func targets(in project: String) -> [(String, String)] {        var blocks: [(String, String)] = []        var inTargets = false        var name: String?        var lines: [String] = []        func close() { if let name { blocks.append((name, lines.joined(separator: "\n"))) } }        for line in project.components(separatedBy: "\n") {            if !line.hasPrefix(" "), !line.isEmpty, !line.hasPrefix("#") {                if inTargets { close(); name = nil; lines = [] }                inTargets = line.hasPrefix("targets:")                continue            }            guard inTargets else { continue }            if line.hasPrefix("  "), !line.hasPrefix("   "), line.hasSuffix(":"), !line.trimmingCharacters(in: .whitespaces).hasPrefix("#") {                close()                name = String(line.dropFirst(2).dropLast())                lines = []            } else {                lines.append(line)            }        }        if inTargets { close() }        return blocks    }}