The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
Verify mobile UI against native Remote revocation
Davida494f4ca1003
diff --git a/e2e/native-mobile-proof.mjs b/e2e/native-mobile-proof.mjsnew file mode 100644index 00000000..f0da2cd0--- /dev/null+++ b/e2e/native-mobile-proof.mjs@@ -0,0 +1,57 @@+import { chromium, expect } from '@playwright/test'+import { createInterface } from 'node:readline'+import { join } from 'node:path'+import process from 'node:process'++const base = process.env.LU_REMOTE_PROOF_URL+const code = process.env.LU_REMOTE_PROOF_PASSCODE+const backend = process.env.LU_REMOTE_PROOF_BACKEND+if (!base || !/^http:\/\/127\.0\.0\.1:\d+$/.test(base) || !/^\d{6}$/.test(code || '') || !['ollama', 'openai'].includes(backend)) {+ process.stdout.write('FAIL configuration\n')+ process.exit(1)+}+let browser+let stage = 'launch'+const input = createInterface({ input: process.stdin })+try {+ browser = await chromium.launch({ headless: true })+ const context = await browser.newContext({ viewport: { width: 390, height: 844 } })+ await context.route('**/*', route => new URL(route.request().url()).origin === base ? route.continue() : route.abort())+ const page = await context.newPage()+ page.setDefaultTimeout(10000)+ stage = 'pairing'+ await page.goto(`${base}/mobile`)+ await page.locator('#auth-code').fill(code)+ await page.getByRole('button', { name: 'Connect', exact: true }).click()+ await expect(page.locator('#msg-input')).toBeVisible()+ stage = 'first reply'+ await page.locator('#msg-input').fill('Synthetic request')+ await page.getByRole('button', { name: 'Send', exact: true }).click()+ await expect(page.locator('#chat-area')).toContainText('synthetic reply')+ await expect(page.getByRole('button', { name: 'Send', exact: true })).toBeVisible()+ const revoked = new Promise(resolve => input.once('line', resolve))+ process.stdout.write('READY_TO_REVOKE\n')+ if (await revoked !== 'REVOKED') throw new Error('Invalid control message')+ stage = 'revoked reply'+ await page.locator('#msg-input').fill('Synthetic request after revocation')+ await page.getByRole('button', { name: 'Send', exact: true }).click()+ await expect(page.locator('#chat-area')).toContainText('Restart Remote Access on your desktop, then reconnect.')+ if (process.env.LU_REMOTE_PROOF_OUTPUT) {+ await page.screenshot({ path: join(process.env.LU_REMOTE_PROOF_OUTPUT, `remote-native-mobile-${backend}.png`), fullPage: true })+ }+ stage = 'revoked reload'+ await page.reload()+ await expect(page.getByRole('alert')).toContainText('Restart Remote Access on your desktop, then reconnect.')+ await expect(page.locator('#msg-input')).toHaveCount(0)+ if (process.env.LU_REMOTE_PROOF_OUTPUT) {+ await page.screenshot({ path: join(process.env.LU_REMOTE_PROOF_OUTPUT, `remote-native-mobile-${backend}-reload.png`), fullPage: true })+ }+ process.stdout.write('PASS\n')+} catch {+ // Never print Playwright exception details, which can include the access code.+ process.stdout.write(`FAIL ${stage}\n`)+ process.exitCode = 1+} finally {+ input.close()+ await browser?.close()+}diff --git a/mobile-client/client.js b/mobile-client/client.jsindex eee30477..4899eddc 100644--- a/mobile-client/client.js+++ b/mobile-client/client.js@@ -535,10 +535,14 @@ import {.then(absorbRefresh).then(function(r){if(r.status===401){clearAuthAndReload();throw new Error('401');}- if(!r.ok) throw new Error('HTTP '+r.status);+ if(!r.ok){+ var error = new Error('HTTP '+r.status);+ error.remoteMemoryRevoked = r.status===409 && r.headers.get('x-lu-remote-memory-revoked')==='1';+ throw error;+ }return r.json();})- .catch(function(){return null;});+ .catch(function(error){if(error && error.remoteMemoryRevoked) throw error; return null;});}loadPersisted();@@ -625,6 +629,15 @@ import {}renderShell();+ }).catch(function(error){+ if(!error || !error.remoteMemoryRevoked){+ el('app').textContent = 'Remote connection unavailable. Reload to try again.';+ return;+ }+ el('app').innerHTML = '<div class="auth-screen" role="alert"><h1>Remote memory changed</h1>' ++ '<p>Restart Remote Access on your desktop, then reconnect. Previously delivered data cannot be recalled.</p>' ++ '<button class="auth-btn" id="retry-remote" type="button">Try again after restart</button></div>';+ el('retry-remote').onclick = function(){location.reload();};});function renderShell(){@@ -1617,6 +1630,11 @@ import {return;}if(!r.ok){+ if(r.status===409 && r.headers.get('x-lu-remote-memory-revoked')==='1'){+ msgs[msgs.length-1].content='Remote memory changed. Restart Remote Access on your desktop, then reconnect. Previously delivered data cannot be recalled.';+ finishStream();+ return;+ }// Retry without the think field at all if the server rejects it// (old Ollama or model that refuses the flag).if(r.status===400 && ('think' in body)){diff --git a/src-tauri/src/commands/remote.rs b/src-tauri/src/commands/remote.rsindex 8a9668db..b6f1861b 100644--- a/src-tauri/src/commands/remote.rs+++ b/src-tauri/src/commands/remote.rs@@ -311,6 +311,7 @@ async fn memory_revocation_middleware(&& path != "/remote-api/auth" && path != "/remote-api/status");if protected && revoked.is_cancelled() {return (StatusCode::CONFLICT,+ [("x-lu-remote-memory-revoked", "1")],"Remote memory context was revoked. Restart Remote Access and reconnect before sending another request.").into_response();}@@ -3369,6 +3370,16 @@ mod memory_revocation_tests {#[tokio::test]async fn authenticated_router_revokes_cached_prompts_for_both_chat_backends() {+ run_authenticated_router_proof(false).await;+ }++ #[tokio::test]+ #[ignore = "requires the installed Node and Playwright Chromium runtimes"]+ async fn native_mobile_browser_revocation() {+ run_authenticated_router_proof(true).await;+ }++ async fn run_authenticated_router_proof(browser: bool) {for backend in ["ollama", "openai"] {let received = Arc::new(TokioMutex::new(Vec::<(String, serde_json::Value)>::new()));let captured = received.clone();@@ -3376,13 +3387,19 @@ mod memory_revocation_tests {let captured = captured.clone();async move {let path = req.uri().path().to_string();+ if path == "/api/tags" {+ return Json(serde_json::json!({"models":[{"name":"fixture-model"}]})).into_response();+ }+ if path == "/v1/models" {+ return Json(serde_json::json!({"data":[{"id":"fixture-model"}]})).into_response();+ }let bytes = axum::body::to_bytes(req.into_body(), 65536).await.unwrap();let body = serde_json::from_slice(&bytes).unwrap();captured.lock().await.push((path.clone(), body));if path == "/v1/chat/completions" {- Json(serde_json::json!({"choices":[{"message":{"role":"assistant","content":"synthetic reply"}}]}))+ Json(serde_json::json!({"choices":[{"message":{"role":"assistant","content":"synthetic reply"}}]})).into_response()} else {- Json(serde_json::json!({"message":{"role":"assistant","content":"synthetic reply"},"done":true}))+ ([(header::CONTENT_TYPE, "application/x-ndjson")], "{\"message\":{\"role\":\"assistant\",\"content\":\"synthetic reply\"},\"done\":true}\n").into_response()}}}));@@ -3410,6 +3427,37 @@ mod memory_revocation_tests {let proxy = tokio::spawn(async move {axum::serve(listener, router.into_make_service_with_connect_info::<SocketAddr>()).await.unwrap();});+ if browser {+ use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};+ let result = tokio::time::timeout(std::time::Duration::from_secs(45), async {+ let script = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../e2e/native-mobile-proof.mjs");+ let mut child = tokio::process::Command::new("node").arg(script)+ .env("LU_REMOTE_PROOF_URL", &base).env("LU_REMOTE_PROOF_PASSCODE", &passcode)+ .env("LU_REMOTE_PROOF_BACKEND", backend)+ .stdin(std::process::Stdio::piped()).stdout(std::process::Stdio::piped())+ .stderr(std::process::Stdio::null()).kill_on_drop(true).spawn().unwrap();+ let mut output = BufReader::new(child.stdout.take().unwrap());+ let mut line = String::new();+ output.read_line(&mut line).await.unwrap();+ if line.trim() != "READY_TO_REVOKE" {+ let _ = child.wait().await;+ return false;+ }+ server.revoke_memory();+ child.stdin.take().unwrap().write_all(b"REVOKED\n").await.unwrap();+ line.clear();+ output.read_line(&mut line).await.unwrap();+ child.wait().await.unwrap().success() && line.trim() == "PASS"+ }).await;+ proxy.abort(); upstream_task.abort();+ assert!(proxy.await.unwrap_err().is_cancelled());+ assert!(upstream_task.await.unwrap_err().is_cancelled());+ assert!(matches!(result, Ok(true)), "Native mobile browser proof failed for {backend}");+ let calls = received.lock().await;+ assert_eq!(calls.len(), 1, "revoked browser request reached upstream");+ assert_eq!(calls[0].1["messages"][0]["content"], "synthetic remembered context");+ continue;+ }let client = reqwest::Client::builder().no_proxy().timeout(std::time::Duration::from_secs(2)).build().unwrap();assert_eq!(client.get(format!("{base}/remote-api/config")).send().await.unwrap().status(), StatusCode::UNAUTHORIZED);let paired = client.post(format!("{base}/remote-api/auth")).json(&serde_json::json!({"passcode":passcode})).send().await.unwrap();