WebPanel final-review fix: truthful browser fallback, focus gate, docs

- Creation-failure fallback sets OpenedInBrowser and says "opened" only
  when the system browser actually opened; otherwise chat says the
  browser did not open. Harness check CreateFailureBrowserFails.
- FocusPage follows the same in-process foreground rule as
  SetForegroundWindow (Show and controller creation). Harness check
  NoFocusFromAnotherProcess; posted-key checks report UNVERIFIED when
  another process holds the foreground.
- PermissionRequested: SavesInProfile = false.
- WEB_PANEL.md: allowlist empty-entry rule, GetState -4, AOT renumber
  caveat, softened focus claim (also in the Changelog).
- Formatting: ChatCommandReplyTests brace, /rc layout comment,
  PluginContract blank line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 16:14:57 -08:00
commit 537a40a430
7 changed files with 116 additions and 21 deletions

View file

@ -107,6 +107,8 @@ internal static unsafe class Program
Guard("LateFailureForSupersededHandle", () => handle = CheckLateFailure(s));
Guard("UnresponsiveCountResetsPerOpen", () => handle = CheckUnresponsiveReset(s));
Guard("CreateFailureFallsBack", () => CheckCreateFailure(s));
Guard("CreateFailureBrowserFails", () => CheckCreateFailureBrowserFails(s));
Guard("NoFocusFromAnotherProcess", () => { int r = CheckNoFocusFromAnotherProcess(s); if (r > 0) handle = r; });
Guard("VisibilitySameProcess", () => handle = CheckVisibilitySameProcess(s));
Unverified("VisibilityOtherProcess", "needs another process to take the foreground (alt-tab); the harness never forces it. Owner in-game check.");
Guard("LayoutRemembered", () => handle = CheckLayout(s, lad));
@ -201,8 +203,21 @@ internal static unsafe class Program
return h;
}
/// <summary>
/// The host moves keyboard focus into the page only while this process holds the foreground (never from
/// another program), so the posted-key checks are meaningful only then.
/// </summary>
private static bool ThisProcessHoldsForeground()
{
IntPtr fg = GetForegroundWindow();
if (fg == IntPtr.Zero) return false;
GetWindowThreadProcessId(fg, out uint pid);
return pid == Environment.ProcessId;
}
private static int CheckKeys(Session s)
{
bool inProcess = ThisProcessHoldsForeground();
var (h, _) = Open(s, "https://panel.test/index.html", Allow, title: "Keys");
if (!WaitStatus(s, h, StatusReady, 30000, out int[] a)) { Fail("KeysStayInPage", $"not Ready [{string.Join(",", a)}]"); return h; }
Thread.Sleep(500);
@ -221,8 +236,9 @@ internal static unsafe class Program
// game could not see them here whatever the host did. Input isolation (unowned popup, separate queue) is an
// owner in-game check: type in the panel, nothing reaches AC's chat.
W($"(informational, cannot fail: game key messages {g})");
if (!value.Contains("x1q")) Fail("KeysStayInPage", $"page input is {value}, want x1q");
else Ok("KeysStayInPage");
if (value.Contains("x1q")) Ok("KeysStayInPage");
else if (!inProcess) Unverified("KeysStayInPage", $"page input is {value}: another process held the foreground at Open ({FgDesc()}), so by design the panel did not focus the page; owner in-game check (type in the panel)");
else Fail("KeysStayInPage", $"page input is {value}, want x1q");
return h;
}
@ -257,6 +273,7 @@ internal static unsafe class Program
private static int CheckPageKeepsEscape(Session s)
{
bool inProcess = ThisProcessHoldsForeground();
var (h, _) = Open(s, "https://panel.test/index.html", Allow, title: "Keeps Escape", flags: FlagFallback | FlagPageKeepsEscape);
if (!WaitStatus(s, h, StatusReady, 30000, out int[] a)) { Fail("PageKeepsEscapeFlag", $"not Ready [{string.Join(",", a)}]"); return h; }
Thread.Sleep(400);
@ -270,6 +287,7 @@ internal static unsafe class Program
int[] st = State(s, h);
W($"flag 2: page keys {keys}, status {st[2]}, AcceleratorKeyPressed events {acc}");
if (st[2] != StatusReady) Fail("PageKeepsEscapeFlag", $"panel status {st[2]}, want Ready (open)");
else if (!keys.Contains("Escape") && !inProcess) Unverified("PageKeepsEscapeFlag", $"the page did not see Escape ({keys}): another process held the foreground at Open ({FgDesc()}), so by design the panel did not focus the page; owner in-game check");
else if (!keys.Contains("Escape")) Fail("PageKeepsEscapeFlag", "the page keydown listener did not see Escape: " + keys);
else if (acc == 0) Unverified("PageKeepsEscapeFlag", "page saw Escape and stayed open, but AcceleratorKeyPressed never fired for posted input, so the flag path itself was not exercised");
else Ok("PageKeepsEscapeFlag");
@ -519,6 +537,59 @@ internal static unsafe class Program
else Ok("CreateFailureFallsBack");
}
private static void CheckCreateFailureBrowserFails(Session s)
{
Drain(BrowserCalls);
Drain(ChatLines);
s.Call("SetBrowserFolder", Path.Combine(_root, "no-such-browser"));
s.Call("SetBrowserFails", true);
int[] st;
bool failed;
try
{
var (h, _) = Open(s, "https://panel.test/launch.html?code=" + Secret, Allow, key: "beta");
failed = WaitStatus(s, h, StatusFailed, 20000, out st);
WaitFor(() => ChatLines.Any(c => c.Contains("could not start")), 3000);
}
finally { s.Call("SetBrowserFails", false); s.Call("SetBrowserFolder", (string?)null); }
string[] chat = ChatLines.ToArray();
W($"create failure, browser fails: state [{string.Join(",", st)}]; browser calls {BrowserCalls.Count}; chat: {string.Join(" | ", chat)}");
if (!failed) Fail("CreateFailureBrowserFails", "status " + st[2]);
else if (st[4] != CodeCreateFailed) Fail("CreateFailureBrowserFails", "error " + st[4] + ", want CreateFailed");
else if ((st[3] & StateOpenedInBrowser) != 0) Fail("CreateFailureBrowserFails", "OpenedInBrowser flag set although the browser did not open");
else if (chat.Any(c => c.Contains("opened the page"))) Fail("CreateFailureBrowserFails", "chat claims the page opened");
else if (!chat.Any(c => c.Contains("could not start (it failed to start), and your web browser did not open"))) Fail("CreateFailureBrowserFails", "no browser-did-not-open chat line");
else Ok("CreateFailureBrowserFails");
}
/// <summary>
/// Only when the foreground already belongs to another process (the harness never arranges it): opening a
/// panel must leave that process in front. When this harness holds the foreground the check is UNVERIFIED.
/// </summary>
private static int CheckNoFocusFromAnotherProcess(Session s)
{
IntPtr fg0 = GetForegroundWindow();
uint pid0 = 0;
if (fg0 != IntPtr.Zero) GetWindowThreadProcessId(fg0, out pid0);
int bpid = (int)s.Call("get_BrowserProcessId")!;
if (fg0 == IntPtr.Zero || pid0 == Environment.ProcessId || (bpid != 0 && pid0 == bpid))
{
Unverified("NoFocusFromAnotherProcess", $"the foreground is not another process ({FgDesc()}); the harness never forces it there. Owner in-game check (alt-tab away, open the panel from a plugin)");
return 0;
}
var (h, _) = Open(s, "https://panel.test/index.html", Allow, title: "No focus");
bool ready = WaitStatus(s, h, StatusReady, 30000, out int[] st);
Thread.Sleep(500);
IntPtr fg1 = GetForegroundWindow();
uint pid1 = 0;
if (fg1 != IntPtr.Zero) GetWindowThreadProcessId(fg1, out pid1);
W($"foreground before pid {pid0}, after open pid {pid1} ({FgDesc()}); state [{string.Join(",", st)}]");
if (!ready) Fail("NoFocusFromAnotherProcess", "not Ready");
else if (pid1 == Environment.ProcessId || (bpid != 0 && pid1 == bpid)) Fail("NoFocusFromAnotherProcess", "the panel took the foreground from another process");
else Ok("NoFocusFromAnotherProcess");
return h;
}
private static int CheckVisibilitySameProcess(Session s)
{
var (h, _) = Open(s, "https://panel.test/index.html", Allow, title: "Visibility");