# Copyright (c) 2026 The Anuvani-Diarization authors # SPDX-License-Identifier: MIT OR Apache-2.0 """Identity check through the serving stack (Triton, the Rust gateway, the Python client) against the raw-audio oracle, byte for byte: every RTTM, every error, and every front-end record the gateway dumps. Jobs arrive concurrently in a shuffled order; most name a file on the server, the rest are uploaded through the gateway's spool. Run through triton/identity_check.sh (it starts Triton and the gateway and sets GATEWAY_URL; its variants set IDENTITY_SEED for another arrival order and RESTART_AT for a Triton restart in the middle of the run). """ import json import os import random import urllib.request from concurrent.futures import ThreadPoolExecutor from pathlib import Path import numpy as np import pytest from conftest import PROJ from test_identity_audio import INPUTS, identity_sample, oracle_log ORACLE = PROJ / "artifacts/oracle_audio" RECORDS = PROJ / "artifacts/identity_serving/records" pytestmark = pytest.mark.skipif("GATEWAY_URL" not in os.environ, reason="needs triton/identity_check.sh") def run_through_gateway(keys, uploads=20, seed=7): from anuvani_diar import Client c = Client(os.environ["GATEWAY_URL"], timeout=3600) order = list(keys) random.Random(seed).shuffle(order) # uploads only for files that succeed: a failing upload's message names the spool file, not the client's path log = oracle_log() upload = set([k for k in order if log[k]["ok"]][:uploads]) def one(k): it = INPUTS[k] job = c.submit(it["path"], uri=it["sid"], server_path=k not in upload) return k, c.wait(job, poll=1.0) with ThreadPoolExecutor(64) as ex: return dict(ex.map(one, order)) def compare(keys, got): log = oracle_log() bad = [] for k in keys: s, sid = k.split("/", 1) want, r = log[k], got[k] if not want["ok"]: if r["error"] != want["error"]: bad.append((k, "error", want["error"], r["error"])) continue # the release's own post-processing raised want_err = want["indic"].get("error") if r["error"] != want_err: bad.append((k, "error", want_err, r["error"])) continue if want_err is None and (r["status"] != "done" or (r["rttm"] or "").encode() != (ORACLE / s / "indic" / f"{sid}.rttm").read_bytes()): bad.append((k, r["status"], "rttm")) d = np.load(ORACLE / s / "records" / f"{sid}.npz") P = np.fromfile(RECORDS / f"{sid}.P", dtype=" 0 @pytest.mark.gpu @pytest.mark.slow def test_identity_serving_all(): keys = list(INPUTS) got = run_through_gateway(keys, uploads=100, seed=SEED) assert compare(keys, got) == [] if os.environ.get("RESTART_AT"): assert gateway_metric("anuvani_diar_triton_retries_total") > 0