Files
ai-passport/tests/test_yao_request.py
T
hex2077 6a7f4e010b chore: 新增大量静态资源、测试桩文件与配置文件,清理旧无用资源
本次提交新增了多种字体、UI图片、音频剪辑等静态资源,添加了测试桩文件与项目配置文件,同时清理了部分已废弃的旧图片与测试桩代码文件。
2026-09-22 00:42:26 +08:00

26 lines
1.2 KiB
Python

"""Verify the compiled request packets match the documented synthetic source."""
from pathlib import Path
import re, struct
root = Path(__file__).resolve().parents[1]
source = (root / "assets/cyberyao/interpret-request.ogg").read_bytes()
packets, pending, offset = [], bytearray(), 0
while offset < len(source):
assert source[offset:offset+4] == b"OggS"
segments = source[offset+26]
sizes = source[offset+27:offset+27+segments]
pos = offset + 27 + segments
for size in sizes:
pending.extend(source[pos:pos+size]); pos += size
if size < 255:
packets.append(bytes(pending)); pending.clear()
offset = pos
assert not pending and packets[0][:8] == b"OpusHead" and packets[1][:8] == b"OpusTags"
assert packets[0][9] == 1
expected = b"".join(struct.pack("<H",len(p)) + p for p in packets[2:])
header = (root / "main/assets/yao_request.h").read_text()
actual = bytes(map(int,re.findall(r"\d+",header.split("[]={",1)[1].split("}",1)[0])))
assert actual == expected
assert len(packets[2:]) == 78 and len(actual) == 5303
assert all(0 < len(p) <= 1500 for p in packets[2:])
print("Synthetic request: compiled/source match; 78 Opus packets; 5303 bytes: PASS")