Febe non estraeva nulla da Instagram per due motivi. Instagram manda i dati di storie e raccolte (GraphQL) come text/javascript, e la cattura leggeva solo le risposte dichiarate JSON: le scartava tutte. E i file di Instagram (lettori, bersagli) erano scheletri, quindi le ricette si rifiutavano di girare. Alberto ha mandato un HAR del suo browser e una guida. La guida descrive richieste costruite a mano, vietate dalle regole 2-4, e un formato che nel HAR non compare: non si usa. Dal HAR si è letta solo la forma; le risposte utili sono diventate campioni grezzi fuori dal repository, ripuliti e verificati con febe-sonda (tests/Febe.Tests/campioni/instagram). Che cosa cambia: - la cattura legge le risposte text/javascript chieste dalla pagina (mai gli script) e ogni blocco JSON incorporato nel documento della pagina, e avvisa quando un corpo atteso non arriverà; - le risposte che non parlano di contenuti (promozioni, «storia vista») si ignorano invece di valere come formato non riconosciuto; - lettori.instagram.json è confermato, con sole chiavi presenti nei campioni; identificativi delle raccolte nella forma dell'indirizzo; - bersagli.instagram.json ha le pagine viste nel traffico vero; i bersagli restano vuoti (H11): storie, raccolte, Taggati e Reel aspettano lo script tools/bersagli/raccogli-bersagli.js; - le ricette del profilo reggono dati in risposte diverse e prendono la paginazione solo dalla risposta che porta i loro post; l'elenco dei seguiti scarta i profili suggeriti; «Tu» si riconosce anche dal solo identificativo dell'account collegato; - il visualizzatore delle raccolte conta i contenuti (l'indirizzo non cambia), chiede il permesso prima di ogni contenuto e si chiude sempre; - una ricetta che la configurazione non lascia girare è «Da configurare»: non è un guasto, non si sospende, non si pianifica; le sospensioni dovute ai file vecchi si azzerano una volta al cambio dei file; - la barra laterale dice «Collegato» dal cookie di sessione; i «Post singolo» per gli indirizzi scaduti non vengono più annullati; - febe-sonda da-har; la ripulitura tiene latest_reel_media e mette un riempitivo neutro sotto le chiavi simili a segreti (gitleaks). Prove su Windows: 783 superate, 76 saltate (Chromium e Xvfb, nella CI). Nulla è stato provato contro Instagram. Dettagli e decisioni in docs/stato.md e docs/decisioni.md (righe del 25 ottobre). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
152 lines
9.0 KiB
C#
152 lines
9.0 KiB
C#
using Febe.Core.Collection;
|
|
using Febe.Core.Collection.Readers;
|
|
using Febe.Core.Domain;
|
|
using Febe.Core.Engine;
|
|
using Febe.Core.Storage;
|
|
using Febe.Tests.Engine.Support;
|
|
using Febe.Tests.Support;
|
|
|
|
namespace Febe.Tests.Engine;
|
|
|
|
/// <summary>
|
|
/// The collection configuration in use (reader vocabulary and target map of the site, as loaded): what the log says of
|
|
/// it, the copies in the Data folder that hide newer embedded files, and the suspensions counted against other files,
|
|
/// cleared once when it changes.
|
|
/// </summary>
|
|
[TestClass]
|
|
public sealed class CollectionConfigurationTests
|
|
{
|
|
private static readonly DateTimeOffset Morning = EngineTestBed.Local(2026, 10, 14, 6, 0);
|
|
|
|
[TestMethod]
|
|
public async Task AChangedCollectionConfigurationLiftsTheSuspensionsOfTheOldFilesOnce()
|
|
{
|
|
await using var bed = await EngineTestBed.CreateAsync(Morning);
|
|
await bed.AddAccountAsync("strano.demo", followed: false, Frequency.High);
|
|
|
|
// What the first Instagram files left in Alberto's database: suspended recipes and failures counted.
|
|
var since = Morning.AddDays(-3).ToUnixTimeMilliseconds();
|
|
await bed.Db.Settings.SetAsync(EngineSettingKeys.SuspendedRecipes, $"AccountStories={since};ProfileCheck={since}");
|
|
await bed.Db.Settings.SetAsync(EngineSettingKeys.RecipeFailures, "AccountStories=3;Backfill=2;ProfileCheck=3");
|
|
|
|
var runner = new ScriptedRunner(bed.Governor, bed.Clock);
|
|
var changed = false;
|
|
var host = await bed.StartAsync(runner, async h => changed = await h.ApplyCollectionConfigurationAsync("impronta-1"));
|
|
Assert.IsTrue(changed, "The first start that knows the configuration counts as a change.");
|
|
Assert.IsEmpty(host.SuspendedRecipes);
|
|
Assert.IsNull(await bed.Db.Settings.GetAsync(EngineSettingKeys.SuspendedRecipes));
|
|
Assert.IsNull(await bed.Db.Settings.GetAsync(EngineSettingKeys.RecipeFailures));
|
|
Assert.AreEqual("impronta-1", await bed.Db.Settings.GetAsync(EngineSettingKeys.CollectionConfiguration));
|
|
|
|
var line = (await bed.Db.Events.ListAsync(new EventQuery())).Single(e => e.Code == EngineEventCodes.CollectionConfigurationChanged);
|
|
Assert.AreEqual("La configurazione della raccolta è cambiata: le ricette sospese ripartono («Le storie», «Il controllo del profilo»).", line.Message);
|
|
Assert.AreEqual(EventSeverity.Info, line.Severity);
|
|
|
|
await bed.RunUntilAsync(Morning.AddDays(1));
|
|
Assert.IsTrue(runner.Runs.Any(r => r.Request.Kind == RecipeKind.ProfileCheck && r.Status == RecipeStatus.Completed), "The recipe runs again.");
|
|
Assert.IsFalse(await host.ApplyCollectionConfigurationAsync("impronta-1"), "Same files: nothing to do.");
|
|
|
|
// A restart with the same files changes nothing; new files with nothing to clear say nothing.
|
|
await bed.ReopenAsync(8);
|
|
var again = true;
|
|
var reopened = await bed.StartAsync(new ScriptedRunner(bed.Governor, bed.Clock), async h => again = await h.ApplyCollectionConfigurationAsync("impronta-1"));
|
|
Assert.IsFalse(again);
|
|
Assert.IsTrue(await reopened.ApplyCollectionConfigurationAsync("impronta-2"));
|
|
Assert.AreEqual("impronta-2", await bed.Db.Settings.GetAsync(EngineSettingKeys.CollectionConfiguration));
|
|
Assert.AreEqual(1, (await bed.Db.Events.ListAsync(new EventQuery())).Count(e => e.Code == EngineEventCodes.CollectionConfigurationChanged));
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task FailuresAloneAreClearedWithTheirOwnLine()
|
|
{
|
|
await using var bed = await EngineTestBed.CreateAsync(Morning);
|
|
await bed.Db.Settings.SetAsync(EngineSettingKeys.RecipeFailures, "ProfileCheck=2");
|
|
var host = new EngineHost(bed.Services, new ScriptedRunner(bed.Governor, bed.Clock));
|
|
await using (host)
|
|
{
|
|
Assert.IsTrue(await host.ApplyCollectionConfigurationAsync("impronta"));
|
|
}
|
|
|
|
Assert.IsNull(await bed.Db.Settings.GetAsync(EngineSettingKeys.RecipeFailures));
|
|
var line = (await bed.Db.Events.ListAsync(new EventQuery())).Single(e => e.Code == EngineEventCodes.CollectionConfigurationChanged);
|
|
Assert.AreEqual("La configurazione della raccolta è cambiata: i problemi delle ricette contati finora non valgono più.", line.Message);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheEmbeddedFilesAreDescribedWithoutTheirContentAndFingerprinted()
|
|
{
|
|
var configuration = CollectionConfiguration.Describe("prova", ReaderVocabulary.LoadTestSite(), SiteMap.LoadTestSite());
|
|
Assert.IsFalse(configuration.VocabularyFile.IsOverride);
|
|
Assert.IsFalse(configuration.MapFile.IsOverride);
|
|
Assert.IsEmpty(configuration.Blocked);
|
|
Assert.IsEmpty(configuration.Warnings);
|
|
CollectionAssert.AreEqual(
|
|
new[]
|
|
{
|
|
"Vocabolario dei lettori per «prova»: il file incorporato in Febe (lettori.prova.json), confermato.",
|
|
"Mappa dei bersagli per «prova»: il file incorporato in Febe (bersagli.prova.json), tutte le voci compilate.",
|
|
"Con questa configurazione tutte le ricette possono girare.",
|
|
},
|
|
configuration.Lines.ToArray());
|
|
Assert.MatchesRegex("^[0-9a-f]{64}$", configuration.Fingerprint);
|
|
Assert.AreEqual(configuration.Fingerprint, CollectionConfiguration.Describe("prova", ReaderVocabulary.LoadTestSite(), SiteMap.LoadTestSite()).Fingerprint);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ACopyInTheDataFolderIsNamedAndOneThatHidesABetterEmbeddedFileIsAWarning()
|
|
{
|
|
using var folder = new TempFolder("configurazione");
|
|
var vocabularyText = SiteMap.ReadEmbeddedText("lettori.prova.json");
|
|
var mapText = SiteMap.ReadEmbeddedText("bersagli.prova.json");
|
|
var embedded = CollectionConfiguration.Describe("prova", ReaderVocabulary.LoadTestSite(), SiteMap.LoadTestSite());
|
|
|
|
// The same map with other line endings is the same configuration.
|
|
var mapPath = folder.Combine("bersagli.prova.json");
|
|
File.WriteAllText(mapPath, mapText.Contains("\r\n", StringComparison.Ordinal) ? mapText.Replace("\r\n", "\n", StringComparison.Ordinal) : mapText.Replace("\n", "\r\n", StringComparison.Ordinal));
|
|
var sameMap = Loaded(folder, "prova");
|
|
Assert.IsTrue(sameMap.MapFile.IsOverride);
|
|
Assert.AreEqual(mapPath, sameMap.MapFile.OverridePath);
|
|
Assert.AreEqual(embedded.Fingerprint, sameMap.Fingerprint);
|
|
Assert.IsEmpty(sameMap.Warnings);
|
|
StringAssert.Contains(sameMap.Lines[1], $"la copia nella cartella dei dati ({mapPath})");
|
|
|
|
// A stale vocabulary, still a hypothesis, hides the confirmed embedded one: every recipe would be refused.
|
|
var vocabularyPath = folder.Combine("lettori.prova.json");
|
|
File.WriteAllText(vocabularyPath, vocabularyText.Replace("\"confermato\"", "\"ipotesi\"", StringComparison.Ordinal));
|
|
var stale = Loaded(folder, "prova");
|
|
Assert.AreNotEqual(embedded.Fingerprint, stale.Fingerprint);
|
|
CollectionAssert.AreEqual(Enum.GetValues<RecipeKind>(), stale.Blocked.ToArray());
|
|
Assert.HasCount(1, stale.Warnings);
|
|
StringAssert.Contains(stale.Warnings[0], vocabularyPath);
|
|
StringAssert.Contains(stale.Warnings[0], "è ancora un'ipotesi, mentre quello incorporato in Febe è confermato");
|
|
StringAssert.EndsWith(stale.Lines[0], ", ipotesi.");
|
|
StringAssert.StartsWith(stale.Lines[2], "Con questa configurazione non possono girare 9 ricette su 9: Giro dei seguiti, ");
|
|
|
|
// A map that lacks what the embedded one has leaves recipes still that could run.
|
|
File.Delete(vocabularyPath);
|
|
File.WriteAllText(mapPath, """{ "site": "prova", "pages": { "home": "/" } }""");
|
|
var poor = Loaded(folder, "prova");
|
|
CollectionAssert.Contains(poor.Blocked.ToArray(), RecipeKind.ProfileCheck);
|
|
CollectionAssert.DoesNotContain(poor.Blocked.ToArray(), RecipeKind.FollowingSweep);
|
|
Assert.HasCount(1, poor.Warnings);
|
|
StringAssert.Contains(poor.Warnings[0], $"La mappa dei bersagli in {mapPath} lascia ferme ricette che con quella incorporata in Febe potrebbero girare (");
|
|
StringAssert.Contains(poor.Warnings[0], "Controllo del profilo");
|
|
|
|
// Never what is in the files.
|
|
var note = ReaderVocabulary.LoadTestSite().Note!;
|
|
foreach (var text in stale.Lines.Concat(stale.Warnings).Concat(poor.Lines).Concat(poor.Warnings))
|
|
{
|
|
Assert.IsFalse(text.Contains(note, StringComparison.Ordinal), text);
|
|
Assert.IsFalse(text.Contains("/profilo/", StringComparison.Ordinal), text);
|
|
}
|
|
}
|
|
|
|
/// <summary>The files loaded as the collection pipeline loads them: the Data-folder copy when it exists.</summary>
|
|
private static CollectionConfiguration Loaded(TempFolder folder, string site)
|
|
{
|
|
var vocabulary = ReaderVocabulary.LoadOrEmbedded(folder.Combine($"lettori.{site}.json"), $"lettori.{site}.json");
|
|
var map = SiteMap.LoadOrEmbedded(folder.Combine($"bersagli.{site}.json"), $"bersagli.{site}.json");
|
|
return CollectionConfiguration.Describe(site, vocabulary, map);
|
|
}
|
|
}
|