Fix what the independent review of Phase 8 found and close the phase
ci / test (postgres) (push) Successful in 6m37s
ci / test (sqlite) (push) Successful in 7m51s
ci / test (postgres) (pull_request) Successful in 5m40s
ci / test (sqlite) (pull_request) Successful in 7m31s
ci / image (push) Successful in 2m29s
ci / image (pull_request) Successful in 59s

Two reviewers with a clean context read the engine and the screens. The
isotonic calibration took its floor from the first step, even of two cases, so
with few winners it flattened every estimate: the first model is rebuilt with
the fix. Learning failures no longer forget the multiplier an operation was
born with, nor stop a decision or the nightly check; recovered decisions read
the outside world as it was when due; models estimate only the strategies they
studied; a newer history does not repeat what was lived. The screens count
examples instead of verifications, show the next threshold and never round an
alarm to 50%; two forms now check the antiforgery token.

Each defect has its test, on both engines. ADR 0018 point 17 has the list.

refs #67

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 13:36:26 +01:00
1 parent f69943f70a
commit 0b0f4a5e75
33 files changed
+659 -145

No files matched your search

+46 -4
View File
@@ -54,6 +54,19 @@ public sealed class LearningScreenTests
Assert.IsFalse(page.Contains("/azioni/modello", StringComparison.Ordinal), "nothing to change in the demo");
HasAll(await server.TextAsync("/"), "Il modello osserva e impara, ma non decide ancora.", "su 300 necessari", "56% su dati mai visti", "domenica 11 ottobre, 03:00");
HasAll(await server.TextAsync("/operazioni"), "Il modello stimava il 61% di probabilità di guadagno (di solito 48%): solo osservazione, non ha cambiato la dimensione");
// The signal was born three days before the purchase, held back meanwhile: same example, same estimate.
var (db, clock) = (server.Host.Services!.Db, server.Host.Clock);
var earlier = Ids.NewId(clock);
await db.WriteAsync(async s =>
{
var at = (await s.FirstOrDefaultAsync("SELECT created_at FROM decisions WHERE stage = 'model' AND symbol = 'MSFT'", r => (DateTimeOffset?)r.Moment("created_at")))!.Value.AddDays(-3);
await s.ExecuteAsync("UPDATE decisions SET decision_id = @d, created_at = @at WHERE stage = 'model' AND symbol = 'MSFT'", _none, ("d", earlier), ("at", at));
await LearningStore.AddAsync(s, clock, new Example(Guid.Empty, StrategyNames.EquityMeanrev, "MSFT", CaseSources.Live, DateOnly.FromDateTime(at.UtcDateTime), at, "x", 0.2m, null, null,
new Dictionary<string, double>())
{ DecisionId = earlier }, _none);
}, _none);
HasAll(await server.TextAsync("/operazioni"), "Il modello stimava il 61% di probabilità di guadagno (di solito 48%)");
using var post = await server.PostFormAsync("/apprendimento", "/azioni/modello/annulla-promozione");
Assert.AreEqual("/apprendimento?errore=motore", ServerHarness.Location(post));
using var settings = await server.PostFormAsync("/impostazioni", "/azioni/modello", (LearningSettings.Aside.Key, "on"));
@@ -118,7 +131,7 @@ public sealed class LearningScreenTests
await LearningStore.SaveStateAsync(s, clock, CycleState.Key, new CycleState { Health = new HealthCheck { At = clock.UtcNow, Precision = 1, Cases = 60 } }, _none);
}, _none);
var page = await server.TextAsync("/apprendimento");
HasAll(page, "<strong>120</strong> <span class=\"muted\">su 300 necessari</span>", "Sfidante, versione 2", "120 su 150", "La versione 2 è ancora in prova.", "Sembra un po' meglio su 120 casi di confronto.",
HasAll(page, "<strong>120</strong> <span class=\"muted\">su 300 necessari</span>", "Sfidante, versione 2", "120 su 100", "La versione 2 è ancora in prova.", "Sembra un po' meglio su 120 casi di confronto. Si decide ",
"Prossima verifica dello sfidante", "Al ritmo attuale, tra", "tra 45% e 50%", "Precisione sugli ultimi 60 casi: 100%, sopra il", "Nessun allarme finora", "Nessuna anomalia");
Assert.IsFalse(page.Contains("Per ora sono i casi storici", StringComparison.Ordinal), "the live bands count now");
Assert.IsFalse(page.Contains("Annulla l'ultima promozione", StringComparison.Ordinal));
@@ -247,6 +260,10 @@ public sealed class LearningScreenTests
events: [new ModelEvent(ModelEvents.SetAside, 1, "a", Now.AddDays(-20)), new ModelEvent(ModelEvents.Back, 1, "b", Now.AddDays(-17))], models: champion);
StringAssert.EndsWith(back.Checks[^1].Text, "Ultimo controllo oggi alle 03:21. Ultimo allarme il 19 settembre, rientrato in 3 giorni");
Assert.AreEqual("wait", back.Checks[0].State, "too few live signals to compare the market");
// A check of another version says nothing of the one in charge now.
var changed = View(new CycleState { Health = health with { Version = 7 } }, models: champion);
StringAssert.StartsWith(changed.Checks.Single().Text, "Il modello in carica è cambiato: il primo controllo è alle 03:00.");
Assert.IsTrue(View(new CycleState { Health = health with { DriftingClues = ["Volumi scambiati"] } }, models: champion).Checks[0] is { State: "warn" });
}
@@ -279,6 +296,28 @@ public sealed class LearningScreenTests
Assert.AreEqual("Al ritmo attuale, più di un anno.", LearningView.PaceWords(80));
}
/// <summary>What is shown as happened is counted, not weighed by maturation.</summary>
[TestMethod]
[TestCategory(Category.Unit)]
public void TheBandsSayWhatReallyHappened()
{
var champion = Row(ModelStatuses.Champion, 1);
var view = View(new CycleState(), estimates: [.. Enumerable.Range(0, 20).Select(i => Seen(champion.Id, 3, i == 0, 0.41))], models: champion);
Assert.AreEqual(new LearningBand(40, 45, 20, 41, 5), view.Bands.Single());
Assert.IsFalse(view.BandsFromHistory);
}
/// <summary>What the trade card says when the model would count but is set aside.</summary>
[TestMethod]
[TestCategory(Category.Unit)]
public void TheTradeCardSaysWhyTheModelChangedNothing()
{
string Line(string tail) => ReasonTexts.Model("{\"probability\":0.61,\"base_rate\":0.48,\"applied\":1" + tail + "}")!;
StringAssert.EndsWith(Line(",\"counts\":false,\"aside\":true"), ": era messo da parte, non ha cambiato la dimensione");
StringAssert.EndsWith(Line(",\"counts\":false,\"aside\":false"), ": solo osservazione, non ha cambiato la dimensione");
StringAssert.EndsWith(Line(",\"counts\":true,\"aside\":false"), ": taglia piena");
}
/// <summary>Bands under 20 cases are said unreliable, in the sentence and one by one.</summary>
[TestMethod]
[TestCategory(Category.Unit)]
@@ -333,9 +372,12 @@ public sealed class LearningScreenTests
StringAssert.StartsWith(few.TrialText, "Sembra un po' meglio, ma ha solo 14 casi di confronto su 100");
StringAssert.StartsWith(View(new CycleState(), estimates: Pairs(1, false), models: [champion, challenger]).TrialText, "Per ora non sembra meglio, e ha solo un caso di confronto su 100");
var more = View(new CycleState(), estimates: Pairs(130, false), models: [champion, challenger]);
Assert.AreEqual((130, 150), (more.Pairs, more.PairsNeeded));
StringAssert.StartsWith(more.TrialText, "Per ora non sembra meglio su 130 casi di confronto. Si decide solo quando i casi superano 100, 150, 200, 250 e 300");
Assert.AreEqual(300, View(new CycleState(), estimates: Pairs(320, false), models: [champion, challenger]).PairsNeeded);
Assert.AreEqual((130, 100), (more.Pairs, more.PairsNeeded), "passed, and not judged yet");
StringAssert.StartsWith(more.TrialText, "Per ora non sembra meglio su 130 casi di confronto. Si decide domenica 11 ottobre alle 03:00: prende il posto della 1 se");
var judged = View(new CycleState(), estimates: Pairs(130, false), models: [champion, challenger with { ThresholdDone = 100 }]);
Assert.AreEqual((130, 150), (judged.Pairs, judged.PairsNeeded));
StringAssert.StartsWith(judged.TrialText, "Per ora non sembra meglio su 130 casi di confronto. Si decide di nuovo a 150 casi:");
Assert.AreEqual(300, View(new CycleState(), estimates: Pairs(320, false), models: [champion, challenger with { ThresholdDone = 250 }]).PairsNeeded);
Assert.AreEqual((5.84m, 6m), (more.Champion!.GainWithout, more.Challenger!.GainWithout));
Assert.AreEqual((56, 0.241m, 7.9m, "4 ottobre"), (more.Champion.Precision, more.Champion.Error, more.Champion.Gain, more.Champion.Trained));
Assert.AreEqual("Nessuno sfidante in prova.", View(new CycleState(), models: champion).TrialTitle);