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>
89 lines
4.4 KiB
C#
89 lines
4.4 KiB
C#
using System.Runtime.CompilerServices;
|
|
using System.Text.Json;
|
|
using Febe.Core.Abstractions;
|
|
using Febe.Core.Domain;
|
|
using Febe.Core.Engine;
|
|
using Febe.Tests.Support;
|
|
using Febe.Tests.Web.Part2Support;
|
|
using Febe.Tests.Web.Support;
|
|
using Febe.Web.Connection;
|
|
using Febe.Web.Engine;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Febe.Tests.Web;
|
|
|
|
/// <summary>
|
|
/// The link to Instagram in the sidebar (<c>/api/engine</c>, «connection»): it comes from the session cookie, as the
|
|
/// engine's mode or the connection says, never from whether the account «Tu» is already known (H10: its name may come
|
|
/// much later, and meanwhile the sidebar says «Collegato» with «Nome non ancora noto»).
|
|
/// </summary>
|
|
[TestClass]
|
|
public sealed class EngineConnectionStateTests
|
|
{
|
|
[TestMethod]
|
|
public async Task TheSidebarSaysConnectedFromTheSessionCookieEvenBeforeTuIsKnown()
|
|
{
|
|
var connection = new RecordingConnection { Status = new ConnectionStatus(ConnectionState.Connected, null, null, false, null) };
|
|
await using var server = await Part2.StartAsync(services: s =>
|
|
{
|
|
s.AddSingleton<IEngineMonitor>(sp => new FixedModeMonitor(sp.GetRequiredService<IClock>()));
|
|
s.AddSingleton<IConnectionService>(connection);
|
|
});
|
|
var monitor = (FixedModeMonitor)server.App.Services.GetRequiredService<IEngineMonitor>();
|
|
async Task<JsonElement> LinkAsync(EngineMode mode)
|
|
{
|
|
monitor.Mode = mode;
|
|
return (await server.GetJsonAsync("/api/engine")).GetProperty("connection");
|
|
}
|
|
|
|
// Collecting (or about to), with the cookie and without «Tu»: connected, no name yet.
|
|
foreach (var mode in new[] { EngineMode.Starting, EngineMode.InSession, EngineMode.Resting, EngineMode.OutsideWindow, EngineMode.Paused, EngineMode.Throttled, EngineMode.UserDriving })
|
|
{
|
|
var link = await LinkAsync(mode);
|
|
Assert.AreEqual("connected", link.Str("state"), mode.ToString());
|
|
Assert.AreEqual(JsonValueKind.Null, link.GetProperty("username").ValueKind, mode.ToString());
|
|
}
|
|
|
|
Assert.AreEqual("notConnected", (await LinkAsync(EngineMode.NotConnected)).Str("state"));
|
|
Assert.AreEqual("disconnected", (await LinkAsync(EngineMode.Disconnected)).Str("state"));
|
|
Assert.AreEqual("verification", (await LinkAsync(EngineMode.StoppedForVerification)).Str("state"));
|
|
|
|
// The engine loop does not run: the connection itself is asked.
|
|
Assert.AreEqual("connected", (await LinkAsync(EngineMode.Off)).Str("state"));
|
|
connection.Status = new ConnectionStatus(ConnectionState.NotConnected, null, null, false, null);
|
|
Assert.AreEqual("notConnected", (await LinkAsync(EngineMode.Off)).Str("state"));
|
|
|
|
// Once «Tu» is known, its name comes along.
|
|
await server.Db.Accounts.AddAsync(Make.Account("tuo.profilo", mine: true));
|
|
var named = await LinkAsync(EngineMode.Resting);
|
|
Assert.AreEqual("connected", named.Str("state"));
|
|
Assert.AreEqual("tuo.profilo", named.Str("username"));
|
|
Assert.AreEqual(JsonValueKind.Null, (await LinkAsync(EngineMode.NotConnected)).GetProperty("username").ValueKind, "Not connected: no name.");
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task WithoutEngineAndBrowserTheSidebarSaysNotConnectedEvenIfTuIsKnown()
|
|
{
|
|
await using var server = await Part2.StartAsync();
|
|
await server.Db.Accounts.AddAsync(Make.Account("tuo.profilo", mine: true));
|
|
var engine = await server.GetJsonAsync("/api/engine");
|
|
Assert.AreEqual("Off", engine.GetProperty("snapshot").Str("mode"));
|
|
Assert.AreEqual("notConnected", engine.GetProperty("connection").Str("state"), "No engine has looked at the cookie and the browser is not there.");
|
|
}
|
|
|
|
/// <summary>An engine that reports the mode the test sets.</summary>
|
|
private sealed class FixedModeMonitor(IClock clock) : IEngineMonitor
|
|
{
|
|
public EngineMode Mode { get; set; } = EngineMode.Resting;
|
|
|
|
public Task<EngineSnapshot> GetSnapshotAsync(CancellationToken ct = default) =>
|
|
Task.FromResult(SnapshotParts.Build(clock, Mode, "Prova", [], "Prova", CautionProfile.Prudent));
|
|
|
|
public async IAsyncEnumerable<EngineNotification> SubscribeAsync([EnumeratorCancellation] CancellationToken ct = default)
|
|
{
|
|
await Task.Delay(Timeout.Infinite, ct);
|
|
yield break;
|
|
}
|
|
}
|
|
}
|