Test the composer minimum size and report UI test failures

Add extra-small Dynamic Type coverage for 36-point control allocations
in both themes using the existing test host.

Print assertion errors and failed test cases from the saved runner log,
and update the coverage documentation.
This commit is contained in:
heyaim 2026-11-06 13:44:24 -06:00
parent 16b783f661
commit 160aeda0ed
6 changed files with 121 additions and 13 deletions

View File

@ -138,13 +138,13 @@ struct ContentComposerView: View {
if conversationUIModel.canSendMediaInCurrentContext {
attachmentButton
#if COMPOSER_TEST_HOST && os(macOS)
#if COMPOSER_TEST_HOST
.localComposerProbeFrame("attachment")
#endif
}
sendOrMicButton
#if COMPOSER_TEST_HOST && os(macOS)
#if COMPOSER_TEST_HOST
.localComposerProbeFrame("action")
#endif
}

View File

@ -1,4 +1,4 @@
#if COMPOSER_TEST_HOST && os(macOS)
#if COMPOSER_TEST_HOST
import SwiftUI
// Compiled only into the inert composer host, never the shipping app.
@ -9,14 +9,34 @@ struct LocalComposerProbeFrames: PreferenceKey {
}
}
extension View {
func localComposerProbeFrame(_ name: String) -> some View {
background(GeometryReader { geometry in
private struct LocalComposerProbeStateKey: EnvironmentKey {
static let defaultValue = ""
}
extension EnvironmentValues {
var localComposerProbeState: String {
get { self[LocalComposerProbeStateKey.self] }
set { self[LocalComposerProbeStateKey.self] = newValue }
}
}
private struct LocalComposerFrameProbe: View {
let name: String
@Environment(\.localComposerProbeState) private var state
var body: some View {
GeometryReader { geometry in
Color.clear.preference(
key: LocalComposerProbeFrames.self,
value: [name: geometry.frame(in: .named("LocalComposerProbe"))]
value: [state + name: geometry.frame(in: .named("LocalComposerProbe"))]
)
}.allowsHitTesting(false))
}.allowsHitTesting(false)
}
}
extension View {
func localComposerProbeFrame(_ name: String) -> some View {
background(LocalComposerFrameProbe(name: name))
}
}
#endif

View File

@ -5,6 +5,8 @@
struct ComposerLayoutFixture: View {
@Environment(\.dynamicTypeSize) private var dynamicTypeSize
@Environment(\.layoutDirection) private var layoutDirection
@State private var controlFrames: [String: CGRect] = [:]
@State private var measuredState = ""
@State private var composerFrame = CGRect.zero
@State private var text = "hello"
@State private var selection = "not selected"
@ -29,6 +31,7 @@
models = makeLayoutFeatureModels(for: vm, displayLocationManager: makeLayoutLocationManager())
}
private var dynamicTypeName: String {
if dynamicTypeSize == .xSmall { return "xSmall" }
if dynamicTypeSize == .large { return "large" }
if dynamicTypeSize == .accessibility5 { return "accessibility5" }
return "unexpected \(String(describing: dynamicTypeSize))"
@ -39,6 +42,15 @@
[composerFrame.minX, composerFrame.minY, composerFrame.width, composerFrame.height]
.map { String(Double($0)) }.joined(separator: ",")
}
private var measurementState: String {
"\(viewModel.canSendMediaInCurrentContext)-\(text.isEmpty)"
}
private var controlBoundsValue: String {
measuredState + "|" + ["attachment", "action"].map { name in
guard let frame = controlFrames[name] else { return name + ":missing" }
return name + ":" + [frame.width, frame.height].map { String(Double($0)) }.joined(separator: ",")
}.joined(separator: "|")
}
var body: some View {
VStack {
Group {
@ -47,6 +59,9 @@
.accessibilityIdentifier("languageDirection")
Text("Dynamic Type: " + dynamicTypeName)
.accessibilityIdentifier("dynamicType")
Text("Control allocations")
.accessibilityIdentifier("controlAllocations")
.accessibilityValue(controlBoundsValue)
Text("Composer bounds")
.accessibilityIdentifier("composerBounds")
.accessibilityValue(composerBoundsValue)
@ -86,6 +101,16 @@
text = ""
}, showImagePicker: $picker, imagePickerSourceType: $source), featureModels: models
)
.coordinateSpace(name: "LocalComposerProbe")
.onPreferenceChange(LocalComposerProbeFrames.self) { [state = measurementState] frames in
let prefix = state + "|"
guard !frames.isEmpty, frames.keys.allSatisfy({ $0.hasPrefix(prefix) }) else { return }
controlFrames = Dictionary(uniqueKeysWithValues: frames.map {
(String($0.key.dropFirst(prefix.count)), $0.value)
})
measuredState = state
}
.environment(\.localComposerProbeState, measurementState + "|")
.frame(width: ProcessInfo.processInfo.environment["NARROW"] == "1" ? 280 : 390)
.background(GeometryReader { geometry in
Color.clear

View File

@ -22,6 +22,50 @@ final class ComposerLayoutUITests: XCTestCase {
super.tearDown()
}
func testMinimumSizeMatrix() { checkMinimumSize(glass: false) }
func testMinimumSizeGlass() { checkMinimumSize(glass: true) }
private func checkMinimumSize(glass: Bool) {
continueAfterFailure = false
let app = XCUIApplication()
activeApp = app
app.launchEnvironment = ["CI": "1", "GLASS": glass ? "1" : "0", "NARROW": "1"]
app.launchArguments = ["-AppleLanguages", "(en)", "-AppleLocale", "en_US",
"-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryXS"]
app.launch()
XCTAssertTrue(app.staticTexts["Dynamic Type: xSmall"].waitForExistence(timeout: 10))
assertMinimumAllocations(app, state: "true-false", attachment: true, action: "send")
app.buttons["Empty draft"].tap()
XCTAssertTrue(app.buttons["record voice note"].waitForExistence(timeout: 3))
assertMinimumAllocations(app, state: "true-true", attachment: true, action: "microphone")
app.buttons["No media context"].tap()
XCTAssertFalse(app.buttons["send message"].isEnabled)
assertMinimumAllocations(app, state: "false-true", attachment: false, action: "disabled send")
app.buttons["Fill draft"].tap()
XCTAssertTrue(app.buttons["send message"].isEnabled)
assertMinimumAllocations(app, state: "false-false", attachment: false, action: "send-only")
}
private func assertMinimumAllocations(_ app: XCUIApplication, state: String,
attachment: Bool, action: String) {
let report = app.staticTexts["controlAllocations"]
let ready = NSPredicate { _, _ in
(report.value as? String)?.hasPrefix(state + "|") == true
}
expectation(for: ready, evaluatedWith: report)
waitForExpectations(timeout: 10)
let value = report.value as? String ?? ""
print("MINIMUM_ALLOCATION \(action): \(value)")
for name in attachment ? ["attachment", "action"] : ["action"] {
let entry = value.split(separator: "|").dropFirst().first { $0.hasPrefix(name + ":") }
let dimensions = entry?.split(separator: ":").last?.split(separator: ",").compactMap { Double($0) } ?? []
XCTAssertEqual(dimensions.count, 2, "Missing measured allocation for \(name): \(value)")
guard dimensions.count == 2 else { return }
XCTAssertEqual(dimensions[0], 36, accuracy: 0.5, "\(name) \(action) width must retain the 36-point minimum")
XCTAssertEqual(dimensions[1], 36, accuracy: 0.5, "\(name) \(action) height must retain the 36-point minimum")
}
}
func testActualPhotoPickerMatrixOrdinary() { checkActualPhotoPicker(glass: false, large: false) }
func testActualPhotoPickerMatrixLarge() { checkActualPhotoPicker(glass: false, large: true) }
func testActualPhotoPickerGlassOrdinary() { checkActualPhotoPicker(glass: true, large: false) }

View File

@ -2,13 +2,14 @@
The Build & Test workflow runs these checks automatically in its existing jobs:
- The iOS simulator job runs 27 XCUITest cases after the standard app tests,
- The iOS simulator job runs 29 XCUITest cases after the standard app tests,
using a fresh disposable simulator of the selected type/runtime and the resolved Xcode package cache. Eleven cases cover
attachment/send and attachment/microphone bounds, ordinary/accessibility XXXL
text, both themes, 280/390-point rows, attachment bindings, sending, synthetic
recording/cancel and narrow text entry. Four additional cases use the actual
production photo picker in both themes at ordinary/accessibility XXXL text. Twelve
selected-language cases add Arabic/Hebrew/German layout coverage described below.
Two minimum-size cases check 36-point control allocations at extra-small text in both themes, covering attachment, send, microphone and disabled/enabled send-only states.
- The native app matrix job runs four macOS button cases serially after coverage
and performance checks, copying resolved dependencies into a separate composer build directory. They send native
in-process mouse events to the fully mounted composer, checking attachment,
@ -24,9 +25,7 @@ extension dependency.
The macOS runner selects the explicit `COMPOSER_TEST_HOST=1` SwiftPM configuration.
That configuration uses the inert entry point and includes composer support in
the existing app test target; the runner selects its four composer cases. Frame readers are declared behind `COMPOSER_TEST_HOST && os(macOS)`;
normal builds exclude their implementation and calls. The readers do not receive
hit tests and report layout allocations, not accessibility bounds.
the existing app test target; the runner selects its four composer cases. Frame readers are declared behind `COMPOSER_TEST_HOST` and used by both test hosts; normal builds exclude their implementation and calls. The readers do not receive hit tests and report layout allocations, not accessibility bounds.
Normal runs do not copy or rewrite source/project files. The macOS runner copies
resolved package inputs, not ordinary build products, into its own configuration
@ -42,7 +41,7 @@ resolved package cache matching `Package.resolved`. Record inputs without buildi
python3 composerLayoutTests/run.py --output /tmp/composer-layout
```
Build and run all 27 cases:
Build and run all 29 cases:
```sh
python3 composerLayoutTests/run.py --output /tmp/composer-layout-run \

View File

@ -15,6 +15,8 @@ from runner_support import Interrupted, bounded, install_signal_handlers, manife
# This inventory is intentionally independent of source discovery: removing or
# replacing a case must require an explicit coverage update, even for subset runs.
EXPECTED = {
'testMinimumSizeMatrix',
'testMinimumSizeGlass',
'testAccessibilityXXXL',
'testAccessibilityXXXLWide',
'testActualPhotoPickerGlassLarge',
@ -154,6 +156,24 @@ def main():
command = common + ['-resultBundlePath', str(output / 'result.xcresult')] + filters + ['test-without-building']
code = bounded(command, host, env, output, 'run', args.test_timeout)
reason = 'tests passed' if code == 0 else 'tests failed'
if code != 0:
try:
with (output / 'run.log').open(errors='replace') as log:
failures = [
line.rstrip()
for line in log
if ': error:' in line
or (line.startswith('Test Case ') and "' failed (" in line)
]
print('Failure details from the test log:', flush=True)
print(
'\n'.join(failures)
if failures
else 'No matching assertion errors or failed test cases were recorded.',
flush=True,
)
except OSError as error:
print(f'Could not read test failure details: {error}', flush=True)
if code == 0:
summary = json.loads(require(['xcrun', 'xcresulttool', 'get', 'test-results', 'summary', '--path',
str(output / 'result.xcresult')], source, env, output, 'summary', 30))