import { existsSync } from"node:fs";import { join } from"node:path";import { describe, expect, it } from"vitest";import { checkApp, missingPurposeStrings } from"../ios-purpose-strings";const ref = (classes: string[], frameworks: string[] = []) => ({ classes: newSet(classes), frameworks: newSet(frameworks) });// RULE (ITMS-90683, Words build 21, 22 Nov 2026): App Store processing reads the binary. A privacy API it references// (a linked framework, a class) without the API's purpose string is a rejected build, used or not.describe("purpose strings against the binary", () => { it("fails Contacts named without NSContactsUsageDescription, as Apple did for Words", () => {const missing = missingPurposeStrings(ref(["CNContactStore", "AVCaptureDevice"], ["Contacts"]), { NSCameraUsageDescription: "Takes a picture." }); expect(missing.map((one) => one.api)).toEqual(["Contacts"]); expect(missing[0].because).toContain("links Contacts"); }); it("passes what is declared, and what is not referenced", () => { expect(missingPurposeStrings(ref(["CNContactStore"]), { NSContactsUsageDescription: "Finds people you know." })).toEqual([]); expect(missingPurposeStrings(ref(["NSString"], ["Foundation"]), {})).toEqual([]); }); it("takes either photo key, and refuses an empty string", () => { expect(missingPurposeStrings(ref(["PHPhotoLibrary"]), { NSPhotoLibraryAddUsageDescription: "Saves a shot." })).toEqual([]); expect(missingPurposeStrings(ref(["SFSpeechRecognizer"]), { NSSpeechRecognitionUsageDescription: " " }).map((one) => one.api)).toEqual(["Speech recognition"]); });// The built apps, when a lane's Debug build is at hand (COTTON_BUILT_PRODUCTS); every cut runs it on the archive.const built = process.env.COTTON_BUILT_PRODUCTS;for (const app of ["CottonNotes", "CottonDays", "CottonStory"]) {const path = built ? join(built, `${app}.app`) : ""; it.skipIf(!built || !existsSync(path))(`${app}: every privacy API its binary references has its purpose string`, () => { expect(checkApp(path).missing).toEqual([]); }); }});