Skip to content

Commit 5ee003e

Browse files
test(web): issue 21397 seeder needs --replace and can shift its clock
The seeder now refuses to clear worktree projections without --replace, and --now shifts every fixture timestamp so the matching snooze still reproduces after the 2026-10-23 reset. The default keeps the captured evidence clock. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cf9f49d commit 5ee003e

1 file changed

Lines changed: 46 additions & 10 deletions

File tree

‎scripts/seed-issue-21397.py‎

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,55 @@
11
#!/usr/bin/env python3
2-
"""With dev stopped: python3 scripts/seed-issue-21397.py [matching|absent|unrelated].
2+
"""With dev stopped: python3 scripts/seed-issue-21397.py --replace [matching|absent|unrelated] [--now [ISO]].
33
4-
Replaces isolated projection state with a synthetic stopped usage-limit run.
5-
Run dev once to initialize migrations first. Never targets the live T3 home.
4+
Replaces ALL thread/project projections in this worktree's .t3 database with a
5+
synthetic stopped usage-limit run, so --replace is required. Run dev once to
6+
initialize migrations first. Never targets the live T3 home.
7+
8+
Fixture times are frozen around the evidence clock, 2026-10-22T19:00:00Z (usage
9+
limit hit; reset and matching snooze at 2026-10-23T08:50:00Z). By default they
10+
are seeded unchanged, reproducing the PR captures. After that reset, pass --now
11+
(current time) or --now ISO to shift every timestamp so the failure happens then.
612
"""
13+
import argparse
14+
import datetime
715
import json
816
import pathlib
17+
import re
918
import sqlite3
10-
import sys
19+
20+
EVIDENCE_CLOCK = datetime.datetime(2026, 10, 22, 19, tzinfo=datetime.timezone.utc)
21+
ISO = re.compile(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$')
22+
23+
24+
def parse_iso(value):
25+
parsed = datetime.datetime.fromisoformat(value.replace('Z', '+00:00'))
26+
return parsed if parsed.tzinfo else parsed.replace(tzinfo=datetime.timezone.utc)
27+
28+
29+
def shift(value, delta):
30+
if isinstance(value, dict):
31+
return {k: shift(v, delta) for k, v in value.items()}
32+
if isinstance(value, str) and ISO.match(value):
33+
moved = parse_iso(value) + delta
34+
return moved.strftime('%Y-%m-%dT%H:%M:%S.') + f'{moved.microsecond // 1000:03d}Z'
35+
return value
36+
37+
38+
parser = argparse.ArgumentParser()
39+
parser.add_argument('mode', nargs='?', default='matching', choices=('matching', 'absent', 'unrelated'))
40+
parser.add_argument('--replace', action='store_true', help='confirm deleting existing worktree projections')
41+
parser.add_argument('--now', nargs='?', const='now', help='shift fixture times so the limit is hit at this ISO time')
42+
args = parser.parse_args()
43+
mode = args.mode
44+
now = None if args.now is None else datetime.datetime.now(datetime.timezone.utc) if args.now == 'now' else parse_iso(args.now)
45+
delta = datetime.timedelta() if now is None else now - EVIDENCE_CLOCK
1146

1247
root = pathlib.Path(__file__).resolve().parent.parent
1348
path = root / '.t3/userdata/statev2.sqlite'
1449
if not path.is_file() or path.resolve() != path.absolute():
1550
raise SystemExit('Expected a migrated, isolated worktree .t3 database')
16-
mode = sys.argv[1] if len(sys.argv) > 1 else 'matching'
17-
if mode not in ('matching', 'absent', 'unrelated'):
18-
raise SystemExit('Unknown fixture mode')
51+
if not args.replace:
52+
raise SystemExit(f'Refusing to replace thread and project projections in {path} without --replace')
1953
fixture = json.loads((root / 'scripts/fixtures/issue-21397.json').read_text())
2054
with sqlite3.connect(path) as db:
2155
# Prevent the old V1 import from bringing unrelated conversations back.
@@ -28,7 +62,7 @@
2862
db.execute("UPDATE orchestration_v2_effect_outbox SET status='cancelled' WHERE status IN ('pending','running')")
2963
for table, rows in fixture.items():
3064
for row in rows:
31-
row = dict(row)
65+
row = shift(dict(row), delta)
3266
if table == 'projection_projects':
3367
row['workspace_root'] = str(root)
3468
if table == 'orchestration_v2_projection_threads':
@@ -37,12 +71,14 @@
3771
payload['snoozedUntil'] = None
3872
elif mode == 'unrelated':
3973
payload['snoozedUntil'] = '2026-10-24T08:50:00.000Z'
40-
row['payload_json'] = json.dumps(payload)
74+
row['payload_json'] = json.dumps(shift(payload, delta))
75+
elif delta and 'payload_json' in row:
76+
row['payload_json'] = json.dumps(shift(json.loads(row['payload_json']), delta))
4177
columns = ','.join(f'"{k}"' for k in row)
4278
placeholders = ','.join('?' for _ in row)
4379
db.execute(f'INSERT INTO "{table}" ({columns}) VALUES ({placeholders})', list(row.values()))
4480
settings_path = root / '.t3/userdata/settings.json'
4581
settings = json.loads(settings_path.read_text()) if settings_path.exists() else {}
4682
settings.update(snoozeLimitedThreads=False, autoResumeLimitedThreads=False)
4783
settings_path.write_text(json.dumps(settings, indent=2) + '\n')
48-
print(f'Seeded synthetic {mode} fixture in {path}')
84+
print(f'Seeded synthetic {mode} fixture in {path} (limit hit at {now or EVIDENCE_CLOCK:%Y-%m-%dT%H:%M:%SZ})')

0 commit comments

Comments
 (0)