Skip to content

"Vibe-Trading: Your Personal Trading Agent"

test: verify journal constraints and report entry paths

Haozhe Wudd23c324a628
diff --git a/agent/tests/test_constraints.py b/agent/tests/test_constraints.py
index 1f1f71474..583db5d88 100644
--- a/agent/tests/test_constraints.py
+++ b/agent/tests/test_constraints.py
@@ -72,6 +72,13 @@ class TestMinWeight:
w = MinWeight(0.2).apply(np.array([0.9, 0.1, 0.0]), ["A", "B", "C"])
assert w[2] == pytest.approx(0.0)
+ def test_infeasible_floor_preserves_signed_active_book(self) -> None:
+ source = pd.DataFrame([[0.02, -0.02, 0.06, 0.0]], columns=["A", "B", "C", "D"])
+ constraints = load_constraints({"constraints": [{"type": "min_weight", "floor": 0.05}]})
+ result = apply_constraints_frame(source, constraints)
+ np.testing.assert_allclose(result.iloc[0], [0.1 / 3, -0.1 / 3, 0.1 / 3, 0])
+ assert result.abs().sum(axis=1).iloc[0] == pytest.approx(0.1)
+
class TestGroupExposure:
def test_violating_group_scaled_pro_rata(self) -> None:
diff --git a/agent/tests/test_shadow_report_route_runtime_root.py b/agent/tests/test_shadow_report_route_runtime_root.py
index b19cb4641..252e637a0 100644
--- a/agent/tests/test_shadow_report_route_runtime_root.py
+++ b/agent/tests/test_shadow_report_route_runtime_root.py
@@ -30,3 +30,47 @@ def test_shadow_report_is_served_from_the_configured_runtime_root(
assert response.status_code == 200
assert "report" in response.text
+
+
+def test_rendered_report_is_readable_through_the_route(monkeypatch, tmp_path) -> None:
+ from src.shadow_account import (
+ AttributionBreakdown,
+ ShadowBacktestResult,
+ ShadowProfile,
+ render_shadow_report,
+ )
+
+ monkeypatch.setenv("VIBE_TRADING_HOME", str(tmp_path / "state-root"))
+ profile = ShadowProfile(
+ shadow_id="shadow_0123abcd",
+ created_at="2026-01-06T00:00:00Z",
+ journal_hash="fixture",
+ source_market="us",
+ profitable_roundtrips=0,
+ total_roundtrips=0,
+ date_range=("2026-01-02", "2026-01-05"),
+ profile_text="Runtime root report integration fixture",
+ rules=(),
+ preferred_markets=("us",),
+ typical_holding_days=(0.0, 0.0),
+ )
+ result = ShadowBacktestResult(
+ shadow_id=profile.shadow_id,
+ per_market={},
+ combined={},
+ equity_curves={},
+ attribution=AttributionBreakdown(0.0, 0.0, 0.0, 0.0, 0.0),
+ shadow_total_pnl=None,
+ real_total_pnl=0.0,
+ delta_pnl=None,
+ )
+ rendered = render_shadow_report(profile, result)
+ with _client() as client:
+ response = client.get(f"/shadow-reports/{profile.shadow_id}?format=html")
+ assert response.status_code == 200
+ assert response.text == Path(rendered["html_path"]).read_text(encoding="utf-8")
+ assert profile.profile_text in response.text
+ if rendered["pdf_path"]:
+ response = client.get(f"/shadow-reports/{profile.shadow_id}?format=pdf")
+ assert response.status_code == 200
+ assert response.content == Path(rendered["pdf_path"]).read_bytes()
diff --git a/agent/tests/test_trade_journal_parser_european_decimal.py b/agent/tests/test_trade_journal_parser_european_decimal.py
index 29e1bb50d..92c2c8385 100644
--- a/agent/tests/test_trade_journal_parser_european_decimal.py
+++ b/agent/tests/test_trade_journal_parser_european_decimal.py
@@ -28,3 +28,22 @@ def test_comma_decimal_with_dot_grouping(raw: str, expected: float) -> None:
)
def test_us_formats_are_unchanged(raw: str, expected: float) -> None:
assert _to_float(raw) == pytest.approx(expected)
+
+
+def test_european_amounts_reach_fifo_analysis(tmp_path, monkeypatch) -> None:
+ import csv
+ import json
+
+ from src.tools.trade_journal_tool import analyze_trade_journal
+
+ monkeypatch.setenv("VIBE_TRADING_ALLOWED_FILE_ROOTS", str(tmp_path))
+ path = tmp_path / "european-journal.csv"
+ with path.open("w", newline="", encoding="utf-8") as stream:
+ writer = csv.writer(stream)
+ writer.writerow(["datetime", "symbol", "side", "quantity", "price", "fee"])
+ writer.writerow(["2026-01-02", "AAPL", "buy", "1.000,00", "1.234,50", "1.000,25"])
+ writer.writerow(["2026-01-05", "AAPL", "sell", "1.000,00", "1.235,50", "1.000,75"])
+ result = json.loads(analyze_trade_journal(str(path), "full"))
+ assert result["status"] == "ok"
+ # 1,000 shares * 1.00 price gain - 1,000.25 entry fee - 1,000.75 exit fee.
+ assert result["profile"]["total_pnl"] == -1001.0