#!/usr/bin/env python3
"""python3 scripts/seed-issue-21397.py --home NEW_DIR [matching|absent|unrelated] [--now [ISO]] [--source DB].
Copies a migrated statev2.sqlite (default: this worktree's .t3, with dev stopped;
run dev once first to migrate it) into NEW_DIR/userdata, then replaces every
thread/project projection in that copy with a synthetic stopped usage-limit run.
The source is only read as bytes, never opened by SQLite, so it stays unchanged.
NEW_DIR must not exist and must not be under the live ~/.t3. Then run the printed
`vp run dev --home-dir NEW_DIR`.
Fixture times are frozen around the evidence clock, 2026-10-22T19:00:00Z (usage
limit hit; reset and matching snooze at 2026-10-23T08:50:00Z). By default they
are seeded unchanged, reproducing the PR captures. After that reset, pass --now
(current time) or --now ISO to shift every timestamp so the failure happens then.
"""
import argparse
import contextlib
import datetime
import json
import pathlib
import re
import shlex
import shutil
import sqlite3
EVIDENCE_CLOCK = datetime.datetime(2026, 10, 22, 19, tzinfo=datetime.timezone.utc)
ISO = re.compile(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z