`export_job.py` is not ready to merge tomorrow: a failed export looks like a success to cron, and that day's invoices are then never sent to finance. The fixes are small, about half a day including tests, so the file is close.

I reviewed by reading the code only; nothing was run. `test_export_job.py`, which the docstring names, is not in this folder, so I could not check the tests.

## Blocking

**1. Failures are swallowed, and the missed day cannot be recovered (high).**
- **Evidence:** `export_job.py:56-57` catches every exception, logs one line and lets the process exit with code 0.
- **Concrete case:** the finance endpoint returns 503 at 02:00 on Tuesday. `raise_for_status()` raises, the job logs "export failed", and cron records success. On Wednesday the job exports only Tuesday's invoices (`export_job.py:47`), so Monday's are never sent.
- **Fix:** log with `log.exception` and re-raise (or `sys.exit(1)`), and accept an optional date argument so a missed day can be re-run.

**2. The upload has no timeout (high).**
- **Evidence:** `requests.post(UPLOAD_URL, files=...)` at `export_job.py:42` has no `timeout`.
- **Impact:** if the endpoint accepts the connection and stalls, the job hangs indefinitely while holding the database connection, and nothing is logged.
- **Fix:** add `timeout=(10, 120)` or similar.

**3. Customer emails are written to the log (high, privacy).**
- **Evidence:** `export_job.py:52` logs `[row[1] for row in rows]`, which is every customer email in the export.
- **Fix:** log the count and the day only.

**4. Tests do not cover the parts that can fail (high against your own standards).**
- **Evidence:** the docstring says the tests cover "CSV header and one row". Nothing covers the date window, an upload failure or `run()`.
- **Minimum to add:**
  - `fetch_invoices` passes the right start and end bounds.
  - `run()` exits non-zero when the upload fails.
  - Amount formatting (see 6).
  - An empty day.

## Should fix, can follow shortly after merge

**5. "Yesterday" depends on the server's and the database's time zones (medium).**
- **Evidence:** `date.today()` at `export_job.py:47` uses the cron host's local time. The query at `export_job.py:21` compares `paid_at` to a bare date, which Postgres reads as midnight in the session time zone.
- **Concrete case:** if the host is UTC and finance works in IST, an invoice paid at 01:00 IST on the 14th lands in the file for the 13th.
- **Fix:** choose the business time zone explicitly and pass timezone-aware bounds.

**6. Amounts are formatted inconsistently (medium).**
- **Evidence:** `amount_cents / 100` at `export_job.py:37` produces a float.
- **Concrete case:** 1000 cents is written as `10.0` and 50 cents as `0.5`, where finance would expect `10.00` and `0.50`.
- **Fix:** `f"{amount_cents // 100}.{amount_cents % 100:02d}"` or `Decimal`.

**7. INFO log lines are not emitted when cron runs the file (medium).**
- **Evidence:** logging is never configured, so only WARNING and above reach stderr, unformatted. The "exporting" and "export finished" lines are dropped.
- **Fix:** call `logging.basicConfig(level=logging.INFO)` under `__main__`.

**8. CSV files containing customer emails accumulate in `/var/exports` (medium).**
- **Evidence:** `export_job.py:33` writes with default permissions, and nothing deletes the file.
- **Fix:** restrict permissions, and delete after a successful upload or add a retention rule.

## Minor

- **Import-time environment read:** `UPLOAD_URL = os.environ[...]` at `export_job.py:16` means importing the module in a test raises `KeyError` unless the variable is set. Read it inside `upload()` or pass it in.
- **File encoding:** `open(path, "w")` does not set `encoding="utf-8"`, so the encoding depends on cron's locale.
- **Hardcoded directory:** `EXPORT_DIR` is fixed and assumed to exist.

## Speculative, worth a quick check

- **Non-two-decimal currencies:** the query selects `currency`, but the code always divides by 100. That is wrong for JPY (no decimals) or KWD (three), if you bill in them.
- **Null amounts:** if `amount_cents` or `paid_at` can be NULL on a PAID invoice, line 37 raises and the whole day's export fails.
- **Upload authentication:** the upload sends no auth header. That is fine only if the URL carries a token or the network is restricted.
- **Duplicate uploads:** once re-runs exist, confirm the finance endpoint tolerates the same day's file twice.
- **Empty days:** a day with no paid invoices uploads a header-only file. Confirm finance wants that.
- **Spreadsheet formulas:** an email starting with `=` or `+` is treated as a formula if finance opens the CSV in Excel.

VERDICT: NOT READY
