Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/WIDGETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ These commands verify signed entitlement declarations. They do not by themselve

`scripts/test-widget-ui-native.sh` compiles the widget views off-device.  It does not place a widget on the iOS Home Screen.  `scripts/test-widget-homescreen.sh` is that check (CC-219).

On a Mac with Xcode, the script creates a disposable iPhone simulator, builds the companion, and refuses to start when any simulator is already booted.  It installs the app, reboots once so WidgetKit can register the extension, and writes a fresh `quota-windows.json` into the App Group container and the app data container.  `occurredAt` is the current time and every `resetAt` is in the future.  A scratch XCUITest host long-presses empty wallpaper, taps Edit, taps Add Widget, searches for CodeCaps, and adds AI Subscription Overview.  `simctl io` writes a PNG of that Home Screen.  The test passes only when SpringBoard's accessibility tree shows the seeded GitHub Copilot reading at 37%, which the gallery placeholders do not render.
On a Mac with Xcode, the script creates a disposable iPhone simulator, builds the companion, and refuses to start when any simulator is already booted.  It installs the app, reboots once so WidgetKit can register the extension, and writes a fresh `quota-windows.json` into the App Group container and the app data container.  `occurredAt` is the current time and every `resetAt` is in the future.  A scratch XCUITest host first declines the companion's pending notification-permission alert — the model asks on first load, and the modal alert would swallow the long-press — then long-presses empty wallpaper, taps Edit, taps Add Widget, searches for CodeCaps, and adds AI Subscription Overview.  `simctl io` writes a PNG of that Home Screen.  The test passes only when SpringBoard's accessibility tree shows the seeded GitHub Copilot reading at 37%, which the gallery placeholders do not render.

The script does not open Simulator.app.

Expand All @@ -64,7 +64,7 @@ The command exits 78 with an `unsupported-path:` line, and that result is not a
- A simulator is already booted.
- No iOS 18 through 27 runtime is installed.
- The App Group container cannot be resolved after install. When `simctl` cannot report the container but the companion's launch hook proves `containerURL(forSecurityApplicationGroupIdentifier:)` resolved a path that exists inside the simulator's own App Group area, the script uses that verified companion-reported path and prints a `widget-homescreen: simctl never reported the App Group container` line; the exit-78 refusal still applies when the companion reports nil, writes no marker, or names a path that fails verification.
- The pinned gallery controls (Edit, Add Widget, the search field, CodeCaps, Done) are absent.
- The pinned gallery controls (Edit, Add Widget, the search field, CodeCaps, Done) are absent, or the permission alert will not dismiss.

A gallery that does not match that contract fails closed.  The script does not try a second path and does not retry.

Expand Down
113 changes: 98 additions & 15 deletions ios/WidgetHomeScreenProbe/UITests/WidgetHomeScreenProbeUITests.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import XCTest

/// Pinned iOS 18–27 home-screen gallery contract: long-press empty wallpaper,
/// Edit, Add Widget, search CodeCaps, add AI Subscription Overview, Done.
/// Pinned iOS 18–27 home-screen gallery contract: decline the companion's
/// pending notification-permission alert, long-press empty wallpaper, Edit,
/// Add Widget, search CodeCaps, add AI Subscription Overview, Done.
/// A missing control fails closed with an `unsupported-path:` message. The
/// test does not try a second gesture and does not retry.
final class WidgetHomeScreenProbeUITests: XCTestCase {
/// SpringBoard labels the notification-permission decline button with a
/// U+2019 apostrophe; the escape keeps the label byte-exact.
private let doNotAllowLabel = "Don\u{2019}t Allow"
private let allowLabel = "Allow"
private let editLabel = "Edit"
private let addWidgetLabel = "Add Widget"
/// The widget page's confirm button is labeled with a leading space.
private let galleryAddWidgetLabel = " Add Widget"
private let doneLabel = "Done"
private let appLabel = "CodeCaps"
private let widgetLabel = "AI Subscription Overview"
Expand All @@ -29,49 +36,55 @@ final class WidgetHomeScreenProbeUITests: XCTestCase {
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
springboard.activate()

guard dismissPermissionAlert(springboard) else {
XCTFail("unsupported-path: notification permission alert could not be dismissed; on-screen: \(elementInventory(springboard))")
return
}

let wallpaper = springboard.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.70))
wallpaper.press(forDuration: 2.0)

guard let edit = waitForControl(springboard, editLabel, timeout: 8) else {
XCTFail("unsupported-path: Edit control missing after long-press")
XCTFail("unsupported-path: Edit control missing after long-press; on-screen: \(elementInventory(springboard))")
return
}
tap(edit)

guard let addWidget = waitForControl(springboard, addWidgetLabel, timeout: 8) else {
XCTFail("unsupported-path: Add Widget control missing")
XCTFail("unsupported-path: Add Widget control missing; on-screen: \(elementInventory(springboard))")
return
}
tap(addWidget)

let search = springboard.searchFields.firstMatch
guard search.waitForExistence(timeout: 8) else {
XCTFail("unsupported-path: widget gallery search field missing")
XCTFail("unsupported-path: widget gallery search field missing; on-screen: \(elementInventory(springboard))")
return
}
tap(search)
search.typeText(appLabel)

guard let widget = waitForWidgetResult(springboard) else {
XCTFail("unsupported-path: CodeCaps widget missing from gallery search")
XCTFail("unsupported-path: CodeCaps widget missing from gallery search; on-screen: \(elementInventory(springboard))")
return
}
tap(widget)

guard let confirm = waitForControl(springboard, addWidgetLabel, timeout: 8) else {
XCTFail("unsupported-path: gallery confirm Add Widget missing")
guard let confirm = waitForControl(springboard, addWidgetLabel, timeout: 8)
?? waitForControl(springboard, galleryAddWidgetLabel, timeout: 3) else {
XCTFail("unsupported-path: gallery confirm Add Widget missing; on-screen: \(elementInventory(springboard))")
return
}
tap(confirm)

guard let done = waitForControl(springboard, doneLabel, timeout: 8) else {
XCTFail("unsupported-path: Done control missing after add")
XCTFail("unsupported-path: Done control missing after add; on-screen: \(elementInventory(springboard))")
return
}
tap(done)

if springboard.searchFields.firstMatch.exists {
XCTFail("unsupported-path: widget gallery search field still present after add")
XCTFail("unsupported-path: widget gallery search field still present after add; on-screen: \(elementInventory(springboard))")
return
}

Expand All @@ -94,18 +107,88 @@ final class WidgetHomeScreenProbeUITests: XCTestCase {
add(attachment)
}

/// Search lists the app, then the widget. Tap the app row only when the
/// widget name is not on screen yet, then require the widget itself.
/// Rows are cells or buttons. The search field's typed text is not a row.
/// The companion asks for notification permission when its model first
/// loads: two alert kinds ship enabled with notifications on, and the
/// model's startup sync assigns its preferences, which makes the model
/// request authorization. On a fresh simulator that system alert is
/// still sitting on SpringBoard when this test starts. The alert is
/// modal — while it is up, the long-press never reaches the Home Screen
/// and no Edit control exists — so the contract declines it first. The
/// probe never grants a permission on the owner's behalf, and the widget
/// render does not need notifications. Returns false when an alert is
/// present but will not dismiss.
private func dismissPermissionAlert(_ app: XCUIApplication) -> Bool {
guard let decline = waitForControl(app, doNotAllowLabel, timeout: 5) else {
// No decline button is not yet proof of no alert: the modal is
// absent only when neither of its buttons is on screen.
return existingControl(app, allowLabel) == nil
}
Comment thread
swu-rob[bot] marked this conversation as resolved.
Resolved
tap(decline)
let deadline = Date().addingTimeInterval(5)
repeat {
if existingControl(app, doNotAllowLabel) == nil && existingControl(app, allowLabel) == nil {
return true
}
RunLoop.current.run(until: Date().addingTimeInterval(0.2))
} while Date() < deadline
return existingControl(app, doNotAllowLabel) == nil && existingControl(app, allowLabel) == nil
}

/// Diagnostic inventory for a contract failure: the labeled elements
/// SpringBoard is presenting right now, so the failure line names what
/// was actually on screen instead of only what was missing.
private func elementInventory(_ app: XCUIApplication) -> String {
Comment thread
swu-rob[bot] marked this conversation as resolved.
Resolved
let kinds: [(String, XCUIElement.ElementType)] = [
("button", .button),
("menuItem", .menuItem),
("cell", .cell),
("icon", .icon),
("staticText", .staticText),
("other", .other),
]
let labeled = NSPredicate(format: "label != ''")
var entries: [String] = []
for (name, type) in kinds {
let query = app.descendants(matching: type).matching(labeled)
for index in 0..<25 {
if entries.count >= 150 {
return entries.joined(separator: " | ")
}
let element = query.element(boundBy: index)
if !element.exists {
break
}
if !element.label.isEmpty {
entries.append("\(name)=\(element.label)")
}
}
}
return entries.isEmpty ? "<no labeled elements>" : entries.joined(separator: " | ")
}

/// Search lists the app, and can also list the widget itself — as a
/// button carrying the compound "CodeCaps, AI Subscription Overview"
/// label, never the bare widget name. The app's gallery page presents
/// that same compound button for the widget preview, with the widget
/// name as a static text and the description underneath. Match what
/// SpringBoard actually presents: the compound button in the results,
/// or the app row first and then the widget on its page.
private func waitForWidgetResult(_ app: XCUIApplication) -> XCUIElement? {
if let widget = waitForResult(app, widgetLabel, timeout: 8) {
let compoundLabel = "\(appLabel), \(widgetLabel)"
if let entry = waitForResult(app, compoundLabel, timeout: 8) {
return entry
}
if let widget = waitForResult(app, widgetLabel, timeout: 2) {
return widget
}
guard let appRow = waitForResult(app, appLabel, timeout: 2) else {
return nil
}
tap(appRow)
return waitForResult(app, widgetLabel, timeout: 8)
if let widget = waitForResult(app, compoundLabel, timeout: 8) {
return widget
}
return waitForResult(app, widgetLabel, timeout: 3)
}

private func waitForResult(_ app: XCUIApplication, _ label: String, timeout: TimeInterval) -> XCUIElement? {
Expand Down
43 changes: 43 additions & 0 deletions scripts/widget_homescreen_probe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,19 @@ def test_a_real_gallery_mismatch_stays_a_refusal(self):
self.assertEqual(outcome_code(outcome), EXIT_UNSUPPORTED)
self.assertIn("Edit control missing", message)

def test_gallery_failure_with_on_screen_inventory_stays_a_refusal(self):
log = (
"error: -[WidgetHomeScreenProbeUITests testHomeScreenRendersSeededQuota] : "
"failed - unsupported-path: Edit control missing after long-press; "
"on-screen: button=Allow | staticText=CodeCaps\n"
"** TEST FAILED **\n"
)
outcome, message = interpret_log(log, 12000)
self.assertEqual(outcome, Outcome.UNSUPPORTED)
self.assertEqual(outcome_code(outcome), EXIT_UNSUPPORTED)
self.assertIn("Edit control missing", message)
self.assertIn("on-screen: button=Allow", message)

def test_success_without_a_screenshot_is_a_failure(self):
log = (
"Test Case '-[WidgetHomeScreenProbeUITests testHomeScreenRendersSeededQuota]' started.\n"
Expand Down Expand Up @@ -807,6 +820,36 @@ def test_swift_oracle_matches_the_seed_and_the_widget_name(self):
self.assertIn('configurationDisplayName("AI Subscription Overview")', bundle)
self.assertIn("AI Subscription Overview", swift)

def test_swift_gallery_contract_declines_the_permission_alert_first(self):
swift = (PROBE_SOURCES / "UITests" / "WidgetHomeScreenProbeUITests.swift").read_text(encoding="utf-8")
# The decline button's label carries a U+2019 apostrophe, written in
# the Swift source as an escape so the label stays byte-exact.
self.assertIn('doNotAllowLabel = "Don\\u{2019}t Allow"', swift)
self.assertIn("dismissPermissionAlert", swift)
# The alert is modal: the dismissal must run before the long-press,
# or the press never reaches the Home Screen and no Edit control
# exists. An alert that will not dismiss stays an exit-78 refusal.
self.assertLess(
swift.index("dismissPermissionAlert(springboard)"),
swift.index("press(forDuration: 2.0)"),
)
self.assertIn(
"unsupported-path: notification permission alert could not be dismissed", swift)
# A contract failure names what SpringBoard actually presented.
self.assertIn("elementInventory", swift)
self.assertIn("on-screen:", swift)
# The gallery never presents the bare widget name as a result row:
# the widget entry is a button with the compound "App, Widget"
# label, and the widget page's confirm button carries a leading
# space. Both presented forms are pinned.
self.assertIn('galleryAddWidgetLabel = " Add Widget"', swift)
self.assertIn('"\\(appLabel), \\(widgetLabel)"', swift)
# The no-alert verdict requires both alert buttons absent, and the
# widget fallback returns a tappable row (cells/buttons), never a
# static text.
self.assertIn("existingControl(app, allowLabel) == nil", swift)
self.assertIn("return waitForResult(app, widgetLabel, timeout: 3)", swift)

def test_off_device_widget_probe_still_compiles_the_real_views(self):
text = (ROOT / "scripts/test-widget-ui-native.sh").read_text(encoding="utf-8")
self.assertIn("swiftc -parse-as-library", text)
Expand Down
Loading