Files
dj/integration-work/verify_storyboard_jobs_deployment.py
T
2026-11-13 11:46:25 +08:00

85 lines
5.2 KiB
Python

"""Read-only deployment audit; allow active video tasks to advance naturally."""
import hashlib
import json
import pathlib
import sqlite3
import urllib.request
ROOT = pathlib.Path(__file__).resolve().parent.parent
BACKUP = pathlib.Path((ROOT / 'integration-work/current-upgrade-backup.txt').read_text('utf-8').strip())
def connect(path):
connection = sqlite3.connect(path.as_uri() + '?mode=ro', uri=True)
connection.row_factory = sqlite3.Row
return connection
with connect(BACKUP / 'huobao-data/huobao.sqlite3') as before, connect(ROOT / 'huobao-data/huobao.sqlite3') as after:
assert after.execute('pragma integrity_check').fetchone()[0] == 'ok'
prior_job_row=before.execute("select value from app_settings where key='storyboard_job:8'").fetchone()
prior_job=json.loads(prior_job_row[0]) if prior_job_row else None
current_job_row=after.execute("select value from app_settings where key='storyboard_job:8'").fetchone()
assert (current_job_row[0] if current_job_row else None)==(prior_job_row[0] if prior_job_row else None), 'Existing split record changed'
unchanged = []
for table in ('dramas', 'episodes', 'ai_service_configs', 'style_presets',
'episode_characters', 'episode_scenes', 'episode_props',
'storyboard_characters', 'storyboard_props'):
query = f'select * from "{table}" order by rowid'
assert [tuple(r) for r in before.execute(query)] == [tuple(r) for r in after.execute(query)], table
unchanged.append(table)
# Preserve every existing asset and storyboard field. Video workers may
# finish during startup and update only these delivery/status columns.
changed = {}
for table in ('storyboards', 'characters', 'scenes', 'props'):
live = {r['id']: dict(r) for r in after.execute(f'select * from "{table}"')}
delta = []
for old in before.execute(f'select * from "{table}"'):
assert old['id'] in live, (table, old['id'], 'missing')
new = live[old['id']]
fields = [k for k in old.keys() if old[k] != new[k]]
allowed = {'updated_at', 'status', 'video_url', 'image_url', 'local_path'}
assert set(fields) <= allowed, (table, old['id'], fields)
if fields:
delta.append({'id': old['id'], 'fields': fields})
changed[table] = delta
live_tasks = {r['id']: dict(r) for r in after.execute('select * from sys_task')}
active = []
for task in before.execute('select * from sys_task'):
assert task['id'] in live_tasks, ('task missing', task['id'])
if task['status'] in ('processing', 'pending', 'running', 'queued'):
new = live_tasks[task['id']]
assert new['status'] != 'cancelled', ('task unexpectedly cancelled', task['id'])
active.append({'id': task['id'], 'before': task['status'], 'after': new['status']})
counts = {table: after.execute(f'select count(*) from "{table}"').fetchone()[0]
for table in ('dramas', 'episodes', 'storyboards', 'ai_service_configs', 'style_presets')}
manifest = json.loads((BACKUP / 'manifest.json').read_text('utf-8'))
media = [item for item in manifest['data_files'] if item['path'].startswith('static/')]
for item in media:
path = ROOT / 'huobao-data' / item['path']
assert path.is_file() and hashlib.sha256(path.read_bytes()).hexdigest() == item['sha256'], item['path']
runtime = ROOT / 'HuobaoDrama/resources'
build = json.loads((runtime / 'huobao-local-build.json').read_text('utf-8'))
assert 'tracked-storyboard-jobs-atomic-bilingual-save' in build['custom_features']
assert 'storyboard-section-coverage-and-dialogue-timing' in build['custom_features']
assert hashlib.sha256((runtime / 'app.asar').read_bytes()).hexdigest() == build['archive_sha256']
frontend = ROOT / 'huobao-source/frontend/.output/public'
for path in frontend.rglob('*'):
if path.is_file():
assert path.read_bytes() == (runtime / 'frontend' / path.relative_to(frontend)).read_bytes(), str(path)
launch = json.loads((ROOT / 'huobao-data/last-launch.json').read_text('utf-8'))
with urllib.request.urlopen(launch['api'] + '/health', timeout=10) as response:
assert response.status == 200
with urllib.request.urlopen(launch['api'] + '/agent/storyboard_breaker/jobs/8', timeout=10) as response:
status = json.load(response)
assert 'data' in status, 'Split job route missing'
assert (status['data'] or {}).get('id')==(prior_job or {}).get('id'), 'Unexpected new production split job'
if prior_job and prior_job.get('status')=='done' and not prior_job.get('sections') and prior_job.get('seconds',0)<prior_job.get('targetSeconds',0)*.8:
assert status['data'].get('qualityWarning'), 'Old compressed split must show warning'
report = {'passed': True, 'backup': str(BACKUP), 'unchanged_tables': unchanged,
'runtime_field_changes': changed, 'existing_tasks_retained': len(live_tasks),
'active_tasks': active, 'counts': counts, 'media_files_unchanged': len(media),
'archive_sha256': build['archive_sha256'], 'frontend_identical': True,
'health': 'ok', 'new_route': 'ok', 'production_model_jobs_started': 0}
(ROOT / 'integration-work/storyboard-jobs-deployed-audit.json').write_text(json.dumps(report, indent=2), 'utf-8')
print(json.dumps(report))