Display executionPlan in UI; add tests for Trader executionPlan parsing and TradingGraph execution step

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-05-16 13:53:04 +02:00
parent 98c1e366a5
commit b9711f2517
3 changed files with 262 additions and 1 deletions
+28
View File
@@ -36,4 +36,32 @@ describe("Trader", () => {
const decision = await trader.decide("AAPL", mockReports, mockDebates);
expect(decision.action).toBe("buy");
});
it("parses executionPlan on sell", async () => {
const mockSellClient = {
createChatCompletion: vi.fn().mockResolvedValue({
choices: [{ message: { content: JSON.stringify({
action: "sell",
confidence: 0.9,
reasoning: "Exit position",
executionPlan: {
amount: 50,
riskManagement: { maxLossPercent: 1.5, method: "trailing" },
takeProfit: 150,
note: "Test plan"
}
}) } }]
}),
};
const trader = new Trader(mockSellClient as any);
const decision = await trader.decide("AAPL", mockReports, mockDebates);
expect(decision.action).toBe("sell");
expect(decision.executionPlan).toBeDefined();
expect(decision.executionPlan?.amount).toBe(50);
expect(decision.executionPlan?.takeProfit).toBe(150);
expect(decision.executionPlan?.riskManagement?.maxLossPercent).toBe(1.5);
});
});
});
@@ -0,0 +1,30 @@
import { describe, it, expect, vi } from "vitest";
import { TradingGraph } from "../tradingGraph";
describe("TradingGraph execution step", () => {
it("returns executionPlan when model provides it", async () => {
const mockClient = {
createChatCompletion: vi.fn().mockResolvedValue({
choices: [{ message: { content: JSON.stringify({
action: "sell",
confidence: 0.85,
reasoning: "Test sell",
executionPlan: { amount: 100, riskManagement: { maxLossPercent: 2 }, takeProfit: 200 }
}) } }]
}),
};
const mockInput = {
financialData: "...",
technicalData: { prices: [1,2,3], sma: 1, ema: 1, rsi: 50, macd: 0 },
sentimentData: { headlines: ["h"], source: "news" },
};
const graph = new TradingGraph(mockClient as any);
const decision = await graph.propagate("AAPL", mockInput as any);
expect(decision.action).toBe("sell");
expect(decision.executionPlan).toBeDefined();
expect(decision.executionPlan?.amount).toBe(100);
});
});