Contratti fra motore e ricette (RecipeRequest, IRecipeRunner, IDataBudget)
verifica / prove (push) Successful in 2m7s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-13 14:51:19 +00:00
1 parent c803bd98b5
commit 79d8368420
1 file changed
+125
+125
View File
@@ -0,0 +1,125 @@
using Febe.Core.Abstractions;
namespace Febe.Core.Engine;
/// <summary>The fixed set of recipes (spec §6.3).</summary>
public enum RecipeKind
{
/// <summary>Giro dei seguiti: home, stories bar, recent posts of followed profiles.</summary>
FollowingSweep,
/// <summary>Storie di un account.</summary>
AccountStories,
/// <summary>Controllo del profilo.</summary>
ProfileCheck,
/// <summary>Storico: one or more history pages, resuming from the stored point.</summary>
Backfill,
/// <summary>Raccolta in evidenza.</summary>
Highlight,
/// <summary>Taggati.</summary>
Tagged,
/// <summary>Reel.</summary>
Reels,
/// <summary>Post singolo: complete data or refresh an expired address.</summary>
SinglePost,
/// <summary>Elenco dei seguiti: only on request.</summary>
FollowingList,
}
/// <summary>What the scheduler asks a recipe to do.</summary>
/// <param name="Kind">Recipe.</param>
/// <param name="AccountId">Febe account id (database id, not the Instagram id); null for FollowingSweep and FollowingList.</param>
/// <param name="EntryId">For SinglePost: the entry whose data or addresses must be refreshed.</param>
/// <param name="HighlightId">For Highlight: the Instagram id of the collection.</param>
/// <param name="MaxPages">For Backfill, Tagged, Reels and FollowingList: how many pages at most in this run.</param>
/// <param name="Manual">True for «Controlla ora» (spec §7.8).</param>
public sealed record RecipeRequest(
RecipeKind Kind,
long? AccountId = null,
long? EntryId = null,
string? HighlightId = null,
int? MaxPages = null,
bool Manual = false);
/// <summary>How a recipe run ended.</summary>
public enum RecipeStatus
{
/// <summary>Finished its purpose (reached known content, the end of the list, or MaxPages).</summary>
Completed,
/// <summary>The Governor refused a counted action: stopped in order.</summary>
Denied,
/// <summary>A stop signal (spec §7.6) was seen: stopped where it was, page left as is.</summary>
StoppedBySignal,
/// <summary>A target of the target map was not found: stopped and reported, no random clicks.</summary>
TargetNotFound,
/// <summary>Responses had an unrecognized shape (spec §6.4).</summary>
UnrecognizedFormat,
/// <summary>The account is not reachable (private not followed, missing, blocked).</summary>
AccountUnreachable,
/// <summary>Cancelled (engine paused, Alberto took the browser, shutdown).</summary>
Cancelled,
/// <summary>Unexpected error; message says what happened.</summary>
Failed,
}
/// <summary>Result of a recipe run, used by the scheduler to plan what comes next.</summary>
public sealed record RecipeOutcome(
RecipeStatus Status,
int CountedActions,
int NewEntries,
string? Message = null)
{
/// <summary>Followed accounts the stories bar flagged as having active stories (FollowingSweep).</summary>
public IReadOnlyList<long> AccountsWithStories { get; init; } = [];
/// <summary>Accounts where the sweep saw new posts (FollowingSweep).</summary>
public IReadOnlyList<long> AccountsWithNewPosts { get; init; } = [];
/// <summary>For Backfill: true when the beginning of the profile has been reached.</summary>
public bool BackfillFinished { get; init; }
}
/// <summary>Information about the session in progress, handed to every recipe.</summary>
public interface ISessionContext
{
long SessionId { get; }
/// <summary>Speed factor drawn once per session (log-normal, median 1, σ 0.2, [0.7, 1.5]); multiplies every wait.</summary>
double Mood { get; }
/// <summary>Planned end of the session; recipes should finish what they are doing and stop after it.</summary>
DateTimeOffset PlannedEnd { get; }
}
/// <summary>Runs one recipe. The real implementation drives the browser; the simulation uses a fake world.</summary>
public interface IRecipeRunner
{
Task<RecipeOutcome> RunAsync(RecipeRequest request, ISessionContext session, CancellationToken ct);
/// <summary>Puts the browser on the empty rest page (end of session, pauses, night).</summary>
Task RestAsync(CancellationToken ct);
}
/// <summary>Daily byte budget for CDN downloads (category «dati scaricati», spec §7.4).</summary>
public interface IDataBudget
{
/// <summary>Bytes still available today (after ramp-up and halving), never negative.</summary>
Task<long> RemainingTodayAsync(CancellationToken ct);
/// <summary>Records bytes actually downloaded.</summary>
Task RecordAsync(long bytes, long? accountId, CancellationToken ct);
}