`export_job.py` is not ready to merge tomorrow as it stands: a failed export looks like a success to cron, and that night's invoices are then never exported. The must-fix changes are small, so tomorrow is still achievable if they go in with tests.

I read the file only; nothing was run. `test_export_job.py`, which the docstring names, is not in the folder next to `export_job.py`, so I could not check what is tested.

## Must fix before merge

**1. A failed export is reported as success. Severity: critical.**
`run()` catches every exception, logs one line and returns normally (lines 56–57), so the process exits with code 0.
- Case: the finance endpoint returns 503 at 02:00.
- What happens: one `export failed: ...` line on stderr with no stack trace, exit code 0, cron sees success.
- Expected: a non-zero exit and a full traceback, so cron or monitoring alerts someone.
- Fix: use `log.exception(...)` and re-raise, or `sys.exit(1)`.

**2. A missed day cannot be re-exported. Severity: high.**
The day is hard-coded to "yesterday" (line 47), with no date argument.
- Case: Monday night's run fails. Tuesday night's run exports Tuesday only.
- What happens: Monday's invoices never reach finance unless someone edits the code.
- Fix: accept an optional date argument, defaulting to yesterday.

**3. The upload has no timeout. Severity: high.**
`requests.post` (line 42) waits forever if the endpoint accepts the connection and then stalls. The job hangs with the database connection open, and the next night's cron starts a second copy.
- Fix: add `timeout=(10, 120)` or similar.

**4. Customer emails are written to the log. Severity: high (privacy).**
Line 52 logs the email address of every invoice exported. This is dormant today only because of problem 5; it starts leaking as soon as logging is configured.
- Fix: log the count and day only.

**5. Logging is never configured. Severity: medium.**
There is no `logging.basicConfig` or handler setup. Run as a script, the two `log.info` lines are discarded, so there is no record that a successful run happened or how many invoices it sent.
- Fix: configure logging under `if __name__ == "__main__":`.

**6. Test coverage is too thin for a finance job. Severity: high against your standards.**
By the docstring's own account, tests cover only the CSV header and one row. Nothing covers the date window in `fetch_invoices`, an upload failure, the failure path in `run()`, or a day with no invoices. Fixes 1–3 should each arrive with a test.

## Should fix, can follow shortly after

**7. Amount formatting is inconsistent. Severity: medium.**
`amount_cents / 100` (line 37) produces a float.
- Case: 1000 cents is written as `10.0`, while 1999 cents is written as `19.99`.
- Expected: `10.00`.
- Also, dividing by 100 is wrong for currencies without two decimal places (JPY, KWD), if the service handles any.
- Fix: format with `Decimal` or `f"{cents // 100}.{cents % 100:02d}"`.

**8. "Yesterday" depends on the server's clock zone. Severity: medium.**
`date.today()` uses the machine's local time, and the query compares that date to `paid_at` in the database session's time zone. If these differ from finance's business day, invoices paid near midnight land in the neighbouring day's file. Pick the zone explicitly.

**9. Invoices recorded late are skipped for good. Severity: medium, depends on how `paid_at` is set.**
- Case: a payment confirmed at 03:00 with a `paid_at` of 23:50 the previous day. That day's export has already run, so the invoice is never in any file.
- Worth confirming whether `paid_at` can be backdated.

**10. A re-run uploads the same file again. Severity: medium, depends on the endpoint.**
If the finance endpoint does not de-duplicate by filename, a manual re-run double-counts the day. Confirm with finance.

**11. `FINANCE_UPLOAD_URL` is read at import time. Severity: low.**
Line 16 raises `KeyError` on import, so any test importing the module needs the variable set. Read it inside `upload()`, as `DATABASE_URL` is already read inside `run()`.

## Minor

- **File encoding (low):** `open(path, "w")` on line 33 uses the locale default. Under cron's minimal environment, a non-ASCII email could fail to write. Pass `encoding="utf-8"`.
- **Partial and old files (low):** a crash mid-write leaves a truncated CSV in `/var/exports`, and files holding customer emails are never deleted.
- **Spreadsheet formula injection (low):** an email starting with `=`, `+`, `-` or `@` is run as a formula if finance opens the CSV in Excel.
- **Memory (low):** `fetchall()` loads the whole day into memory; fine at current volumes, I assume.
- **No authentication visible on the upload (question):** fine if the URL carries a token or the network is private; worth confirming.
- **No retry on upload (low):** one transient network error fails the night. Acceptable once problems 1 and 2 are fixed.

VERDICT: NOT READY
