From 1c7205024f0a03b3ba8da84ec6634143b8d62f16 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Wed, 11 Nov 2026 21:40:41 +0100 Subject: [PATCH] Count short gaps at the edges of the soak window as covered (refs #53) The scheduler's first jobs finish about a minute after the bot starts, so a run started exactly at the window's start was reported as covering slightly less than 48 hours. A gap shorter than the allowed silence (15 minutes) at either edge now counts as covered, like one in the middle. Co-Authored-By: Claude Opus 5.5 --- src/Anubis/Supervision/SoakReport.cs | 6 ++++-- tests/Anubis.Tests/SoakReportTests.cs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Anubis/Supervision/SoakReport.cs b/src/Anubis/Supervision/SoakReport.cs index b3e979b..da54803 100644 --- a/src/Anubis/Supervision/SoakReport.cs +++ b/src/Anubis/Supervision/SoakReport.cs @@ -83,8 +83,10 @@ public static class SoakReporter .ConfigureAwait(false); var absences = await s.QueryAsync("SELECT started_at, ended_at FROM absences WHERE ended_at >= @from AND started_at <= @to ORDER BY started_at", r => (Start: r.Moment("started_at"), End: r.Moment("ended_at")), window).ConfigureAwait(false); - var start = jobs.First is { } first && first > from ? first : from; - var end = jobs.Last is { } lastJob && lastJob < to ? lastJob : to; + // A gap shorter than the longest silence allowed at either end (the first jobs come a minute after the start, + // the last one up to 5 minutes before the end) is no more a hole than one in the middle. + var start = jobs.First is { } first && first > from + MaxSilence ? first : from; + var end = jobs.Last is { } lastJob && lastJob < to - MaxSilence ? lastJob : to; var covered = jobs.First is null || jobs.Last is null || end <= start ? TimeSpan.Zero : end - start - absences.Aggregate(TimeSpan.Zero, (sum, a) => sum + (Min(a.End, end) - Max(a.Start, start) is { } span && span > TimeSpan.Zero ? span : TimeSpan.Zero)); checks.Add(new SoakCheck($"Durata coperta dal lavoro del bot: {SoakReport.Hours(covered)} (servono almeno {SoakReport.Hours(minimum)}).", covered >= minimum)); diff --git a/tests/Anubis.Tests/SoakReportTests.cs b/tests/Anubis.Tests/SoakReportTests.cs index 5a534ff..02620a6 100644 --- a/tests/Anubis.Tests/SoakReportTests.cs +++ b/tests/Anubis.Tests/SoakReportTests.cs @@ -54,7 +54,7 @@ public sealed class SoakReportTests var text = report.Markdown(Zones.Rome); Assert.IsTrue(report.Passed, text); Assert.Contains("**Esito: regolare.**", text); - Assert.Contains("Durata coperta dal lavoro del bot: 49,0 ore", text); + Assert.Contains("Durata coperta dal lavoro del bot: 49 ore", text); Assert.Contains("Al lavoro dall'inizio alla fine della finestra.", text); Assert.Contains("Ogni conto riconciliato fino alla fine e in regola: ", text); Assert.Contains("Decisioni di crypto_trend: 2 su 2 chiusure giornaliere.", text);