Skip to content

fix: trap when a mediaUploader is set without site credentials - #632

Draft
jkmassel wants to merge 1 commit into
refactor/media-upload-handler-objectfrom
fix/media-uploader-credentials-trap
Draft

fix: trap when a mediaUploader is set without site credentials#632
jkmassel wants to merge 1 commit into
refactor/media-upload-handler-objectfrom
fix/media-uploader-credentials-trap

Conversation

@jkmassel

@jkmassel jkmassel commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Stacked on #631. Ninth of ten PRs splitting #621.

What?

Setting a mediaUploader without site credentials is a configuration error, and now fails fast instead of silently doing nothing.

Why?

Setting a mediaUploader means the host is taking over uploads. With no site credentials the server would previously just not start, silently dropping the uploader — and its media deletes still need the internal media client to reach the configured site, since every attachment lives there no matter who delivered it. Starting anyway would give a server whose every delete 500s.

How?

The behavior forks by intent:

  • A mediaProcessor with no credentials leaves the server down and uploads fall to the default WebView path — there is nothing to deliver through, so nothing to process.
  • A mediaUploader with no credentials traps: precondition on iOS, check on Android.

The iOS policy lives in MediaServerCredentials (added in #624) rather than EditorViewController, which is #if canImport(UIKit) and therefore absent from the macOS host — the one platform that can run Swift Testing's exit tests. Living outside the gate, the trap itself is testable, not just the predicate.

Testing Instructions

  • Two iOS exit tests run the trap in a child process; neutering the precondition fails both
  • Three Android tests through GutenbergView — the two uploader arms and the processor arm; neutering the check fails the two uploader tests
  • swift test — host suite green
  • Android :Gutenberg:testDebugUnitTest green
  • iOS Simulator xcodebuild
  • SwiftLint + Detekt clean

Setting a `mediaUploader` means the host is taking over uploads. With no
site credentials the server would previously just not start, silently
dropping the uploader — and its media deletes still need the internal
media client to reach the configured site, since every attachment lives
there no matter who delivered it. Starting anyway would give a server
whose every delete 500s.

So the behavior forks by intent. A `mediaProcessor` with no credentials
leaves the server down and uploads fall to the default WebView path —
there is nothing to deliver through, so nothing to process. A
`mediaUploader` with no credentials is a configuration error and fails
fast: `precondition` on iOS, `check` on Android.

The iOS policy lives in `MediaServerCredentials` rather than
`EditorViewController`, which is `#if canImport(UIKit)` and therefore
absent from the macOS host — the one platform that can run Swift Testing's
exit tests. Living outside the gate, the trap itself is testable, not just
the predicate: two exit tests run it in a child process, and neutering the
precondition fails both. Android's `check` is covered through
`GutenbergView`, and neutering it fails those two as well.
@jkmassel jkmassel added [Type] Bug An existing feature does not function as intended Android iOS labels Sep 5, 2026
@jkmassel jkmassel self-assigned this Sep 5, 2026
@wpmobilebot

Copy link
Copy Markdown

XCFramework Build

This PR's XCFramework is available for testing. Add the following to your Package.swift:

.package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/632")

Built from 9ee12ea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android iOS [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants