Sessione salvata: correzioni della revisione di S4b (#36)

Un errore imprevisto durante la copia senza «Ho finito» (database, disco) non trattiene più per sempre il permesso di guida: la copia scrive solo il tipo d'errore e la guida finisce lo stesso, così il motore non resta in «Stai usando il browser». Un «Ho finito» tardivo dopo una copia fatta lasciando il browser dice che la sessione era già stata copiata invece di chiedere un nuovo accesso. Il registro distingue la finestra chiusa da quella ridotta a icona troppo a lungo. /api/engine e gli eventi prendono «Serve «Ho finito»» dall'istantanea del motore (EngineSnapshot.SessionCopyMissing) senza chiedere al browser a ogni evento. La prova di WebView2 aspetta la riga del registro, non solo la sessione in memoria. Documenti: nove operazioni GraphQL con __spin_*, H23 descritta in prove-dal-vivo (parte E), guida aggiornata.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 12:13:25 +01:00
1 parent 883ea4683c
commit c69755db23
20 files changed
+310 -54

No files matched your search

@@ -61,6 +61,33 @@ public sealed class EngineConnectionStateTests
Assert.AreEqual(JsonValueKind.Null, (await LinkAsync(EngineMode.NotConnected)).GetProperty("username").ValueKind, "Not connected: no name.");
}
[TestMethod]
public async Task NotConnectedTakesCopyMissingFromTheSnapshotWithoutAskingTheBrowser()
{
// Issue #36, S4b: the engine already knows whether the copy for the requests is missing (its headline says
// «Serve «Ho finito»»); every event of the stream must not cost a look at the browser for it.
var connection = new RecordingConnection { Status = new ConnectionStatus(ConnectionState.SessionCopyMissing, null, null, false, null) };
await using var server = await Part2.StartAsync(services: s =>
{
s.AddSingleton<IEngineMonitor>(sp => new FixedModeMonitor(sp.GetRequiredService<IClock>()) { Mode = EngineMode.NotConnected });
s.AddSingleton<IConnectionService>(connection);
});
var monitor = (FixedModeMonitor)server.App.Services.GetRequiredService<IEngineMonitor>();
var reads = connection.StatusReads;
Assert.AreEqual("notConnected", (await server.GetJsonAsync("/api/engine")).GetProperty("connection").Str("state"), "the engine's word, not the connection's");
monitor.CopyMissing = true;
var engine = await server.GetJsonAsync("/api/engine");
Assert.AreEqual("copyMissing", engine.GetProperty("connection").Str("state"));
Assert.IsTrue(engine.GetProperty("snapshot").GetProperty("sessionCopyMissing").GetBoolean());
Assert.AreEqual(reads, connection.StatusReads, "no status asked while the engine runs");
// Only when the engine loop does not run is the connection asked.
monitor.Mode = EngineMode.Off;
Assert.AreEqual("copyMissing", (await server.GetJsonAsync("/api/engine")).GetProperty("connection").Str("state"));
Assert.AreEqual(reads + 1, connection.StatusReads);
}
[TestMethod]
public async Task WithoutEngineAndBrowserTheSidebarSaysNotConnectedEvenIfTuIsKnown()
{
@@ -76,8 +103,10 @@ public sealed class EngineConnectionStateTests
{
public EngineMode Mode { get; set; } = EngineMode.Resting;
public bool CopyMissing { get; set; }
public Task<EngineSnapshot> GetSnapshotAsync(CancellationToken ct = default) =>
Task.FromResult(SnapshotParts.Build(clock, Mode, "Prova", [], "Prova", CautionProfile.Prudent));
Task.FromResult(SnapshotParts.Build(clock, Mode, "Prova", [], "Prova", CautionProfile.Prudent) with { SessionCopyMissing = CopyMissing });
public async IAsyncEnumerable<EngineNotification> SubscribeAsync([EnumeratorCancellation] CancellationToken ct = default)
{
@@ -69,6 +69,7 @@ internal sealed class FixedProblems(params ConfigurationProblem[] problems) : IC
internal sealed class RecordingConnection : IConnectionService
{
private readonly Lock _gate = new();
private int _statusReads;
public List<string> Calls { get; } = [];
@@ -86,7 +87,14 @@ internal sealed class RecordingConnection : IConnectionService
}
}
public Task<ConnectionStatus> GetStatusAsync(CancellationToken ct) => Task.FromResult(Status);
/// <summary>How many times the status was asked (each one costs the real connection a look at the browser).</summary>
public int StatusReads => Volatile.Read(ref _statusReads);
public Task<ConnectionStatus> GetStatusAsync(CancellationToken ct)
{
Interlocked.Increment(ref _statusReads);
return Task.FromResult(Status);
}
public Task BeginUserDrivingAsync(bool openLogin, CancellationToken ct)
{