File size: 2,533 Bytes
11330a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
"""Regression: a portable bundle validates and reconstructs its WebM bytes."""
import base64
import json
import subprocess
import sys
import tempfile
from pathlib import Path

root = Path(__file__).resolve().parents[1]
webm = b'\x1a\x45\xdf\xa3\x93\x42\x82\x84webm'  # minimal EBML signature for bundle transport validation
bundle = {
    'version': 2, 'schema': 'notepilot.debug-bundle/v2', 'meta': {
        'score': 'test', 'inputMode': 'mic', 'userAgent': 'test',
        'scoreEvents': {'solo': [{'scoreEventId': 0}], 'accompaniment': []},
        'follower': {'options': {'test': True}}, 'micEngine': 'follower', 'latency': {'effectiveMs': 1},
    },
    'clocks': {'master': 'sessionTimeMs'},
    'schemaDocumentation': {'sal': 'test'},
    'events': [
        {'type': 'session.start', 'sessionTimeMs': 0},
        {'type': 'mic.gateCalibration', 'sessionTimeMs': 1},
        {'type': 'blind.pitch', 'sessionTimeMs': 2, 'blindPitch': {'valid': True}},
        {'type': 'tracker', 'sessionTimeMs': 3},
        {'type': 'mic.gate', 'sessionTimeMs': 3.5, 'state': 'open'},
        {'type': 'follow.frame', 'sessionTimeMs': 4, 'db': -20},
    ], 'diagnostics': {'timeline': [{'tMs': 4, 'db': -20, 'gateOpen': True, 'onsetValue': 1, 'blindMidi': 60, 'expectedMidi': 60, 'posterior': .9, 'wrongProbability': .01, 'noiseFloorDb': -40, 'committedPosterior': .8, 'evidenceNats': 2, 'attack': True}]},
    'analysis': {'attempts': [], 'falseAdvances': [], 'autoSkips': [], 'resyncs': [], 'hostRejections': [], 'missedAttempts': []},
    'audio': {'microphone': {'codec': 'audio/webm;codecs=opus', 'sampleRate': 48000, 'channels': 1, 'durationMs': 4, 'captureStartSessionMs': 0, 'captureEndSessionMs': 4, 'bytes': len(webm), 'base64': base64.b64encode(webm).decode()},
              'digitalOutput': {'kind': 'EXACT_EVENT_MANIFEST', 'events': 'audio.note', 'captured': False}},
}
with tempfile.TemporaryDirectory() as td:
    path = Path(td) / 'bundle.json'; path.write_text(json.dumps(bundle))
    subprocess.run([sys.executable, root / 'scripts/validate_debug_bundle.py', path], check=True)
    out = Path(td) / 'audio'
    subprocess.run([sys.executable, root / 'scripts/extract_debug_audio.py', path, out], check=True)
    assert (out / 'mic.webm').read_bytes() == webm
    plots = Path(td) / 'plots'
    subprocess.run([sys.executable, root / 'scripts/plot_debug_bundle.py', path, plots], check=True)
    assert len(list(plots.glob('*.svg'))) == 4
print('PASS: debug bundle validation and audio extraction')