Repository navigation
core: Fail sign-in at once where no link can bring the callback back - #2722
Conversation
|
💡 Needs the maintainer's call on a new public field: Reviewed 9370660. The fix is right: on the web, GPUI and TUI backends an |
huacnlee
left a comment
There was a problem hiding this comment.
✅ API accepted: Environment::scheme_links follows the existing clipboard_images pattern and is only set by platform backends.
The maintainers accepted the new field after the earlier 💡 review (head 9370660, unchanged). Ready to merge once CI is green.
Closes #2709
Description
open_auth_sessionin a Rust app that claims its callback scheme waited forever on the platforms that hand the app no links of its schemes: the web (a page hears only its own address), and the GPUI and terminal backends (no URL-scheme events at all). #2285 meant such a session to fail at once withERR_FEATURE_UNAVAILABLE_ON_PLATFORM, andrust.mdandopen_auth_session's doc say so. It now does.This takes the first of the two ways #2709 offers, since
os == Os::Webalone would leave GPUI and the terminal backend waiting:nsh_core::platform::Environment::scheme_links: Option<bool>, withEnvironment::scheme_links(). It followsclipboard_images:None(the default) is as NSH's native backends onos, every OS but the web. The GPUI backend (initial_environment) and the terminal backend (AppView::new) saySome(false). A platform built outside NSH that hears no links saysSome(false)too:platform-extensions.md's example anddocs/dev/platforms.mdnow say so. The Mini Program platform reports iOS or Android, so it needs that one line to get the immediate failure; until it has it, it behaves as today.open_auth_sessionnever answers where no link can bring its callback back (the web, GPUI, the terminal platform) #2709 also floated) so that nothing changes for headless runs, embedders or platforms built outside NSH that do deliver links.nsh_core::element::Environment::scheme_links: bool, inui_environment), andstart_auth_sessionrefuses a session the platform does not show itself (Environment::auth_session) wherescheme_linksis false, before the claimed-scheme check, with its own message: "openAuthSession: no in-app sign-in here, and no link ofmyapp:can reach the app on this platform".Noneand resolve totrue, as do headless runs (Os::default()).auth_sessionmodule doc,open_auth_session's andAuthSessionError::unavailable's doc,Headless::on_auth_session's doc,docs/dev/platforms.md,docs/dev/api-naming.md's decision row, andrust.mdandplatform-extensions.mdin en and zh-CN.Making sign-in complete on the web is a separate question, as #2709 says.
Public API
nsh_core::platform::Environment::scheme_links: Option<bool>: whether the platform hands the app links of the schemes it claims;Nonefollowsos.nsh_core::platform::Environment::scheme_links(&self) -> bool: the field, or by the OS (all but the web).nsh_core::element::Environment::scheme_links: bool: the resolved value the core reads.Breaking Changes
Environmentstructs gain a public field and are not#[non_exhaustive], so a struct literal without..Default::default()outside NSH no longer compiles, as withtab_bar,clipboard_images,shadersandauth_sessionbefore it. Every literal in the repository uses...open_auth_sessionwith a claimed scheme now fails at once instead of opening the page and never answering. No JS API changes (open_auth_sessionis Rust only).// A platform built outside NSH, or a test, that writes `Environment` out in full: Environment { os: Os::Ios, platform: Some("miniprogram"), + // It hands the app no links of its schemes: + scheme_links: Some(false), - // (every other field) + ..Environment::default() }How to Test
cargo test -p nsh-testing --lib -- session: 4 passed, including the newwhere_no_link_of_the_apps_schemes_comes_the_session_fails_at_once: the web refuses at once and opens nothing;Some(false)refuses on an OS that would otherwise hear links;Some(true)on the web opens the page and the callback link ends the session; a session the platform shows itself needs no link.cargo test -p nsh-core --lib -- scheme_links auth_session:scheme_links_follow_the_os_unless_the_platform_sayscovers everyOswithNone,Some(false)andSome(true).start_auth_session, and withui_environmenthanding the coretrue, the headless test fails (the session waits).cargo testwith core CI's packages and features (-p nsh-core -p nsh-macros -p nsh-js -p nsh-base -p nsh-engine -p nsh-bundler -p nsh-package -p nsh-testing --features nsh-bundler/bundle,nsh-testing/bundle,nsh-testing/agent,--no-fail-fast): all pass but two that fail the same way onmain(228a4eb) on this Mac:nsh-core's lib tests abort with a stack overflow in a spawned thread, andnsh-base'srich_editor::view_features::selection_boxes_are_drawn_in_task_items_and_code_blocks.cargo test -p nsh-platform-tui: passes.cargo clippy --all-targets -p nsh-core -p nsh-engine -p nsh-testing -p nsh-platform-tui --features nsh-testing/bundle,nsh-testing/agent -- -D warnings: clean.cargo clippy --manifest-path crates/gpui/Cargo.toml -p nsh-platform-gpui --all-targets --features runtime-shaders -- -D warnings: clean (runtime-shadersbecause this Mac has no Metal toolchain).cargo test --manifest-path crates/gpui/Cargo.toml -p nsh-platform-gpui --features runtime-shaders: 301 passed.cargo +nightly fmt --all -- --check: nothing in the changed files (its only diff isnsh-platform-linux/src/text.rs, as onmain).Checklist
cargo test --workspace,cargo +nightly fmt --alland clippy (including the Catalyst and Android runs for platform code): core CI's test command, clippy and fmt above; not the whole workspace, Catalyst or Android (iOS and Android are not touched).tests/compat/(cargo xtask compat): no JS change.examples/gallerydemos on iOS and Android (if the change is visible or platform-specific): not touched on iOS or Android.