[GAP-057]: runner trail source regression seam

- NT8StrategyBaseRunnerTrailTests.cs: assert no runner SetStopLoss after SetTrailStop and no post-entry runner stop resets

- SPRINT_BOARD.md/decisions.md: record Option B source-text seam choice and verification evidence

Build: clean | Tests: 558 passing; Core 469 passing | Dual-deployed: no - test-only skipped by prompt
This commit is contained in:
2026-08-25 13:33:54 -04:00
parent cdd9aa25bb
commit 0607d44388
4 changed files with 221 additions and 2 deletions

View File

@@ -83,10 +83,13 @@
**[GAP-056] `EnableAutoBreakeven`/`BreakevenTriggerTicks`/`BreakevenOffsetTicks` are fully inert** | Stage 1 | ✅ IMPLEMENTED — deploy skipped by prompt **[GAP-056] `EnableAutoBreakeven`/`BreakevenTriggerTicks`/`BreakevenOffsetTicks` are fully inert** | Stage 1 | ✅ IMPLEMENTED — deploy skipped by prompt
- Found during GAP-054 verification (`DEC-20260821-01`): GAP-054 removed the only code path that ever read these three parameters (the runner breakeven block that was clobbering the trailing stop). They remain declared, defaulted, and exposed in the NinjaTrader UI but do nothing — harmless, but an operator toggling `EnableAutoBreakeven` would reasonably expect an effect. - Found during GAP-054 verification (`DEC-20260821-01`): GAP-054 removed the only code path that ever read these three parameters (the runner breakeven block that was clobbering the trailing stop). They remain declared, defaulted, and exposed in the NinjaTrader UI but do nothing — harmless, but an operator toggling `EnableAutoBreakeven` would reasonably expect an effect.
- Prompt: `TASK_GAP056_INERT_BREAKEVEN_PARAMS_PROMPT.md`. Implemented Option A: retained the properties for saved workspace/settings compatibility, hid all three from the NT8 property grid with `[Browsable(false)]`, and labeled the SimpleORB settings export as `UNUSED`. No order-flow, sizing, risk, `SetStopLoss`, or `SetTrailStop` logic changed. Verification: focused tests 3/3, `verify-build.bat` 555/555, Core Release no-build 466/466. Deploy intentionally skipped by task prompt. - Prompt: `TASK_GAP056_INERT_BREAKEVEN_PARAMS_PROMPT.md`. Implemented Option A: retained the properties for saved workspace/settings compatibility, hid all three from the NT8 property grid with `[Browsable(false)]`, and labeled the SimpleORB settings export as `UNUSED`. No order-flow, sizing, risk, `SetStopLoss`, or `SetTrailStop` logic changed. Verification: focused tests 3/3, `verify-build.bat` 555/555, Core Release no-build 466/466. Deploy intentionally skipped by task prompt.
**[GAP-057] No test seam for NinjaScript's SetStopLoss/SetTrailStop managed-order calls** | Stage 1 | ✅ IMPLEMENTED — test-only, deploy skipped by prompt
- Found during GAP-054 verification (`DEC-20260821-01`): the regression test GAP-054's own task asked for (no `SetStopLoss` after `SetTrailStop` for a runner signal) was never written because no test seam exists — Kilocode correctly declined to fabricate coverage rather than write a fake test. Same defect class as GAP-054 (silent exit-order clobbering) currently has zero regression protection.
- Prompt: `TASK_GAP057_STOP_TRAIL_TEST_SEAM_PROMPT.md`. Implemented Option B: source-text regression seam. Added tests proving the runner entry block never calls `SetStopLoss(_runnerSignalName...)` after `SetTrailStop(_runnerSignalName...)`, the post-entry runner monitor in `OnBarUpdate()` contains no `SetStopLoss`/`SetTrailStop` calls, and no production order-management indirection was introduced. Verification: focused tests 3/3, `verify-build.bat` 558/558, Core Release no-build 469/469. Deploy intentionally skipped by task prompt.
### Also raised by the review, not yet prompted ### Also raised by the review, not yet prompted
GAP-051 (`MicroUpgradeThreshold` fires every session) · GAP-052 (two hardcoded tick-value tables) · GAP-051 (`MicroUpgradeThreshold` fires every session) · GAP-052 (two hardcoded tick-value tables) ·
GAP-053 (`executive_summary.md` and `roadmap.md` Sprint 3 list present ~12 completed tasks as open) · GAP-053 (`executive_summary.md` and `roadmap.md` Sprint 3 list present ~12 completed tasks as open) ·
plus GAP-057 (no test seam for NinjaScript managed-order SetStopLoss/SetTrailStop calls) ·
plus the standing dirty working tree — 17 modified, 5 untracked, including two live strategy files. plus the standing dirty working tree — 17 modified, 5 untracked, including two live strategy files.
--- ---

View File

@@ -0,0 +1,103 @@
# TASK: GAP-057 — no test seam exposes NinjaScript's SetStopLoss/SetTrailStop managed-order calls
# Staged: 2026-08-21 (found during GAP-054 verification, DEC-20260821-01), promoted 2026-08-25
# Sprint: Stage 1 — test coverage only, zero trading-behaviour risk
# Owner: Kilocode
# Deploy: COMMIT ONLY — do NOT run deploy-to-nt8.bat or copy build output to
# the live NT8 install as part of this task. Verify-build and commit
# as usual; leave the deploy step for the operator to run manually
# once ready.
# ─────────────────────────────────────────────────────────────────
## THE DEFECT
GAP-054 fixed a real, expensive bug: `SetStopLoss()` on `_runnerSignalName`
was replacing the `SetTrailStop()` issued at entry, silently disabling the
runner's trailing stop for its entire life (confirmed in 4/4 broker-
confirmed trades — the trail was 12-16 ticks in profit when breakeven
fired and got moved back to +1).
The original `TASK_GAP054_RUNNER_TRAIL_PROMPT.md` asked for a regression
test asserting no `SetStopLoss` call is issued after `SetTrailStop` for a
runner signal, with instructions to propose the smallest test seam if none
existed. Kilocode correctly declined to fabricate coverage rather than
write a fake-passing test — but no concrete seam proposal was written up
either, so this defect class (silent exit-order clobbering via NT8's
managed-order Set() calls) currently has zero regression protection. If a
future change reintroduces a similar clobber — even accidentally, e.g. a
new breakeven-style feature calling `SetStopLoss` for a runner signal — it
would not be caught by tests, only by the kind of manual source review
that caught GAP-054 and this review's other findings tonight.
## READ-FIRST
1. Read `DEC-20260821-01` for the original finding.
2. Read the current runner/scaler order-management code in
`NT8StrategyBase.cs` (the block GAP-054 touched, and the
`SetTrailStop`/`SetStopLoss` call sites at entry, ~2188/2196 per
`DEC-...` references) to understand the current (correct) call
sequence you need to protect.
3. NinjaScript's `SetStopLoss`/`SetTrailStop`/managed-order calls
(`EnterLongManaged` etc.) are NinjaTrader platform APIs — confirm
whether they can be reached through any existing test double/wrapper
in this codebase (check `NT8.Adapters/Wrappers/` — `SimpleORBNT8Wrapper.cs`
and similar were used elsewhere this session for testability) or
whether `NT8StrategyBase`/`SimpleORBNT8` call them directly with no
seam at all, same as the class-can't-be-instantiated situation this
session already established for other tests in these files.
## THE CHANGE
Propose and implement the smallest seam that lets a test assert the call
*sequence* (no `SetStopLoss` after `SetTrailStop` for the same signal
name) without needing a live NinjaTrader instance. Options to weigh,
pick one and justify it in your writeback:
**Option A — extract an interface.** A thin `IOrderManagementCalls` (or
similar) interface wrapping just the handful of Set()/managed-order calls
this block uses, with a real NinjaScript-backed implementation and a
test-double implementation that records call order. Larger diff, reusable
for future order-flow tests beyond just this one defect class.
**Option B — source-text assertion, same as established precedent.** If
extracting a real seam would require touching NinjaScript-derived classes
in a way that risks the actual order-flow code (not just adding a test
hook), fall back to the same source-text-assertion pattern already used
and accepted this session for `NT8StrategyBase.cs`/`SimpleORBNT8.cs`
tests — assert the compiled method body contains the correct guard/order
and does not contain the reintroduced-clobber pattern. Weaker coverage
tier, but consistent with this class's established constraints and zero
risk of the test scaffolding itself touching production order flow.
State clearly in your writeback which you chose and why — this is exactly
the kind of judgment call the original GAP-054 task asked for and didn't
get answered.
## DO NOT
- Do not change any order-flow, `SetStopLoss`/`SetTrailStop`, runner, or
scaler logic — this task adds test coverage only, it does not touch
GAP-054's fix.
- Do not introduce a seam that changes real order submission timing or
behavior, even subtly — if Option A is chosen, the real implementation
must be a pure pass-through with no behavior change.
## TESTS (required)
1. A regression test proving the current (correct) behavior: no
`SetStopLoss` call for `_runnerSignalName` after its `SetTrailStop`
call. This is the test GAP-054 asked for and didn't get.
2. Whichever seam is chosen, a test proving the seam itself doesn't alter
real call behavior (e.g. the real implementation forwards to the actual
NinjaScript call unchanged).
## VALIDATION (operator)
None required — test-only change, zero order-flow/risk/sizing behavior
change.
## GOVERNANCE
Track as [GAP-057] in SPRINT_BOARD.md. Update `docs/00-governance/decisions.md`
`DEC-20260821-01` status to note GAP-057 implemented, which seam option was
chosen and why.
Reference: this task, `DEC-20260821-01`, `TASK_GAP054_RUNNER_TRAIL_PROMPT.md`.

View File

@@ -106,7 +106,8 @@ Use this file to record durable project decisions that affect implementation pat
- **Decision:** Track both, do not action either as part of GAP-054. No operator decision required to log them. - **Decision:** Track both, do not action either as part of GAP-054. No operator decision required to log them.
- **Related Files:** `src/NT8.Adapters/Strategies/NT8StrategyBase.cs`, `TASK_GAP054_RUNNER_TRAIL_PROMPT.md` - **Related Files:** `src/NT8.Adapters/Strategies/NT8StrategyBase.cs`, `TASK_GAP054_RUNNER_TRAIL_PROMPT.md`
- **GAP-056 Implementation Note (2026-08-25):** Implemented Option A for the inert breakeven parameters. `EnableAutoBreakeven`, `BreakevenTriggerTicks`, and `BreakevenOffsetTicks` remain declared/defaulted for saved workspace and settings compatibility, but are now `[Browsable(false)]` and their `Display` descriptions state they are currently unused. `SimpleORBNT8` settings export now labels the values as `UNUSED (retained for compatibility)`. This is reversible and avoids breaking persisted templates; Option B removal was not chosen because there was no concrete need to delete the fields and no benefit worth risking workspace/settings references. Added source-level tests proving the properties are hidden/marked unused and not read by `OnBarUpdate()` or `SubmitOrderToNT8()`. Verification: focused GAP-056 tests passed 3/3; `verify-build.bat` passed with 555/555 tests (466 Core, 79 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 466/466. Deploy intentionally skipped by task prompt. - **GAP-056 Implementation Note (2026-08-25):** Implemented Option A for the inert breakeven parameters. `EnableAutoBreakeven`, `BreakevenTriggerTicks`, and `BreakevenOffsetTicks` remain declared/defaulted for saved workspace and settings compatibility, but are now `[Browsable(false)]` and their `Display` descriptions state they are currently unused. `SimpleORBNT8` settings export now labels the values as `UNUSED (retained for compatibility)`. This is reversible and avoids breaking persisted templates; Option B removal was not chosen because there was no concrete need to delete the fields and no benefit worth risking workspace/settings references. Added source-level tests proving the properties are hidden/marked unused and not read by `OnBarUpdate()` or `SubmitOrderToNT8()`. Verification: focused GAP-056 tests passed 3/3; `verify-build.bat` passed with 555/555 tests (466 Core, 79 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 466/466. Deploy intentionally skipped by task prompt.
- **Action Required:** GAP-056 complete. GAP-057 remains ready as the remaining follow-up from this decision. - **GAP-057 Implementation Note (2026-08-25):** Implemented Option B, a source-text regression seam, because extracting a real `IOrderManagementCalls` wrapper would require routing live NinjaScript `SetStopLoss`/`SetTrailStop`/entry calls through new production indirection inside `SubmitOrderToNT8`, creating unnecessary order-timing risk for a test-only task. Added `NT8StrategyBaseRunnerTrailTests`: one test proves no `SetStopLoss(_runnerSignalName...)` appears after the runner `SetTrailStop(_runnerSignalName...)` calls in `SubmitOrderToNT8`; one proves the post-entry runner monitor in `OnBarUpdate()` contains no `SetStopLoss`/`SetTrailStop` calls; one proves the source-text seam did not add an order-management wrapper and the real implementation still uses direct NinjaScript managed-order calls. No production source changed for GAP-057. Verification: focused GAP-057 tests passed 3/3; `verify-build.bat` passed with 558/558 tests (469 Core, 79 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 469/469. Deploy intentionally skipped by task prompt.
- **Action Required:** GAP-056 and GAP-057 complete. GAP-054 still requires SIM/replay validation before RUNNER-001 or live gate evidence.
### DEC-20260819-01 ### DEC-20260819-01
- **ID:** DEC-20260819-01 - **ID:** DEC-20260819-01

View File

@@ -0,0 +1,112 @@
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace NT8.Core.Tests.Adapters
{
[TestClass]
public class NT8StrategyBaseRunnerTrailTests
{
[TestMethod]
public void SubmitOrderToNT8_RunnerSignal_DoesNotSetStopLossAfterTrailStop()
{
string source = File.ReadAllText(FindStrategyBaseSourceFile());
string submitOrder = ExtractMethodBlock(source, "private void SubmitOrderToNT8");
string runnerBlock = ExtractBlockStartingAt(submitOrder, "if (useRunnerLeg)");
int initialStop = runnerBlock.IndexOf("SetStopLoss(_runnerSignalName", StringComparison.Ordinal);
int atrTrail = runnerBlock.IndexOf("SetTrailStop(_runnerSignalName", StringComparison.Ordinal);
int fixedTrail = runnerBlock.LastIndexOf("SetTrailStop(_runnerSignalName", StringComparison.Ordinal);
Assert.IsTrue(initialStop >= 0, "Runner entry must still arm an initial protective stop before the trail takes over.");
Assert.IsTrue(atrTrail >= 0, "Runner entry must still arm a trailing stop for the runner signal.");
Assert.IsTrue(initialStop < atrTrail, "The only runner SetStopLoss call must occur before SetTrailStop at entry.");
Assert.IsTrue(fixedTrail >= atrTrail, "Expected at least one runner SetTrailStop call.");
string afterLastTrail = runnerBlock.Substring(fixedTrail + "SetTrailStop(_runnerSignalName".Length);
Assert.IsFalse(afterLastTrail.Contains("SetStopLoss(_runnerSignalName"), "Regression: SetStopLoss after SetTrailStop would clobber the runner trailing stop for the same signal.");
}
[TestMethod]
public void OnBarUpdate_RunnerMonitor_DoesNotResetRunnerStopsAfterEntry()
{
string source = File.ReadAllText(FindStrategyBaseSourceFile());
string onBarUpdate = ExtractMethodBlock(source, "protected override void OnBarUpdate");
string runnerMonitor = ExtractBlockStartingAt(onBarUpdate, "if (_runnerActive && !string.IsNullOrEmpty(_runnerSignalName) && Position.Quantity != 0)");
Assert.IsFalse(runnerMonitor.Contains("SetStopLoss("), "Runner monitor must not call SetStopLoss after entry.");
Assert.IsFalse(runnerMonitor.Contains("SetTrailStop("), "Runner monitor must not call SetTrailStop after entry.");
Assert.IsTrue(runnerMonitor.Contains("Do NOT call SetStopLoss here either"), "Runner monitor should retain the regression guard comment explaining the managed-order clobber risk.");
}
[TestMethod]
public void SourceTextSeam_DoesNotAddOrderManagementIndirection()
{
string source = File.ReadAllText(FindStrategyBaseSourceFile());
string submitOrder = ExtractMethodBlock(source, "private void SubmitOrderToNT8");
string runnerBlock = ExtractBlockStartingAt(submitOrder, "if (useRunnerLeg)");
Assert.IsFalse(source.Contains("IOrderManagementCalls"), "GAP-057 selected source-text coverage, not a production order-management wrapper.");
Assert.IsFalse(source.Contains("OrderManagementCalls"), "GAP-057 selected source-text coverage, not a production order-management wrapper.");
Assert.IsTrue(runnerBlock.Contains("SetStopLoss(_runnerSignalName, CalculationMode.Ticks, (int)intent.StopTicks, false)"), "The real runner implementation must still call NinjaScript SetStopLoss directly.");
Assert.IsTrue(runnerBlock.Contains("SetTrailStop(_runnerSignalName, CalculationMode.Ticks"), "The real runner implementation must still call NinjaScript SetTrailStop directly.");
Assert.IsTrue(runnerBlock.Contains("EnterLong(runnerQty, _runnerSignalName)"), "The real runner implementation must still submit long runner entries directly.");
Assert.IsTrue(runnerBlock.Contains("EnterShort(runnerQty, _runnerSignalName)"), "The real runner implementation must still submit short runner entries directly.");
}
private static string FindStrategyBaseSourceFile()
{
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);
return ExtractBracedBlock(source, start);
}
private static string ExtractBlockStartingAt(string source, string startText)
{
int start = source.IndexOf(startText, StringComparison.Ordinal);
if (start < 0)
Assert.Fail("Source does not contain block: " + startText);
return ExtractBracedBlock(source, start);
}
private static string ExtractBracedBlock(string source, int start)
{
int brace = source.IndexOf("{", start, StringComparison.Ordinal);
if (brace < 0)
Assert.Fail("Block has no opening brace.");
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("Block has no closing brace.");
return string.Empty;
}
}
}