Merge remote-tracking branch 'origin/main' into funzione/video-fermi

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 16:44:13 +01:00
commit 19119064f0
29 files changed
+922 -519

No files matched your search

@@ -54,6 +54,128 @@ public sealed class BrowserStartPageTests
Assert.IsTrue(status.GetProperty("userIsDriving").GetBoolean());
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task ABrowserThatDoesNotAnswerYetIsWaitedForAndThenOpensTheLogin()
{
var ct = TestContext.CancellationToken;
await using var bed = await DesktopTestBed.StartAsync();
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
var browser = bed.Browser!;
// Just restarted (after «Scollega», issue #67): the browser does not say its page yet. Febe asks again and waits.
browser.FakeCdp.Silent = true;
var asked = browser.FakeCdp.SilentAnswers;
var begin = BeginAsync(bed, openLogin: false);
await DesktopTestBed.WaitUntilAsync(() => browser.FakeCdp.SilentAnswers >= asked + 3, TimeSpan.FromSeconds(5), "le domande ripetute al browser che non risponde");
Assert.IsFalse(begin.IsCompleted, "still waiting for the browser");
Assert.DoesNotContain(Login, browser.FakeCdp.Visited);
// It answers, on the empty rest page: the login page, never a white window (issue #52).
browser.FakeCdp.Silent = false;
await begin.WaitAsync(TimeSpan.FromSeconds(10), ct);
Assert.AreEqual(Login, browser.FakeCdp.Url);
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task ABrowserSilentBeyondTheWaitCountsAsAtRestAndOpensTheLogin()
{
var ct = TestContext.CancellationToken;
await using var bed = await DesktopTestBed.StartAsync();
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
var browser = bed.Browser!;
var connection = bed.App.Connection!;
connection.AddressWait = TimeSpan.FromMilliseconds(400);
browser.FakeCdp.Silent = true;
var watch = System.Diagnostics.Stopwatch.StartNew();
await BeginAsync(bed, openLogin: false);
watch.Stop();
Assert.IsGreaterThanOrEqualTo(TimeSpan.FromMilliseconds(350), watch.Elapsed, "it waited for the browser first");
Assert.AreEqual(Login, browser.FakeCdp.Url, "still silent: the rest page, and the login opens");
Assert.AreEqual(1, browser.FakeCdp.Visited.Count(v => v == Login));
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task ABrowserThatAnswersLateWithAPageOfAlbertosLeavesItAlone()
{
var ct = TestContext.CancellationToken;
await using var bed = await DesktopTestBed.StartAsync();
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
var browser = bed.Browser!;
await BeginAsync(bed, openLogin: false);
browser.FakeCdp.Navigated("https://www.instagram.com/marta.prova/");
var navigations = Navigations(browser);
browser.FakeCdp.Silent = true;
var asked = browser.FakeCdp.SilentAnswers;
var begin = BeginAsync(bed, openLogin: false);
await DesktopTestBed.WaitUntilAsync(() => browser.FakeCdp.SilentAnswers >= asked + 2, TimeSpan.FromSeconds(5), "le domande ripetute al browser che non risponde");
browser.FakeCdp.Silent = false;
await begin.WaitAsync(TimeSpan.FromSeconds(10), ct);
Assert.AreEqual("https://www.instagram.com/marta.prova/", browser.FakeCdp.Url);
Assert.AreEqual(navigations, Navigations(browser), "no navigation of his page");
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task TheWaitForASilentBrowserEndsWithTheRequest()
{
var ct = TestContext.CancellationToken;
await using var bed = await DesktopTestBed.StartAsync();
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
var browser = bed.Browser!;
var connection = bed.App.Connection!;
var navigations = Navigations(browser);
browser.FakeCdp.Silent = true;
var asked = browser.FakeCdp.SilentAnswers;
using var request = new CancellationTokenSource();
var begin = connection.BeginUserDrivingAsync(openLogin: false, request.Token);
await DesktopTestBed.WaitUntilAsync(() => browser.FakeCdp.SilentAnswers >= asked + 2, TimeSpan.FromSeconds(5), "le domande ripetute al browser che non risponde");
await request.CancelAsync();
await Assert.ThrowsAsync<OperationCanceledException>(() => begin.WaitAsync(TimeSpan.FromSeconds(10), ct));
Assert.AreEqual(navigations, Navigations(browser), "nothing opened after the request went away");
Assert.AreEqual("about:blank", browser.FakeCdp.Url);
// The commands of the connection are free again: the next request, with the browser answering, opens the login.
browser.FakeCdp.Silent = false;
await BeginAsync(bed, openLogin: false);
Assert.AreEqual(Login, browser.FakeCdp.Url);
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task ABrowserThatAnswersNothingStillComesToTheFrontWithoutAnError()
{
var ct = TestContext.CancellationToken;
await using var bed = await DesktopTestBed.StartAsync();
await bed.App.Running.WaitAsync(TimeSpan.FromSeconds(20), ct);
var browser = bed.Browser!;
bed.App.Connection!.AddressWait = TimeSpan.FromMilliseconds(300);
// Still restarting (issue #67): no page and no navigation either. The window comes all the same, never a 500.
browser.FakeCdp.Silent = true;
browser.FakeCdp.RefusesNavigation = true;
var shown = browser.Shown;
await BeginAsync(bed, openLogin: false);
Assert.AreEqual(shown + 1, browser.Shown, "«Usa il browser»: the window came to the front");
var result = await bed.JsonAsync(HttpMethod.Post, "/api/browser/show");
StringAssert.Contains(result.GetProperty("message").GetString(), "primo piano");
Assert.AreEqual(shown + 2, browser.Shown, "«Apri il browser»: the window came to the front");
Assert.AreEqual("about:blank", browser.FakeCdp.Url, "nothing could open");
Assert.DoesNotContain(Login, browser.FakeCdp.Visited);
browser.FakeCdp.Silent = false;
browser.FakeCdp.RefusesNavigation = false;
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task ApriIlBrowserBringsTheWindowWithItsStartPageAndTheLoginAfterADisconnection()
@@ -263,6 +263,9 @@ internal sealed class FakeCdp : ICdpSession
private readonly Dictionary<string, List<Action<JsonElement>>> _handlers = new(StringComparer.Ordinal);
private int _captureReads;
private int _cookieReads;
private bool _silent;
private int _silentAnswers;
private bool _refusesNavigation;
public bool LoggedIn { get; set; }
@@ -313,6 +316,29 @@ internal sealed class FakeCdp : ICdpSession
public string Url { get; private set; } = "about:blank";
/// <summary>
/// While true the page does not say where it is, like a browser that has just restarted and does not answer yet
/// (issue #67): <c>Page.getFrameTree</c> fails as a closed connection, and is counted in <see cref="SilentAnswers"/>.
/// </summary>
public bool Silent
{
get => Volatile.Read(ref _silent);
set => Volatile.Write(ref _silent, value);
}
/// <summary>How many times <c>Page.getFrameTree</c> was asked while <see cref="Silent"/>.</summary>
public int SilentAnswers => Volatile.Read(ref _silentAnswers);
/// <summary>
/// While true <c>Page.navigate</c> fails as a closed connection too, like a browser that has not finished restarting
/// (issue #67): with <see cref="Silent"/>, a browser that answers nothing at all.
/// </summary>
public bool RefusesNavigation
{
get => Volatile.Read(ref _refusesNavigation);
set => Volatile.Write(ref _refusesNavigation, value);
}
public ConcurrentQueue<string> Methods { get; } = new();
/// <summary>Every address a <c>Page.navigate</c> asked for, in order.</summary>
@@ -329,6 +355,17 @@ internal sealed class FakeCdp : ICdpSession
{
CdpCommandPolicy.EnsureAllowed(method);
Methods.Enqueue(method);
if (method == "Page.getFrameTree" && Silent)
{
Interlocked.Increment(ref _silentAnswers);
return Task.FromException<JsonElement>(new CdpDisconnectedException());
}
if (method == "Page.navigate" && RefusesNavigation)
{
return Task.FromException<JsonElement>(new CdpDisconnectedException());
}
JsonNode result = method switch
{
"Page.getFrameTree" => new JsonObject { ["frameTree"] = new JsonObject { ["frame"] = new JsonObject { ["id"] = "F1", ["url"] = Url } } },
@@ -519,6 +519,49 @@ public sealed class EngineHostTests
Assert.AreEqual(restsWhenTaken + 1, runner.Rests, "The verification page is left as it is.");
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task ARestThatGetsThePageOnlyAfterAlbertoTookTheBrowserAgainLeavesHisPage()
{
var driving = false;
await using var bed = await EngineTestBed.CreateAsync(Morning, userIsDriving: () => driving);
await bed.AddAccountAsync("uno.demo", followed: true);
var runner = new ScriptedRunner(bed.Governor, bed.Clock);
var host = bed.Start(runner);
await host.PauseAsync();
driving = true;
host.NotifyUserDrivingChanged();
await bed.RunForAsync(TimeSpan.FromSeconds(1));
var rests = runner.Rests;
// He lets go while his own navigation still holds the page (the turn of «Usa il browser»): the rest waits for it.
var turns = bed.Services.PageTurns;
var albertos = await turns.TakeAsync(PageUser.Engine, CancellationToken.None);
driving = false;
host.NotifyUserDrivingChanged();
// Real time: the loop, woken, waits for the turn and for no timer of the virtual clock.
var watch = System.Diagnostics.Stopwatch.StartNew();
while (!turns.IsWaiting(PageUser.Engine))
{
Assert.IsLessThan(TimeSpan.FromSeconds(10), watch.Elapsed, "the rest waits for the page turn");
await Task.Delay(TimeSpan.FromMilliseconds(10));
}
// He takes the browser again and his page opens before the rest gets the turn: the page is his, not rested.
driving = true;
host.NotifyUserDrivingChanged();
albertos.Dispose();
await bed.RunForAsync(TimeSpan.FromSeconds(1));
Assert.AreEqual(rests, runner.Rests, "the page he took is not put to rest under him");
Assert.IsFalse(turns.IsWaiting(PageUser.Engine));
// The rest is still owed: when he lets go again, the page goes back to rest.
driving = false;
host.NotifyUserDrivingChanged();
await bed.RunForAsync(TimeSpan.FromSeconds(1));
Assert.AreEqual(rests + 1, runner.Rests, "back to rest once he lets go");
}
[TestMethod]
public async Task ChangingTheAccountsDuringARecipeDoesNotBringItsNextCheckForward()
{
@@ -169,6 +169,10 @@ public sealed partial class PackagingTests
StringAssert.Contains(image, "pubblicata: ${{ steps.pubblicazione.outputs.pubblicata }}");
StringAssert.Contains(release, "PUBBLICATA: ${{ needs.immagine.outputs.pubblicata }}");
StringAssert.Contains(release, "non è stata pubblicata");
// The first publication has no earlier image on the registry: the note without an image must not promise one.
var unpublished = release.Split('\n').Single(line => line.Contains("non è stata pubblicata"));
StringAssert.Contains(unpublished, "non aggiorna \\`:latest\\`");
Assert.DoesNotContain("versione precedente", unpublished, "the first publication has no earlier image");
// Without the secret the image is built and tested, and the job still succeeds: the release says so.
var secret = Step(image, "Segreto per il registro");
@@ -58,6 +58,37 @@ public sealed partial class PipelineTests
}
}
/// <summary>
/// The state of the machine sampled while the tests run (runs 502 and 532 stopped with every test in progress): the
/// test step starts it, ends it and keeps the result of the tests; the log goes up with the .trx files.
/// </summary>
[TestMethod]
public async Task TheVerificationKeepsTheStateOfTheMachineDuringTheTests()
{
var tests = Code(Workflow("verifica.yml"));
StringAssert.Contains(tests, "bash .gitea/scripts/macchina.sh out/prove/macchina.log &");
StringAssert.Contains(tests, "trap 'kill \"$macchina\" 2> /dev/null || true' EXIT");
StringAssert.Contains(tests, "risultati+=(out/prove/macchina.log)");
CiPath("scripts", "macchina.sh");
var bash = RequireBash();
using var folder = new TempFolder("febe-macchina");
var log = folder.Combine("prove", "macchina.log");
var run = await RunProcessAsync(bash, ["--noprofile", "--norc", ".gitea/scripts/macchina.sh", log.Replace('\\', '/'), "0", "3"]);
Assert.AreEqual(0, run.Code, run.Errors);
var lines = await File.ReadAllLinesAsync(log, TestContext.CancellationToken);
Assert.HasCount(3, lines);
foreach (var line in lines)
{
StringAssert.Matches(line, MachineLine());
}
Assert.AreEqual(2, (await RunProcessAsync(bash, ["--noprofile", "--norc", ".gitea/scripts/macchina.sh", log.Replace('\\', '/'), "presto"])).Code);
}
[System.Text.RegularExpressions.GeneratedRegex(@"^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ carico=[\d. ]* memoria=\d* MB scambio=\d* MB psi cpu=[\d.]* memoria=[\d.]* disco=[\d.]*$")]
private static partial System.Text.RegularExpressions.Regex MachineLine();
/// <summary>riepilogo-prove.sh with no skipped test allowed, on one .trx file of the given results.</summary>
private async Task<(int Code, string Output, string Errors, string Report)> RunSummaryAsync(string bash, params (string Outcome, string Name, string? Message)[] results)
{
+12 -1
View File
@@ -122,12 +122,23 @@ public sealed partial class PipelineTests
}
// tests/Febe.Tests.Windows runs only on Windows: never «dotnet test» on the solution or without a project.
// Every run of the tests ends, naming the culprit, when a test is stuck for 20 minutes (no dump of the test host).
foreach (var name in new[] { "verifica.yml", "rilascio.yml" })
{
foreach (Match test in DotnetTest().Matches(Code(Workflow(name))))
var code = Code(Workflow(name));
var runs = 0;
foreach (Match test in DotnetTest().Matches(code))
{
Assert.AreEqual("tests/Febe.Tests", test.Groups["target"].Value, $"{name}: {test.Value}");
var end = code.IndexOf("--results-directory", test.Index, StringComparison.Ordinal);
if (code.AsSpan(test.Index + test.Length).StartsWith(" -c Release") && end > test.Index)
{
runs++;
StringAssert.Contains(code[test.Index..end], "--blame-hang-timeout 20m --blame-hang-dump-type none", $"{name}: {test.Value}");
}
}
Assert.AreEqual(name == "verifica.yml" ? 2 : 1, runs, $"{name}: le esecuzioni delle prove");
}
}