Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(mobile): load development pages through native bootstrap (#960)
Gener99cf3d309cc9
diff --git a/scripts/ci/native-oauth-desktop.test.ts b/scripts/ci/native-oauth-desktop.test.tsindex 8b6fb1014..0e7a3e508 100644--- a/scripts/ci/native-oauth-desktop.test.ts+++ b/scripts/ci/native-oauth-desktop.test.ts@@ -17,7 +17,7 @@ describe("desktop native OAuth security configuration", () => {}const oauth = merged.find(c => c.permissions.includes("native-oauth"))!const isProduction = config === production- expect(config.build.frontendDist).toBe(isProduction ? "alook-recovery://localhost/bootstrap" : "http://localhost:3000/c")+ expect(config.build.frontendDist).toBe(isProduction ? "alook-recovery://localhost/bootstrap" : "http://localhost:3000")expect(oauth.windows).toEqual(["main"])expect(oauth.platforms).toEqual(expect.arrayContaining(["linux", "macOS", "windows"]))expect(oauth.remote?.urls).toEqual(isProduction ? ["https://alook.ai"] : ["http://localhost:3000"])diff --git a/scripts/ci/tauri-startup.test.ts b/scripts/ci/tauri-startup.test.tsindex cd3958ce5..cfe54a410 100644--- a/scripts/ci/tauri-startup.test.ts+++ b/scripts/ci/tauri-startup.test.ts@@ -20,7 +20,11 @@ describe("Tauri startup release separation", () => {})))expect(release.bundle.iOS.infoPlist).toBe("Info.ios.release.plist")expect(base.app.windows.every((window: Record<string, unknown>) => !window.limitNavigationsToAppBoundDomains)).toBe(true)- expect(development.app.windows).toBeUndefined()+ expect(development.app.windows).toEqual(base.app.windows.map((window: object) => ({+ ...window,+ url: "alook-recovery://localhost/bootstrap",+ })))+ expect(development.build).toEqual({ frontendDist: "http://localhost:3000", devUrl: "http://localhost:3000" })expect(development.bundle?.iOS?.infoPlist).toBeUndefined()expect(existsSync(resolve(tauriRoot, "Info.ios.plist"))).toBe(false)const plist = read("Info.ios.release.plist")diff --git a/src/desktop/src-tauri/src/native_command_guard.rs b/src/desktop/src-tauri/src/native_command_guard.rsindex df4a8590e..0f13e14a7 100644--- a/src/desktop/src-tauri/src/native_command_guard.rs+++ b/src/desktop/src-tauri/src/native_command_guard.rs@@ -1,7 +1,7 @@use tauri::WebviewWindow;-pub fn caller_allowed(label: &str, url: &url::Url, debug: bool) -> bool {- let expected = if debug {+pub fn caller_allowed(label: &str, url: &url::Url, development: bool) -> bool {+ let expected = if development {"http://localhost:3000"} else {"https://alook.ai"@@ -14,7 +14,7 @@ pub fn caller_allowed(label: &str, url: &url::Url, debug: bool) -> bool {pub fn guard(window: &WebviewWindow) -> Result<(), &'static str> {let url = window.url().map_err(|_| "untrusted_caller")?;- if caller_allowed(window.label(), &url, cfg!(debug_assertions)) {+ if caller_allowed(window.label(), &url, tauri::is_dev()) {Ok(())} else {Err("untrusted_caller")@@ -25,6 +25,31 @@ pub fn guard(window: &WebviewWindow) -> Result<(), &'static str> {mod tests {use super::caller_allowed;+ #[test]+ fn proxy_origins_never_grant_command_access() {+ for development in [false, true] {+ for target in [+ "tauri://localhost/c",+ "http://tauri.localhost/c",+ "http://tauri.localhost:80/c",+ "http://localhost:3001/c",+ "http://127.0.0.1:3000/c",+ "http://user@localhost:3000/c",+ "http://user:password@localhost:3000/c",+ "https://alook.ai:8443/c",+ "alook-recovery://localhost/bootstrap",+ "http://alook-recovery.localhost/bootstrap",+ ] {+ let url = url::Url::parse(target).unwrap();+ assert!(+ !caller_allowed("main", &url, development),+ "accepted {target}"+ );+ assert!(!caller_allowed("other", &url, development));+ }+ }+ }+#[test]fn accepts_only_the_main_window_and_exact_origin() {assert!(caller_allowed(diff --git a/src/desktop/src-tauri/src/native_oauth_runtime.rs b/src/desktop/src-tauri/src/native_oauth_runtime.rsindex 4d0ac427f..6a6e768b4 100644--- a/src/desktop/src-tauri/src/native_oauth_runtime.rs+++ b/src/desktop/src-tauri/src/native_oauth_runtime.rs@@ -227,7 +227,7 @@ pub fn native_oauth_open_start(start_url: String,) -> Result<(), &'static str> {guard(&window)?;- state.transact(|record| record.open(&attempt_id, &start_url, cfg!(debug_assertions)))?;+ state.transact(|record| record.open(&attempt_id, &start_url, tauri::is_dev()))?;window.app_handle().opener()diff --git a/src/desktop/src-tauri/src/webview_recovery.rs b/src/desktop/src-tauri/src/webview_recovery.rsindex e9ff0c83f..d9cb26949 100644--- a/src/desktop/src-tauri/src/webview_recovery.rs+++ b/src/desktop/src-tauri/src/webview_recovery.rs@@ -1,6 +1,5 @@use std::sync::atomic::{AtomicBool, Ordering};use tauri::http::{Request, Response, StatusCode};-#[cfg(desktop)]use tauri::Manager;use url::Url;@@ -272,8 +271,8 @@ pub fn attach(window: &tauri::WebviewWindow) {let error_window = window.clone();if let Err(error) = window.with_webview(move |webview| match platform::attach(webview) {Ok(()) => {- if !tauri::is_dev() && STARTUP.signal_hooks_ready() {- replace_window_with_production(&startup_window);+ if STARTUP.signal_hooks_ready() {+ replace_window_with_initial_target(&startup_window);}}Err(error) => {@@ -297,32 +296,50 @@ pub fn on_page_load<R: tauri::Runtime>(STARTUP.abandon();}if webview.label() != "main"- || tauri::is_dev()|| !matches!(payload.event(), tauri::webview::PageLoadEvent::Finished)|| !is_bootstrap_url(payload.url()){return;}if STARTUP.signal_bootstrap_finished() {- replace_webview_with_production(webview);+ replace_webview_with_initial_target(webview);}}-fn production_replace_script() -> String {- let target = serde_json::to_string(PRODUCTION_TARGET)- .expect("production target must serialize as JavaScript string");- format!("location.replace({target})")+fn initial_replace_script(+ development: bool,+ development_url: Option<&Url>,+) -> Result<String, &'static str> {+ let target = if development {+ let root = development_url+ .filter(|url| url.as_str() == "http://localhost:3000/")+ .ok_or("untrusted_development_root")?;+ root.join("c")+ .expect("validated development root must accept the main route")+ .to_string()+ } else {+ PRODUCTION_TARGET.to_string()+ };+ let target =+ serde_json::to_string(&target).expect("initial target must serialize as JavaScript string");+ Ok(format!("location.replace({target})"))}-fn replace_window_with_production(window: &tauri::WebviewWindow) {- if let Err(error) = window.eval(production_replace_script()) {+fn replace_window_with_initial_target(window: &tauri::WebviewWindow) {+ let result = initial_replace_script(tauri::is_dev(), window.config().build.dev_url.as_ref())+ .map_err(str::to_owned)+ .and_then(|script| window.eval(script).map_err(|error| error.to_string()));+ if let Err(error) = result {eprintln!("webview recovery initial navigation unavailable: {error}");initialization_failure(window);}}-fn replace_webview_with_production<R: tauri::Runtime>(webview: &tauri::Webview<R>) {- if let Err(error) = webview.eval(production_replace_script()) {+fn replace_webview_with_initial_target<R: tauri::Runtime>(webview: &tauri::Webview<R>) {+ let result = initial_replace_script(tauri::is_dev(), webview.config().build.dev_url.as_ref())+ .map_err(str::to_owned)+ .and_then(|script| webview.eval(script).map_err(|error| error.to_string()));+ if let Err(error) = result {eprintln!("webview recovery initial navigation unavailable: {error}");if STARTUP.signal_failure() {if let Err(error) = webview.navigate(initialization_error_url()) {@@ -1150,6 +1167,137 @@ mod tests {));}+ #[test]+ fn initial_navigation_selects_only_the_original_development_root() {+ let root = Url::parse("http://localhost:3000").unwrap();+ assert_eq!(+ initial_replace_script(true, Some(&root)),+ Ok(r#"location.replace("http://localhost:3000/c")"#.to_string())+ );+ assert_eq!(+ initial_replace_script(false, None),+ Ok(r#"location.replace("https://alook.ai/c")"#.to_string())+ );+ assert_eq!(+ initial_replace_script(false, Some(&root)),+ initial_replace_script(false, None)+ );+ assert_eq!(+ initial_replace_script(true, None),+ Err("untrusted_development_root")+ );+ for target in [+ "http://localhost:3000/c",+ "http://localhost:3000/?source=other",+ "http://localhost:3000/#fragment",+ "http://user@localhost:3000/",+ "http://user:password@localhost:3000/",+ "http://localhost:3001/",+ "http://127.0.0.1:3000/",+ "http://192.168.1.2:3000/",+ "https://localhost:3000/",+ "tauri://localhost/",+ "http://tauri.localhost/",+ ] {+ let target = Url::parse(target).unwrap();+ assert_eq!(+ initial_replace_script(true, Some(&target)),+ Err("untrusted_development_root"),+ "accepted {target}"+ );+ assert_eq!(+ initial_replace_script(false, Some(&target)),+ initial_replace_script(false, None)+ );+ }+ }++ #[test]+ fn development_config_keeps_the_local_bootstrap_and_http_upstream_separate() {+ use tauri::utils::{+ config::{parse::read_from, Config, WebviewUrl},+ platform::Target,+ };+ struct Fixture(PathBuf);+ impl Drop for Fixture {+ fn drop(&mut self) {+ let _ = fs::remove_dir_all(&self.0);+ }+ }+ let project = PathBuf::from(env!("CARGO_MANIFEST_DIR"));+ let (base, _) = read_from(Target::Android, &project).unwrap();+ let nonce = std::time::SystemTime::now()+ .duration_since(std::time::UNIX_EPOCH)+ .unwrap()+ .as_nanos();+ let fixture = Fixture(+ std::env::temp_dir().join(format!("alook-config199r4-{}-{nonce}", std::process::id())),+ );+ fs::create_dir(&fixture.0).unwrap();+ fs::write(+ fixture.0.join("tauri.conf.json"),+ serde_json::to_vec(&base).unwrap(),+ )+ .unwrap();+ fs::write(+ fixture.0.join("tauri.android.conf.json"),+ include_str!("../tauri.dev.conf.json"),+ )+ .unwrap();+ let (merged, _) = read_from(Target::Android, &fixture.0).unwrap();+ let mut window = merged["app"]["windows"][0].clone();+ assert_eq!(+ window.as_object_mut().unwrap().remove("url"),+ Some(serde_json::json!("alook-recovery://localhost/bootstrap"))+ );+ assert_eq!(window, base["app"]["windows"][0]);+ assert_eq!(merged["identifier"], base["identifier"]);+ assert_eq!(+ merged["app"]["security"]["capabilities"],+ serde_json::from_str::<serde_json::Value>(include_str!("../tauri.dev.conf.json"))+ .unwrap()["app"]["security"]["capabilities"]+ );+ fs::write(+ fixture.0.join("tauri.conf.json"),+ serde_json::to_vec(&merged).unwrap(),+ )+ .unwrap();+ fs::write(+ fixture.0.join("tauri.android.conf.json"),+ r#"{"bundle":{"android":{"debugApplicationIdSuffix":".qa.config199r4"}}}"#,+ )+ .unwrap();+ let (with_qa, _) = read_from(Target::Android, &fixture.0).unwrap();+ assert_eq!(with_qa["app"], merged["app"]);+ assert_eq!(+ with_qa["bundle"]["android"]["debugApplicationIdSuffix"],+ ".qa.config199r4"+ );+ let config: Config = serde_json::from_value(with_qa).unwrap();+ let upstream = config.build.dev_url.as_ref().unwrap();+ assert_eq!(upstream.as_str(), "http://localhost:3000/");+ assert_eq!(config.app.windows.len(), 1);+ match &config.app.windows[0].url {+ WebviewUrl::CustomProtocol(url) => {+ assert_eq!(url.as_str(), "alook-recovery://localhost/bootstrap")+ }+ other => panic!("unexpected main entry {other:?}"),+ }+ assert_eq!(+ initial_replace_script(true, Some(upstream)),+ Ok(r#"location.replace("http://localhost:3000/c")"#.to_string())+ );+ for path in [+ "c",+ "_next/static/chunk.js",+ "api/health",+ "api/auth/sign-in/email",+ "api/community/users/me/inbox",+ ] {+ assert_eq!(upstream.join(path).unwrap().path(), format!("/{path}"));+ }+ }+#[test]fn invalid_fragment_fails_closed() {let html = recovery_html();@@ -1159,7 +1307,7 @@ mod tests {}#[test]- fn build_configuration_bootstraps_only_production() {+ fn build_configuration_preserves_production_bootstrap_and_target() {let config = include_str!("../tauri.conf.json");assert!(config.contains("\"devUrl\": \"http://localhost:3000/c\""));assert!(config.contains("\"frontendDist\": \"alook-recovery://localhost/bootstrap\""));diff --git a/src/desktop/src-tauri/tauri.dev.conf.json b/src/desktop/src-tauri/tauri.dev.conf.jsonindex 5bfa83e3d..24161d70b 100644--- a/src/desktop/src-tauri/tauri.dev.conf.json+++ b/src/desktop/src-tauri/tauri.dev.conf.json@@ -93,9 +93,30 @@]}]- }+ },+ "windows": [+ {+ "label": "main",+ "title": "Alook",+ "dragDropEnabled": false,+ "width": 1200,+ "height": 800,+ "minWidth": 800,+ "minHeight": 600,+ "center": true,+ "visible": false,+ "titleBarStyle": "Overlay",+ "hiddenTitle": true,+ "trafficLightPosition": {+ "x": 16,+ "y": 21+ },+ "url": "alook-recovery://localhost/bootstrap"+ }+ ]},"build": {- "frontendDist": "http://localhost:3000/c"+ "frontendDist": "http://localhost:3000",+ "devUrl": "http://localhost:3000"}}