- SimpleORBNT8.cs: clone daily context for STATE telemetry and set direction/session-open fields - SimpleORBNT8DefaultsTests.cs: add source tests for telemetry clone and orb_range_ticks metadata - OrbConfluenceFactorTests.cs: prove sell/down-gap alignment scores correctly - SPRINT_BOARD.md and decisions.md: record implementation, P1-E finding, verification, and deploy evidence Build: clean | Tests: 538 passing; Core 449 passing | Deploy: backup 20260823_151931
102 lines
5.1 KiB
C#
102 lines
5.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace NT8.Core.Tests.Adapters
|
|
{
|
|
[TestClass]
|
|
public class SimpleORBNT8DefaultsTests
|
|
{
|
|
[TestMethod]
|
|
public void SetDefaults_DirectionFlags_EnableLongAndShortTrades()
|
|
{
|
|
string source = File.ReadAllText(FindSourceFile());
|
|
string setDefaults = ExtractSetDefaultsBlock(source);
|
|
|
|
Assert.IsTrue(setDefaults.Contains("EnableLongTrades = true;"), "SetDefaults must enable long trades by default.");
|
|
Assert.IsTrue(setDefaults.Contains("EnableShortTrades = true;"), "SetDefaults must enable short trades by default per DEC-20260814-04.");
|
|
Assert.IsFalse(setDefaults.Contains("EnableShortTrades = false;"), "SetDefaults must not disable short trades by default.");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void BuildStateTelemetryIntent_DailyContext_UsesDirectionCorrectClone()
|
|
{
|
|
string source = File.ReadAllText(FindSourceFile());
|
|
string method = ExtractMethodBlock(source, "protected override StrategyIntent BuildStateTelemetryIntent");
|
|
|
|
Assert.IsTrue(method.Contains("CloneDailyBarContextForTelemetry((DailyBarContext)dailySource, side, barData, context)"), "Telemetry must clone daily context and set clone-only fields.");
|
|
Assert.IsTrue(method.Contains("metadata.Add(\"daily_bars\", telemetryDaily);"), "Telemetry must attach the cloned daily context.");
|
|
Assert.IsTrue(method.Contains("metadata.Add(\"orb_range_ticks\", telemetryDaily.OrbRangeTicks);"), "Telemetry must expose ORB range metadata for OrbRangeVsAtr.");
|
|
Assert.IsFalse(method.Contains("metadata.Add(\"daily_bars\", _strategyConfig.Parameters[\"daily_bars\"]);"), "Telemetry must not attach the shared daily context directly.");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CloneDailyBarContextForTelemetry_UsesTelemetrySideAndSessionOpen()
|
|
{
|
|
string source = File.ReadAllText(FindSourceFile());
|
|
string method = ExtractMethodBlock(source, "private static DailyBarContext CloneDailyBarContextForTelemetry");
|
|
|
|
Assert.IsTrue(method.Contains("daily.TradeDirection = side == OrderSide.Buy ? 1 : -1;"), "Telemetry clone must derive direction from the synthetic intent side.");
|
|
Assert.IsTrue(method.Contains("context.CustomData.ContainsKey(\"session_open_price\")"), "Telemetry clone must prefer session_open_price over current bar open.");
|
|
Assert.IsTrue(method.Contains("daily.TodayOpen = (double)sessionOpen;"), "Telemetry clone must apply the session open value.");
|
|
Assert.IsTrue(method.Contains("context.CustomData.ContainsKey(\"avg_volume\")"), "Telemetry clone must mirror trade-path avg_volume context.");
|
|
Assert.IsTrue(method.Contains("daily.BreakoutBarVolume = (double)barData.Volume;"), "Telemetry clone must use current bar volume for breakout-volume scoring.");
|
|
}
|
|
|
|
private static string FindSourceFile()
|
|
{
|
|
DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
|
|
while (dir != null)
|
|
{
|
|
string candidate = Path.Combine(dir.FullName, "src", "NT8.Adapters", "Strategies", "SimpleORBNT8.cs");
|
|
if (File.Exists(candidate))
|
|
return candidate;
|
|
dir = dir.Parent;
|
|
}
|
|
|
|
throw new FileNotFoundException("Could not locate src\\NT8.Adapters\\Strategies\\SimpleORBNT8.cs from test output directory.");
|
|
}
|
|
|
|
private static string ExtractSetDefaultsBlock(string source)
|
|
{
|
|
const string marker = "if (State == State.SetDefaults)";
|
|
int start = source.IndexOf(marker, StringComparison.Ordinal);
|
|
if (start < 0)
|
|
Assert.Fail("SimpleORBNT8.cs does not contain the SetDefaults state block.");
|
|
|
|
int end = source.IndexOf("else if (State == State.Configure)", start, StringComparison.Ordinal);
|
|
if (end < 0)
|
|
Assert.Fail("SimpleORBNT8.cs does not contain the Configure state block after SetDefaults.");
|
|
|
|
return source.Substring(start, end - start);
|
|
}
|
|
|
|
private static string ExtractMethodBlock(string source, string signature)
|
|
{
|
|
int start = source.IndexOf(signature, StringComparison.Ordinal);
|
|
if (start < 0)
|
|
Assert.Fail("SimpleORBNT8.cs does not contain method: " + signature);
|
|
|
|
int brace = source.IndexOf("{", start, StringComparison.Ordinal);
|
|
if (brace < 0)
|
|
Assert.Fail("SimpleORBNT8.cs 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("SimpleORBNT8.cs method has no closing brace: " + signature);
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|