WebPanel: publish Failed together with the browser-fallback outcome
A plugin polling between Failed and OpenedInBrowser saw Failed with no flag and, per the docs, opened the page itself: a second open with a spent code. While the fallback is pending the status keeps its pre-failure value; after OpenInBrowser (outside the lock) one lock sets Failed, the error and, when the browser opened, the flag. The no-fallback path is unchanged. Harness: OpenInBrowser delay mode and a continuous poll in CreateFailureFallsBack. Show comments reworded as defensive, not observed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
537a40a430
commit
7e2cf67e30
3 changed files with 49 additions and 11 deletions
|
|
@ -524,12 +524,32 @@ internal static unsafe class Program
|
|||
Drain(BrowserCalls);
|
||||
Drain(ChatLines);
|
||||
s.Call("SetBrowserFolder", Path.Combine(_root, "no-such-browser"));
|
||||
var (h, _) = Open(s, "https://panel.test/launch.html?code=" + Secret, Allow, key: "beta");
|
||||
bool failed = WaitStatus(s, h, StatusFailed, 20000, out int[] st);
|
||||
s.Call("SetBrowserFolder", (string?)null);
|
||||
s.Call("SetBrowserDelay", 300); // a slow browser launch widens any Failed-before-flag window
|
||||
int samples = 0, failedNoFlag = 0;
|
||||
bool failed = false;
|
||||
int[] st;
|
||||
try
|
||||
{
|
||||
var (h, _) = Open(s, "https://panel.test/launch.html?code=" + Secret, Allow, key: "beta");
|
||||
// Poll continuously: a plugin that sees Failed without OpenedInBrowser would open the page a second time.
|
||||
var sw = Stopwatch.StartNew();
|
||||
st = State(s, h);
|
||||
while (sw.ElapsedMilliseconds < 20000)
|
||||
{
|
||||
st = State(s, h);
|
||||
samples++;
|
||||
if (st[2] == StatusFailed && (st[3] & StateOpenedInBrowser) == 0) failedNoFlag++;
|
||||
if (st[2] == StatusFailed && (st[3] & StateOpenedInBrowser) != 0) { failed = true; break; }
|
||||
if (st[2] == StatusFailed && failedNoFlag > 400) break; // the flag is not coming
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
if (!failed) failed = st[2] == StatusFailed;
|
||||
}
|
||||
finally { s.Call("SetBrowserDelay", 0); s.Call("SetBrowserFolder", (string?)null); }
|
||||
string[] calls = BrowserCalls.ToArray();
|
||||
W($"forced create failure: state [{string.Join(",", st)}]; browser calls {calls.Length}; chat: {string.Join(" | ", ChatLines)}");
|
||||
W($"forced create failure: state [{string.Join(",", st)}]; {samples} samples, {failedNoFlag} showed Failed without OpenedInBrowser; browser calls {calls.Length}; chat: {string.Join(" | ", ChatLines)}");
|
||||
if (!failed) Fail("CreateFailureFallsBack", "status " + st[2]);
|
||||
else if (failedNoFlag > 0) Fail("CreateFailureFallsBack", $"{failedNoFlag} of {samples} samples showed Failed without OpenedInBrowser (a polling plugin would open the page twice)");
|
||||
else if (st[4] != CodeCreateFailed) Fail("CreateFailureFallsBack", "error " + st[4] + ", want CreateFailed");
|
||||
else if ((st[3] & StateOpenedInBrowser) == 0) Fail("CreateFailureFallsBack", "OpenedInBrowser flag not set");
|
||||
else if (calls.Length != 1 || Redact(calls[0]) != "https://panel.test/launch.html") Fail("CreateFailureFallsBack", $"{calls.Length} browser call(s)");
|
||||
|
|
|
|||
Loading…
Reference in a new issue