Run artifact

workspace/targets/FxRates/blueprint/FEATURE-Load.md

FEATURE: ECB CSV Loading

FieldValue
Version20261026 V1
DescriptionValidates and loads ECB history CSV files atomically while preserving published rate text.
Depends OnFEATURE-CLI.md, DATABASE.md

Purpose

./fxrates load <csv> reads an ECB history file, validates the entire file before its first database write, then stores every rate other than N/A. A valid rate replaces the stored value for the same publication date and currency. On success, print CSV output with header dates,rates and one data row containing the number of dates with at least one rate and the number of rates stored from this file.

CSV Rules

Database Interface

Programmatic Acceptance

=== AC load-valid-file ===
Intent: Loading the supplied January history succeeds and reports the fixture-derived date and rate counts. import csv from cli.testing import cli_runner

path = "sources/eurofxref-hist_2025-01.csv" code, stdout, stderr = cli_runner("load", path) rows = list(csv.reader(stdout.splitlines())) assert code == 0 assert rows[0] == ["dates", "rates"] assert rows[1] == [str(22), str(22 * 8)] === END AC load-valid-file ===

=== AC load-rejects-atomically ===
Intent: A rejected CSV file leaves the rates it would otherwise have changed untouched. from cli.testing import cli_runner from persistence.testing import db_session

date = "2025-02-04" currency = "USD" rate = "9.876"

with db_session() as db: seeded = db.rates.upsert(date=date, currency=currency, rate=rate) assert seeded.rate == rate code, stdout, stderr = cli_runner("load", "sources/eurofxref-hist_bad.csv") stored = db.rates.by_date(date=date) assert code == 3 assert stdout == "" assert any(row.currency == currency and row.rate == rate for row in stored) === END AC load-rejects-atomically ===

=== AC load-replaces-published-text ===
Intent: Loading a valid file stores its rate text exactly and replaces a matching stored rate. from cli.testing import cli_runner from persistence.testing import db_session

date = "2025-01-31" currency = "USD" published = "1.0393" prior = "9.876"

with db_session() as db: seeded = db.rates.upsert(date=date, currency=currency, rate=prior) assert seeded.rate == prior code, stdout, stderr = cli_runner("load", "sources/eurofxref-hist_2025-01.csv") stored = db.rates.by_date(date=date) found = next(row for row in stored if row.currency == currency) assert code == 0 assert found.rate == published === END AC load-replaces-published-text ===

User Acceptance

Guardrails