Repository navigation
feat: AUTO binding by default, and mocks wired out of the box - #13
Merged
Merged
Conversation
Two defaults changed, aimed at the same first-run complaint: a fresh integration handed back a 127.0.0.1 URL that needed `adb forward` before it showed anything, and a Mocks screen that could not add a mock. Binding: add BindingMode.AUTO / BrowserBinding.AUTO and make them the default. AUTO binds a real interface when the device has one and falls back to loopback when it does not, so a start always yields a working server. Added as a third mode rather than by re-pointing the default at LAN, because LAN earns its keep by *not* degrading -- a host sharing a connect URL with another device needs NoEligibleNetwork/PermissionRequired back, not a 127.0.0.1 link that works for nobody but itself. The fallback decision lives in AutoBinding as pure functions, since the real thing needs an API 37+ device or a machine with its interfaces down. This loosens a security default: the dashboard speaks plaintext HTTP, so AUTO exposes headers, tokens, and bodies to anyone who can see the traffic. THREAT_MODEL.md is rewritten around the new default rather than patched. AUTO also never prompts for ACCESS_LOCAL_NETWORK -- it settles for loopback instead -- so hosts wanting the prompt ask for LAN by name, which all three samples still do. Mocks: installDevConsole now wires the mock interceptor from an engine the facade publishes to the new MockEngineRegistry at initialize, closing a layering gap (sdk:network-okhttp sits below the facade and cannot call DevConsole.mockEngine()). EditingCapabilities.mocks defaults to true -- a mock rule writes nothing of the host's, it only short-circuits DevConsole's own interceptor -- while readOnly() still grants nothing. Guards a real upgrade regression: a host keeping its manual DevConsoleMockInterceptor would have had two in the chain, and a Delay rule would have slept in both passes. The second one now stands down. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
maksudur03
approved these changes
Aug 17, 2026
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two defaults changed, aimed at the same first-run complaint: a fresh integration handed back a
127.0.0.1URL that neededadb forwardbefore it showed anything, and a Mocks screen that could not add a mock.Binding:
AUTOby defaultAdds
BindingMode.AUTO/BrowserBinding.AUTOand makes them the default forStartRequest.bindingModeandBrowserConfig.binding. AUTO binds a real network interface when the device has one and falls back to loopback when it does not, so a start always yields a working server and the QR code is scannable from another machine with no configuration.Added as a third mode rather than by re-pointing the default at
LAN, becauseLANearns its keep by not degrading: a host sharing a connect URL with another device needsNoEligibleNetwork/PermissionRequiredback, not a127.0.0.1link that works for nobody but itself. ExplicitLOOPBACKandLANbehave exactly as before.BrowserEndpoint.bindingModenever reportsAUTO— it reports the socket that actually bound, so the connect URL, QR code, and "LAN MODE — UNENCRYPTED" banner stay truthful. Fallbacks are logged with their reason.The fallback decision lives in
AutoBindingas pure functions, because the real thing needs an API 37+ device or a machine with its interfaces torn down — neither stageable in Robolectric.startLockedleaves the first attempt unmapped until the retry is settled, so a rescued start never drags the runtime throughserverFailed()on its way toserverStarted().This loosens a security default
The dashboard speaks plaintext HTTP, so wherever AUTO reaches the network, headers, tokens, and bodies are readable by anyone who can see that traffic.
docs/THREAT_MODEL.mdis rewritten around the new default rather than patched.One consequence worth flagging for review: AUTO never prompts for
ACCESS_LOCAL_NETWORK. It treats a missing grant as a reason to bind loopback, not a reason to fail, so on an API 37+ device it settles for127.0.0.1until something requests the grant. Hosts wanting the prompt ask forBindingMode.LANby name — which all three samples still do, keeping that path exercised.AUTOis a reused name, not a restored feature: the pre-1.0BindingMode.AUTOcame with zero-config auto-start and NSD discovery, both still removed. This one only picks a binding. Called out in the KDoc and docs so nobody assumes the old semantics.Mocks: wired out of the box
installDevConsolenow wires the mock interceptor from an engine the facade publishes to a newMockEngineRegistryatinitialize. That registry exists to close a layering gap —sdk:network-okhttpsits below the facade and cannot callDevConsole.mockEngine()— so the separate.addInterceptor(DevConsoleMockInterceptor(DevConsole.mockEngine()))line is no longer needed. PassmockEngine = nullto opt out. The protected build publishes nothing, so a release APK readsnulland wires no mock interceptor.EditingCapabilities.mocksnow defaults totrue, andDevConsoleConfigseedsEditingCapabilities()instead ofreadOnly(). A mock rule writes nothing of the host's — it only short-circuits DevConsole's own interceptor — so the read-only posture that protects preferences, databases, and files had nothing to protect here.readOnly()is now spelled out field by field, so it still grants nothing at all, mocks included.One real regression found and guarded
A host keeping their existing manual
DevConsoleMockInterceptorline would have ended up with two in the chain, and aDelayrule whose next action proceeds up the chain would have slept in both passes — silently doubling every simulated latency on upgrade. The second interceptor now detects the first one's request tag and stands down.Two things for the reviewer to decide
The version number is deliberately unresolved. Under
CHANGELOG.md's own policy, adding a constant to a public enum is source-breaking for any host thatwhens exhaustively overBindingMode/BrowserBinding, and flipping a security default is a behavioural break. That reads as a major, not a minor. The changelog entry sits under## Unreleasedwith a note, andSDK_VERSIONis left at1.2.0.The API surface is additive.
apiDumpis in the diff. The 2- and 3-argumentinstallDevConsole/DevConsoleOkHttp.installoverloads are still emitted via@JvmOverloads, so Java call sites and existing bytecode are unaffected; Kotlin callers relying on default arguments should recompile, since the synthetic$defaultsignature changed.Verification
The protected-artifact check was force-re-run on all three samples specifically because this PR adds a
:sdk:mocksdependency tosdk:network-okhttp— the release APKs carry no full runtime.Two flakes surfaced during verification, both unrelated to this change and both passing on isolated re-run:
CrashPolicyGatingTest(a 200 ms thread-state poll) andDevConsoleKtorModuleTest(a 3-minute coroutine timeout under--rerun-tasksload, in a module this PR does not touch). Separately, the ninegradle-pluginfunctional tests fail identically on a stashed clean tree — pre-existing in this environment, not introduced here.Tests added
AutoBindingTest— the fallback decision, including the failures loopback cannot rescuePlatformFacadeProviderAutoBindingTest— thatstartLockedconsults it, and AUTO never surfaces as a bound modeMockEngineRegistryTest/MockEnginePublishingTest— publish/replace/clear, and that a disabledMOCKScategory still publishes a passthrough engineDevConsoleOkHttpMockInstallTest— real calls throughMockWebServer: a served mock the upstream never sees, untouched passthrough with no matching rule, and the double-DelayguardUpdated to pin the new contract:
FocusedConfigurationTest,DevConsoleContractTest,PlatformFacadeProviderMoreScreenBindingTest,FullFacadeTest.Docs
README,
THREAT_MODEL,LAN_PERMISSION_AND_TROUBLESHOOTING,FAQ_TROUBLESHOOTING,COMPOSER_AND_MOCKS,DATA_INSPECTORS_AND_EXPORTS, and a new "Upgrading from 1.2.0" section inMIGRATION.🤖 Generated with Claude Code