61 lines
2.4 KiB
Python
61 lines
2.4 KiB
Python
"""Native saved-file evidence; local templates are opt-in and never redistributed."""
|
|
|
|
import hashlib
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from riff_groove_builder.articulations import compile_score
|
|
from riff_groove_builder.formats.sdp import (
|
|
inspect_sdp_template,
|
|
parse_sdp_project,
|
|
validate_sdp_file,
|
|
write_sdp,
|
|
)
|
|
from riff_groove_builder.profiles import load_profile_registry
|
|
from riff_groove_builder.schemas import ProfileSelection, Score
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
pytestmark = pytest.mark.integration
|
|
|
|
|
|
def test_retained_generated_original_and_optional_read_only_local_template() -> None:
|
|
fixtures = ROOT / "tests" / "fixtures" / "sd3"
|
|
profile = load_profile_registry().select(
|
|
["drums"], ProfileSelection(drums="toontrack.sd3.3.4.4.core.v1")
|
|
)["drums"]
|
|
score = Score.model_validate_json((fixtures / "original-score.json").read_bytes())
|
|
plan = compile_score(score, {"drums": profile})
|
|
sources = [("synthetic-original", fixtures / "original-template.sd3p")]
|
|
configured = os.environ.get("RIFF_SD3_TEMPLATE")
|
|
if configured is not None:
|
|
sources.append(("operator-local", Path(configured)))
|
|
for label, template in sources:
|
|
before = template.stat()
|
|
raw = template.read_bytes()
|
|
source = parse_sdp_project(raw)
|
|
info = inspect_sdp_template(template)
|
|
directory = ROOT / ".test-artifacts" / "native-sd3-evidence-v1" / label
|
|
directory.mkdir(parents=True, exist_ok=True)
|
|
path = directory / "original-drums.sd3p"
|
|
if not path.exists():
|
|
write_sdp(path, plan, "drums", profile, template=template)
|
|
readback = validate_sdp_file(path, plan, "drums", profile, template=template)
|
|
output = path.read_bytes()
|
|
saved = parse_sdp_project(output)
|
|
assert len(saved.tracks) == 1 and len(readback.notes) == 3
|
|
assert saved.non_song_bytes == source.non_song_bytes
|
|
assert template.read_bytes() == raw
|
|
after = template.stat()
|
|
assert (before.st_ino, before.st_size, before.st_mtime_ns) == (
|
|
after.st_ino,
|
|
after.st_size,
|
|
after.st_mtime_ns,
|
|
)
|
|
assert readback.non_song_sha256 == info.non_song_sha256
|
|
print(
|
|
f"{label}: bytes={len(output)}, sha256={hashlib.sha256(output).hexdigest()}, "
|
|
f"source_notes_replaced={info.event_count}, saved={readback}"
|
|
)
|