HttpSiteRequester è l'unica classe che parla col sito: va solo a https://www.instagram.com/ o a un sito di prova di loopback, non segue i rinvii, una richiesta per volta col permesso del Governatore, solo le intestazioni del catalogo con l'user agent della sessione, e registra solo operazione, forma del percorso e stato. Cookie rinnovati e claim finiscono nella sessione (ISiteSession, per ora in memoria; la copia cifrata è S4). SiteAnswerSignals traduce le risposte nei segnali di §7.6: 429 rallenta; rinvii, 401/403, HTML o campi mancanti valgono come Verifica (H16). Il sito di prova risponde alle richieste dirette come dice richieste.prova.json e simula i casi d'arresto; una visita senza sessione viva apre una sessione nuova anche per il client. Nulla è ancora collegato al motore (S3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
2.3 KiB
C#
48 lines
2.3 KiB
C#
using System.Globalization;
|
|
using Febe.SitoDiProva;
|
|
|
|
namespace Febe.Tests.Support;
|
|
|
|
/// <summary>
|
|
/// The one way the tests start the local test site (spec §14.2), so that a run can choose the seed of its synthetic
|
|
/// world: <see cref="Variable"/> when it is set, <see cref="DefaultSeed"/> otherwise (nothing changes when it is unset).
|
|
/// The CI runs the whole suite with the default seed, then the tests of <see cref="Category"/> again with a seed of
|
|
/// its own that it prints in the log: a failure is reproduced by setting the same variable.
|
|
/// </summary>
|
|
internal static class SyntheticSite
|
|
{
|
|
/// <summary>Environment variable with the seed of the synthetic world.</summary>
|
|
public const string Variable = "FEBE_SEME_PROVA";
|
|
|
|
/// <summary>The seed when the variable is not set: the one of the command-line site and of the cleaned samples.</summary>
|
|
public const int DefaultSeed = 13;
|
|
|
|
/// <summary>Test category of the tests whose world comes from the seed (the CI runs them with a second seed).</summary>
|
|
public const string Category = "SitoDiProva";
|
|
|
|
/// <summary>The seed of this run.</summary>
|
|
public static int Seed => ParseSeed(Environment.GetEnvironmentVariable(Variable));
|
|
|
|
/// <summary>Starts the test site with the seed of this run, and says which one in the output of the test.</summary>
|
|
/// <param name="time">Clock of the site (dates, signed addresses); the system clock by default.</param>
|
|
public static Task<TestSite> StartAsync(TimeProvider? time = null)
|
|
{
|
|
var seed = Seed;
|
|
Console.WriteLine($"Sito di prova con il seme {seed.ToString(CultureInfo.InvariantCulture)} (si cambia con {Variable}).");
|
|
return TestSite.StartAsync(new TestSiteOptions { Seed = seed, Time = time ?? TimeProvider.System });
|
|
}
|
|
|
|
/// <summary>The seed written in <paramref name="value"/>: the default when it is empty, an error when it is not a number.</summary>
|
|
public static int ParseSeed(string? value)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
return DefaultSeed;
|
|
}
|
|
|
|
return int.TryParse(value.Trim(), NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var seed)
|
|
? seed
|
|
: throw new InvalidOperationException($"{Variable} deve essere un numero intero (fra -2147483648 e 2147483647), non «{value}».");
|
|
}
|
|
}
|