[GAP-022-FOLLOWUP]: connection-state seam complete
- src/NT8.Adapters/NinjaTrader/ConnectionStateMonitor.cs: added plain testable connection-state monitor - src/NT8.Adapters/Strategies/NT8StrategyBase.cs: wired monitor and added pre-submit ConnectionLost check - tests/NT8.Core.Tests/Scenarios/ScenarioTests.cs: added disconnect scenario coverage - SPRINT_BOARD.md: GAP-022-FOLLOWUP implemented/deployed - docs/00-governance/current_status.md: updated - docs/00-governance/decisions.md: added DEC-20260826-07 Build: clean | Tests: 580 passing | Dual-deployed: yes, backup 20260826_011650
This commit is contained in:
@@ -17,8 +17,8 @@ namespace NT8.Core.Tests.Scenarios
|
||||
/// Executable scenario coverage for behaviors already exposed by Core APIs.
|
||||
///
|
||||
/// Intentionally not represented as passing tests here because no truthful
|
||||
/// Core seam exists yet: NEWS_DAY_REDUCED_SIZE, MID_TRADE_DISCONNECT, and
|
||||
/// PRE_ENTRY_DISCONNECT. See the TODO block at the end of this file.
|
||||
/// Core seam exists yet: NEWS_DAY_REDUCED_SIZE. See the TODO block at the
|
||||
/// end of this file.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class ScenarioTests
|
||||
@@ -118,6 +118,76 @@ namespace NT8.Core.Tests.Scenarios
|
||||
Assert.IsFalse(breaker.ShouldAllowOrder());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CONNECTION_MONITOR_DisconnectAndReconnectUpdatesEntryPermission()
|
||||
{
|
||||
var monitor = new ConnectionStateMonitor();
|
||||
|
||||
Assert.IsTrue(monitor.TryAllowNewEntry(DateTime.UtcNow, null));
|
||||
Assert.IsTrue(monitor.ReportDisconnected());
|
||||
Assert.IsFalse(monitor.TryAllowNewEntry(DateTime.UtcNow, null));
|
||||
Assert.IsTrue(monitor.ReportConnected());
|
||||
Assert.IsTrue(monitor.TryAllowNewEntry(DateTime.UtcNow, null));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MID_TRADE_DISCONNECT_BlocksNewEntriesWithoutFlatteningExistingPosition()
|
||||
{
|
||||
var monitor = new ConnectionStateMonitor();
|
||||
var context = CreateContextWithPosition(1);
|
||||
var rejects = new List<string>();
|
||||
|
||||
monitor.ReportDisconnected();
|
||||
bool allowed = monitor.TryAllowNewEntry(context.CurrentTime, delegate(string reason, string detail, DateTime time)
|
||||
{
|
||||
rejects.Add(reason);
|
||||
});
|
||||
|
||||
Assert.IsFalse(allowed);
|
||||
Assert.AreEqual(1, context.CurrentPosition.Quantity, "Disconnect handling must not invent flatten-on-disconnect behavior.");
|
||||
Assert.AreEqual(1, rejects.Count);
|
||||
Assert.AreEqual("ConnectionLost", rejects[0]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PRE_ENTRY_DISCONNECT_BlocksSignalBeforeSubmit()
|
||||
{
|
||||
var monitor = new ConnectionStateMonitor();
|
||||
var intent = CreateIntent();
|
||||
var context = CreateContext();
|
||||
var rejects = new List<string>();
|
||||
|
||||
Assert.IsNotNull(intent, "Scenario setup represents a generated signal before submit.");
|
||||
monitor.ReportDisconnected();
|
||||
bool allowed = monitor.TryAllowNewEntry(context.CurrentTime, delegate(string reason, string detail, DateTime time)
|
||||
{
|
||||
rejects.Add(string.Format("{0}|{1}", reason, detail));
|
||||
});
|
||||
|
||||
Assert.IsFalse(allowed);
|
||||
Assert.AreEqual(1, rejects.Count);
|
||||
Assert.IsTrue(rejects[0].Contains("ConnectionLost"));
|
||||
Assert.IsTrue(rejects[0].Contains("Broker connection lost; new orders halted"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PRE_ENTRY_CONNECTED_AllowsSignalBeforeSubmit()
|
||||
{
|
||||
var monitor = new ConnectionStateMonitor();
|
||||
var intent = CreateIntent();
|
||||
var context = CreateContext();
|
||||
bool rejectLogged = false;
|
||||
|
||||
bool allowed = monitor.TryAllowNewEntry(context.CurrentTime, delegate(string reason, string detail, DateTime time)
|
||||
{
|
||||
rejectLogged = true;
|
||||
});
|
||||
|
||||
Assert.IsNotNull(intent);
|
||||
Assert.IsTrue(allowed);
|
||||
Assert.IsFalse(rejectLogged);
|
||||
}
|
||||
|
||||
private static StrategyIntent CreateIntent()
|
||||
{
|
||||
return new StrategyIntent(
|
||||
@@ -143,6 +213,17 @@ namespace NT8.Core.Tests.Scenarios
|
||||
new Dictionary<string, object>());
|
||||
}
|
||||
|
||||
private static StrategyContext CreateContextWithPosition(int quantity)
|
||||
{
|
||||
return new StrategyContext(
|
||||
"NQ",
|
||||
DateTime.UtcNow,
|
||||
new Position("NQ", quantity, 18000.0, 0, 0, DateTime.UtcNow),
|
||||
new AccountInfo(100000, 100000, 0, 0, DateTime.UtcNow),
|
||||
new MarketSession(DateTime.Today.AddHours(9.5), DateTime.Today.AddHours(16), true, "RTH"),
|
||||
new Dictionary<string, object>());
|
||||
}
|
||||
|
||||
private static BarData CreateBar()
|
||||
{
|
||||
return new BarData("NQ", DateTime.UtcNow, 18000, 18010, 17990, 18005, 1000, TimeSpan.FromMinutes(1));
|
||||
@@ -163,7 +244,5 @@ namespace NT8.Core.Tests.Scenarios
|
||||
|
||||
// TODO GAP-022 follow-ons (not claimed as covered):
|
||||
// NEWS_DAY_REDUCED_SIZE requires high-impact-event calendar and sizing-policy APIs.
|
||||
// MID_TRADE_DISCONNECT requires an injectable connection-state seam around NT8StrategyBase.
|
||||
// PRE_ENTRY_DISCONNECT requires an atomic pre-submit connection check and test seam.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user