Il prodotto prende il nome del repository, come chiesto per allineare la struttura agli altri progetti: soluzione Mimante.slnx, progetti src/Mimante, tests/Mimante.Tests e tools/Mimante.Schermate, spazi dei nomi Mimante.*, immagine alby96/mimante, modello docker/unraid/mimante.xml, compose in docker/, documenti in minuscolo (stato.md, architettura.md, come-funziona.md, schermate/), versioni dei pacchetti in Directory.Packages.props. Versione 2.0.0. Non cambiano database, tabelle, variabili d'ambiente, /config, chiave della sessione e riferimenti del sito: bidoo.default.json è identico e i nomi logici delle risorse incorporate restano quelli che le migrazioni cercano. divSaldoBidBottom è l'id di Bidoo. Compatibilità: il cookie dell'interfaccia diventa mimante_sessione (un accesso in più per browser dopo l'aggiornamento); le preferenze del browser passano da bidbot.* a mimante.* con una copia una tantum. Corretto anche il tema della pagina d'accesso, che leggeva il valore salvato senza togliere le virgolette del JSON. Tolto il codice non compilato: il riferimento del riscatto (lo sostituisce il riscatto nuovo) e il formato SQLite della versione desktop (ora la issue #31); sono leggibili al tag v1.2.0. Nuovi docs/processo.md, docs/decisioni.md, docs/docker.md (con i passi per sostituire il container su Unraid) e ADR 0014. Il Dockerfile copia Directory.Packages.props e .dockerignore esclude dati/. Build con gli avvisi come errori; 288 test verdi, i 14 sul database saltati perché Docker Desktop su questo PC non parte: girano nella CI con il suo PostgreSQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
4.0 KiB
C#
94 lines
4.0 KiB
C#
using System.Reflection;
|
|
using System.Text.Json;
|
|
using Mimante.Settings;
|
|
using Xunit;
|
|
|
|
namespace Mimante.Tests;
|
|
|
|
/// <summary>Le impostazioni che valgono solo dal prossimo avvio (<see cref="SettingsStore.RestartRequired"/>).</summary>
|
|
public class SettingsRestartTests
|
|
{
|
|
private static Dictionary<string, JsonElement> Patch(string json) =>
|
|
JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(json)!;
|
|
|
|
private const string StartupKey = nameof(AppSettings.LearningBootstrapSecondsPerStart);
|
|
|
|
[Fact]
|
|
public void Ogni_chiave_dell_elenco_del_riavvio_e_un_impostazione_vera_con_la_sua_etichetta()
|
|
{
|
|
Assert.NotEmpty(SettingsStore.RestartRequired);
|
|
foreach (var key in SettingsStore.RestartRequired)
|
|
{
|
|
var prop = typeof(AppSettings).GetProperty(key, BindingFlags.Public | BindingFlags.Instance);
|
|
Assert.True(prop is { CanRead: true, CanWrite: true }, $"{key} non è una proprietà di AppSettings");
|
|
Assert.NotEqual(nameof(AppSettings.SettingsSchemaVersion), key);
|
|
|
|
var label = SettingsStore.RestartLabel(key);
|
|
Assert.False(string.IsNullOrWhiteSpace(label));
|
|
Assert.NotEqual(key, label);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Lo_studio_all_avvio_vale_dal_prossimo_riavvio_e_il_resto_subito()
|
|
{
|
|
Assert.Contains(StartupKey, SettingsStore.RestartRequired);
|
|
// Riapplicate a ogni salvataggio (Bot.ApplyLogSettings e Bot.OnSettingsChanged): non chiedono il riavvio.
|
|
Assert.DoesNotContain(nameof(AppSettings.MaxLogLinesPerAuction), SettingsStore.RestartRequired);
|
|
Assert.DoesNotContain(nameof(AppSettings.MaxGlobalLogLines), SettingsStore.RestartRequired);
|
|
Assert.DoesNotContain(nameof(AppSettings.MaxRequestsPerSecond), SettingsStore.RestartRequired);
|
|
// L'etichetta per una chiave fuori elenco è la chiave stessa.
|
|
Assert.Equal("DailyBudgetEuro", SettingsStore.RestartLabel("DailyBudgetEuro"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Il_salvataggio_segnala_le_chiavi_che_chiedono_il_riavvio()
|
|
{
|
|
var store = new SettingsStore(null, null);
|
|
|
|
var mixed = await store.SaveAsync(Patch($$"""{"{{StartupKey}}": 300, "DailyBudgetEuro": 5}"""));
|
|
Assert.True(mixed.Ok);
|
|
Assert.Equal(new[] { StartupKey }, mixed.RestartKeys);
|
|
Assert.Equal(300, store.Current.LearningBootstrapSecondsPerStart);
|
|
Assert.Equal(2, mixed.Changes.Count);
|
|
|
|
// Solo chiavi che valgono subito: nessun avviso.
|
|
var live = await store.SaveAsync(Patch("""{"DailyBudgetEuro": 7, "MaxLogLinesPerAuction": 800}"""));
|
|
Assert.True(live.Ok);
|
|
Assert.Empty(live.RestartKeys);
|
|
|
|
// Lo stesso valore di prima non è una modifica: niente da segnalare.
|
|
var same = await store.SaveAsync(Patch($$"""{"{{StartupKey}}": 300}"""));
|
|
Assert.True(same.Ok);
|
|
Assert.Empty(same.Changes);
|
|
Assert.Empty(same.RestartKeys);
|
|
|
|
// Un salvataggio rifiutato non segnala nulla.
|
|
var bad = await store.SaveAsync(Patch($$"""{"{{StartupKey}}": "tanto"}"""));
|
|
Assert.False(bad.Ok);
|
|
Assert.Empty(bad.RestartKeys);
|
|
}
|
|
|
|
[Fact]
|
|
public void Le_chiavi_cambiate_si_confrontano_dopo_la_normalizzazione()
|
|
{
|
|
var before = new AppSettings();
|
|
var after = SettingsStore.Clone(before);
|
|
after.DailyBudgetEuro = 12;
|
|
Assert.Empty(SettingsStore.RestartKeysChanged(before, after));
|
|
|
|
after.LearningBootstrapSecondsPerStart = 5; // sotto il minimo: diventa 10, sempre diverso da 120
|
|
SettingsStore.Normalize(after);
|
|
Assert.Equal(new[] { StartupKey }, SettingsStore.RestartKeysChanged(before, after));
|
|
}
|
|
|
|
[Fact]
|
|
public void Il_messaggio_elenca_le_etichette_della_pagina()
|
|
{
|
|
var msg = SettingsStore.RestartMessage(new[] { StartupKey });
|
|
Assert.StartsWith("Salvato. Queste modifiche valgono dal prossimo riavvio: ", msg);
|
|
Assert.Contains("Studio all'avvio (secondi)", msg);
|
|
Assert.DoesNotContain(StartupKey, msg);
|
|
}
|
|
}
|