Skip to content

Commit e4fa557

Browse files
Pigbibicodex
andcommitted
fix: handle unbounded JSON integers
Co-Authored-By: Codex <noreply@openai.com>
1 parent 8b79647 commit e4fa557

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/quant_platform_kit/strategy_spec/validation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,11 @@ def _parse_datetime(value: str) -> datetime | None:
455455

456456

457457
def _is_number(value: Any) -> bool:
458-
return isinstance(value, (int, float)) and not isinstance(value, bool) and math.isfinite(value)
458+
if isinstance(value, bool):
459+
return False
460+
if isinstance(value, int):
461+
return True
462+
return isinstance(value, float) and math.isfinite(value)
459463

460464

461465
def _is_int(value: Any) -> bool:

tests/test_strategy_spec_validation.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ def test_optimization_spec_rejects_schema_invalid_optional_parameter_fields_and_
284284
assert "promotion.max_fractional_kelly must be a number in (0, 1)" in issues
285285

286286

287+
def test_optimization_spec_handles_huge_json_integers_without_crashing() -> None:
288+
payload = _optimization_spec()
289+
promotion = payload["promotion"]
290+
assert isinstance(promotion, dict)
291+
promotion["max_fractional_kelly"] = 10**1000
292+
293+
assert "promotion.max_fractional_kelly must be a number in (0, 1)" in validate_optimization_spec(payload)
294+
295+
287296
def test_file_and_cli_validation_are_evidence_gate_friendly(tmp_path: Path) -> None:
288297
valid_path = tmp_path / "research-spec.json"
289298
valid_path.write_text(json.dumps(_research_spec()), encoding="utf-8")

0 commit comments

Comments
 (0)