I criteri della specifica §9.11 (frame, blocchi del thread, riga aggiornata entro 100 ms, riconnessione sotto i 2 s, nessun ridisegno della griglia con maniglie e finestra) non li misurava nessuno. Ora il simulatore prende --simulatore-aste N (solo con --simulatore): N aste in elenco, tre su quattro in Attiva, ciclo di 5 s e due autopuntate senza fine per asta, così almeno dieci aste stanno sempre sotto i 4 s; senza l'argomento il simulatore resta quello di sempre. tools/Mimante.Schermate ha la modalità --misura <secondi>, tutta via CDP: uno script nella pagina cronometra frame, compiti dell'interfaccia (timer, frame, eventi del puntatore, ResizeObserver) e messaggi del bot, chiude il canale per la riconnessione, trascina la maniglia e ridimensiona la finestra controllando che i <tr data-id> restino gli stessi nodi, che la griglia non scorra né si virtualizzi e che anche lì nessun compito blocchi il thread; scrive misura.json e misura.txt ed esce con 1 se un criterio vincolante fallisce (anche un solo compito lungo del browser) o la misura non vale (basta un campione con meno di dieci aste in finestra critica; la CPU si riporta soltanto). La password può venire da UI_PASSWORD. prove-a-mano.yml ha il lavoro «prestazioni», dopo carico e schermate per non dividere la CPU, e il commento sul mondo del simulatore è corretto. Le prove dei conti della misura stanno in tests/Mimante.Tests con un riferimento a tools/Mimante.Schermate che esiste solo se la cartella c'è: il contesto dell'immagine non ha tools/ e lì quelle prove restano fuori, così la costruzione dell'immagine non si rompe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
5.3 KiB
C#
128 lines
5.3 KiB
C#
using System.Globalization;
|
|
using Mimante.Data;
|
|
|
|
namespace Mimante.Config;
|
|
|
|
/// <summary>
|
|
/// La configurazione del container: solo le variabili della specifica (§10.1). Tutto il
|
|
/// resto vive nel database (impostazioni) o in <c>/config</c>.
|
|
///
|
|
/// <para>Obbligatorie <c>DB_HOST</c>, <c>DB_PASSWORD</c>, <c>UI_PASSWORD</c>; facoltative
|
|
/// <c>DB_USER</c> (admin), <c>DB_NAME</c> (autobidder), <c>DB_PORT</c> (5432), <c>PORT</c>
|
|
/// (8080), <c>TZ</c>, <c>PUID</c>/<c>PGID</c> (le usa l'entrypoint). Le password non escono
|
|
/// mai da qui: <see cref="Describe"/> non le contiene.</para>
|
|
/// </summary>
|
|
public sealed class EnvConfig
|
|
{
|
|
public string? DbHostRaw { get; init; }
|
|
public string DbHost { get; init; } = "";
|
|
public int DbPort { get; init; } = 5432;
|
|
public string DbUser { get; init; } = "admin";
|
|
public string DbName { get; init; } = "autobidder";
|
|
public string? DbPassword { get; init; }
|
|
public string? UiPassword { get; init; }
|
|
public int HttpPort { get; init; } = 8080;
|
|
public string ConfigDir { get; init; } = "/config";
|
|
public string TimeZone { get; init; } = "Europe/Rome";
|
|
|
|
/// <summary>
|
|
/// Modalità debug con il simulatore (<c>--simulatore</c>): senza sessione Bidoo il bot segue le
|
|
/// aste finte del simulatore interno. Solo per test e sviluppo: il container non lo passa mai,
|
|
/// e in produzione senza sessione il bot segue il sito vero senza puntare.
|
|
/// </summary>
|
|
public bool SimulatorMode { get; init; }
|
|
|
|
/// <summary>
|
|
/// Quante aste tiene in elenco il simulatore (<c>--simulatore-aste N</c>, da 1 a
|
|
/// <see cref="MaxSimulatorAuctions"/>): per la misura delle prestazioni dell'interfaccia
|
|
/// (specifica §9.11). Vale solo insieme a <c>--simulatore</c>; null = il simulatore di sempre.
|
|
/// </summary>
|
|
public int? SimulatorAuctions { get; init; }
|
|
|
|
/// <summary>Il limite di <c>--simulatore-aste</c>: oltre, il simulatore misurerebbe sé stesso.</summary>
|
|
public const int MaxSimulatorAuctions = 500;
|
|
|
|
public bool HasDbHost => !string.IsNullOrWhiteSpace(DbHost);
|
|
public bool HasDbPassword => !string.IsNullOrEmpty(DbPassword);
|
|
public bool HasUiPassword => !string.IsNullOrEmpty(UiPassword);
|
|
|
|
public DbConfig ToDbConfig() => new(DbHost, DbPort, DbUser, DbPassword ?? "", DbName);
|
|
|
|
/// <summary>
|
|
/// Legge l'ambiente e gli argomenti, che servono solo allo sviluppo: <c>--config cartella</c>,
|
|
/// <c>--simulatore</c> e, con questo, <c>--simulatore-aste N</c>. Un numero non valido si ignora.
|
|
/// </summary>
|
|
public static EnvConfig Read(Func<string, string?> env, string[] args)
|
|
{
|
|
var rawHost = env("DB_HOST")?.Trim();
|
|
var (host, portInHost) = SplitHost(rawHost);
|
|
|
|
var port = portInHost
|
|
?? (int.TryParse(env("DB_PORT"), NumberStyles.Integer, CultureInfo.InvariantCulture, out var p) && p is > 0 and < 65536 ? p : 5432);
|
|
|
|
var httpPort = int.TryParse(env("PORT"), NumberStyles.Integer, CultureInfo.InvariantCulture, out var hp) && hp is > 0 and < 65536 ? hp : 8080;
|
|
|
|
var configDir = "/config";
|
|
for (var i = 0; i < args.Length - 1; i++)
|
|
{
|
|
if (args[i] == "--config") configDir = Path.GetFullPath(args[i + 1]);
|
|
}
|
|
var simulator = args.Contains("--simulatore");
|
|
int? simulatorAuctions = null;
|
|
for (var i = 0; simulator && i < args.Length - 1; i++)
|
|
{
|
|
if (args[i] == "--simulatore-aste" &&
|
|
int.TryParse(args[i + 1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var n) && n is > 0 and <= MaxSimulatorAuctions)
|
|
simulatorAuctions = n;
|
|
}
|
|
|
|
return new EnvConfig
|
|
{
|
|
DbHostRaw = rawHost,
|
|
DbHost = host,
|
|
DbPort = port,
|
|
DbUser = NonEmpty(env("DB_USER")) ?? "admin",
|
|
DbName = NonEmpty(env("DB_NAME")) ?? "autobidder",
|
|
DbPassword = env("DB_PASSWORD"),
|
|
UiPassword = env("UI_PASSWORD"),
|
|
HttpPort = httpPort,
|
|
ConfigDir = configDir,
|
|
TimeZone = NonEmpty(env("TZ")) ?? "Europe/Rome",
|
|
SimulatorMode = simulator,
|
|
SimulatorAuctions = simulatorAuctions
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// <c>192.168.30.23</c> oppure <c>192.168.30.23:5432</c>. Un indirizzo IPv6 va scritto fra
|
|
/// quadre (<c>[::1]:5432</c>).
|
|
/// </summary>
|
|
public static (string Host, int? Port) SplitHost(string? raw)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(raw)) return ("", null);
|
|
var text = raw.Trim();
|
|
|
|
if (text.StartsWith('['))
|
|
{
|
|
var close = text.IndexOf(']');
|
|
if (close > 0)
|
|
{
|
|
var h = text[1..close];
|
|
var rest = text[(close + 1)..];
|
|
return rest.StartsWith(':') && int.TryParse(rest[1..], NumberStyles.Integer, CultureInfo.InvariantCulture, out var pp) ? (h, pp) : (h, null);
|
|
}
|
|
}
|
|
|
|
var colon = text.LastIndexOf(':');
|
|
if (colon > 0 && text.IndexOf(':') == colon &&
|
|
int.TryParse(text[(colon + 1)..], NumberStyles.Integer, CultureInfo.InvariantCulture, out var port) && port is > 0 and < 65536)
|
|
{
|
|
return (text[..colon], port);
|
|
}
|
|
|
|
return (text, null);
|
|
}
|
|
|
|
private static string? NonEmpty(string? s) => string.IsNullOrWhiteSpace(s) ? null : s.Trim();
|
|
}
|