sinks: feed /import/check enrichment into /import body

/import/check hydrates each ActivityImport with resolved assetId,
exchangeMic, quoteCcy, instrumentType, quoteMode. The /import endpoint
on Wealthfolio 3.2 does NOT re-resolve — passing an un-enriched row
returns 200 OK but silently drops the activity (activities=[] in the
response).

The first live run returned `imported=63 failed=0` but nothing reached
the database. Fixed by posting the hydrated rows from the check response
to /import instead of the original.

Requires the test to also return list-shaped check responses (matches
the upstream Json<Vec<ActivityImport>> signature on the Rust side).

poetry run pytest -q     70 passed
poetry run mypy          clean
poetry run ruff check    clean
This commit is contained in:
Viktor Barzin 2026-04-17 20:54:17 +00:00
parent 80ca009373
commit b363032e42
3 changed files with 47 additions and 25 deletions

View file

@ -218,14 +218,24 @@ async def test_import_dry_run_then_real(tmp_path: Path) -> None:
async def handler(req: httpx.Request) -> httpx.Response:
calls.append(req.url.path)
if req.url.path == "/api/v1/activities/import/check":
return httpx.Response(200, json={"ok": True, "rows": 1})
# /import/check hydrates and returns a list of ActivityImport.
return httpx.Response(200, json=[
{
"symbol": "VUAG",
"isValid": True,
"errors": None,
"assetId": "enriched-asset-uuid",
"exchangeMic": "XLON",
},
])
if req.url.path == "/api/v1/activities/import":
return httpx.Response(
200,
json=[{
"id": "wf-1",
"external_id": "t212:1"
}],
json={
"activities": [
{"id": "wf-1", "external_id": "t212:1"},
],
},
)
return httpx.Response(500)

View file

@ -83,17 +83,21 @@ async def test_pipeline_skips_dedup_then_imports_new(tmp_path: Path) -> None:
}],
)
if req.url.path == "/api/v1/activities/import/check":
return httpx.Response(200, json={"ok": True})
body = json.loads(req.content)
# Echo each activity back marked valid (mimic Wealthfolio's
# hydrate step).
return httpx.Response(200, json=[
{**a, "isValid": True, "errors": None} for a in body["activities"]
])
if req.url.path == "/api/v1/activities/import":
body = req.content.decode()
posted_batches.append(body)
# Echo back external_ids so dedup.record gets the WF activity id.
return httpx.Response(
200,
json=[{
"id": f"wf-{i}",
"external_id": ext
} for i, ext in enumerate(["a", "b", "c"])],
json={"activities": [
{"id": f"wf-{i}", "external_id": ext}
for i, ext in enumerate(["a", "b", "c"])
]},
)
return httpx.Response(500)