tests: miner.py — first coverage (validate_local_config + sha256_dir) - #6
Conversation
Spec source: docstring ("Compare king and challenger config.json
locally. Returns None if OK, or a human-readable rejection reason.")
+ signature + parallel inference from validator.validate_challenger_config.
Outcome: confirms-behavior plus one resolved spec-ambiguity. 7 tests
cover the happy path, missing king config (returns None per docstring),
arch and vocab mismatches, missing challenger config, missing
safetensors, and *.py upload rejection.
Spec-ambiguity resolved: my initial happy-path test only set up
config.json on both sides. It went RED because the function also
requires .safetensors files in the challenger directory. Added a
helper (_make_valid_challenger) and an explicit
test_..._missing_safetensors_rejects test to lock in the discovered
spec.
Also added test_..._python_file_rejects since the security rule from
validate_challenger_config (deny *.py to prevent auto_map code execution)
should reasonably apply on the miner side too — confirmed it does.
This is the first coverage for miner.py (previously 0% covered).
Spec source: signature (no docstring) + name + call sites in miner.py
(king_hash = sha256_dir(king_dir), challenger_hash = sha256_dir(challenger_dir))
+ comment in validator.py:776 ("king_hash miners encode in their
on-chain commits — see miner.sha256_dir").
Outcome: confirms-behavior. 5 tests cover return format (64-char hex),
determinism, content-sensitivity, that non-.safetensors files are
ignored, and that multiple .safetensors files combine deterministically
regardless of filesystem ordering (the impl sorts).
The sort-invariance test is the highest-value: miner and validator
must agree on the king hash regardless of which order files were
written to disk; a bug there would silently invalidate every miner's
on-chain hash commit.
Two additional tests covering edge cases I identified while reviewing the PR diff: - `test_validate_local_config_accepts_sharded_safetensors`: real-world models are typically sharded into multiple safetensors files (model-0000N-of-N.safetensors). Confirms multi-file checkpoints are accepted, not just single-file ones. - `test_sha256_dir_empty_directory_returns_empty_hash`: documents the defined behavior for an empty directory (returns hashlib.sha256() empty digest e3b0c44...).
Self-reviewSubstantive (added in
|
Summary
First test coverage for
miner.py(previously 0% covered). Two purefilesystem functions tested with
tmp_path— no mocking needed.Functions covered
validate_local_config(king_dir, challenger_dir)sha256_dir(path)12 tests, all green.
Coverage
validate_local_config— the miner-side equivalent ofvalidator.validate_challenger_config:.pyfile present → rejected (security)sha256_dir— content hash of*.safetensorsfiles. Criticalbecause the miner encodes this hash on-chain and the validator
recomputes it; any divergence silently invalidates every miner's
commit:
Findings during testing
validate_local_configonly set upconfig.json. It went RED with"no .safetensors files in challenger"— the function also checksthe directory contents. Reframed the helper (
_make_valid_challenger)to include safetensors and added an explicit
test_..._missing_safetensors_rejectstest to lock in thediscovered behavior. Also added
test_..._python_file_rejectssincethe same security rule from
validate_challenger_configapplies.Verification
Series context
PR 6 of foundation series. With this merged, foundation will have
68 tests across 11 functions/surfaces. Coverage now spans
validator.py, eval_torch.py, AND miner.py (no longer 0%).
PR 5 (new helpers from upstream
unarbos/teutonic#3)
remains the only deferred item — those symbols don't exist in the
current main yet.