Storico chiuso dal controllo del profilo: il motore lo chiude subito, con la sua riga
Se un profilo sta tutto nella prima pagina, il controllo del profilo segnava lo storico come completato ma non cambiava lo stato e non scriveva righe. Dalla sessione dopo l'account usciva dai candidati dello Storico, quindi nessuno lo chiudeva più: restava «Storico in corso» per sempre, senza riga e senza avviso. Con due account in «Storico in corso» succedeva sempre (rilievo F1 della revisione). - Il controllo del profilo lo dice al motore con BackfillFinished, solo per un account «Storico in corso»: chi tiene solo i post nuovi non ha uno storico da annunciare. - Il motore chiude lo storico anche dopo il controllo del profilo, con la stessa FinishBackfillAsync, e prosegue con l'account aggiornato. - La fase dello Storico rilegge gli account invece di usare quelli di inizio sessione: altrimenti tornava a scorrere lo storico appena chiuso e scriveva una seconda riga. - A inizio sessione il motore chiude gli account rimasti «Storico in corso» con lo storico già completato (Febe fermata a metà, o lasciati così dalla 0.1.0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
afbd0b4a1a
commit
9d959f910b
4 files changed
+142
-10
No files matched your search
@@ -106,6 +106,96 @@ public sealed class BackfillCompletedTests
|
||||
Assert.HasCount(1, bed.Shell.Notifications.Where(n => n.Title == AlertCatalog.Title(AlertKind.BackfillDone)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A profile that fits on its first page: the profile check completes its history. When the walk of the session
|
||||
/// went to another account «Storico in corso», the small one stayed so for ever, with no line and no alert (review
|
||||
/// F1). Added first, the small one is the walk's next pick in that very session: it must not get a second line.
|
||||
/// An account that keeps only the new posts has no history to announce.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
[DataRow(false)]
|
||||
[DataRow(true)]
|
||||
public async Task AHistoryCompletedByTheProfileCheckIsClosedAtOnceWithOneLine(bool smallFirst)
|
||||
{
|
||||
await using var bed = await AlertBed.CreateAsync(start: Morning);
|
||||
var engine = bed.Engine;
|
||||
var (runner, site) = RealRecipes(engine);
|
||||
var big = site.Add(new ScriptedAccount("3003", "grande.prova") { Followed = false });
|
||||
big.Posts.AddRange(ScriptedBed.Posts(0, 400, Morning.AddDays(-30), prefix: "g"));
|
||||
var small = site.Add(new ScriptedAccount("4004", "piccolo.prova") { Followed = false });
|
||||
small.Posts.AddRange(ScriptedBed.Posts(0, 5, Morning.AddDays(-30), prefix: "s"));
|
||||
var news = site.Add(new ScriptedAccount("5005", "nuovi.prova") { Followed = false });
|
||||
news.Posts.AddRange(ScriptedBed.Posts(0, 3, Morning.AddDays(-30), prefix: "n"));
|
||||
|
||||
// Among the accounts «Storico in corso» the walk takes the lowest id first.
|
||||
Account smallAccount;
|
||||
if (smallFirst)
|
||||
{
|
||||
smallAccount = await AddBackfillingAsync(engine, small, postCount: 5);
|
||||
await AddBackfillingAsync(engine, big, postCount: 400);
|
||||
}
|
||||
else
|
||||
{
|
||||
await AddBackfillingAsync(engine, big, postCount: 400);
|
||||
smallAccount = await AddBackfillingAsync(engine, small, postCount: 5);
|
||||
}
|
||||
|
||||
var newsAccount = await engine.Db.Accounts.AddAsync(Account.Create(news.Username, StartingPoint.OnlyNewFromToday, engine.Clock.Now, EngineTestBed.Zone, engine.Runtime.Profile) with
|
||||
{
|
||||
InstagramId = news.Id,
|
||||
IsFollowed = news.Followed,
|
||||
ContentTypes = ContentTypes.PostPhotos | ContentTypes.PostVideos,
|
||||
PostCount = 3,
|
||||
});
|
||||
Assert.AreEqual(AccountState.UpToDate, newsAccount.State);
|
||||
|
||||
engine.Start(runner);
|
||||
await engine.RunUntilAsync(Morning.AddDays(4));
|
||||
await engine.StopAsync();
|
||||
await bed.Alerts.FlushAsync();
|
||||
|
||||
var lines = await engine.Db.Events.ListAsync(new EventQuery { Codes = [EngineEventCodes.BackfillCompleted] });
|
||||
var all = string.Join(" | ", lines.Select(e => e.Message));
|
||||
var done = await engine.Db.Accounts.GetAsync(smallAccount.Id);
|
||||
Assert.IsNotNull(done!.BackfillCompletedAt, "The whole profile is on its first page.");
|
||||
Assert.AreEqual(AccountState.UpToDate, done.State, all);
|
||||
const string Expected = "Storico di @piccolo.prova completato: 5 post in libreria. Da ora lo tengo aggiornato.";
|
||||
Assert.HasCount(1, lines.Where(e => e.AccountId == smallAccount.Id).ToList(), all);
|
||||
Assert.AreEqual(Expected, lines.Single(e => e.AccountId == smallAccount.Id).Message);
|
||||
Assert.AreEqual(1, bed.Shell.Notifications.Count(n => n.Message == Expected));
|
||||
|
||||
Assert.IsFalse(lines.Any(e => e.AccountId == newsAccount.Id), "«Solo i nuovi»: no history. " + all);
|
||||
Assert.AreEqual(AccountState.UpToDate, (await engine.Db.Accounts.GetAsync(newsAccount.Id))!.State);
|
||||
Assert.IsTrue(lines.GroupBy(e => e.AccountId).All(g => g.Count() == 1), "One line per history: " + all);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An account «Storico in corso» whose history is already complete (a profile check closed it and Febe stopped
|
||||
/// before recording the outcome, or a version that left it so): closed when the next session starts, with its
|
||||
/// line, without walking anything.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public async Task AnAccountLeftStoricoInCorsoWithItsHistoryCompleteIsClosedWhenASessionStarts()
|
||||
{
|
||||
await using var bed = await AlertBed.CreateAsync(start: Morning);
|
||||
var engine = bed.Engine;
|
||||
var account = await engine.AddAccountAsync("anna.prova", followed: true, state: AccountState.Backfilling, postCount: 7);
|
||||
await engine.Db.Accounts.SetBackfillAsync(account.Id, null, engine.Clock.Now);
|
||||
var runner = new ScriptedRunner(engine.Governor, engine.Clock);
|
||||
engine.Start(runner);
|
||||
await engine.RunUntilAsync(Morning.AddDays(1));
|
||||
await engine.StopAsync();
|
||||
await bed.Alerts.FlushAsync();
|
||||
|
||||
Assert.AreEqual(AccountState.UpToDate, (await engine.Db.Accounts.GetAsync(account.Id))!.State);
|
||||
var lines = await engine.Db.Events.ListAsync(new EventQuery { Codes = [EngineEventCodes.BackfillCompleted] });
|
||||
Assert.HasCount(1, lines);
|
||||
Assert.AreEqual("Storico di @anna.prova completato: 0 post in libreria. Da ora lo tengo aggiornato.", lines[0].Message);
|
||||
Assert.IsNotNull(lines[0].SessionId);
|
||||
Assert.IsFalse(runner.Runs.Any(r => r.Request.Kind == RecipeKind.Backfill), "Nothing left to walk.");
|
||||
Assert.HasCount(1, bed.Shell.Notifications.Where(n => n.Title == AlertCatalog.Title(AlertKind.BackfillDone)));
|
||||
}
|
||||
|
||||
/// <summary>The real recipes over the scripted site, on the engine's database, clock, Governor and breaker.</summary>
|
||||
private static (RecipeRunner Runner, ScriptedSite Site) RealRecipes(EngineTestBed engine)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user