Sessione salvata: seconda revisione di S4b (#36)

La scelta per la copia incompleta si legge prima dell'ultimo controllo che la pagina sia ancora di Alberto, così fra quello sguardo e la scrittura non passa nessuna attesa (regola 7); se l'impostazione non si legge vale «Sostituisci comunque» e il registro scrive solo il tipo d'errore, invece di far fallire «Ho finito» lasciando il permesso di guida trattenuto. Ogni abbandono del browser senza «Ho finito» dimentica la copia di un abbandono precedente dello stesso uso prima di provare la sua: un «Ho finito» tardivo dopo una seconda chiusura rifiutata (pagina di accesso) non dice più che la sessione era già stata copiata. Tre prove nuove, che senza le correzioni non passano. Fine riga già conformi: indice LF come il resto del repository, nessuna conversione necessaria.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 13:03:59 +01:00
1 parent c69755db23
commit 74e67adbab
5 files changed
+120 -10

No files matched your search

@@ -333,6 +333,59 @@ public sealed class SessionCaptureTests
AssertNoSecret(string.Join("\n", log));
}
[TestMethod]
public async Task AChoiceThatCannotBeReadIsTheDefaultAndTheCopyGoesOn()
{
// The setting lives in the database: a failure there must not make «Ho finito» fail (the lease would stay held).
var log = new List<string>();
var store = new InMemorySiteSession(null);
await new BrowserSessionCopier(Page($"http://{SiteHost}/"), Plan, store, new VirtualClock(), log.Add).CopyAsync(() => true, CancellationToken.None);
var complete = store.Read();
Assert.IsNotNull(complete);
var lacking = PageValues();
((JsonObject)lacking["values"]!).Remove("lsd");
var copier = new BrowserSessionCopier(Page($"http://{SiteHost}/", page: lacking), Plan, store, new VirtualClock(), log.Add)
{
IncompleteCopy = _ => throw new InvalidOperationException("prova: impostazione illeggibile"),
};
var outcome = await copier.CopyAsync(() => true, CancellationToken.None);
Assert.AreEqual(SessionCopyStatus.Saved, outcome.Status, "«Sostituisci comunque», the default");
Assert.AreNotSame(complete, store.Read());
var text = string.Join("\n", log);
StringAssert.Contains(text, "Scelta per la copia incompleta non letta (InvalidOperationException)");
Assert.DoesNotContain("impostazione illeggibile", text, "the kind of error only (rule 10)");
AssertNoSecret(text);
}
[TestMethod]
public async Task ThePageIsLookedAtLastAfterTheChoiceIsRead()
{
// Rule 7: nothing awaited between the last look at whose page it is and the decision on the saved session. Here
// the page goes back to the engine while the choice is read: the copy is thrown away, not kept nor saved.
var store = new InMemorySiteSession(null);
await new BrowserSessionCopier(Page($"http://{SiteHost}/"), Plan, store, new VirtualClock(), _ => { }).CopyAsync(() => true, CancellationToken.None);
var complete = store.Read();
var lacking = PageValues();
((JsonObject)lacking["values"]!).Remove("lsd");
var lost = false;
var copier = new BrowserSessionCopier(Page($"http://{SiteHost}/", page: lacking), Plan, store, new VirtualClock(), _ => { })
{
IncompleteCopy = _ =>
{
lost = true;
return Task.FromResult(IncompleteCopyChoice.KeepComplete);
},
};
var outcome = await copier.CopyAsync(() => !lost, CancellationToken.None);
Assert.IsTrue(lost, "the choice was read");
Assert.AreEqual(SessionCopyStatus.Discarded, outcome.Status);
Assert.AreSame(complete, store.Read());
}
[TestMethod]
public async Task TheReportCountsAndNamesWhatTheSavedSessionHoldsAndNeverAValue()
{
@@ -118,6 +118,36 @@ public sealed class SessionCopyOnLetGoTests
Assert.AreEqual(2, browser.FakeCdp.CaptureReads, "refused before the modules are read");
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task ALateHoFinitoFollowsTheLastLettingGoNotAnEarlierOne()
{
var ct = TestContext.CancellationToken;
await using var bed = await StartAsync();
var browser = bed.Browser!;
var connection = bed.App.Connection!;
connection.DrivingGrace = TimeSpan.FromMilliseconds(400);
// «Usa il browser», the window closed on the site's home: copied.
await BeginAsync(bed, openLogin: false);
browser.FakeCdp.LoggedIn = true;
browser.FakeCdp.Navigated(Site + "/");
await browser.CloseWindowAsync(ct);
Assert.AreEqual(1, browser.FakeCdp.CaptureReads);
// Same use: the window back in front, then closed again on the login page (perhaps another account): refused.
await connection.ShowBrowserAsync(openLogin: false, ct);
browser.FakeCdp.Navigated(Site + "/accesso/");
await browser.CloseWindowAsync(ct);
await DesktopTestBed.WaitUntilAsync(() => !browser.UserIsDriving, TimeSpan.FromSeconds(10), "la fine della guida");
// A late «Ho finito» must not say that the session was already copied: the last letting go copied nothing.
var finish = await bed.JsonAsync(HttpMethod.Post, "/api/connection/finish");
var message = finish.GetProperty("message").GetString()!;
StringAssert.Contains(message, "non è stata copiata");
Assert.DoesNotContain("era già stata copiata", message);
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task AnErrorDuringTheCopyWhenAlbertoLetsGoStillGivesThePageBackToTheEngine()