// **No screen branches on the platform for LAYOUT.** The one rule (design spec // §0). ScreenPlatformSweepTests.swift (CottonUITests), ported to vitest: it // only ever read the Swift sources as text. The describe keeps the Swift // suite's name, so a source comment that names it still finds its guard here. // // One app, one set of screens, one host: the phone's `StackHost` renders every // `RouteScreen` inside `cottonScreenFrame()`, and the host alone decides where a // route lands. A screen that grew an `#if os(macOS)` to look different would be // the first of two designs. The BOOT layer may branch at file scope; `Screens/` // (and `Paper/`, where a screen's layout now lives) may not, except at named // CAPABILITY sites — none today. // // Path ownership: everything swept is `apps/cotton/Sources/CottonUI/Screens/**` // and `…/Paper/**`. import { describe, expect, it } from "vitest"; import { matches, swiftSources, withoutComments } from "./helpers/swift-source-sweep"; describe("ScreenPlatformSweepTests", () => { /** The capability sites, each with the sentence that earns it: none today. */ const capabilitySites: Record = {}; /** **`os(macOS)` alone.** A screen saying `#if os(macOS)` is answering "what does this look like on a Mac", and that question is the host's. */ const branch = String.raw`#if\s+os\(macOS\)`; // RULE: There is one set of screens for the phone and the Mac: only the startup code branches on which platform it is running on. it("no screen branches on the platform beyond the named capability sites", () => { const screens = swiftSources().filter(({ name }) => name.startsWith("CottonUI/Screens/") || name.startsWith("CottonUI/Paper/")); const branching: string[] = []; for (const { name, text } of screens) { if (matches(branch, withoutComments(text)).length === 0) continue; const relativeName = name.replaceAll("CottonUI/", ""); if (capabilitySites[relativeName] !== undefined) continue; branching.push(relativeName); } expect( branching, `a screen branches on the platform: ${branching.join(", ")} — the host (Boot/StackHost.swift) decides layout, never a screen. If a screen must look different on one platform, the fix goes in the shared component.`, ).toEqual([]); }); });