Ricette fatte di richieste, un permesso per richiesta (#36, S3)
verifica / controlli (push) Successful in 22s
verifica / prove (push) Successful in 21m4s
verifica / installatore (push) Successful in 5m21s
verifica / immagine (push) Successful in 19m0s

Otto ricette (controllo del profilo, storico, taggati, reel, storie di un
account, raccolta in evidenza, post singolo, elenco dei seguiti) hanno una
strada per richieste dirette accanto a quella con il browser. Ci vanno solo
se ogni ruolo che servono è un'operazione configurata di richieste.<sito>.json:
con Instagram nessuna lo è e Febe non costruisce il client del sito, quindi il
comportamento con Instagram non cambia fino a S4.

Ogni richiesta prende il suo permesso dal Governatore nella categoria di ciò
che chiede (la prima pagina dei post conta come profilo); i segnali delle
risposte vanno all'interruttore e fermano la ricetta prima di ogni altra
richiesta. Se manca un valore o la pagina successiva, la ricetta torna alle
pagine per quella volta e il motore controlla tutti e due i tetti. I tetti non
cambiano: il dimezzamento delle storie viste è tolto perché toccava anche il
browser e i «Su misura» salvati, e resta una domanda per Alberto prima di S4.

Il simulatore ha --raccolta pagine|richieste con il costo delle operazioni
separate di Instagram: sei simulazioni di 30 giorni senza superamenti.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-17 12:10:54 +01:00
1 parent 4dcbd0b096
commit 63acae4e73
46 files changed
+3724 -136

No files matched your search

@@ -0,0 +1,217 @@
using Febe.Core.Abstractions;
using Febe.Core.Collection.Recipes;
using Febe.Core.Collection.Requests;
using Febe.Core.Domain;
using Febe.Core.Engine;
using Febe.Core.Storage;
using Febe.SitoDiProva;
using Febe.Tests.Collection.Support;
using Febe.Tests.Support;
using VirtualClock = Febe.Tests.Browser.TestSupport.VirtualClock;
namespace Febe.Tests.Collection;
/// <summary>
/// The recipes by requests (issue #36, S3) against the real test site on 127.0.0.1, through the HTTP site client, never
/// Instagram: what the site has comes into the archive without the page, one permit per request, and the stop cases of
/// the site stop the run.
/// </summary>
[TestClass]
[TestCategory(SyntheticSite.Category)]
public sealed class RequestRecipeSiteTests
{
private static readonly RequestCatalog Catalog = RequestCatalog.LoadTestSite();
[TestMethod]
public async Task TheCheckAndTheHistoryReadTheWholeGrid()
{
await using var site = await SyntheticSite.StartAsync();
await using var bed = await BedAsync(site);
var (id, posts) = Facts(site, "luca.prova", a => a.Posts.Count);
var luca = await bed.AddAccountAsync(id, "luca.prova", a => a with { State = AccountState.Backfilling });
var check = await bed.RunAsync(RecipeKind.ProfileCheck, luca.Id);
var history = await bed.RunAsync(RecipeKind.Backfill, luca.Id, maxPages: 10);
Assert.AreEqual(RecipeStatus.Completed, check.Status, check.Message);
Assert.AreEqual(RecipeStatus.Completed, history.Status, history.Message);
Assert.IsTrue(history.BackfillFinished, "The beginning of the profile was reached.");
Assert.AreEqual(0, bed.Page.Touched);
Assert.AreEqual(posts, (await bed.Db.Entries.ListByAccountAsync(luca.Id, new EntryListOptions { Kind = EntryKind.Post, Limit = 1000 })).Count);
Assert.IsNotNull((await bed.Db.Accounts.GetAsync(luca.Id))!.BackfillCompletedAt);
Assert.AreEqual(bed.Governor.Requests.Count, bed.Governor.Requests.Count(r => r.Kind is ActionKind.ProfileOpen or ActionKind.BackfillPage));
}
[TestMethod]
public async Task StoriesCollectionTaggedAndReelsComeWithoutThePage()
{
await using var site = await SyntheticSite.StartAsync();
await using var bed = await BedAsync(site);
var (martaId, _) = Facts(site, "marta.prova", a => 0);
string highlight;
int items;
lock (site.World.Gate)
{
var account = site.World.FindByUsername("marta.prova")!;
highlight = account.Highlights[0].Id;
items = account.Highlights[0].Items.Count;
}
var (lucaId, reels) = Facts(site, "luca.prova", a => a.Posts.Count(p => p.IsReel));
var marta = await bed.AddAccountAsync(martaId, "marta.prova", a => a with { ContentTypes = a.ContentTypes | ContentTypes.Tagged });
var luca = await bed.AddAccountAsync(lucaId, "luca.prova");
var stories = await bed.RunAsync(RecipeKind.AccountStories, marta.Id);
var check = await bed.RunAsync(RecipeKind.ProfileCheck, marta.Id);
var collection = await bed.RunAsync(RecipeKind.Highlight, marta.Id, highlightId: highlight);
var tagged = await bed.RunAsync(RecipeKind.Tagged, marta.Id);
var reel = await bed.RunAsync(RecipeKind.Reels, luca.Id);
foreach (var outcome in new[] { stories, check, collection, tagged, reel })
{
Assert.AreEqual(RecipeStatus.Completed, outcome.Status, outcome.Message);
}
Assert.AreEqual(0, bed.Page.Touched);
Assert.IsTrue(stories.NewEntries > 0);
var stored = (await bed.Db.Highlights.FindAsync(marta.Id, highlight))!;
Assert.AreEqual(items, (await bed.Db.Highlights.ListItemsAsync(stored.Id)).Count, "Every content of the collection is linked, in its order.");
Assert.IsTrue((await bed.Db.Entries.ListByAccountAsync(marta.Id, new EntryListOptions { Kind = EntryKind.Tagged, Limit = 100 })).Count > 0);
Assert.AreEqual(reels, reel.NewEntries, "Every reel of the account, in one page.");
}
[TestMethod]
public async Task TheFollowingListIsReadToTheEndByItsCursors()
{
await using var site = await SyntheticSite.StartAsync();
await using var bed = await BedAsync(site);
int following;
lock (site.World.Gate)
{
following = site.World.Following.Count;
}
await bed.AddAccountAsync("1000", "alberto.prova", isMine: true);
var outcome = await bed.RunAsync(RecipeKind.FollowingList, maxPages: 10);
Assert.AreEqual(RecipeStatus.Completed, outcome.Status, outcome.Message);
Assert.IsTrue(outcome.BackfillFinished, outcome.Message);
StringAssert.StartsWith(outcome.Message, $"Elenco dei seguiti letto: {following} profili");
Assert.AreEqual(0, bed.Page.Touched);
Assert.IsTrue(bed.Governor.Requests.All(r => r.Kind == ActionKind.FollowingListPage));
}
[TestMethod]
public async Task APrivateProfileAndAMissingOneAreUnreachable()
{
await using var site = await SyntheticSite.StartAsync();
await using var bed = await BedAsync(site);
var hidden = await bed.AddAccountAsync("1006", "riservato.prova");
var missing = await bed.AddAccountAsync(null, "nessuno.prova");
var first = await bed.RunAsync(RecipeKind.ProfileCheck, hidden.Id);
var second = await bed.RunAsync(RecipeKind.ProfileCheck, missing.Id);
Assert.AreEqual(RecipeStatus.AccountUnreachable, first.Status, first.Message);
Assert.AreEqual(UnreachableReason.PrivateNotFollowed, (await bed.Db.Accounts.GetAsync(hidden.Id))!.UnreachableReason);
Assert.AreEqual(RecipeStatus.AccountUnreachable, second.Status, second.Message);
Assert.AreEqual(UnreachableReason.NotFound, (await bed.Db.Accounts.GetAsync(missing.Id))!.UnreachableReason);
Assert.AreEqual(0, bed.Breaker.Signals.Count);
}
[TestMethod]
public async Task TheStoriesOfAPrivateProfileNotFollowedMakeItUnreachableAsByThePage()
{
await using var site = await SyntheticSite.StartAsync();
await using var bed = await BedAsync(site);
var hidden = await bed.AddAccountAsync("1006", "riservato.prova");
var outcome = await bed.RunAsync(RecipeKind.AccountStories, hidden.Id);
Assert.AreEqual(RecipeStatus.AccountUnreachable, outcome.Status, outcome.Message);
Assert.AreEqual(UnreachableReason.PrivateNotFollowed, (await bed.Db.Accounts.GetAsync(hidden.Id))!.UnreachableReason);
CollectionAssert.AreEqual(new[] { ActionKind.StoryView, ActionKind.ProfileOpen }, bed.Governor.Requests.Select(r => r.Kind).ToArray());
Assert.AreEqual(0, bed.Breaker.Signals.Count);
Assert.AreEqual(0, bed.Page.Touched);
}
[TestMethod]
public async Task TheGapBelowANewFirstPageIsFilledByTheNextPageUntilKnownPosts()
{
await using var site = await SyntheticSite.StartAsync();
await using var bed = await BedAsync(site);
var (id, _) = Facts(site, "luca.prova", a => 0);
var luca = await bed.AddAccountAsync(id, "luca.prova");
var first = await bed.RunAsync(RecipeKind.ProfileCheck, luca.Id);
var known = (await bed.Db.Entries.ListByAccountAsync(luca.Id, new EntryListOptions { Kind = EntryKind.Post, Limit = 1000 })).Count;
lock (site.World.Gate)
{
var account = site.World.FindByUsername("luca.prova")!;
for (var i = 0; i < 14; i++)
{
site.World.Publish(account, "foto", DateTimeOffset.UtcNow.AddMinutes(i));
}
}
var requestsBefore = bed.Governor.Requests.Count;
var second = await bed.RunAsync(RecipeKind.ProfileCheck, luca.Id);
Assert.AreEqual(RecipeStatus.Completed, first.Status, first.Message);
Assert.AreEqual(RecipeStatus.Completed, second.Status, second.Message);
Assert.AreEqual(14, second.NewEntries, "The first page and the two new posts of the page after it.");
Assert.AreEqual(known + 14, (await bed.Db.Entries.ListByAccountAsync(luca.Id, new EntryListOptions { Kind = EntryKind.Post, Limit = 1000 })).Count);
CollectionAssert.AreEqual(new[] { ActionKind.ProfileOpen, ActionKind.BackfillPage }, bed.Governor.Requests.Skip(requestsBefore).Select(r => r.Kind).ToArray(), "One page of the gap, then known posts.");
Assert.IsNull(await bed.Db.Settings.GetAsync($"raccolta.lacuna.{luca.Id.ToString(System.Globalization.CultureInfo.InvariantCulture)}.cursore"), "The gap is filled: no point left.");
Assert.AreEqual(0, bed.Page.Touched);
}
[TestMethod]
public async Task TooManyRequestsOfTheSiteStopTheRun()
{
await using var site = await SyntheticSite.StartAsync();
await using var bed = await BedAsync(site);
var (id, _) = Facts(site, "marta.prova", a => 0);
var marta = await bed.AddAccountAsync(id, "marta.prova");
site.Control.Set(StopMode.TooManyRequests);
var outcome = await bed.RunAsync(RecipeKind.ProfileCheck, marta.Id);
Assert.AreEqual(RecipeStatus.StoppedBySignal, outcome.Status, outcome.Message);
Assert.AreEqual(SignalLevel.Throttle, bed.Breaker.Signals.Single().Level);
Assert.AreEqual(1, bed.Governor.Requests.Count, "Nothing asked after the signal.");
}
[TestMethod]
public async Task WithoutASavedSessionTheRunStopsAsADisconnection()
{
await using var site = await SyntheticSite.StartAsync();
var clock = new VirtualClock(DateTimeOffset.UtcNow);
var requester = new HttpSiteRequester(Catalog, new InMemorySiteSession(null), HttpSiteRequesterOptions.TestSite(new Uri(site.SiteUrl + "/")), clock);
await using var bed = await RequestBed.CreateAsync(catalog: Catalog, requester: requester, clock: clock);
var (id, _) = Facts(site, "marta.prova", a => 0);
var marta = await bed.AddAccountAsync(id, "marta.prova");
var outcome = await bed.RunAsync(RecipeKind.ProfileCheck, marta.Id);
Assert.AreEqual(RecipeStatus.StoppedBySignal, outcome.Status, outcome.Message);
Assert.AreEqual(SignalLevel.Disconnect, bed.Breaker.Signals.Single().Level);
Assert.AreEqual(0, bed.Page.Touched, "Never a way back to the pages (rule 7).");
}
private static async Task<RequestBed> BedAsync(TestSite site)
{
var clock = new VirtualClock(DateTimeOffset.UtcNow);
var requester = new HttpSiteRequester(Catalog, new InMemorySiteSession(HttpSiteRequesterTests.Values()), HttpSiteRequesterOptions.TestSite(new Uri(site.SiteUrl + "/")), clock);
return await RequestBed.CreateAsync(catalog: Catalog, requester: requester, clock: clock);
}
private static (string Id, int Count) Facts(TestSite site, string username, Func<SiteAccount, int> count)
{
lock (site.World.Gate)
{
var account = site.World.FindByUsername(username)!;
return (account.Id, count(account));
}
}
}