I want to see the file the agent made

Test an agent's CSV export with Python. Catch duplicate rows, closed tickets and stale downloads using two sample records.

Two LinkedIn drafts passed a model review. I read them and didn't want to publish either. With writing, I sometimes need a second read to work out what bothers me. With software, I can often decide what the answer should be before the agent starts.

Here's a test you can run with Python 3. You'll check whether an agent exported exactly the open tickets. Then you'll deliberately break the file and see which check catches it.

Start with two tickets

A ticket has an ID and a status. Give your test system two tickets: A17 is open and B24 is closed. Ask the agent to export open tickets as a CSV, a plain text file with a header line followed by one line per record. Save the download as open.csv. To try this without a ticket system, create that file yourself:

id,status
A17,open

Read the requirement literally. The file needs the columns id and status. A17 belongs in it once. B24 does not belong in it at all. That's our expected result. We worked it out from the two source tickets, independently of whatever the agent tells us.

Read the actual download

Save this next to the CSV as check_export.py. It uses only Python's standard library.

import csv
import sys
from collections import Counter

filename, *open_ids = sys.argv[1:]
with open(filename, encoding="utf-8-sig", newline="") as file:
    reader = csv.DictReader(file)
    if reader.fieldnames != ["id", "status"]:
        raise SystemExit(f"Wrong header: {reader.fieldnames!r}")
    rows = list(reader)

expected = Counter((ticket_id, "open") for ticket_id in open_ids)
if any(None in row or None in row.values() for row in rows):
    raise SystemExit("A row has extra or missing fields")
actual = Counter((row["id"], row["status"]) for row in rows)
if actual != expected:
    raise SystemExit(
        f"Missing: {dict(expected - actual)}; "
        f"unexpected: {dict(actual - expected)}"
    )
print(f"PASS (data rows: {len(rows)})")

Run python check_export.py open.csv A17. You should see PASS (data rows: 1). The last argument says which ticket you expect to be open. The script gets the actual IDs and statuses from the download. If it got both answers from the download, a broken export could agree with itself.

Break it on purpose

Add a second A17,open line. Run the same command. This time the check reports one unexpected ('A17', 'open'). That's why I used Counter: it remembers how many copies of a row it saw. A set would turn two identical rows into one and let this bug through.

Remove the duplicate, then append B24,closed. Run it again. Now B24 is the unexpected row. If you delete A17 instead, the message also tells you what's missing. Checking only the number of rows would miss a one-for-one swap.

Make sure you're seeing fresh data

Close A17 in the test system, export again, and save the new download as closed.csv. If you're following by hand, create a second file with just the line id,status. Run python check_export.py closed.csv with no IDs. You should get PASS (data rows: 0). An empty result still has to be a readable CSV with the agreed header.

Now try the same command against your original one-row file. It fails because A17 is still there. That's what this test catches if the agent hands you yesterday's download. It doesn't tell you whether the browser reused a file or the export read stale data. It gives you the two files, the changed input and a failure someone else can reproduce. That's the handoff I'd ask for.

The team guide · My original notes on testing coding agents · Working with Lightbulb Partners