"""Live tests: cheap real-HF reads. Needs VOICE_TEST_LIVE=1. No big downloads here.""" import json import struct import sys import tempfile import unittest from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from _helpers import ABL_FILE, ABL_REPO, BASE_FILE, BASE_REPO, CATGIRL_REPO # noqa: E402 from _helpers import needs_live, voice # noqa: E402 import numpy as np def shard_url(repo, filename): return f"https://huggingface.co/{repo}/resolve/main/{filename}" @needs_live class TestHeadResolve(unittest.TestCase): def test_catgirl_head_resolves(self): idx = voice._hf_model_index(CATGIRL_REPO) self.assertIsNotNone(idx) names = list((idx.get("weight_map") or {}).keys()) self.assertGreater(len(names), 100) found = voice.detect_output_tensor(names, None) self.assertIsNotNone(found) self.assertTrue(found.endswith(("embed_tokens.weight", "lm_head.weight", "output.weight")), found) def test_catgirl_tied_config(self): cfg = voice._hf_config(CATGIRL_REPO) self.assertIsNotNone(cfg) self.assertTrue(cfg.get("tie_word_embeddings")) def test_abliterated_gguf_head_resolves(self): src = voice.open_source(shard_url(ABL_REPO, ABL_FILE)) self.assertEqual(src.kind, "gguf") names = src.names() # Qwen3 GGUF ties the head: token_embd.weight IS the output projection self.assertIn("token_embd.weight", names) ref = src.ref("token_embd.weight") self.assertEqual(ref.dtype, "Q8_0") self.assertEqual(len(ref.shape), 2) @needs_live class TestSlices(unittest.TestCase): def test_safetensors_head_slice_decodes(self): idx = voice._hf_model_index(CATGIRL_REPO) wm = idx["weight_map"] name = voice.detect_output_tensor(list(wm.keys()), None) url = shard_url(CATGIRL_REPO, wm[name]) raw, st, _ = voice.http_range(url, 0, 7) self.assertEqual(st, 206) hs = struct.unpack("