Raccolta (M0/M2): sito di prova completo, lettori per forma, ricette su browser vero, coda degli scaricamenti, sonda con ripulitura e verifica; documenti delle ipotesi e delle prove dal vivo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
74 files changed
+12689
-13
No files matched your search
@@ -1,4 +1,108 @@
|
||||
// Local test site (spec §14.2). Filled in by milestones M0 and M2.
|
||||
var app = WebApplication.CreateBuilder(args).Build();
|
||||
app.MapGet("/", () => "Sito di prova di Febe");
|
||||
app.Run();
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Febe.SitoDiProva;
|
||||
|
||||
// Local test site (spec §14.2).
|
||||
// febe-sito-di-prova [--porta 8481] [--porta-cdn 8482] [--indirizzo-cdn 127.0.0.2] [--seme 13]
|
||||
// febe-sito-di-prova campioni --cartella <cartella fuori dal repository> [--seme 13]
|
||||
if (args.Length > 0 && args[0] == "campioni")
|
||||
{
|
||||
return await DumpSamplesAsync(args[1..]);
|
||||
}
|
||||
|
||||
var options = new TestSiteOptions
|
||||
{
|
||||
Port = IntOption(args, "--porta", 8481),
|
||||
CdnPort = IntOption(args, "--porta-cdn", 8482),
|
||||
CdnAddress = Option(args, "--indirizzo-cdn") ?? "127.0.0.2",
|
||||
Seed = IntOption(args, "--seme", 13),
|
||||
ConsoleLog = true,
|
||||
};
|
||||
await using var site = await TestSite.StartAsync(options);
|
||||
Console.WriteLine($"Sito di prova: {site.SiteUrl}/ · CDN: {site.CdnUrl}/ · seme {options.Seed.ToString(CultureInfo.InvariantCulture)}");
|
||||
Console.WriteLine($"Casi di arresto: {site.SiteUrl}/_controllo/modo?valore=troppe-richieste|verifica|sessione-scaduta|vuoto|normale");
|
||||
Console.WriteLine("Ctrl+C per fermare.");
|
||||
var stop = new TaskCompletionSource();
|
||||
Console.CancelKeyPress += (_, e) =>
|
||||
{
|
||||
e.Cancel = true;
|
||||
stop.TrySetResult();
|
||||
};
|
||||
await stop.Task;
|
||||
return 0;
|
||||
|
||||
// Writes the JSON responses of the main pages in the raw format of the probe (descriptor + body), to be cleaned with
|
||||
// «febe-sonda ripulisci». The data is synthetic, but the samples follow the same path as real ones (spec §14.5).
|
||||
static async Task<int> DumpSamplesAsync(string[] args)
|
||||
{
|
||||
var folder = Option(args, "--cartella");
|
||||
if (string.IsNullOrWhiteSpace(folder))
|
||||
{
|
||||
Console.Error.WriteLine("Indicare --cartella <cartella fuori dal repository>.");
|
||||
return 2;
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(folder);
|
||||
await using var site = await TestSite.StartAsync(new TestSiteOptions { Seed = IntOption(args, "--seme", 13) });
|
||||
string marta, luca, code;
|
||||
lock (site.World.Gate)
|
||||
{
|
||||
marta = site.World.FindByUsername("marta.prova")!.Username;
|
||||
luca = site.World.FindByUsername("luca.prova")!.Username;
|
||||
code = site.World.FindByUsername("marta.prova")!.Posts.First(p => p.Files.Count > 1).Code;
|
||||
}
|
||||
|
||||
var samples = new (string Name, string Path)[]
|
||||
{
|
||||
("inizio", "/dati/inizio"),
|
||||
("profilo-pubblico", $"/dati/profilo/{marta}?scheda=post"),
|
||||
("profilo-pagina-successiva", $"/dati/profilo/{luca}/altri?scheda=post&dopo=c12"),
|
||||
("profilo-privato-non-seguito", "/dati/profilo/riservato.prova?scheda=post"),
|
||||
("post-serie", $"/dati/post/{code}"),
|
||||
("storie", $"/dati/storie/{marta}"),
|
||||
("raccolta", $"/dati/evidenza/{site.World.FindByUsername("marta.prova")!.Highlights[0].Id}"),
|
||||
("seguiti", "/dati/seguiti"),
|
||||
("taggati", $"/dati/profilo/{marta}?scheda=taggati"),
|
||||
};
|
||||
|
||||
var number = 0;
|
||||
foreach (var (name, path) in samples)
|
||||
{
|
||||
var body = JsonNode.Parse(await site.GetDataAsync(path));
|
||||
await WriteSampleAsync(folder, ++number, name, site.Url(path), 200, body);
|
||||
}
|
||||
|
||||
site.Control.Set(StopMode.EmptyPages);
|
||||
await WriteSampleAsync(folder, ++number, "pagina-vuota", site.Url($"/dati/profilo/{luca}/altri?scheda=post&dopo=c48"), 200, JsonNode.Parse(await site.GetDataAsync($"/dati/profilo/{luca}/altri?scheda=post&dopo=c48")));
|
||||
Console.WriteLine($"Scritti {number.ToString(CultureInfo.InvariantCulture)} campioni grezzi in {folder}.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static async Task WriteSampleAsync(string folder, int number, string name, string url, int status, JsonNode? body)
|
||||
{
|
||||
var sample = new JsonObject
|
||||
{
|
||||
["descrittore"] = new JsonObject
|
||||
{
|
||||
["indirizzo"] = url.Split('?')[0],
|
||||
["host"] = "sito",
|
||||
["stato"] = status,
|
||||
["tipo"] = "application/json",
|
||||
["risorsa"] = "Fetch",
|
||||
["nome"] = name,
|
||||
},
|
||||
["corpo"] = body,
|
||||
};
|
||||
var file = Path.Combine(folder, $"{number.ToString("000000", CultureInfo.InvariantCulture)}-{name}.json");
|
||||
await File.WriteAllTextAsync(file, sample.ToJsonString(new JsonSerializerOptions { WriteIndented = true }));
|
||||
}
|
||||
|
||||
static string? Option(string[] args, string name)
|
||||
{
|
||||
var index = Array.IndexOf(args, name);
|
||||
return index >= 0 && index + 1 < args.Length ? args[index + 1] : null;
|
||||
}
|
||||
|
||||
static int IntOption(string[] args, string name, int fallback) =>
|
||||
int.TryParse(Option(args, name), NumberStyles.Integer, CultureInfo.InvariantCulture, out var value) ? value : fallback;
|
||||
Reference in new issue
Block a user