Record the golden reports of the trial judge before the seam
ci / test (postgres) (push) Successful in 8m10s
ci / test (sqlite) (push) Successful in 8m5s
ci / image (push) Successful in 2m34s

Three reports, byte for byte, with the elapsed seconds set to zero: the average
cross with prior trials, the crypto_trend protocol and a judged variant outside
the grid. The seam between the judge and the engines must leave them unchanged.

refs #118

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-04 09:27:38 +01:00
1 parent 93cdf7850d
commit 04bb5737d6
4 files changed
+89

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
using Anubis.Backtest;
using Anubis.Data;
using Anubis.Strategies;
using Anubis.Trading;
namespace Anubis.Tests;
/// <summary>
/// The golden reports of the trial judge (Phase 12, issue #118). They were written before the seam between the judge and the
/// engines, so the seam must leave every byte of the report as it was. Elapsed seconds are the only field set to zero.
/// To rewrite them on purpose: <c>ANUBIS_WRITE_GOLDEN=1</c>, then read the diff.
/// </summary>
[TestClass]
public sealed class TrialSeamTests
{
private static readonly CancellationToken _none = CancellationToken.None;
private static readonly DateTimeOffset Now = new(2027, 1, 5, 2, 10, 0, TimeSpan.Zero);
private static readonly Guid Id = new("6d2f3a51-0c4e-4b7a-9a61-3f1e2d0c9b12");
private static readonly DateOnly Through = new(2026, 12, 31);
[TestMethod]
[TestCategory(Category.Golden)]
public void TheReportOfTheAverageCrossDoesNotMove()
{
var data = BacktestData.One(BacktestData.Btc(), BacktestData.Walk(1500, 7, start: 20_000, drift: 0.0008, volatility: 0.03));
var plan = Laboratory.BuildPlan(new TrialRequest(MovingAverageCrossFamily.FamilyId, TrialSources.Database, Venues.Okx, ["BTC-EUR"],
new DateOnly(2018, 6, 1), new DateOnly(2022, 2, 8), 10_000m), Now).Plan;
var prior = new PriorTrials(2, 18, [0.4, 0.9, -0.1]);
var report = TrialRunner.Run(Id, plan, TrialPlan.Hash(plan.ToJson()), MovingAverageCrossFamily.Instance, data, prior, Now).Report;
Same("sma_cross", report);
}
[TestMethod]
[TestCategory(Category.Golden)]
public async Task TheReportOfTheCryptoTrendProtocolDoesNotMove()
{
Same("crypto_trend", await CryptoTrendAsync(null).ConfigureAwait(false));
}
[TestMethod]
[TestCategory(Category.Golden)]
public async Task TheReportOfAJudgedVariantOutsideTheGridDoesNotMove()
{
Same("crypto_trend_judged", await CryptoTrendAsync("coin_vol=12;max_stop=15").ConfigureAwait(false));
}
private static async Task<BacktestReport> CryptoTrendAsync(string? judged)
{
var folder = TempFolder.Create("golden-report");
try
{
var store = new ResearchStore(folder);
var seed = 21u;
foreach (var coin in new[] { "BTC", "ETH", "SOL", "XRP" })
{
var bars = LiveRig.Synthetic(Through.AddDays(-799), 800, 100, seed++).Select(b => new ResearchBar(new DateTimeOffset(b.Day.ToDateTime(TimeOnly.MinValue), TimeSpan.Zero),
(decimal)b.Open, (decimal)b.High, (decimal)b.Low, (decimal)b.Close, (decimal)b.Volume)).ToList();
await store.WriteAsync(EuroHistory.Venue, coin + "EUR", Timeframes.Day, bars, _none).ConfigureAwait(false);
}
var plan = Laboratory.BuildPlan(new TrialRequest(StrategyNames.CryptoTrend, TrialSources.Research, EuroHistory.Venue, CryptoTrendProtocol.Narrow,
CryptoTrendProtocol.From, Through, CryptoTrendProtocol.Capital, null), Now).Plan with
{ Judged = judged };
var data = await Laboratory.LoadResearchAsync(folder, plan.Data, _none).ConfigureAwait(false);
return TrialRunner.Run(Id, plan, TrialPlan.Hash(plan.ToJson()), StrategyCatalog.Find(StrategyNames.CryptoTrend)!, data, PriorTrials.None, Now).Report;
}
finally
{
TempFolder.Delete(folder);
}
}
private static void Same(string name, BacktestReport report)
{
var json = (report with { Seconds = 0 }).ToJson();
var relative = Path.Combine("golden", name + ".report.json");
if (Environment.GetEnvironmentVariable("ANUBIS_WRITE_GOLDEN") == "1")
{
var target = Path.Combine(Repo.Root.FullName, "tests", "Anubis.Tests", "Fixtures", relative);
Directory.CreateDirectory(Path.GetDirectoryName(target)!);
File.WriteAllText(target, json);
}
Assert.AreEqual(Fixture.Text(relative), json, $"The report of {name} changed.");
}
}