Portierung der beiden fehlenden Grundbausteine aus PolytraderSharp (voller Ausbau). Core S-0 (Datenfundament fuer Analyse/Forensik): - core_decision_journal + core_order_events (+ ReasonCode/Decision/OrderEvent-Enums), IDecisionJournal/IOrderEventLog mit fehlertoleranten EF-Impls (Handel bricht nie). - SignalId-Durchreichung TradeSignal -> ExecutionService -> core_trade_history; ExecutionService schreibt an jeder Verzweigung Journal/Order-Events. - JSONL-Log-Sink (LogJson + Dual-Sink), pure Analytik: RealizedPnlEngine (FIFO), TradeAnalytics, DossierBuilder. Migration AddAnalysisFoundation. Accounting-Modul (acc_): unabhaengiger IBKR-Kontoauszug (Activity Flex Query) hinter Interfaces mit Offline-Null-Stubs -> append-only Ledger + Periodenabrechnung/BWA + FX (USD/EUR) + CSV/PDF (PDFsharp/MigraDoc). Steuerschicht bewusst offen (Platzhalter-Tab). Kein Handel. Migration InitialAccounting. Supervisor-Modul (sup_): read-only OpenRouter-Agent (Function-Calling-Loop) + read-only Tool-Registry (8 Tools) + Profile + Dossier-Browser + Counterfactual-Job (Stub) + Tagesbericht/MCP-Light (opt-in). Migration InitialSupervisor. Verdrahtung: Program.cs (beide Module + Icons), slnx/App/Tests-Referenzen, provision-db.ps1, AppSettings-Sektionen, docs/konzepte, README. Tests: 79 -> 117 gruen (FIFO/KPIs/Dossier/JSONL, Classifier/Engine/FX/Idempotenz, OpenRouter/Registry/Agent/MCP, STA-Konstruktion beider neuen Fenster). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using FluentAssertions;
|
|
using IBKRTrader.Modules.Supervisor.Agent;
|
|
|
|
namespace IBKRTrader.Tests.Modules.Supervisor;
|
|
|
|
[Trait("cat", "unit")]
|
|
public class OpenRouterClientTests
|
|
{
|
|
private static SupervisorTool Tool() => new(
|
|
"get_kpis", "KPIs", """{"type":"object","properties":{"module":{"type":"string"}}}""", _ => "{}");
|
|
|
|
[Fact]
|
|
public void BuildRequestBody_IncludesModelMessagesAndTools()
|
|
{
|
|
var messages = new[] { ChatMessage.System("sys"), ChatMessage.User("frage?") };
|
|
var body = OpenRouterClient.BuildRequestBody("openrouter/auto", messages, new[] { Tool() });
|
|
|
|
body.Should().Contain("\"model\":\"openrouter/auto\"");
|
|
body.Should().Contain("\"role\":\"system\"");
|
|
body.Should().Contain("frage?");
|
|
body.Should().Contain("\"name\":\"get_kpis\"");
|
|
body.Should().Contain("\"parameters\"");
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseResponse_ExtractsContentAndUsage()
|
|
{
|
|
const string json = """
|
|
{"choices":[{"message":{"content":"Antwort","role":"assistant"}}],
|
|
"usage":{"prompt_tokens":12,"completion_tokens":3}}
|
|
""";
|
|
|
|
var r = OpenRouterClient.ParseResponse(json);
|
|
|
|
r.Content.Should().Be("Antwort");
|
|
r.ToolCalls.Should().BeEmpty();
|
|
r.PromptTokens.Should().Be(12);
|
|
r.CompletionTokens.Should().Be(3);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseResponse_ExtractsToolCalls()
|
|
{
|
|
const string json = """
|
|
{"choices":[{"message":{"role":"assistant","content":null,
|
|
"tool_calls":[{"id":"call_1","type":"function","function":{"name":"get_kpis","arguments":"{\"module\":\"CT\"}"}}]}}]}
|
|
""";
|
|
|
|
var r = OpenRouterClient.ParseResponse(json);
|
|
|
|
r.ToolCalls.Should().HaveCount(1);
|
|
r.ToolCalls[0].Name.Should().Be("get_kpis");
|
|
r.ToolCalls[0].ArgumentsJson.Should().Contain("CT");
|
|
}
|
|
}
|