- NT8StrategyBase.cs: made reject summary snapshots ORB-window/date-aware with heartbeat flush - SimpleORBNT8.cs: bound summary suppression to configured opening range - tests: added reject summary source guards and SimpleORB no-breakout rejection coverage - SPRINT_BOARD.md: marked GAP-060 implemented with deploy blocker - docs/00-governance/decisions.md: recorded DEC-20260823-08 implementation evidence Build: clean | Tests: 543 passing | Dual-deployed: no - NinjaTrader.exe PID 18800 locked NT8.Core.dll
95 lines
4.8 KiB
C#
95 lines
4.8 KiB
C#
using System;
|
|
using System.IO;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace NT8.Core.Tests.Adapters
|
|
{
|
|
[TestClass]
|
|
public class NT8StrategyBaseRejectSummaryTests
|
|
{
|
|
[TestMethod]
|
|
public void MaybeWriteRejectSummarySnapshot_IsNotSuppressedByBlanketMidnightToTenGate()
|
|
{
|
|
string source = File.ReadAllText(FindSourceFile("NT8StrategyBase.cs"));
|
|
string method = ExtractMethodBlock(source, "private void MaybeWriteRejectSummarySnapshot");
|
|
|
|
Assert.IsFalse(method.Contains("barTime.TimeOfDay < new TimeSpan(10, 0, 0)"), "Reject summaries must not suppress the whole midnight-to-10am span.");
|
|
Assert.IsTrue(method.Contains("IsRejectSummarySnapshotSuppressed(barTime)"), "Reject summary suppression must be ORB-window-aware.");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void MaybeWriteRejectSummarySnapshot_ResetsAfterOrbTriggerPerTradingDate()
|
|
{
|
|
string source = File.ReadAllText(FindSourceFile("NT8StrategyBase.cs"));
|
|
string method = ExtractMethodBlock(source, "private void MaybeWriteRejectSummarySnapshot");
|
|
|
|
Assert.IsTrue(source.Contains("private DateTime _rejectSummarySnapshotTradingDate = DateTime.MinValue;"), "Reject summary once-after-ORB tracking must have a date key.");
|
|
Assert.IsTrue(method.Contains("DateTime tradingDate = barTime.Date;"), "Reject summary tracking must derive a date from each bar.");
|
|
Assert.IsTrue(method.Contains("_rejectSummarySnapshotTradingDate != tradingDate"), "Reject summary tracking must detect day changes.");
|
|
Assert.IsTrue(method.Contains("_orbRejectSummarySnapshotWritten = false;"), "The once-after-ORB flag must reset on a new day.");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void OnBarUpdate_ChecksRejectSummarySnapshotOnHeartbeat()
|
|
{
|
|
string source = File.ReadAllText(FindSourceFile("NT8StrategyBase.cs"));
|
|
string method = ExtractMethodBlock(source, "protected override void OnBarUpdate");
|
|
|
|
Assert.IsTrue(method.Contains("MaybeWriteRejectSummarySnapshot(Time[0]);"), "OnBarUpdate must check summary flush cadence independently of new rejects.");
|
|
Assert.IsTrue(method.IndexOf("MaybeWriteRejectSummarySnapshot(Time[0]);", StringComparison.Ordinal) < method.IndexOf("BuildStrategyContext()", StringComparison.Ordinal), "Heartbeat flush must not depend on a strategy-generated rejection.");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SimpleORB_RejectSummarySuppressionWindow_UsesConfiguredOpeningRangeMinutes()
|
|
{
|
|
string source = File.ReadAllText(FindSourceFile("SimpleORBNT8.cs"));
|
|
string method = ExtractMethodBlock(source, "protected override bool TryGetRejectSummarySnapshotSuppressionWindow");
|
|
|
|
Assert.IsTrue(method.Contains("suppressionStart = barTime.Date.AddHours(9.5);"), "SimpleORB suppression must be anchored to today's RTH ORB start.");
|
|
Assert.IsTrue(method.Contains("suppressionEnd = suppressionStart.AddMinutes(OpeningRangeMinutes);"), "SimpleORB suppression must use the configured ORB length.");
|
|
Assert.IsTrue(method.Contains("return OpeningRangeMinutes > 0;"), "SimpleORB suppression must be disabled for invalid ORB lengths.");
|
|
}
|
|
|
|
private static string FindSourceFile(string fileName)
|
|
{
|
|
DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
|
|
while (dir != null)
|
|
{
|
|
string candidate = Path.Combine(dir.FullName, "src", "NT8.Adapters", "Strategies", fileName);
|
|
if (File.Exists(candidate))
|
|
return candidate;
|
|
dir = dir.Parent;
|
|
}
|
|
|
|
throw new FileNotFoundException("Could not locate src\\NT8.Adapters\\Strategies\\" + fileName + " from test output directory.");
|
|
}
|
|
|
|
private static string ExtractMethodBlock(string source, string signature)
|
|
{
|
|
int start = source.IndexOf(signature, StringComparison.Ordinal);
|
|
if (start < 0)
|
|
Assert.Fail("Source does not contain method: " + signature);
|
|
|
|
int brace = source.IndexOf("{", start, StringComparison.Ordinal);
|
|
if (brace < 0)
|
|
Assert.Fail("Method has no opening brace: " + signature);
|
|
|
|
int depth = 0;
|
|
for (int i = brace; i < source.Length; i++)
|
|
{
|
|
if (source[i] == '{')
|
|
depth++;
|
|
else if (source[i] == '}')
|
|
{
|
|
depth--;
|
|
if (depth == 0)
|
|
return source.Substring(start, i - start + 1);
|
|
}
|
|
}
|
|
|
|
Assert.Fail("Method has no closing brace: " + signature);
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|