Skip to content

Commit 1bbb930

Browse files
authored
Desktop on Windows: a closed approval prompt says approval, and is told by exit code 1223 (#2715)
* Desktop on Windows: a closed approval prompt asks for approval, not a password The Docker Desktop update on Windows asks through Windows' approval prompt. When the person closed it, the card was headed "Your password is needed" and the row said "Waiting for your password.", which Windows never asked for. On Windows they now say "Your approval is needed" and "Waiting for your approval."; macOS keeps the password words. * Desktop on Windows: tell a no to the Docker update's approval prompt by exit code 1223 A no to Windows' approval prompt was told by PowerShell's English words, so on a Windows in another language it read as a failed installer and Docker's installer was opened for the person to finish. The install script now finds ERROR_CANCELLED (1223) in the error Start-Process throws and exits with it, as the WSL fix does, and only that exit code counts as a no. * Status window browser test: a finished Start is brought in by the shell's word, not the 30 s timer Since the Status window reads every 30 s, the test that waits for Running after a Start waited on that timer for its whole 30 s timeout and failed on a slow run. The shell tells the window when a Start finishes (status:refresh), so the test now says that, as the native side does, and waits at most 10 s. * Status window browser test: the locator's own wait, which its type allows * Desktop: a stopped server is checked as its silence reaches 10 s, not a backoff later On Windows an ask to a port nobody listens on takes about 2 s to fail. With the watcher's failure backoff on top, a window whose server went away reached setup only after about 19 s, and the test that holds it to 18 s failed on CI's Windows runner. The ask after a failure now comes no later than the moment the silence reaches 10 s.
1 parent 056f836 commit 1bbb930

6 files changed

Lines changed: 169 additions & 31 deletions

File tree

‎desktop/src-tauri/src/docker_desktop_update.rs‎

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,34 @@ pub fn powershell_with_path(script: &str, variable: &str, path: &Path) -> std::p
254254
command
255255
}
256256

257+
/// The exit code that means the person said no to Windows' approval prompt: `ERROR_CANCELLED`, as
258+
/// the WSL fix reads it (`windows::DECLINED`).
259+
const ERROR_CANCELLED: i32 = 1223;
260+
257261
/// The all-users install: Windows' approval prompt, then Docker's installer as an administrator,
258262
/// waited for, its exit code PowerShell's. The installer's path is `INSTALLER_PATH`.
259263
pub fn elevated_install(installer: &Path, arguments: &[String]) -> std::process::Command {
260264
let quoted: Vec<String> = arguments
261265
.iter()
262266
.map(|argument| format!("'{}'", argument.replace('\'', "''")))
263267
.collect();
264-
let script = format!(
268+
let start = format!(
265269
"$p = Start-Process -FilePath $env:{INSTALLER_PATH} -ArgumentList {} -Verb RunAs -Wait \
266-
-PassThru; exit $p.ExitCode",
270+
-PassThru",
267271
quoted.join(",")
268272
);
269-
powershell_with_path(&script, INSTALLER_PATH, installer)
273+
powershell_with_path(&elevated_script(&start), INSTALLER_PATH, installer)
274+
}
275+
276+
/// `start`, which raises Windows' approval prompt and sets `$p`, exiting with `$p`'s exit code. A
277+
/// no to the prompt exits `ERROR_CANCELLED`, found by its Win32 code in the error, never by its
278+
/// words, which are in Windows' own language.
279+
fn elevated_script(start: &str) -> String {
280+
format!(
281+
"$ErrorActionPreference = 'Stop'; try {{ {start}; exit $p.ExitCode }} catch {{ \
282+
$e = $_.Exception; while ($e) {{ if ($e.NativeErrorCode -eq {ERROR_CANCELLED}) \
283+
{{ exit {ERROR_CANCELLED} }}; $e = $e.InnerException }}; throw }}"
284+
)
270285
}
271286

272287
/// Whether the answer to `AUTHENTICODE_QUERY` is a valid signature by Docker Inc.
@@ -776,11 +791,12 @@ fn run_installer(mounted: &Mounted) -> Installed {
776791
}
777792
}
778793

779-
/// Whether `elevated_install` stopped because the person said no to Windows' approval prompt:
780-
/// `Start-Process -Verb RunAs` then fails with "The operation was canceled by the user."
794+
/// Whether `elevated_install` stopped because the person said no to Windows' approval prompt: it
795+
/// then exits `ERROR_CANCELLED` (`elevated_script`). What PowerShell said is in Windows' own
796+
/// language, so it is never read for this.
781797
#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
782-
fn closed_the_prompt(said: &str) -> bool {
783-
said.contains("canceled by the user") || said.contains("cancelled by the user")
798+
fn closed_the_prompt(code: Option<i32>) -> bool {
799+
code == Some(ERROR_CANCELLED)
784800
}
785801

786802
#[cfg(target_os = "windows")]
@@ -795,7 +811,7 @@ fn run_installer(installer: &Path, per_user: bool) -> Installed {
795811
Ok(output) if output.status.success() => Installed::Done,
796812
Ok(output) => {
797813
let said = crate::quiet::said(&output.stderr);
798-
if closed_the_prompt(&said) {
814+
if closed_the_prompt(output.status.code()) {
799815
return Installed::Declined;
800816
}
801817
Installed::Failed(Problem::with(
@@ -1719,22 +1735,52 @@ Internal requirements count=1 size=180
17191735
);
17201736
}
17211737

1722-
/// What Windows PowerShell prints when the person says no to the approval prompt that
1723-
/// `elevated_install` raises, and when Docker's installer fails behind it.
1738+
/// A no to Windows' approval prompt is told by `elevated_install`'s exit code, 1223
1739+
/// (`ERROR_CANCELLED`), as the WSL fix tells it. It was told by PowerShell's English words,
1740+
/// so on a German or Japanese Windows a no read as a failed installer, and Docker's own
1741+
/// installer was opened for the person to finish.
17241742
#[test]
1725-
fn a_no_to_windows_approval_prompt_is_told_from_a_failed_installer() {
1726-
const SAID_NO: &str = "Start-Process : This command cannot be run due to the error: The \
1727-
operation was canceled by the user.\r\nAt line:1 char:6\r\n+ $p = Start-Process \
1728-
-FilePath $env:OPENBOT_INSTALLER_PATH -ArgumentList 'install','--quiet' ...\r\n+ \
1729-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + \
1730-
CategoryInfo : InvalidOperation: (:) [Start-Process], \
1731-
InvalidOperationException\r\n + FullyQualifiedErrorId : \
1732-
InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand\r\n";
1733-
assert!(closed_the_prompt(SAID_NO));
1734-
assert!(!closed_the_prompt(""));
1735-
assert!(!closed_the_prompt(
1736-
"Start-Process : This command cannot be run due to the error: The system cannot find \
1737-
the file specified."
1738-
));
1743+
fn a_no_to_windows_approval_prompt_is_told_by_its_exit_code_in_any_language() {
1744+
assert!(closed_the_prompt(Some(ERROR_CANCELLED)));
1745+
// Any other exit is the installer failing, whatever the words say.
1746+
assert!(!closed_the_prompt(Some(1)));
1747+
assert!(!closed_the_prompt(Some(0)));
1748+
assert!(!closed_the_prompt(None));
1749+
// The script reads the Win32 code, never the words.
1750+
let script = elevated_script("$p = Start-Process x -Verb RunAs -Wait -PassThru");
1751+
assert!(script.contains("NativeErrorCode -eq 1223"), "{script}");
1752+
assert!(script.contains("exit 1223"), "{script}");
1753+
assert!(
1754+
script.contains("$ErrorActionPreference = 'Stop'"),
1755+
"{script}"
1756+
);
1757+
assert!(!script.contains("canceled"), "{script}");
1758+
}
1759+
1760+
/// The script `elevated_install` runs, in real Windows PowerShell, with `Start-Process` standing
1761+
/// in for by the error it throws when the person says no: a Win32 `ERROR_CANCELLED` inside the
1762+
/// `InvalidOperationException`, worded in German. It exits 1223. Any other error exits 1.
1763+
#[test]
1764+
#[cfg(windows)]
1765+
fn the_elevated_install_script_exits_1223_on_a_no_in_any_language() {
1766+
let run = |native: i32| {
1767+
let start = format!(
1768+
"throw [System.InvalidOperationException]::new('Dieser Befehl kann aufgrund des \
1769+
folgenden Fehlers nicht ausgeführt werden.', \
1770+
[System.ComponentModel.Win32Exception]::new({native}))"
1771+
);
1772+
let output = powershell_with_path(
1773+
&elevated_script(&start),
1774+
INSTALLER_PATH,
1775+
Path::new(r"C:\nowhere\Docker Desktop Installer.exe"),
1776+
)
1777+
.output()
1778+
.unwrap();
1779+
output.status.code()
1780+
};
1781+
assert_eq!(run(ERROR_CANCELLED), Some(ERROR_CANCELLED));
1782+
let other = run(2);
1783+
assert_ne!(other, Some(ERROR_CANCELLED));
1784+
assert_ne!(other, Some(0));
17391785
}
17401786
}

‎desktop/src-tauri/src/main.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13144,9 +13144,19 @@ fn watch_connections<R: tauri::Runtime>(
1314413144
}
1314513145
poll_failed = true;
1314613146
let since = *unanswered_since.get_or_insert_with(std::time::Instant::now);
13147-
if setup_shown || since.elapsed() < SERVER_GONE_AFTER {
13147+
if setup_shown {
1314813148
continue;
1314913149
}
13150+
if let Some(left) = SERVER_GONE_AFTER.checked_sub(since.elapsed()) {
13151+
// Asked again as the silence reaches `SERVER_GONE_AFTER`, not a backoff
13152+
// later: on Windows an ask to a port nobody listens on takes about 2 s to
13153+
// fail, and with the backoff on top the window went to setup only after
13154+
// about 19 s.
13155+
if !left.is_zero() {
13156+
next_ask_after = next_ask_after.min(left);
13157+
continue;
13158+
}
13159+
}
1315013160
match show_setup_when_stopped(&app, &root, generation) {
1315113161
Ok(Unanswered::Stopped) => setup_shown = true,
1315213162
// Still up after all: ask again only after as long a silence again.

‎desktop/src/App.test.tsx‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,6 +3050,58 @@ test("macOS's password prompt waits for Continue in the window, and a closed one
30503050
expectBehind(view, 1, PODMAN_PROMPTING);
30513051
});
30523052

3053+
// What the Docker Desktop update says after the person closed the system's prompt
3054+
// (`docker_desktop_update::declined_line`).
3055+
const DOCKER_UPDATE_DECLINED =
3056+
"OpenBot needs your approval to update Docker. Choose Try again when you're ready.";
3057+
3058+
/**
3059+
* On Windows the Docker Desktop update asks through Windows' approval prompt, not for a password.
3060+
* A closed one was headed "Your password is needed" and its row said "Waiting for your password.",
3061+
* which Windows never asked for. Both now say approval.
3062+
*/
3063+
test("a closed approval prompt on Windows asks for approval, not a password", async () => {
3064+
Object.defineProperty(navigator, "userAgent", {
3065+
configurable: true,
3066+
value:
3067+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0",
3068+
});
3069+
try {
3070+
setupRootConfiguration("/tmp/local-eval-docker-update-approval", async () =>
3071+
emptyConfiguration(),
3072+
);
3073+
const browser = deferred<{ signedIn: boolean }>();
3074+
withLocalCli({
3075+
prepare_installation: () => new Promise(() => {}),
3076+
local_eval_terms: () => ({ status: "engine-not-ready" }),
3077+
sign_in_to_copilotkit: () => browser.promise,
3078+
copilotkit_sign_in_page: () => null,
3079+
allow_podman_install: () => true,
3080+
});
3081+
const view = await renderApp();
3082+
await installLocal(view);
3083+
await view.findByText("Checking your OpenBot account…");
3084+
await emitProgress({
3085+
step: "engine",
3086+
ok: true,
3087+
running: true,
3088+
asks: true,
3089+
detail: DOCKER_UPDATE_DECLINED,
3090+
});
3091+
const card = await view.findByRole("region", {
3092+
name: "Your approval is needed",
3093+
});
3094+
expect(card.textContent).toContain(DOCKER_UPDATE_DECLINED);
3095+
expect(
3096+
view.queryByRole("region", { name: "Your password is needed" }),
3097+
).toBeNull();
3098+
expectBehind(view, 1, "Waiting for your approval.", { waiting: true });
3099+
expect(view.getByRole("button", { name: "Try again" })).toBeTruthy();
3100+
} finally {
3101+
delete (navigator as { userAgent?: string }).userAgent;
3102+
}
3103+
});
3104+
30533105
// What Install says on a Mac whose own Podman OpenBot can't use (`own_machine::PAUSE_OFFER`).
30543106
const PAUSE_OFFER =
30553107
"Your Podman is set up in a way OpenBot can't use. OpenBot will use its own, and pause yours while OpenBot is running. Yours starts again when you quit OpenBot.";

‎desktop/src/PodmanGoAhead.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { invoke } from "@tauri-apps/api/core";
22
import { type RefObject, useEffect, useRef, useState } from "react";
3-
import type { GoAhead } from "./SetupProgress";
3+
import { type GoAhead, systemPromptAsks } from "./SetupProgress";
44

55
/** The heading over the explanation before macOS asks for the person's password. */
66
export const PASSWORD_NEXT = "Your Mac will ask for your password";
77

88
/** The heading over a password prompt the person closed. */
99
export const PASSWORD_AGAIN = "Your password is needed";
1010

11+
/** The heading over Windows' approval prompt the person closed. */
12+
export const APPROVAL_AGAIN = "Your approval is needed";
13+
1114
/**
1215
* Keep a card that waits on the person in view in a step that scrolls. Nothing goes on until they
1316
* answer it. At the window's smallest size the button sat under the step's pinned foot
@@ -92,7 +95,11 @@ export function GoAheadButton({ label }: { label: "Continue" | "Try again" }) {
9295
export function PodmanGoAhead({ goAhead }: { goAhead: GoAhead }) {
9396
const offered = useRef<HTMLElement>(null);
9497
useKeptInView(offered);
95-
const heading = goAhead.beforePrompt ? PASSWORD_NEXT : PASSWORD_AGAIN;
98+
const heading = goAhead.beforePrompt
99+
? PASSWORD_NEXT
100+
: systemPromptAsks() === "approval"
101+
? APPROVAL_AGAIN
102+
: PASSWORD_AGAIN;
96103
return (
97104
<section ref={offered} className="local-alert needs" aria-label={heading}>
98105
<h2>{heading}</h2>

‎desktop/src/SetupProgress.tsx‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ export function pauseOfferNow(steps: Progress[]): string | null {
188188
return offering?.detail ?? null;
189189
}
190190

191+
/**
192+
* What the system's prompt asks the person for on this computer: Windows asks them to approve,
193+
* macOS for their password.
194+
*/
195+
export function systemPromptAsks(
196+
userAgent = navigator.userAgent,
197+
): "password" | "approval" {
198+
return /Windows/.test(userAgent) ? "approval" : "password";
199+
}
200+
191201
/** Where OpenBot's own icon is, as this computer names it: macOS has a menu bar, Windows a tray. */
192202
export function trayPlace(userAgent = navigator.userAgent): string {
193203
return /Macintosh|Mac OS X/.test(userAgent)
@@ -759,7 +769,9 @@ export function installingBehind({
759769
? "Waiting for you to pause your Podman."
760770
: now?.beforePrompt
761771
? "Waiting for you to choose Continue."
762-
: "Waiting for your password.",
772+
: systemPromptAsks() === "approval"
773+
? "Waiting for your approval."
774+
: "Waiting for your password.",
763775
{
764776
waiting,
765777
startedAt: since ?? undefined,

‎desktop/src/setupLayout.browser.test.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4135,10 +4135,21 @@ describe.skipIf(!asked)(
41354135
await open(page, "?started#status");
41364136
await page.getByRole("region", { name: "App" }).waitFor();
41374137
await page.waitForTimeout(400);
4138-
// The main window's Start brings everything up; the window's own reading sees the parts.
4138+
// The main window's Start brings everything up, and the shell tells this window so
4139+
// (`status_changed`). The window reads every 30 s now, so it is the shell's word that
4140+
// brings the parts in, not a timer: waiting on the timer took the locator's whole 30 s
4141+
// and failed on a slow run.
41394142
await page.evaluate(() => {
4140-
(globalThis as unknown as { __fake: { up: boolean } }).__fake.up =
4141-
true;
4143+
const fake = (
4144+
globalThis as unknown as {
4145+
__fake: {
4146+
up: boolean;
4147+
emit: (name: string, payload: unknown) => void;
4148+
};
4149+
}
4150+
).__fake;
4151+
fake.up = true;
4152+
fake.emit("status:refresh", null);
41424153
});
41434154
await page
41444155
.locator('section[aria-label="App"] .status-state', {

0 commit comments

Comments
 (0)