fix: align research metadata with live WorldQuant responses

This commit is contained in:
yuxuanhui
2026-09-08 23:32:52 +08:00
parent a6e36e50ec
commit c67031a7cb
16 changed files with 900 additions and 12 deletions
+70
View File
@@ -444,3 +444,73 @@ def test_partial_availability_and_deep_expression_fail_closed():
)
assert result["status"] == "needs_review"
assert analyze("+".join(["close"] * 2000), {"close": "MATRIX"}, set())["status"] == "invalid"
def test_real_field_detail_data_requires_explicit_instrument_context():
from app.catalog.research_metadata import normalize_availability
response = {
"id": "close",
"type": "MATRIX",
"data": [
{"region": "USA", "delay": 1, "universe": "TOP3000", "coverage": 1.0},
{"region": "EUR", "delay": 1, "universe": "TOP2500", "coverage": 1.0},
],
}
assert normalize_availability(response)["status"] == "needs_review"
result = normalize_availability(response, instrument_type="EQUITY")
assert result["status"] == "available" and result["items"] == [
SCOPE,
{**SCOPE, "region": "EUR", "universe": "TOP2500"},
]
response["data"].append({"region": "USA", "delay": 1})
assert normalize_availability(response, instrument_type="EQUITY")["status"] == "needs_review"
assert (
normalize_availability(
{"availability": [{"region": "USA", "delay": 1, "universe": "TOP3000"}]}, instrument_type="EQUITY"
)["status"]
== "needs_review"
)
async def test_field_detail_identity_mismatch_preserves_snapshot(app):
from fastapi import HTTPException
from app.catalog.contracts import Scope
from app.catalog.research_metadata import availability_key
from app.research.workspace_contracts import FieldAvailabilityInput
class WrongField:
async def field_availability(self, field_id, scope):
return {"id": "open", "data": [{"region": "USA", "delay": 1, "universe": "TOP3000"}]}
body = FieldAvailabilityInput(field_id="close", scope=Scope(**SCOPE))
key = availability_key("close", body.scope)
async with app.state.sessions.begin() as db:
service = ResearchMetadata(db, WrongField())
original = {"field_id": "close", "status": "needs_review", "items": []}
await service.publish(key, "availability", original)
with pytest.raises(HTTPException) as exc:
await service.refresh_availability(body)
assert exc.value.status_code == 502
assert (await service.get(key))["content"] == original
def test_real_seed_settings_preserve_execution_options_and_reject_unknowns():
from pydantic import ValidationError
from app.research.experiments import seed_settings
snapshot = {
"region": "USA",
"universe": "TOP3000",
"delay": 1,
"maxPosition": "ON",
"startDate": "2014-01-01",
"endDate": "2023-12-31",
}
settings = seed_settings(snapshot)
assert settings.maxPosition == "ON" and "startDate" not in settings.model_dump()
assert snapshot["startDate"] == "2014-01-01"
with pytest.raises(ValidationError):
seed_settings({**snapshot, "unknownOption": True})