@xiaolikt/ai-vault 0.11.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,416 @@
1
+ // Windows: how the extension finds and starts things there.
2
+ //
3
+ // The other suites answer through POSIX shell-script mocks, which cannot run
4
+ // on Windows; these use the real npm wrapper format, the real Windows
5
+ // PowerShell and, when it is installed, the real Bitwarden CLI and Git Bash.
6
+ // The first group is plain parsing and runs everywhere; the rest skip off
7
+ // Windows.
8
+ import assert from "node:assert/strict";
9
+ import { spawn, spawnSync } from "node:child_process";
10
+ import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { dirname, join } from "node:path";
13
+ import { test } from "node:test";
14
+ import { fileURLToPath, pathToFileURL } from "node:url";
15
+ import { cleanUpOnExit, cliBinary, useMocks } from "./helpers.mjs";
16
+
17
+ const WIN32 = process.platform === "win32";
18
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
19
+ /** Taken once, before any test clears AI_VAULT_BIN. */
20
+ const CLI_BINARY = cliBinary();
21
+ const PS = join(process.env.SystemRoot ?? "C:/", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
22
+ const PS_ARGS = ["-NoProfile", "-NonInteractive", "-STA"];
23
+ const windowsOnly = { skip: WIN32 ? false : "Windows only" };
24
+
25
+ const { npmShimLaunch } = await import("../packages/pi-ai-vault/src/cli.ts");
26
+
27
+ /** npm's `.cmd` wrapper, byte for byte in the parts that matter. */
28
+ function cmdShim(target) {
29
+ return [
30
+ "@ECHO off",
31
+ "GOTO start",
32
+ ":find_dp0",
33
+ "SET dp0=%~dp0",
34
+ "EXIT /b",
35
+ ":start",
36
+ "SETLOCAL",
37
+ "CALL :find_dp0",
38
+ 'IF EXIST "%dp0%\\node.exe" (',
39
+ ' SET "_prog=%dp0%\\node.exe"',
40
+ ") ELSE (",
41
+ ' SET "_prog=node"',
42
+ ")",
43
+ `endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\${target}" %*`,
44
+ ].join("\r\n");
45
+ }
46
+
47
+ /**
48
+ * A small but faithful npm tree: the plugin, the dispatcher package with its
49
+ * JavaScript shim, the prebuilt platform package, and the `.cmd` wrapper npm
50
+ * links into .bin.
51
+ */
52
+ function fakeNpm(dir, { wrapper = true, platform = "hoisted", dispatcher = true } = {}) {
53
+ const nm = join(dir, "node_modules");
54
+ const plugin = join(nm, "pi-ai-vault", "src");
55
+ mkdirSync(plugin, { recursive: true });
56
+ const src = join(ROOT, "packages", "pi-ai-vault", "src");
57
+ for (const name of readdirSync(src)) copyFileSync(join(src, name), join(plugin, name));
58
+ if (dispatcher) {
59
+ const pkg = join(nm, "@xiaolikt", "ai-vault");
60
+ mkdirSync(join(pkg, "bin"), { recursive: true });
61
+ writeFileSync(
62
+ join(pkg, "package.json"),
63
+ JSON.stringify({ name: "@xiaolikt/ai-vault", version: "0.0.0", bin: { "ai-vault": "./bin/ai-vault.cjs" } }),
64
+ );
65
+ copyFileSync(join(ROOT, "bin", "ai-vault.cjs"), join(pkg, "bin", "ai-vault.cjs"));
66
+ }
67
+ if (platform !== "none") {
68
+ // "hoisted": resolvable from the plugin. "nested": only from the dispatcher.
69
+ const pkg =
70
+ platform === "nested"
71
+ ? join(nm, "@xiaolikt", "ai-vault", "node_modules", "@xiaolikt", `ai-vault-${process.platform}-${process.arch}`)
72
+ : join(nm, "@xiaolikt", `ai-vault-${process.platform}-${process.arch}`);
73
+ mkdirSync(join(pkg, "bin"), { recursive: true });
74
+ writeFileSync(
75
+ join(pkg, "package.json"),
76
+ JSON.stringify({ name: `@xiaolikt/ai-vault-${process.platform}-${process.arch}`, version: "0.0.0", os: [process.platform], cpu: [process.arch] }),
77
+ );
78
+ copyFileSync(CLI_BINARY, join(pkg, "bin", WIN32 ? "ai-vault.exe" : "ai-vault"));
79
+ }
80
+ if (wrapper) {
81
+ mkdirSync(join(nm, ".bin"), { recursive: true });
82
+ writeFileSync(join(nm, ".bin", WIN32 ? "ai-vault.cmd" : "ai-vault"), cmdShim("..\\@xiaolikt\\ai-vault\\bin\\ai-vault.cjs"));
83
+ }
84
+ return { nm, cli: join(plugin, "cli.ts") };
85
+ }
86
+
87
+ function scratch() {
88
+ return mkdtempSync(join(tmpdir(), "ai-vault-windows-"));
89
+ }
90
+
91
+ /**
92
+ * Remove a scratch directory. On Windows a binary that just ran from it can
93
+ * still be held for a moment (an antivirus scanning the fresh copy), so the
94
+ * removal is retried before it is left to the temp cleaner.
95
+ */
96
+ function removeScratch(dir) {
97
+ for (let attempt = 0; attempt < 30; attempt++) {
98
+ try {
99
+ rmSync(dir, { recursive: true, force: true });
100
+ return;
101
+ } catch {
102
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 100);
103
+ }
104
+ }
105
+ }
106
+
107
+ /** Run `fn` with these variables unset: `AI_VAULT_BIN` in particular always wins, and the tests set it. */
108
+ async function withoutEnv(names, fn) {
109
+ const saved = Object.fromEntries(names.map((name) => [name, process.env[name]]));
110
+ for (const name of names) delete process.env[name];
111
+ try {
112
+ return await fn();
113
+ } finally {
114
+ Object.assign(process.env, saved);
115
+ }
116
+ }
117
+
118
+ // ---------------------------------------------------------------- parsing the wrapper
119
+
120
+ // The fixture is npm's Windows wrapper, backslashes and all: on a POSIX host
121
+ // `join` keeps those inside one file name, so nothing it names can exist.
122
+ test("an npm .cmd wrapper is read, not run: it names a script for this Node, or a program", windowsOnly, async (t) => {
123
+ if (!WIN32) return t.skip();
124
+ const dir = scratch();
125
+ const sep = WIN32 ? "\\" : "/";
126
+ const shim = join(dir, "tool.cmd");
127
+ const script = join(dir, "node_modules", "pkg", "bin", "tool.cjs");
128
+ const program = join(dir, "node_modules", "pkg", "bin", "tool.exe");
129
+ try {
130
+ mkdirSync(dirname(script), { recursive: true });
131
+ writeFileSync(script, "");
132
+ writeFileSync(program, "");
133
+ writeFileSync(shim, cmdShim(["node_modules", "pkg", "bin", "tool.cjs"].join(sep)));
134
+ assert.deepEqual(npmShimLaunch(shim), { program: process.execPath, pre: [script] }, "a .cjs is started with this Node");
135
+
136
+ writeFileSync(shim, cmdShim(["node_modules", "pkg", "bin", "tool.exe"].join(sep)));
137
+ assert.deepEqual(npmShimLaunch(shim), { program, pre: [] }, "a program is started as itself");
138
+
139
+ writeFileSync(shim, cmdShim(["node_modules", "pkg", "bin", "missing.js"].join(sep)));
140
+ assert.equal(npmShimLaunch(shim), undefined, "what it names must exist");
141
+
142
+ writeFileSync(shim, "@ECHO off\r\nsomething else entirely\r\n");
143
+ assert.equal(npmShimLaunch(shim), undefined, "not npm's format");
144
+ assert.equal(npmShimLaunch(join(dir, "no-such.cmd")), undefined, "no wrapper at all");
145
+
146
+ // The other place npm puts one: node_modules/.bin, where it points with `..\\`.
147
+ const binShim = join(dir, "node_modules", ".bin", "tool.cmd");
148
+ mkdirSync(dirname(binShim), { recursive: true });
149
+ writeFileSync(binShim, cmdShim(["..", "pkg", "bin", "tool.cjs"].join(sep)));
150
+ assert.deepEqual(npmShimLaunch(binShim), { program: process.execPath, pre: [join(dir, "node_modules", "pkg", "bin", "tool.cjs")] });
151
+ } finally {
152
+ removeScratch(dir);
153
+ }
154
+ });
155
+
156
+ // ---------------------------------------------------------------- starting the CLI
157
+
158
+ test("Windows: npm layout, everything hoisted: the prebuilt ai-vault.exe is started directly", windowsOnly, async (t) => {
159
+ if (!WIN32) return t.skip();
160
+ const dir = scratch();
161
+ return withoutEnv(["AI_VAULT_BIN"], async () => {
162
+ try {
163
+ const tree = fakeNpm(dir);
164
+ const mod = await import(pathToFileURL(tree.cli).href);
165
+ const cli = new mod.VaultCli();
166
+ assert.equal(cli.bin, join(tree.nm, "@xiaolikt", "ai-vault-win32-x64", "bin", "ai-vault.exe"));
167
+ const run = await cli.run(["--version"]);
168
+ assert.equal(run.code, 0, run.stderr);
169
+ assert.match(run.stdout, /^ai-vault \d+\.\d+\.\d+/, "the real binary answered, not a wrapper error");
170
+ } finally {
171
+ removeScratch(dir);
172
+ }
173
+ });
174
+ });
175
+
176
+ test("Windows: platform package nested under the dispatcher: the .cmd is unwrapped to Node + its script", windowsOnly, async (t) => {
177
+ if (!WIN32) return t.skip();
178
+ const dir = scratch();
179
+ return withoutEnv(["AI_VAULT_BIN"], async () => {
180
+ try {
181
+ const tree = fakeNpm(dir, { platform: "nested" });
182
+ const mod = await import(pathToFileURL(tree.cli).href);
183
+ const cli = new mod.VaultCli();
184
+ assert.equal(cli.bin, process.execPath, "never the .cmd itself");
185
+ const launch = mod.resolveLaunch();
186
+ assert.deepEqual(launch.pre, [join(tree.nm, "@xiaolikt", "ai-vault", "bin", "ai-vault.cjs")]);
187
+ const run = await cli.run(["--version"]);
188
+ assert.equal(run.code, 0, run.stderr);
189
+ assert.match(run.stdout, /^ai-vault \d+\.\d+\.\d+/);
190
+ } finally {
191
+ removeScratch(dir);
192
+ }
193
+ });
194
+ });
195
+
196
+ test("Windows: only a .ps1 and a sh wrapper, nothing on PATH: the CLI is reported missing, and run() says so", windowsOnly, async (t) => {
197
+ if (!WIN32) return t.skip();
198
+ const dir = scratch();
199
+ return withoutEnv(["AI_VAULT_BIN"], async () => {
200
+ const saved = { PATH: process.env.PATH, USERPROFILE: process.env.USERPROFILE };
201
+ try {
202
+ const tree = fakeNpm(dir, { wrapper: false, platform: "none", dispatcher: false });
203
+ mkdirSync(join(tree.nm, ".bin"), { recursive: true });
204
+ writeFileSync(join(tree.nm, ".bin", "ai-vault.ps1"), "# a wrapper Node cannot start either");
205
+ writeFileSync(join(tree.nm, ".bin", "ai-vault"), "#!/bin/sh\n");
206
+ process.env.PATH = "";
207
+ process.env.USERPROFILE = join(dir, "home"); // the "usual install spots" look under the profile
208
+ const mod = await import(pathToFileURL(tree.cli).href);
209
+ assert.equal(mod.resolveLaunch(), undefined);
210
+ const cli = new mod.VaultCli();
211
+ assert.equal(cli.available, false);
212
+ await assert.rejects(cli.run(["--version"]), (error) => error instanceof mod.CliError && error.code === 1 && /not found/.test(error.message));
213
+ } finally {
214
+ Object.assign(process.env, saved);
215
+ removeScratch(dir);
216
+ }
217
+ });
218
+ });
219
+
220
+ test("Windows: AI_VAULT_BIN pointing at a wrapper is unwrapped too; at nothing, it is ignored", windowsOnly, async (t) => {
221
+ if (!WIN32) return t.skip();
222
+ const dir = scratch();
223
+ return withoutEnv(["AI_VAULT_BIN"], async () => {
224
+ const saved = process.env.AI_VAULT_BIN;
225
+ try {
226
+ const tree = fakeNpm(dir, { platform: "none" });
227
+ const mod = await import(pathToFileURL(tree.cli).href);
228
+ process.env.AI_VAULT_BIN = join(tree.nm, ".bin", "ai-vault.cmd");
229
+ assert.equal(mod.resolveLaunch().program, process.execPath);
230
+ process.env.AI_VAULT_BIN = join(dir, "nowhere", "ai-vault.exe");
231
+ assert.equal(mod.resolveLaunch(), undefined);
232
+ } finally {
233
+ if (saved === undefined) delete process.env.AI_VAULT_BIN;
234
+ else process.env.AI_VAULT_BIN = saved;
235
+ removeScratch(dir);
236
+ }
237
+ });
238
+ });
239
+
240
+ // ---------------------------------------------------------------- the Bitwarden half, with the real machine
241
+
242
+ const mocks = useMocks();
243
+ const { clipboardBackend, killTree, resolveBash, resolveBw } = await import("../packages/pi-ai-vault/src/bitwarden.ts");
244
+ cleanUpOnExit(mocks);
245
+
246
+ test("Windows: npm's bw.cmd is found and started through Node", windowsOnly, async (t) => {
247
+ if (!WIN32) return t.skip();
248
+ const bw = await resolveBw().catch(() => undefined);
249
+ if (!bw) return t.skip("no Bitwarden CLI on this machine");
250
+ const r = spawnSync(bw.program, [...bw.pre, "--version"], { encoding: "utf8", timeout: 60_000, windowsHide: true });
251
+ assert.equal(r.status, 0, r.stderr);
252
+ assert.match(r.stdout, /\d{4}\.\d+\.\d+/);
253
+ });
254
+
255
+ test("Windows: the clipboard carries a non-ASCII value byte for byte", windowsOnly, async (t) => {
256
+ if (!WIN32) return t.skip();
257
+ // No interactive session (a CI runner): there is no clipboard anyone could read.
258
+ const interactive = spawnSync(PS, ["-NoProfile", "-NonInteractive", "-Command", "[Environment]::UserInteractive"], { encoding: "utf8", windowsHide: true, timeout: 20_000 });
259
+ if (interactive.stdout.trim() !== "True") return t.skip("not an interactive session");
260
+ // The real clipboard is used: put back whatever text the user had, and
261
+ // leave alone anything that is not text.
262
+ const probe = spawnSync(
263
+ PS,
264
+ [...PS_ARGS, "-Command", "Add-Type -AssemblyName System.Windows.Forms; if ([System.Windows.Forms.Clipboard]::ContainsImage() -or [System.Windows.Forms.Clipboard]::ContainsFileDropList() -or [System.Windows.Forms.Clipboard]::ContainsAudio()) { 'nontext'; exit 0 }; [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes([System.Windows.Forms.Clipboard]::GetText()))"],
265
+ { encoding: "utf8", timeout: 20_000, windowsHide: true },
266
+ );
267
+ if (probe.stdout.trim() === "nontext") return t.skip("the clipboard holds something that is not text");
268
+ // GetText() throws when the clipboard cannot be opened (a locked or
269
+ // disconnected session, another tool holding it): nothing to test against then.
270
+ if (probe.status !== 0) return t.skip("the clipboard cannot be opened right now (a locked session?)");
271
+ const saved = probe.stdout.trim();
272
+ const backend = clipboardBackend();
273
+ assert.ok(backend, "Windows has a clipboard backend");
274
+ const read = () => {
275
+ const r = spawnSync(backend.read[0], backend.read[1], { windowsHide: true, timeout: 20_000 });
276
+ assert.equal(r.status, 0, r.stderr?.toString());
277
+ return new TextDecoder().decode(r.stdout);
278
+ };
279
+ const value = "密码-Pässw0rd-42";
280
+ try {
281
+ await new Promise((resolve, reject) => {
282
+ const child = spawn(backend.copy[0], backend.copy[1], { stdio: ["pipe", "ignore", "pipe"], windowsHide: true });
283
+ let stderr = "";
284
+ child.stderr.on("data", (chunk) => (stderr += chunk));
285
+ child.on("error", reject);
286
+ child.on("close", (code) => (code === 0 ? resolve() : reject(new Error(`copy exited with ${code}: ${stderr}`))));
287
+ child.stdin.on("error", reject);
288
+ child.stdin.end(value);
289
+ });
290
+ assert.equal(read(), value);
291
+ assert.equal(backend.lingers, false, "the copy command exits after setting the clipboard");
292
+ assert.equal(spawnSync(backend.clear[0], backend.clear[1], { windowsHide: true, timeout: 20_000 }).status, 0);
293
+ assert.equal(read(), "", "cleared");
294
+ } finally {
295
+ const restore = saved
296
+ ? `$t = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${saved}')); [System.Windows.Forms.Clipboard]::SetText($t)`
297
+ : "[System.Windows.Forms.Clipboard]::Clear()";
298
+ spawnSync(PS, [...PS_ARGS, "-Command", `Add-Type -AssemblyName System.Windows.Forms; ${restore}`], { windowsHide: true, timeout: 20_000 });
299
+ }
300
+ });
301
+
302
+ test("Windows: bw_run's shell is found even when bash.exe is not on PATH", windowsOnly, async (t) => {
303
+ if (!WIN32) return t.skip();
304
+ const gitCmd = join(process.env.ProgramFiles ?? "", "Git", "cmd");
305
+ if (!existsSync(join(gitCmd, "git.exe"))) return t.skip("Git for Windows is not in its default place");
306
+ const saved = process.env.PATH;
307
+ process.env.PATH = gitCmd; // git.exe only: Git's installer does not add bin\bash.exe
308
+ try {
309
+ const bash = resolveBash();
310
+ assert.equal(bash.program, join(process.env.ProgramFiles, "Git", "bin", "bash.exe"), "derived from where git.exe came from");
311
+ } finally {
312
+ process.env.PATH = saved;
313
+ }
314
+ });
315
+
316
+ test("Windows: a command that is killed takes what it started with it", windowsOnly, async (t) => {
317
+ if (!WIN32) return t.skip();
318
+ const bash = resolveBash();
319
+ if (!existsSync(bash.program)) return t.skip("no bash on this machine");
320
+ const child = spawn(bash.program, [...bash.pre, "-c", "sleep 60 & wait"], { stdio: "ignore", windowsHide: true });
321
+ await new Promise((resolve) => setTimeout(resolve, 1500)); // let `sleep` start
322
+ killTree(child.pid);
323
+ await new Promise((resolve) => setTimeout(resolve, 800));
324
+ assert.notEqual(child.exitCode, null, "the shell itself is gone");
325
+ const left = spawnSync(
326
+ PS,
327
+ [...PS_ARGS, "-Command", `(Get-CimInstance Win32_Process -Filter "Name='sleep.exe'" | Where-Object { $_.ParentProcessId -eq ${child.pid} } | Measure-Object).Count`],
328
+ { encoding: "utf8", timeout: 20_000, windowsHide: true },
329
+ );
330
+ assert.equal(left.stdout.trim(), "0", "the sleep it started is gone as well");
331
+ });
332
+
333
+ // ---------------------------------------------------------------- the CLI's own windows
334
+
335
+ // The scripts are taken verbatim from dialog.rs and answered by a WinForms
336
+ // timer inside the window, so the real ShowDialog() and the real stdout path
337
+ // are covered without anyone at the keyboard. They need a desktop; a locked
338
+ // screen is fine, a service session is not.
339
+ const canShowWindows = () =>
340
+ WIN32 &&
341
+ spawnSync(PS, [...PS_ARGS, "-Command", "[Environment]::UserInteractive"], { encoding: "utf8", windowsHide: true, timeout: 20_000 }).stdout.trim() === "True";
342
+ const onDesktop = { skip: WIN32 ? (canShowWindows() ? false : "no interactive session") : "Windows only" };
343
+
344
+ /** A dialog script exactly as the Rust source holds it. */
345
+ function dialogScript(name) {
346
+ const source = readFileSync(join(ROOT, "crates", "ai-vault", "src", "dialog.rs"), "utf8");
347
+ const match = new RegExp(`const ${name}: &str = r#"(.*?)"#;`, "s").exec(source);
348
+ assert.ok(match, `${name} is in dialog.rs`);
349
+ return match[1];
350
+ }
351
+
352
+ /** Answers the window in place of the user, 600 ms after it is shown. */
353
+ const autoAnswer = (action) =>
354
+ [" $t = New-Object System.Windows.Forms.Timer", " $t.Interval = 600", ` $t.Add_Tick({ $t.Stop(); ${action} })`, " $t.Start()"].join("\n");
355
+
356
+ function showWindow(script) {
357
+ return spawnSync(PS, [...PS_ARGS, "-Command", script], {
358
+ encoding: "buffer",
359
+ timeout: 60_000,
360
+ windowsHide: true,
361
+ env: {
362
+ ...process.env,
363
+ AI_VAULT_DLG_TITLE: "ai-vault · test window",
364
+ AI_VAULT_DLG_TEXT: "master password / 主密码",
365
+ AI_VAULT_DLG_SECRET: "1",
366
+ AI_VAULT_DLG_CANCEL: "取消",
367
+ },
368
+ });
369
+ }
370
+
371
+ const SHOWN = " if ($f.ShowDialog() -eq 'OK') {";
372
+ const passwordWindow = (action) => {
373
+ const script = dialogScript("PREAMBLE");
374
+ assert.ok(script.includes(SHOWN), "the password window still calls ShowDialog()");
375
+ return script.replace(SHOWN, `${autoAnswer(action)}\n${SHOWN}`);
376
+ };
377
+
378
+ test("Windows: the password window answers in UTF-8, whatever the console's code page", onDesktop, () => {
379
+ const value = "密码测试-Pässw0rd";
380
+ const r = showWindow(passwordWindow(`$box.Text = '${value}'; $f.DialogResult = 'OK'`));
381
+ assert.equal(r.status, 0, r.stderr.toString());
382
+ assert.equal(new TextDecoder().decode(r.stdout), value);
383
+ });
384
+
385
+ test("Windows: cancel and an empty field end the prompt cleanly (exit 1 / empty, nothing on stderr)", onDesktop, () => {
386
+ const cancel = showWindow(passwordWindow("$f.DialogResult = 'Cancel'"));
387
+ assert.equal(cancel.status, 1);
388
+ assert.equal(cancel.stdout.length, 0);
389
+ assert.equal(cancel.stderr.length, 0);
390
+ const empty = showWindow(passwordWindow("$box.Text = ''; $f.DialogResult = 'OK'"));
391
+ assert.equal(empty.status, 0);
392
+ assert.equal(empty.stdout.length, 0);
393
+ });
394
+
395
+ test("Windows: a window that cannot open exits 2; a script that will not parse exits 1 with the error on stderr", onDesktop, () => {
396
+ const script = dialogScript("PREAMBLE");
397
+ // A policy that forbids Add-Type, simulated by shadowing the cmdlet.
398
+ const forbidden = showWindow("function Add-Type { throw 'Add-Type is blocked by policy (simulated)' }\n" + script);
399
+ assert.equal(forbidden.status, 2, "reported as no window, which is needs-ui to the host");
400
+ assert.match(forbidden.stderr.toString(), /blocked by policy/);
401
+ // WinForms that will not load.
402
+ const missing = showWindow(script.replace("System.Windows.Forms, System.Drawing", "System.Windows.Forms.NoSuchAssembly"));
403
+ assert.equal(missing.status, 2);
404
+ // PowerShell's own parse error is exit 1: only the text on stderr tells it from a cancel.
405
+ const unparsable = showWindow(script + "\nif ( { not powershell\n");
406
+ assert.equal(unparsable.status, 1);
407
+ assert.notEqual(unparsable.stderr.toString().trim(), "");
408
+ });
409
+
410
+ test("Windows: the confirm window is owned by a top-most form, and losing that owner is not a Yes", onDesktop, () => {
411
+ const script = dialogScript("CONFIRM");
412
+ const shown = " $r = [System.Windows.Forms.MessageBox]::Show(";
413
+ assert.ok(script.includes(shown), "the confirm window still asks through a MessageBox owned by $owner");
414
+ const closed = showWindow(script.replace(shown, `${autoAnswer("$owner.Close()")}\n${shown}`));
415
+ assert.notEqual(closed.status, 0, "a closed window must never read as approval");
416
+ });