droboticflow/tests/backend/export_delivery_v4_fixture.py

40 lines
2.1 KiB
Python

"""Synthetic v4 examples from the actual package entry point, with private audit kept separately."""
import argparse
import hashlib
import json
import shutil
from pathlib import Path
from backend.operators.builtin.package import operator as package
from tests.backend.test_delivery_v4_package import NODE, ACTION, prepare, original_source
from tests.backend.test_part_index_package import helpers
def export(destination):
destination.mkdir(parents=True, exist_ok=True)
for part in ("part0001", "part0002"):
work=destination/("work-"+part)
work.mkdir()
inputs=prepare(work,[{"id":"blank","description":"","clipStartMs":0,"clipEndMs":500,"startTimestampUs":1000000,"endTimestampUs":1500000},{"id":"pick","description":"拿起杯子","dictionary":ACTION,"clipStartMs":500,"clipEndMs":1000,"startTimestampUs":1500000,"endTimestampUs":2000000}])
inputs[1]["data"]["capture"].update(captureId="capture-A/"+part,prefix="incoming/capture-A/"+part)
manifest_path=Path(inputs[0]["path"])/"revision-manifest.json"
m=json.loads(manifest_path.read_text());m["runId"]="source-run-"+part;m["originalSource"]=original_source(part=part)
if part=="part0002":
m["items"][0]["deliveryDisposition"]="discard"
m["items"][0]["discardEvidence"]=m["items"][1]["discardEvidence"]
manifest_path.write_text(json.dumps(m))
inputs[1]["data"]["acceptedMaterializations"][0]["manifestSha256"]=hashlib.sha256(manifest_path.read_bytes()).hexdigest()
artifacts=package.run("package-"+part,"package",work/"out",NODE,inputs,helpers())
shutil.copytree(artifacts[0]["path"],destination/part)
audit=destination/"internal"/part
audit.mkdir(parents=True)
shutil.copy2(artifacts[1]["path"],audit/"review-history.json")
shutil.rmtree(work)
(destination/"meta_capture-A.json").write_text('{"synthetic":true,"parts":["part0001","part0002"]}\n')
if __name__=="__main__":
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument("output",type=Path)
export(parser.parse_args().output)