"""Structural tests: NOEON's declared dimensions must match the real sources. These read weights/source_tensors.json (real safetensors headers) and assert that every integration assumption holds. They fail if a source's real width stops matching NOEON's shared dimension. """ import json from pathlib import Path import pytest from noeon.core.config import NoeonConfig from noeon.core.registry import SHARED_DIM ROOT = Path(__file__).resolve().parent.parent TENSORS = ROOT / "weights" / "source_tensors.json" def _tensors(): if not TENSORS.exists(): pytest.skip("source_tensors.json not built") return json.loads(TENSORS.read_text()) def test_every_source_exposes_shared_dim(): t = _tensors() for key, entry in t.items(): widths = {d for s in entry["tensors"].values() for d in s["shape"]} assert SHARED_DIM in widths, ( f"{key} has no {SHARED_DIM}-d tensor; NOEON's shared dim is wrong" ) def test_bridges_match_shared_dim(): cfg = NoeonConfig() for b in cfg.bridges: assert b.in_dim == SHARED_DIM assert b.out_dim == SHARED_DIM def test_vision_and_computer_use_shapes_agree(): t = _tensors() if "vision" not in t or "computer_use" not in t: pytest.skip("need both understanding slots") def strip(name): for p in ("model.language_model.", "language_model.", "model."): if name.startswith(p): return name[len(p):] return name vl = {strip(n): tuple(s["shape"]) for n, s in t["vision"]["tensors"].items()} cw = {strip(n): tuple(s["shape"]) for n, s in t["computer_use"]["tensors"].items()} common = set(vl) & set(cw) assert len(common) > 200, "expected a large shared trunk" conflicts = [k for k in common if vl[k] != cw[k]] assert not conflicts, f"shape conflicts between the two trunks: {conflicts[:5]}" def test_generation_context_dim_is_shared(): t = _tensors() if "generation" not in t: pytest.skip("generation slot not inspected") entry = t["generation"] # the diffusion transformer's context projection must accept 2560-d has_ctx = any( len(s["shape"]) == 2 and SHARED_DIM in s["shape"] and "transformer" in s["file"] for s in entry["tensors"].values() ) assert has_ctx, "generation slot exposes no 2560-d context input" def test_generation_txt_in_accepts_generation_head_output(): """NOEON's GenerationHead emits a 2560-d context; the generation slot's diffusion transformer must accept exactly that width. Checked against the real weight `txt_in.weight` (3072, 2560).""" t = _tensors() if "generation" not in t: pytest.skip("generation slot not inspected") tensors = t["generation"]["tensors"] if "txt_in.weight" not in tensors: pytest.skip("txt_in.weight not in inspected files") shape = tuple(tensors["txt_in.weight"]["shape"]) assert shape == (3072, SHARED_DIM), ( f"generation txt_in is {shape}; NOEON emits {SHARED_DIM}-d context" )