«Predefinito» nella finestra Aggiungi asta; tolti Tema scuro e Menu compresso dalle Impostazioni (#48)
La finestra «Aggiungi asta» mandava sempre un modo (Osserva per primo), e il server lo usava prima di tutto il resto: un'aggiunta a mano ignorava sia il modo scritto sulla scheda del prodotto sia «Modo delle aste aggiunte a mano», che pure il suo suggerimento prometteva. Ora la prima scelta, proposta, è «Predefinito» e manda mode null: il server applica il modo della scheda e, se manca, l'impostazione (l'ordine in ProductRules.Resolve era già giusto, ora è commentato e provato da un test puro e da uno sul monitor contro il simulatore). Il suggerimento di «Predefinito» dice quale modo vale adesso, perché il messaggio mode porta il valore dell'impostazione (newAuctionMode). Il catalogo continua a mandare il suo modo. I suggerimenti della colonna Stato dei Prodotti dicono che quel modo vale anche per le aste aggiunte con il + in Predefinito. «Tema scuro» valeva solo per il browser da cui si salvava, «Menu compresso» arrivava al browser ma nessuno lo leggeva: si tolgono da AppSettings, dal messaggio mode e dalla pagina Impostazioni (la sezione diventa «Registri»). Tema e menu restano ai loro bottoni, ricordati da ogni browser. Una riga delle impostazioni che contiene ancora le due chiavi si legge lo stesso (chiavi sconosciute ignorate): lo provano un test puro su SettingsStore.Parse e uno su PostgreSQL. Lo scostamento dalla specifica §15 è annotato in fondo all'ADR 0016; guida aggiornata in Aste, Impostazioni, Cerca e prodotti e Primo avvio. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 68ab6fdee7f38eb57584c4c60476e74034198fe9)
This commit is contained in:
1 parent
213b18add9
commit
a39da80e32
17 files changed
+182
-31
No files matched your search
@@ -106,6 +106,26 @@ public class DatabaseTests
|
||||
await again.LoadAsync(_fx.Db);
|
||||
Assert.Equal(20, again.Current.DataCapGb);
|
||||
}
|
||||
|
||||
[DbFact]
|
||||
public async Task Una_riga_delle_impostazioni_con_tema_e_menu_compresso_si_carica_lo_stesso()
|
||||
{
|
||||
// Le chiavi DarkMode e NavCollapsed non esistono più (#48): un database che le ha ancora parte.
|
||||
await _fx.TruncateAsync();
|
||||
await _fx.Db!.ExecuteAsync("INSERT INTO settings(id, value) VALUES(1, $1) ON CONFLICT(id) DO UPDATE SET value = excluded.value",
|
||||
new Jsonb($$"""{"SettingsSchemaVersion": {{SettingsStore.CurrentSchema}}, "DarkMode": true, "NavCollapsed": true, "DataCapGb": 33}"""));
|
||||
await using var queue = new WriteQueue(_fx.Db.Writer);
|
||||
var store = new SettingsStore(queue, null);
|
||||
await store.LoadAsync(_fx.Db);
|
||||
Assert.Equal(33, store.Current.DataCapGb);
|
||||
|
||||
// Al primo salvataggio la riga si riscrive senza le due chiavi.
|
||||
var patch = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>("""{"DataCapGb": 34}""")!;
|
||||
Assert.True((await store.SaveAsync(patch)).Ok);
|
||||
var json = await _fx.Db.ScalarAsync<string>("SELECT value::text FROM settings WHERE id = 1");
|
||||
Assert.DoesNotContain("DarkMode", json);
|
||||
Assert.DoesNotContain("NavCollapsed", json);
|
||||
}
|
||||
}
|
||||
|
||||
public class WriteQueueCapacityTests
|
||||
|
||||
@@ -341,6 +341,24 @@ public class SettingsTests
|
||||
Assert.Equal(50, s.PollCriticalMs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Tema_e_menu_compresso_non_sono_piu_impostazioni_e_una_riga_vecchia_si_legge_lo_stesso()
|
||||
{
|
||||
// Una riga salvata dalla 1.9.2 o prima: le due chiavi tolte con #48 si ignorano, le altre restano.
|
||||
var old = SettingsStore.Parse("""{"SettingsSchemaVersion": 2, "DarkMode": false, "NavCollapsed": true, "DailyBudgetEuro": 12.5, "DefaultNewAuctionState": "Ferma"}""");
|
||||
Assert.Equal(12.5, old.DailyBudgetEuro);
|
||||
Assert.Equal("Ferma", old.DefaultNewAuctionState);
|
||||
Assert.Equal(2, old.SettingsSchemaVersion);
|
||||
Assert.False(SettingsStore.Migrate(old));
|
||||
|
||||
Assert.Null(typeof(AppSettings).GetProperty("DarkMode"));
|
||||
Assert.Null(typeof(AppSettings).GetProperty("NavCollapsed"));
|
||||
// Salvarle dalla pagina non si può più, come ogni impostazione sconosciuta.
|
||||
var store = new SettingsStore(null, null);
|
||||
Assert.False((await store.SaveAsync(Patch("""{"DarkMode": true}"""))).Ok);
|
||||
Assert.False((await store.SaveAsync(Patch("""{"NavCollapsed": true}"""))).Ok);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Il_salvataggio_vale_subito_e_si_scrive_nel_registro()
|
||||
{
|
||||
|
||||
@@ -277,4 +277,61 @@ public class ApplyProductLimitsTests
|
||||
Assert.Equal(7, b.MaxPrice); // l'altra resta com'era
|
||||
Assert.False(monitor.ReturnToProductLimits("nessuna").Ok);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Aggiunta_a_mano_con_Predefinito_prende_il_modo_della_scheda_e_poi_quello_delle_impostazioni()
|
||||
{
|
||||
var world = new SimWorld(seed: 33, populate: false);
|
||||
var settings = new AppSettings { QuietHoursEnabled = false, DefaultNewAuctionState = "Ferma", AutoAddNewAuctionState = "Attiva" };
|
||||
var one = world.AddRunningAuction(seconds: 600);
|
||||
var two = world.AddRunningAuction(seconds: 600);
|
||||
var three = world.AddRunningAuction(seconds: 600);
|
||||
|
||||
await using var sim = await SimulatedBidoo.StartAsync(world);
|
||||
var refs = sim.References();
|
||||
using var transport = new BidooTransport(() => refs, 0);
|
||||
using var lane = new BidLane(transport, () => refs, keepWarm: false);
|
||||
var api = new BidooApi(transport, lane, () => refs) { Username = world.MyUsername };
|
||||
var docs = new MemoryDocumentStore();
|
||||
var log = new AppLog(null);
|
||||
var account = new AccountState();
|
||||
account.SetUser(world.MyUsername, world.MyUserId);
|
||||
var risk = new RiskManager(docs, new ListLedger());
|
||||
var learning = new LearningService(docs, new MemoryLearningData(), () => settings, log);
|
||||
var products = new ProductStore(null);
|
||||
await using var monitor = new AuctionMonitor(new MonitorDeps
|
||||
{
|
||||
Settings = () => settings,
|
||||
References = () => refs,
|
||||
Api = api,
|
||||
Clock = new ServerClock(),
|
||||
Strategy = new BidStrategy(risk, learning, products, () => account.Balance),
|
||||
Risk = risk,
|
||||
Learning = learning,
|
||||
Latency = new LatencyModel(docs),
|
||||
Recorder = new AuctionRecorder(null, null, () => settings, () => world.MyUsername, Worlds.Simulator),
|
||||
Products = products,
|
||||
Account = account,
|
||||
Log = log,
|
||||
Documents = docs,
|
||||
World = Worlds.Simulator,
|
||||
Limits = new ProductLimits(products, () => settings)
|
||||
});
|
||||
|
||||
// «Predefinito» (mode null) senza modo sulla scheda: «Modo delle aste aggiunte a mano».
|
||||
var (a, message) = await monitor.AddAsync(new AddAuctionRequest(one.Id), CancellationToken.None);
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal(RunMode.Stopped, a!.Mode);
|
||||
Assert.Contains("Ferma", message);
|
||||
|
||||
// Con il modo scritto sulla scheda vince la scheda.
|
||||
products.Upsert(new ProductRecord { ProductKey = a.ProductKey, DisplayName = a.Name, AutoState = "osserva" });
|
||||
var (b, _) = await monitor.AddAsync(new AddAuctionRequest(two.Id), CancellationToken.None);
|
||||
Assert.Equal(a.ProductKey, b!.ProductKey);
|
||||
Assert.Equal(RunMode.Watch, b.Mode);
|
||||
|
||||
// Un modo scelto nella finestra vince su scheda e impostazioni.
|
||||
var (c, _) = await monitor.AddAsync(new AddAuctionRequest(three.Id, Mode: RunMode.Active), CancellationToken.None);
|
||||
Assert.Equal(RunMode.Active, c!.Mode);
|
||||
}
|
||||
}
|
||||
@@ -189,6 +189,26 @@ public class ProductTests
|
||||
Assert.Equal(RunMode.Watch, ProductRules.ParseMode("boh"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Il_modo_di_un_asta_nuova_viene_dalla_scheda_e_poi_dalle_impostazioni_della_sua_strada()
|
||||
{
|
||||
var s = new AppSettings { DefaultNewAuctionState = "Ferma", AutoAddNewAuctionState = "Attiva" };
|
||||
|
||||
// Senza scheda: a mano «Modo delle aste aggiunte a mano», da sola «Modo delle aste aggiunte».
|
||||
Assert.Equal(RunMode.Stopped, ProductRules.Resolve(null, s, autoAdded: false).Mode);
|
||||
Assert.Equal(RunMode.Active, ProductRules.Resolve(null, s, autoAdded: true).Mode);
|
||||
|
||||
// Una scheda senza modo (colonna Stato «Predefinito») non cambia nulla.
|
||||
var noMode = new ProductRecord { ProductKey = "x", MaxPrice = 8 };
|
||||
Assert.Equal(RunMode.Stopped, ProductRules.Resolve(noMode, s, autoAdded: false).Mode);
|
||||
Assert.Equal(RunMode.Active, ProductRules.Resolve(noMode, s, autoAdded: true).Mode);
|
||||
|
||||
// Il modo scritto sulla scheda vince sulle impostazioni, per tutte e due le strade.
|
||||
var watch = new ProductRecord { ProductKey = "x", AutoState = "osserva" };
|
||||
Assert.Equal(RunMode.Watch, ProductRules.Resolve(watch, s, autoAdded: false).Mode);
|
||||
Assert.Equal(RunMode.Watch, ProductRules.Resolve(watch, s, autoAdded: true).Mode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void I_paletti_scritti_vincono_sui_calcolati_che_vincono_sui_predefiniti()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user