fix(ios,android): close the acceptance gaps the review found, add Android CI

- T-iOS-34's stated acceptance is "最大字号不破版" and it was failing: the key bar
  froze its height at 52pt while an AX5 keycap needs 108.24pt, so caps clipped —
  recorded as a withKnownIssue rather than fixed. Height now derives from the
  content size category (and tracks live changes via registerForTraitChanges);
  the known-issue marker is gone, replaced by positive assertions including a
  12-category no-clip sweep and a guard that stays red if anyone writes the
  constant back. Honest tradeoff: the keycap font is clamped at .accessibility2,
  the same policy the design system already applies to dense content, because an
  unclamped AX5 bar would eat the terminal. A test pins the clamp so the two
  cannot drift.

- Thumbnails silently 401'd on a token-gated host: the pipeline built its own
  transport with no token source, and by design never throws, so every preview
  degraded to a placeholder with no signal. Assembled from AppEnvironment now.

- Android had zero CI while the token wave shipped 24 files of secret-handling
  code. The instrumented leg is workflow_dispatch-only and says why in the file:
  no one has ever seen it green on a runner, and a required leg nobody trusts
  just produces a false green.

- Android persisted a validated token before the host probe succeeded, stranding
  a secret for a host that never paired.

App bundle 534 -> 550 on both simulators, zero known issues. Android 687 -> 691.
This commit is contained in:
Yaojia Wang
2026-07-30 16:46:20 +02:00
parent 284cfd193a
commit 5cc755b0b6
14 changed files with 1120 additions and 102 deletions

View File

@@ -103,26 +103,105 @@ struct DynamicTypeLayoutTests {
#expect(size.height.isFinite)
}
// MARK: - F29 · KeyBarUIKit vs
// MARK: - F29 · KeyBarUIKit inputAccessoryView
/// F1 · `withKnownIssue` ****`KeyBarMetrics.barHeight`
/// 52pt44 + 8 AX5 ~108ptfootnote 52.51 +
/// caption2 47.73 + 4+4 T-iOS-34
/// FAIL****
/// 44pt DS
/// 绿`withKnownIssue`
@Test("KeyBar 在 AX5 下条高容得下它真正画出的键帽(原缺口:裁掉一半以上)")
func keyBarFitsItsKeycapsAtLargestType() {
let measured = KeyBarProbe.measure(at: KeyBarProbe.largestCategory)
#expect(
measured.keycap <= measured.barHeight + LayoutProbe.epsilon,
"AX5 键帽需 \(measured.keycap)pt条高只有 \(measured.barHeight)pt"
)
#expect(
measured.typographic <= measured.barHeight + LayoutProbe.epsilon,
"AX5 排版需求 \(measured.typographic)pt条高只有 \(measured.barHeight)pt"
)
}
@Test("KeyBar 在全部 12 个字号档都不裁切,且条高始终 ≥ 44pt 命中目标")
func keyBarFitsItsKeycapsAtEveryContentSize() {
for category in KeyBarProbe.allCategories {
let measured = KeyBarProbe.measure(at: category)
/// iPhone 16 Pro AX5
/// **108.24pt**footnote 52.51 + caption2 47.73 + 4+4
/// `KeyBarMetrics.barHeight` ** 52pt**44 + 8
///
/// `barHeight` Dynamic Type
/// `UIFontMetrics(forTextStyle: .footnote).scaledValue(for: DS.Layout.minHitTarget + DS.Space.sm8)`
/// `intrinsicContentSize`
/// **`Components/KeyBar.swift` C4 Owns **
/// `withKnownIssue`
/// "known issue was not recorded"
@Test("KeyBar 键帽在 AX5 下超出固定条高已知缺口KeyBar.swift 属他人 Owns")
func keyBarKeycapExceedsBarHeightAtLargestType() {
withKnownIssue("KeyBarMetrics.barHeight 固定 52ptAX5 键帽需约 108pt → 裁切") {
let requirement = KeyBarProbe.largestTypeRequirement()
#expect(
requirement.needed <= requirement.barHeight,
"AX5 键帽 \(requirement.needed)pt,条高只有 \(requirement.barHeight)pt"
measured.keycap <= measured.barHeight + LayoutProbe.epsilon,
"\(category.rawValue)键帽 \(measured.keycap)pt > 条高 \(measured.barHeight)pt"
)
#expect(
measured.typographic <= measured.barHeight + LayoutProbe.epsilon,
"\(category.rawValue):排版需求 \(measured.typographic)pt > 条高 \(measured.barHeight)pt"
)
#expect(
measured.barHeight >= DS.Layout.minHitTarget,
"\(category.rawValue):条高 \(measured.barHeight)pt 低于命中目标"
)
}
}
/// + **** AX5 108.24pt =
/// footnote 52.51 + caption2 47.73 + 8 52pt
/// `barHeight`
@Test("未封顶的 AX5 排版需求远超出厂 52pt 固定条高(这就是原缺口)")
func unclampedLargestTypeOverflowsTheOldFixedBar() {
let shipped = DS.Layout.minHitTarget + DS.Space.sm8
let unclamped = KeyBarProbe.typographicRequirement(at: KeyBarProbe.largestCategory)
#expect(unclamped > shipped * 2)
}
/// ** 44pt **XSXL
/// L 52ptXXL 44pt
///
@Test("默认与更小字号档条高逐点不变44 + 8 = 52零回归")
func keyBarKeepsItsShippedHeightAtTheSmallerSizes() {
let shipped = DS.Layout.minHitTarget + DS.Space.sm8
for category in [UIContentSizeCategory.extraSmall, .small, .medium,
.large, .extraLarge] {
#expect(KeyBarMetrics.barHeight(category) == shipped, "\(category.rawValue)")
}
#expect(KeyBarProbe.measure(at: .large).barHeight == shipped)
}
@Test("键帽真的随字号长大(不是把字号焊死换来的假绿)")
func keyBarActuallyGrowsWithType() {
let standard = KeyBarProbe.measure(at: .large)
let largest = KeyBarProbe.measure(at: KeyBarProbe.largestCategory)
#expect(largest.keycap > standard.keycap)
#expect(largest.barHeight > standard.barHeight)
}
///
/// DS `numericClamp`
@Test("字号封顶 == DS 密集内容策略,封顶后条高不再增长且不超出货架高度的两倍")
func keyBarTypeCeilingMatchesTheDesignSystemPolicy() {
let shipped = DS.Layout.minHitTarget + DS.Space.sm8
#expect(DynamicTypeSize(KeyBarMetrics.typeCeiling) == DS.Typography.numericClamp)
let ceiling = KeyBarMetrics.barHeight(KeyBarMetrics.typeCeiling)
#expect(KeyBarMetrics.barHeight(KeyBarProbe.largestCategory) == ceiling)
//
#expect(ceiling > KeyBarMetrics.barHeight(.large))
// AX5
#expect(ceiling <= shipped * 2)
}
@Test("frame 高度与 intrinsicContentSize 一致(自适应输入视图靠后者自量)")
func keyBarFrameMatchesItsIntrinsicHeight() {
for category in [UIContentSizeCategory.large, KeyBarProbe.largestCategory] {
let bar = KeyBarView(contentSizeCategory: category)
#expect(bar.frame.height == bar.intrinsicContentSize.height)
}
}
}
@@ -148,30 +227,60 @@ enum LayoutProbe {
}
}
/// UIKit AX5 ********
/// UIKit **** `KeyBarView` ****
/// ****
///
///
/// `KeyBarView` AX5 trait `KeyBarView`
/// `UIFont.preferredFont(forTextStyle:)` `compatibleWith:`
/// `UITraitCollection.performAsCurrent { KeyBarView() }`
/// `UIFont.preferredFont(forTextStyle:)`**** `compatibleWith:`
/// **App ** `preferredContentSizeCategory`**** `UITraitCollection.current`
/// `performAsCurrent { KeyBarView() }` 38pt
/// ""绿 `compatibleWith:` AX5
/// glyph + caption+
/// 38pt**绿**
/// `KeyBarView(contentSizeCategory:)` `compatibleWith:`
/// 西
@MainActor
enum KeyBarProbe {
/// AX5
private static let largestCategory = UIContentSizeCategory
static let largestCategory = UIContentSizeCategory
.accessibilityExtraExtraExtraLarge
/// - Returns: (, AX5 )
static func largestTypeRequirement() -> (barHeight: CGFloat, needed: CGFloat) {
let traits = UITraitCollection(preferredContentSizeCategory: largestCategory)
/// 12 7 + 5 ****
static let allCategories: [UIContentSizeCategory] = [
.extraSmall, .small, .medium, .large, .extraLarge, .extraExtraLarge,
.extraExtraExtraLarge, .accessibilityMedium, .accessibilityLarge,
.accessibilityExtraLarge, .accessibilityExtraExtraLarge,
.accessibilityExtraExtraExtraLarge,
]
/// - Returns:
/// - `barHeight` `intrinsicContentSize`
/// - `keycap` **** `KeyBarView`
/// - `typographic` **** +
/// AX5 108.24pt vs 52pt
/// `keycap` 68.86 vs 54.67****
///
static func measure(
at category: UIContentSizeCategory
) -> (barHeight: CGFloat, keycap: CGFloat, typographic: CGFloat) {
let bar = KeyBarView(contentSizeCategory: category)
let keycap = (bar.keyButtons + [bar.voiceButton].compactMap { $0 })
.map { $0.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height }
.max() ?? 0
return (
barHeight: bar.intrinsicContentSize.height,
keycap: keycap,
//
typographic: typographicRequirement(
at: KeyBarMetrics.effectiveCategory(category)
)
)
}
/// + 沿
static func typographicRequirement(at category: UIContentSizeCategory) -> CGFloat {
let traits = UITraitCollection(preferredContentSizeCategory: category)
let glyph = UIFont.preferredFont(forTextStyle: .footnote, compatibleWith: traits)
let caption = UIFont.preferredFont(forTextStyle: .caption2, compatibleWith: traits)
// KeyBarMetrics.buttonInsets xs4
let verticalInsets = DS.Space.xs4 * 2
return (
barHeight: KeyBarView().intrinsicContentSize.height,
needed: glyph.lineHeight + caption.lineHeight + verticalInsets
)
return glyph.lineHeight + caption.lineHeight + DS.Space.xs4 * 2
}
}

View File

@@ -75,6 +75,102 @@ struct KeyBarTests {
#expect(recorder.keys == KeyBarLayout.buttons.map(\.key))
}
// MARK: - Dynamic Type (T-iOS-34 · the bar tracks the keycap it draws)
/// Measured height of every keycap, in layout order (the mic key last when
/// present) the only honest way to ask "did the keycaps really re-render".
private func keycapHeights(_ bar: KeyBarView) -> [CGFloat] {
(bar.keyButtons + [bar.voiceButton].compactMap { $0 })
.map { $0.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height }
}
@Test("changing the text size re-renders every keycap and re-measures the bar")
func contentSizeCategoryChangeRebuildsTheKeycaps() {
// Arrange: a bar born at the standard size, mic key included.
let bar = KeyBarView(
voice: KeyBarVoiceHandlers(onDown: {}, onUp: {}),
contentSizeCategory: .large
)
let standardHeight = bar.intrinsicContentSize.height
let standardKeycaps = keycapHeights(bar)
// Act: the user drags the text-size slider to the maximum.
bar.apply(contentSizeCategory: .accessibilityExtraExtraExtraLarge)
// Assert: EVERY keycap grew (mic included) and the bar grew to hold them.
let largestKeycaps = keycapHeights(bar)
#expect(bar.contentSizeCategory == .accessibilityExtraExtraExtraLarge)
#expect(bar.intrinsicContentSize.height > standardHeight)
#expect(bar.frame.height == bar.intrinsicContentSize.height)
#expect(standardKeycaps.count == KeyBarLayout.buttons.count + 1)
#expect(zip(standardKeycaps, largestKeycaps).allSatisfy { $1 > $0 })
#expect(largestKeycaps.allSatisfy { $0 <= bar.intrinsicContentSize.height })
}
/// The runtime path, not just the direct call: the user changes the text size
/// in Settings while a terminal is open, UIKit pushes a new trait collection,
/// and the bar must re-measure itself otherwise it keeps whatever height it
/// was born with until the terminal is reopened.
@Test("a trait-collection change re-lays-out the bar (no reopen needed)")
func traitChangePropagatesToTheBar() {
// Arrange: a bar inside a real window (trait propagation needs one).
let bar = KeyBarView(contentSizeCategory: .large)
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 390, height: 844))
window.addSubview(bar)
window.layoutIfNeeded()
let before = bar.intrinsicContentSize.height
// Act: what UIKit does when the system text size changes.
window.traitOverrides.preferredContentSizeCategory =
.accessibilityExtraExtraExtraLarge
window.layoutIfNeeded()
// Assert
#expect(bar.contentSizeCategory == .accessibilityExtraExtraExtraLarge)
#expect(bar.intrinsicContentSize.height > before)
}
@Test("re-applying the same text size is a no-op (trait callbacks fire for anything)")
func reapplyingTheSameCategoryChangesNothing() {
// Arrange
let bar = KeyBarView(contentSizeCategory: .large)
let before = keycapHeights(bar)
let beforeHeight = bar.intrinsicContentSize.height
// Act
bar.apply(contentSizeCategory: .large)
// Assert
#expect(bar.contentSizeCategory == .large)
#expect(keycapHeights(bar) == before)
#expect(bar.intrinsicContentSize.height == beforeHeight)
}
/// The HIG floor is enforced by a constraint, not by the glyph: at the small
/// text sizes a keycap's own content is only ~37pt tall, so without this the
/// bar would shrink below a tappable target. Asserted structurally because
/// `systemLayoutSizeFitting` reports the CONTENT size (it is what the
/// clipping test needs) and would not show the constraint at all.
@Test("every keycap carries the 44pt HIG hit-target floor, at every text size")
func keycapsCarryTheHitTargetFloor() {
for category in [UIContentSizeCategory.extraSmall, .large,
.accessibilityExtraExtraExtraLarge] {
let bar = KeyBarView(
voice: KeyBarVoiceHandlers(onDown: {}, onUp: {}),
contentSizeCategory: category
)
for button in bar.keyButtons + [bar.voiceButton].compactMap({ $0 }) {
#expect(button.constraints.contains {
$0.firstAttribute == .height
&& $0.relation == .greaterThanOrEqual
&& $0.constant == DS.Layout.minHitTarget
})
}
#expect(bar.intrinsicContentSize.height >= DS.Layout.minHitTarget)
}
}
// MARK: - Hardware keyboard (UIKeyCommand, same KeyByteMap mapping)
@Test("hardware chords: Esc, Shift+Tab and the 7 Ctrl chords map through KeyByteMap")

View File

@@ -0,0 +1,231 @@
import APIClient
import Foundation
import HostRegistry
import TestSupport
import Testing
import UIKit
import WireProtocol
@testable import WebTerm
/// F1 · 线
///
/// `SessionThumbnailPipeline.live()` ****
/// `URLSessionHTTPTransport` `WEBTERM_TOKEN`
/// `GET /live-sessions/:id/preview` 401线****
/// 401
///
///
///
/// 1. preview ****
/// `URLSessionHTTPTransport.authenticated`
/// 2. preview RO**** `Origin`Origin-iff-G
/// 3. / 401****
@MainActor
@Suite("SessionThumbnail 令牌接线")
struct SessionThumbnailTokenTests {
/// 32 §1.1 `[A-Za-z0-9._~+/=-]` 16512
private static let token = "0123456789abcdefghijklmnopqrstuv"
private static let base = "http://192.168.1.20:3000"
// MARK: - Fixtures
/// `URLSessionHTTPTransport.authenticated`
/// Cookie
private struct StampingTransport: HTTPTransport {
let stamper: URLSessionHTTPTransport
let recorder: FakeHTTPTransport
func send(_ request: URLRequest) async throws -> (Data, HTTPURLResponse) {
try await recorder.send(await stamper.authenticated(request))
}
}
private func makeEndpoint(_ base: String = SessionThumbnailTokenTests.base) throws
-> HostEndpoint {
let url = try #require(URL(string: base))
return try #require(HostEndpoint(baseURL: url))
}
private func makeStore(token: String?) async throws -> InMemoryHostStore {
let store = InMemoryHostStore()
_ = try await store.upsert(
HostRegistry.Host(
id: UUID(), name: "mac", endpoint: try makeEndpoint(),
accessToken: try token.map { try AccessToken(validating: $0) }
)
)
return store
}
private func previewURL(_ sessionId: UUID) throws -> URL {
try #require(
URL(string: "\(Self.base)/live-sessions/\(sessionId.uuidString.lowercased())/preview")
)
}
private func previewBody(_ sessionId: UUID) throws -> Data {
try #require("""
{"id":"\(sessionId.uuidString.lowercased())","cols":80,"rows":24,"data":"hello"}
""".data(using: .utf8))
}
/// ****线
private func makePipeline(
store: any HostStore
) -> (pipeline: SessionThumbnailPipeline, recorder: FakeHTTPTransport) {
let recorder = FakeHTTPTransport()
let transport = StampingTransport(
stamper: AppEnvironment.thumbnailTransport(
hostStore: store, identityProvider: { nil }
),
recorder: recorder
)
return (SessionThumbnailPipeline.live(http: transport), recorder)
}
// MARK: -
@Test("令牌门主机preview 请求带上 Cookie: webterm_auth=<t>,且缩略图真渲染出来")
func previewRequestCarriesTheAccessTokenCookie() async throws {
// Arrange
let sessionId = UUID()
let (pipeline, recorder) = makePipeline(store: try await makeStore(token: Self.token))
await recorder.queueSuccess(
url: try previewURL(sessionId), body: try previewBody(sessionId)
)
// Act
let image = await pipeline.thumbnail(
for: SessionThumbnailRequest(
endpoint: try makeEndpoint(), sessionId: sessionId, lastOutputAt: 1
)
)
// Assert
let requests = await recorder.recordedRequests
#expect(requests.count == 1)
#expect(requests.first?.value(forHTTPHeaderField: AccessTokenCookie.header)
== "\(AccessTokenCookie.name)=\(Self.token)")
#expect(!image.isPlaceholder, "带上令牌后 preview 应当成功并渲染")
}
@Test("preview 是只读路由:带令牌也绝不带 OriginOrigin-iff-G 零回归)")
func previewStaysOriginFree() async throws {
// Arrange
let sessionId = UUID()
let (pipeline, recorder) = makePipeline(store: try await makeStore(token: Self.token))
await recorder.queueSuccess(
url: try previewURL(sessionId), body: try previewBody(sessionId)
)
// Act
_ = await pipeline.thumbnail(
for: SessionThumbnailRequest(
endpoint: try makeEndpoint(), sessionId: sessionId, lastOutputAt: 1
)
)
// Assert
let requests = await recorder.recordedRequests
#expect(requests.first?.value(forHTTPHeaderField: "Origin") == nil)
}
// MARK: - /
@Test("主机没有令牌 → 请求逐字不带 CookieLAN 零配置主机零回归)")
func tokenlessHostSendsNoCookie() async throws {
// Arrange
let sessionId = UUID()
let (pipeline, recorder) = makePipeline(store: try await makeStore(token: nil))
await recorder.queueSuccess(
url: try previewURL(sessionId), body: try previewBody(sessionId)
)
// Act
let image = await pipeline.thumbnail(
for: SessionThumbnailRequest(
endpoint: try makeEndpoint(), sessionId: sessionId, lastOutputAt: 1
)
)
// Assert
let requests = await recorder.recordedRequests
#expect(requests.first?.value(forHTTPHeaderField: AccessTokenCookie.header) == nil)
#expect(!image.isPlaceholder)
}
@Test("令牌缺失导致 401 → 降级成占位图,不崩不抛(管线的错误 UI 就是占位图)")
func unauthorizedDegradesToPlaceholder() async throws {
// Arrange 401
let sessionId = UUID()
let (pipeline, recorder) = makePipeline(store: try await makeStore(token: nil))
await recorder.queueSuccess(
url: try previewURL(sessionId), status: 401,
body: try #require(#"{"error":"unauthorized"}"#.data(using: .utf8))
)
// Act
let image = await pipeline.thumbnail(
for: SessionThumbnailRequest(
endpoint: try makeEndpoint(), sessionId: sessionId, lastOutputAt: 1
)
)
// Assert
#expect(image == .placeholder)
#expect(await recorder.recordedRequests.count == 1)
}
@Test("主机根本不在存储里(存储读不到该 origin→ 无 Cookie仍不崩")
func unknownOriginDegradesGracefully() async throws {
// Arrange
let sessionId = UUID()
let store = InMemoryHostStore()
let otherEndpoint = try makeEndpoint("http://192.168.1.99:3000")
_ = try await store.upsert(
HostRegistry.Host(
id: UUID(), name: "other", endpoint: otherEndpoint,
accessToken: try AccessToken(validating: Self.token)
)
)
let (pipeline, recorder) = makePipeline(store: store)
await recorder.queueSuccess(
url: try previewURL(sessionId), body: try previewBody(sessionId)
)
// Act
let image = await pipeline.thumbnail(
for: SessionThumbnailRequest(
endpoint: try makeEndpoint(), sessionId: sessionId, lastOutputAt: 1
)
)
// Assert
let requests = await recorder.recordedRequests
#expect(requests.first?.value(forHTTPHeaderField: AccessTokenCookie.header) == nil)
#expect(!image.isPlaceholder)
}
// MARK: -
@Test("thumbnailTransport 就是 App 的同一条盖章传输(按 origin 取本主机令牌)")
func thumbnailTransportStampsPerOrigin() async throws {
// Arrange
let transport = AppEnvironment.thumbnailTransport(
hostStore: try await makeStore(token: Self.token), identityProvider: { nil }
)
let mine = URLRequest(url: try previewURL(UUID()))
let other = URLRequest(
url: try #require(URL(string: "http://192.168.1.99:3000/live-sessions"))
)
// Act
let stamped = await transport.authenticated(mine)
let untouched = await transport.authenticated(other)
// Assert
#expect(stamped.value(forHTTPHeaderField: AccessTokenCookie.header)
== "\(AccessTokenCookie.name)=\(Self.token)")
#expect(untouched.value(forHTTPHeaderField: AccessTokenCookie.header) == nil)
}
}