# DGR-017 — exact commands and real results (2026-07-13)
# Project venv is used explicitly. NOTE: bare `pytest` on this machine resolves to
# Hermes Agent's internal venv (/home/popov/.hermes/...), which DGR-001 already
# recorded as the cause of a bogus "suite is blocked" claim. Always use $VP.
VP=/run/media/popov/d/DEV/repos/d-popov.com/AI/.venv/bin/python   # Python 3.14.6

# ---------------------------------------------------------------------------
# 1. Resolve the target from upstream metadata ONLY. No weight payload downloaded.
#    Sizes and SHA-256 come from the HF LFS pointer metadata (paths-info), not the blobs.
# ---------------------------------------------------------------------------
curl -sS "https://huggingface.co/api/models/zai-org/GLM-5.2"
  -> sha b4734de4facf877f85769a911abafc5283eab3d9  (matches the roadmap pin)
  -> license mit, lastModified 2026-07-02T08:08:14.000Z

curl -sS "https://huggingface.co/api/models/unsloth/GLM-5.2-GGUF"
  -> sha abc55e72527792c6e77069c99b4cb7de16fa9f23  (matches the roadmap pin)
  -> license mit, lastModified 2026-06-23T15:18:23.000Z
  -> six UD-IQ1_S shards present

curl -sS -X POST -d '{"paths": [<6 UD-IQ1_S shards>]}' \
  "https://huggingface.co/api/models/unsloth/GLM-5.2-GGUF/paths-info/abc55e7..."
  -> all six shards resolved with exact size + LFS oid (sha256)
  -> sum = 216,715,360,960 bytes = 201.832 GiB = 216.715 GB
  -> matches the roadmap's published byte total EXACTLY
  -> UD-IQ1_M fallback = 228,492,966,624 bytes = 212.801 GiB (also matches)

curl -sS ".../resolve/b4734de4.../{config.json,chat_template.jinja,
          generation_config.json,tokenizer_config.json}"
  -> config.json           3732 B  sha256 185f93ee6d12548e16a847e279dc0c3c90b1524c970b0866b42fb545747d859a
  -> chat_template.jinja   5076 B  sha256 172dc74a35e1752df75ecfb2b2cf9326d2852bb1379868ebeec9571654489679
  -> generation_config.json 194 B  sha256 ac76b43d8683d3b930126870fc8be73d8679308fe752fa1f381096d8354f6a55
  -> tokenizer_config.json  761 B  sha256 98b1271574f41abf89427ae2dda030d94dc9478f0edc5a8bd240db213c6fd5fc

# ---------------------------------------------------------------------------
# 2. Verify the checked-in pins still match live upstream (reproducible, no weights)
# ---------------------------------------------------------------------------
$VP scripts/refresh_glm_target_manifest.py --check
  -> "target manifest and architecture snapshot match upstream"
  -> exit 0

# ---------------------------------------------------------------------------
# 3. Upstream llama.cpp / donor status refresh (GitHub REST API, read-only)
# ---------------------------------------------------------------------------
curl -sS "https://api.github.com/repos/ggml-org/llama.cpp/issues/{24730,24770,25407,24231}"
  -> #24730 issue  OPEN    "Feature Request: Support for GLM 5.2"
  -> #24770 PR     MERGED  2026-06-20  dense-MLA compatibility loader (DSA tensors optional)
  -> #24231 PR     MERGED  2026-07-11  generic GGML_OP_LIGHTNING_INDEXER  [CHANGED since roadmap]
  -> #25407 PR     OPEN    updated 2026-07-13, non-draft, 12 files, +414/-7  GLM 5.2 Indexer support
curl -sS "https://api.github.com/repos/Mesh-LLM/mesh-llm{,/branches/feat%2Fjianyang-glm-52}"
  -> Apache-2.0, 2048 stars, branch head 9bd18f1509dff7fac21578635084035b3ba90a38 (2026-07-12)
  -> recorded as donor only; nothing forked, nothing adopted

# ---------------------------------------------------------------------------
# 4. Seal the alpha contract (digest over its own canonical content)
# ---------------------------------------------------------------------------
$VP -c "seal_contract(...)"  -> contract_sha256 aab23220280c053a3c14ff559df3cb5c9e1bf7f0f7188c6519e2e9d9ad036ed9

# ---------------------------------------------------------------------------
# 5. Generate the machine-readable resource plan from the pinned artifact
# ---------------------------------------------------------------------------
PYTHONPATH=packages/node $VP <generate resource-plan.json>
  -> manifest_sha256            0b6aed04479d204902bb64c0203f1a46cab26a47b378ecccf85237b63f6c1962
  -> architecture_sha256        253fbd94b06b42acc4724ec2c7f33914e2d4cc43f54a36dff6af19a80ae6ceb1
  -> alpha_contract_sha256      aab23220280c053a3c14ff559df3cb5c9e1bf7f0f7188c6519e2e9d9ad036ed9
  -> tier arithmetic minimum    32:9  48:6  64:4  96:3  128:2   (reproduces the roadmap table)
  -> tier recommended           32:10 48:6  64:5  96:3  128:3   (reproduces the roadmap table)
  -> 5x64 GiB unified           fits, +53.28 GiB headroom
  -> 3x96 GiB unified           fits, +27.68 GiB headroom
  -> 2x128 / 4x64 (fit probes)  fit with only +2.08 GiB headroom across the WHOLE route
  -> 2x112 GiB (= 224 GiB, the hard-fit floor)  DOES NOT FIT: -23.52 GiB
  -> 3x64 GiB                   does not fit: -49.12 GiB

# ---------------------------------------------------------------------------
# 6. Quality gates (project .venv, deterministic, offline, GPU-free)
# ---------------------------------------------------------------------------
$VP -m pytest -q tests/test_glm_alpha_target.py
  -> 97 passed in 0.12s
  -> includes coordinated shard/config substitution, malformed telemetry, and
     contract-ID reseal rejection tests added during controller review

$VP -m pip wheel --no-deps packages/node -w /tmp/dgr017-wheel
$VP -m pip install --no-deps --target /tmp/dgr017-install /tmp/dgr017-wheel/*.whl
$VP -I -c "... from meshnet_node.glm_alpha import load_locked_target ..."
  -> INSTALLED_WHEEL_PASS
  -> packaged alpha-contract.json, target-manifest.json, and architecture-snapshot.json
     load and cross-bind successfully outside the source tree

$VP -m compileall -q packages tests
  -> exit 0

git diff --check
  -> exit 0

$VP -m pytest -q            # full deterministic suite
  -> first final run: 1 failed, 851 passed, 13 skipped; only the tracker cancellation
     race already documented by DGR-001/DGR-002 failed
$VP -m pytest -q tests/test_tracker_routing.py::test_tracker_dashboard_can_cancel_inflight_proxy
  -> 1 passed, repeated 5/5 in isolation
$VP -m pytest -q            # integrated rerun
  -> 852 passed, 13 skipped in 253.30s (0:04:13)

# ---------------------------------------------------------------------------
# 7. Late independent-review repair (2026-07-14)
# ---------------------------------------------------------------------------
PYTHONPATH=packages/node $VP -m pytest -q tests/test_glm_alpha_target.py
  -> 99 passed in 0.15s
  -> adds trusted-v1-digest rejection after coordinated mutation + reseal
  -> adds nested parsed-state immutability and isolated to_dict() coverage

$VP -m pytest -q            # after DGR-003 integration and DGR-017 repair
  -> first run: 871 passed, 13 skipped, 1 known cancellation-race failure
$VP -m pytest -q tests/test_tracker_routing.py::test_tracker_dashboard_can_cancel_inflight_proxy
  -> 5/5 passed in isolation
$VP -m pytest -q            # integrated rerun
  -> 872 passed, 13 skipped in 253.46s (0:04:13)
