Docker: lasciare la pagina del browser copia la sessione (#36, S4b, risposta 1)
verifica / controlli (push) Successful in 24s
verifica / prove (push) Failing after 41m21s
verifica / installatore (push) Skipped
verifica / immagine (push) Skipped

In Docker lasciare la pagina «Browser» o la vista remota di Collegamento mentre
Alberto guida (un'altra pagina, la scheda chiusa, il collegamento perso) valeva
«Annulla» e la sessione non si copiava. Ora è come chiudere la finestra del
browser su Windows: `cancel` con `pageLeft` va a LeavePageAsync, la vista
remota chiusa dalla sua pagina lo dice alla connessione, e se per 5 secondi
non si apre un'altra vista né arriva un `begin` (una pagina ricaricata) il
controllo del permesso copia la sessione con CopyOnLetGoAsync, solo da una
pagina del sito che non sia di accesso o di verifica, poi rilascia il permesso
e il motore rimette il browser a riposo. Il pulsante «Annulla» continua a non
copiare; Windows non cambia.

Prove nuove per la copia lasciando la pagina, la ricarica che non è lasciare,
la pagina di accesso, la vista sostituita o chiusa da Febe; guida, protocollo
e una riga in decisioni.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-25 10:52:51 +01:00
1 parent 537517b855
commit 2fc4b40c41
15 files changed
+312 -44

No files matched your search

@@ -295,6 +295,102 @@ public sealed class SessionCopyOnLetGoTests
StringAssert.Contains(ReadLog(bed), "Finestra del browser chiusa: sessione copiata");
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task LeavingTheBrowserPageInDockerCopiesTheSessionOnceNoViewOpensAgain()
{
var ct = TestContext.CancellationToken;
await using var bed = await StartAsync();
var browser = bed.Browser!;
var connection = bed.App.Connection!;
connection.PageLeaveGrace = TimeSpan.FromMilliseconds(400);
// «Usa il browser» from the Browser page of Docker: no window, the remote view holds the engine still.
var view = await DockerBeginAsync(bed);
browser.FakeCdp.LoggedIn = true;
browser.FakeCdp.Navigated(Site + "/");
bool? drivingWhileCopying = null;
browser.FakeCdp.OnCapture = () => drivingWhileCopying = browser.UserIsDriving;
// The page says it is left; while its view (or another tab's) is still open nothing happens.
await connection.LeavePageAsync(ct);
await Task.Delay(TimeSpan.FromMilliseconds(900), ct);
Assert.IsTrue(browser.UserIsDriving, "a view is still open");
Assert.AreEqual(0, browser.FakeCdp.CaptureReads);
// Its view closes with it and no other opens: the copy while the page is still his, then it goes back to the engine.
view.Dispose();
connection.RemoteViewClosed();
await DesktopTestBed.WaitUntilAsync(() => ReadLog(bed).Contains("Pagina del browser lasciata: nessuna vista del browser riaperta, il motore può riprendere.", StringComparison.Ordinal), TimeSpan.FromSeconds(10), "la fine della guida lasciando la pagina");
Assert.IsFalse(browser.UserIsDriving);
Assert.AreEqual(1, browser.FakeCdp.CaptureReads);
Assert.IsTrue(drivingWhileCopying, "the page is still Alberto's while it is read");
Assert.IsNotNull(bed.App.SavedSession!.Read());
StringAssert.Contains(ReadLog(bed), "Pagina del browser lasciata: sessione copiata");
// A late «Ho finito» from another tab reads nothing and says that the session was already copied.
var finish = (await bed.JsonAsync(HttpMethod.Post, "/api/connection/finish")).GetProperty("message").GetString()!;
StringAssert.Contains(finish, "era già stata copiata");
Assert.AreEqual(1, browser.FakeCdp.CaptureReads);
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task AReloadOfTheBrowserPageIsNotLeavingItAndAnnullaStillCopiesNothing()
{
var ct = TestContext.CancellationToken;
await using var bed = await StartAsync();
var browser = bed.Browser!;
var connection = bed.App.Connection!;
connection.PageLeaveGrace = TimeSpan.FromSeconds(1);
var view = await DockerBeginAsync(bed);
browser.FakeCdp.LoggedIn = true;
browser.FakeCdp.Navigated(Site + "/");
// A reload: the old page says it left and its view closes, the new page takes the browser and opens its view.
await connection.LeavePageAsync(ct);
view.Dispose();
connection.RemoteViewClosed();
view = await DockerBeginAsync(bed);
await Task.Delay(TimeSpan.FromSeconds(2), ct);
Assert.IsTrue(browser.UserIsDriving, "a reload is not leaving the browser");
Assert.AreEqual(0, browser.FakeCdp.CaptureReads);
// «Annulla» on the reloaded page: the browser goes back to rest, nothing is copied.
view.Dispose();
using (var cancel = await bed.SendAsync(HttpMethod.Post, "/api/connection/cancel"))
{
Assert.AreEqual(HttpStatusCode.NoContent, cancel.StatusCode);
}
Assert.IsFalse(browser.UserIsDriving);
await Task.Delay(TimeSpan.FromSeconds(1.5), ct);
Assert.AreEqual(0, browser.FakeCdp.CaptureReads, "«Annulla» never copies");
Assert.IsNull(bed.App.SavedSession!.Read());
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task LeavingTheBrowserPageOnTheLoginPageCopiesNothingButGivesThePageBack()
{
var ct = TestContext.CancellationToken;
await using var bed = await StartAsync();
var browser = bed.Browser!;
var connection = bed.App.Connection!;
connection.PageLeaveGrace = TimeSpan.FromMilliseconds(300);
var view = await DockerBeginAsync(bed);
browser.FakeCdp.LoggedIn = true;
browser.FakeCdp.Navigated(Site + "/accesso/");
// The tab closed on the site's login page (a path of its stop rules): the copier refuses it.
view.Dispose();
connection.RemoteViewClosed();
await DesktopTestBed.WaitUntilAsync(() => !browser.UserIsDriving, TimeSpan.FromSeconds(10), "la fine della guida lasciando la pagina di accesso");
Assert.AreEqual(0, browser.FakeCdp.CaptureReads, "refused before the modules are read");
Assert.IsNull(bed.App.SavedSession!.Read());
await DesktopTestBed.WaitUntilAsync(() => ReadLog(bed).Contains("Pagina del browser lasciata: sessione non copiata", StringComparison.Ordinal), TimeSpan.FromSeconds(10), "la riga della copia rifiutata");
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task WithRichiesteCollegatoNeedsTheSavedSessionAndTheEngineWaitsForIt()
@@ -481,6 +577,17 @@ public sealed class SessionCopyOnLetGoTests
Assert.AreEqual(HttpStatusCode.NoContent, begin.StatusCode);
}
/// <summary>
/// «Usa il browser» as the Browser page of Docker takes it: the lease of the connection and the lease of its remote
/// view (returned), without the window of this composition (put away at once).
/// </summary>
private async Task<IDisposable> DockerBeginAsync(DesktopTestBed bed)
{
await BeginAsync(bed, openLogin: false);
await bed.Browser!.HideFromUserAsync(TestContext.CancellationToken);
return bed.Browser.UserDriving.Begin();
}
/// <summary>«Accedi» or «Usa il browser», the site's home with the session, «Ho finito». Returns the message.</summary>
private static async Task<string> FinishOnSiteAsync(DesktopTestBed bed, bool openLogin)
{
@@ -132,6 +132,33 @@ public sealed class RemoteViewStartTests
}
}
[TestMethod]
[Timeout(30_000, CooperativeCancellation = true)]
public async Task OnlyAViewClosedByItsPageIsToldToTheConnection()
{
// Docker (answer of 25 November 2026): a view closed by its page may be Alberto leaving the browser; one replaced
// by another tab, one that did not start, or one closed because Febe stops is not.
var ct = TestContext.CancellationToken;
var told = 0;
await using var bed = new Bed(attempt => attempt == 3 ? new CdpDisconnectedException("Il collegamento con il browser si è chiuso.") : null, viewClosed: () => Interlocked.Increment(ref told));
var older = await bed.Host.OpenAsync(ct);
var newer = await bed.Host.OpenAsync(ct);
Assert.AreEqual(RemoteViewEnd.Replaced, older.Ended);
Assert.AreEqual(0, Volatile.Read(ref told), "replaced by another tab: Alberto is still at the browser");
await newer.DisposeAsync();
Assert.AreEqual(1, Volatile.Read(ref told), "the page closed its view");
await Assert.ThrowsExactlyAsync<RemoteViewUnavailableException>(() => bed.Host.OpenAsync(ct));
Assert.AreEqual(1, Volatile.Read(ref told), "a view that did not start was never the page's");
var last = await bed.Host.OpenAsync(ct);
await bed.Host.ShutdownAsync();
Assert.AreEqual(RemoteViewEnd.ShuttingDown, last.Ended);
Assert.AreEqual(1, Volatile.Read(ref told), "Febe stopping is not Alberto leaving");
}
[TestMethod]
[Timeout(30_000, CooperativeCancellation = true)]
public async Task PaginaInizialeOpensTheStartPageOfTheMoment()
@@ -300,7 +327,8 @@ public sealed class RemoteViewStartTests
/// tested in BrowserStartPageTests); null: nowhere.
/// </param>
/// <param name="open">What «Pagina iniziale» does instead (it wins over <paramref name="startPage"/>).</param>
public Bed(Func<int, Exception?> startFailure, Func<string>? startPage = null, Func<CancellationToken, Task>? open = null)
/// <param name="viewClosed">What the connection is told when a view is closed by its page.</param>
public Bed(Func<int, Exception?> startFailure, Func<string>? startPage = null, Func<CancellationToken, Task>? open = null, Action? viewClosed = null)
{
Clock = new VirtualClock();
_start = Clock.Now;
@@ -326,7 +354,7 @@ public sealed class RemoteViewStartTests
};
Browser = new PageBrowser(Cdp);
_log = new FebeLog(null, null, Clock);
Host = new BrowserRemoteViewHost(Browser, new BrowserUseTracker(), Clock, _log, browserClock: Clock, openStartPage: open ?? (startPage is null ? null : async ct => await Cdp.NavigateAsync(startPage(), ct)))
Host = new BrowserRemoteViewHost(Browser, new BrowserUseTracker(), Clock, _log, browserClock: Clock, openStartPage: open ?? (startPage is null ? null : async ct => await Cdp.NavigateAsync(startPage(), ct)), viewClosed: viewClosed)
{
// The virtual clock moves only in the pauses: a watchdog on it would never wait.
Watchdog = null,
+5 -3
View File
@@ -63,19 +63,21 @@ public sealed class ConnectionApiTests
}
[TestMethod]
public async Task LeavingThePageIsAnnullaInDockerAndOnlyTheEndOfTheHoldOnWindows()
public async Task LeavingThePageLetsGoOfTheBrowserInDockerAndOnlyEndsTheHoldOnWindows()
{
// Docker: the remote view is the page, leaving it gives the browser back to rest.
// Docker: the remote view is the page; leaving it lets go of the browser like closing the window on Windows (the
// session is copied: answer of 25 November 2026), while the button «Annulla» still cancels.
var docker = new RecordingConnection();
await using (var server = await Part2.StartAsync(services: s => s.AddSingleton<IConnectionService>(docker)))
{
var (status, _) = await server.SendJsonAsync(HttpMethod.Post, "/api/connection/cancel", new { pageLeft = true });
Assert.AreEqual(HttpStatusCode.NoContent, status);
await server.SendJsonAsync(HttpMethod.Post, "/api/connection/cancel");
var (showStatus, _) = await server.SendJsonAsync(HttpMethod.Post, "/api/browser/show");
Assert.AreEqual(HttpStatusCode.BadRequest, showStatus, "in Docker the browser is the Browser page");
}
CollectionAssert.AreEqual(new[] { "cancel" }, docker.Calls);
CollectionAssert.AreEqual(new[] { "leave", "cancel" }, docker.Calls);
// Windows (issue #52): the window stays as it is; «Annulla» is still «Annulla»; «Apri il browser» says which page.
var windows = new RecordingConnection();
+5 -5
View File
@@ -90,12 +90,12 @@ public sealed class InterfaceTests
await ui.OpenAsync(new Uri(server.Address, "/browser"));
await ui.WaitForAsync(() => connection.Snapshot().Contains("begin:False") && view.Opened.Count == 1, "il browser in uso con la vista aperta");
// Another page from the sidebar: the view closes and the lease of «begin» goes too (like «Annulla»).
// Another page from the sidebar: the view closes and the page lets go of the browser (not «Annulla»: the session is copied).
await ui.EvalAsync("document.querySelector('a[data-nav=libreria]').click()");
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
await ui.WaitForAsync(() => connection.Snapshot().Contains("cancel"), "il browser restituito lasciando la pagina");
await ui.WaitForAsync(() => connection.Snapshot().Contains("leave"), "il browser restituito lasciando la pagina");
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa");
CollectionAssert.AreEqual(new[] { "begin:False", "cancel" }, connection.Snapshot());
CollectionAssert.AreEqual(new[] { "begin:False", "leave" }, connection.Snapshot());
}
[TestMethod]
@@ -111,7 +111,7 @@ public sealed class InterfaceTests
// The document goes away (tab closed, reload, another site): only the page-hide event is left to say so.
await ui.SendAsync("Page.navigate", new JsonObject { ["url"] = "about:blank" });
await ui.WaitForAsync(() => connection.Snapshot().Contains("cancel"), "il browser restituito chiudendo la scheda");
await ui.WaitForAsync(() => connection.Snapshot().Contains("leave"), "il browser restituito chiudendo la scheda");
}
[TestMethod]
@@ -258,7 +258,7 @@ public sealed class InterfaceTests
await ui.NavigateAsync("/libreria");
await ui.WaitAsync("location.pathname === '/libreria'", "Libreria");
await ui.WaitForQuietAsync("richieste della pagina finite");
CollectionAssert.AreEqual(new[] { "begin:False", "finish", "begin:False", "cancel" }, connection.Snapshot(), "leaving the page gives the browser back");
CollectionAssert.AreEqual(new[] { "begin:False", "finish", "begin:False", "leave" }, connection.Snapshot(), "leaving the page gives the browser back");
await ui.WaitForAsync(() => view.Opened.All(v => v.Disposed), "vista remota chiusa");
}
@@ -124,6 +124,14 @@ internal sealed class RecordingConnection : IConnectionService
return Task.CompletedTask;
}
/// <summary>Docker: the page of the browser left without «Ho finito» or «Annulla» (not «Annulla»: it copies).</summary>
public Task LeavePageAsync(CancellationToken ct)
{
Record("leave");
Status = Status with { UserIsDriving = false };
return Task.CompletedTask;
}
public Task ReleaseAsync(CancellationToken ct)
{
Record("release");