[GAP-050]: quantity-aware risk contract complete
- IRiskManager.cs: add quantity-aware ValidateOrder contract - AdvancedRiskManager.cs: delegate Tier 1 through sized BasicRiskManager overload and preserve 3-arg behavior - NT8StrategyBase.cs: remove BasicRiskManager type-check workaround and call sized interface method - NT8OrderAdapter.cs: size before risk validation and pass actual contracts - tests: add AdvancedRiskManager, NT8OrderAdapter, and NT8StrategyBase coverage Build: clean | Tests: 566 passing; Core 476 passing | Dual-deployed: no - skipped by prompt
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace NT8.Core.Tests.Adapters
|
||||
{
|
||||
[TestClass]
|
||||
public class NT8StrategyBaseRiskContractTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProcessStrategyIntent_UsesQuantityAwareRiskInterfaceCall()
|
||||
{
|
||||
string source = File.ReadAllText(FindSourceFile());
|
||||
string method = ExtractMethodBlock(source, "private void ProcessStrategyIntent");
|
||||
|
||||
Assert.IsTrue(method.Contains("_riskManager.ValidateOrder(intent, context, _riskConfig, sizingResult.Contracts)"), "Sized risk validation must use the IRiskManager quantity-aware overload.");
|
||||
Assert.IsFalse(method.Contains("_riskManager as BasicRiskManager"), "Sized risk validation must not depend on a BasicRiskManager type check.");
|
||||
}
|
||||
|
||||
private static string FindSourceFile()
|
||||
{
|
||||
DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
|
||||
while (dir != null)
|
||||
{
|
||||
string candidate = Path.Combine(dir.FullName, "src", "NT8.Adapters", "Strategies", "NT8StrategyBase.cs");
|
||||
if (File.Exists(candidate))
|
||||
return candidate;
|
||||
dir = dir.Parent;
|
||||
}
|
||||
|
||||
throw new FileNotFoundException("Could not locate src\\NT8.Adapters\\Strategies\\NT8StrategyBase.cs 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user