5.7 KiB
SilverSight Testing Rules
Testing is not an afterthought. Every module that claims a property must
provide a way to witness that property — at minimum a #eval witness for Lean
and a unit test for Python. This document defines the rules before the project
outgrows them.
1. Philosophy
- A theorem without a witness is a draft. Lean proofs are required for
gates;
#evalwitnesses are required for computable claims. - A shim without a unit test is untrusted. Every Python module that performs I/O, parsing, or feature extraction must have matching unit tests.
- A receipt without a roundtrip is incomplete. Any receipt format must be serializable, deserializable, and byte-identical on the roundtrip.
- A new term without a glossary entry is undocumented. The glossary lint
(
python3 .github/scripts/glossary_lint.py) must stay green.
2. Lean tests
Location and naming
formal/CoreFormalism/Foo.lean ← implementation
formal/CoreFormalism/Foo/Test.lean ← Lean tests for Foo (when test count grows)
tests/lean/FooTest.lean ← alternatively, a central tests/lean tree
For small modules, tests may live at the bottom of the implementation file as
#eval witnesses. When a module exceeds ~500 lines or has more than five
witnesses, split tests into a separate Test.lean file.
Required witnesses
Every Lean module in the active build must include at least one of the following:
- Type-correctness smoke test —
#checkthe main definition. - Computational witness —
#evalshowing the definition produces the expected value on a concrete input. - Property witness — a short
exampleblock proving a trivial but representative instance of the main theorem. - Roundtrip witness — for any encoder/decoder pair, prove or
#evaldecode (encode x) = xon a concretex.
Anti-patterns
- Do not rely on
sorryoradmitin committed code. CI rejects them. - Do not put long-running
#evalwitnesses in files built by default unless they are necessary for the proof story. - Do not import test files into production modules.
Running Lean tests
# Build the whole formal library
lake build SilverSightFormal
# Build a specific module and its witnesses
lake build CoreFormalism.FixedPoint
# Check for sorries/admits in formal code
rg "sorry|admit" formal/ Core/
3. Python tests
Location and naming
python/foo.py ← implementation
tests/test_foo.py ← pytest unit tests
qubo/bar.py ← implementation
tests/test_bar.py ← pytest unit tests
Use the tests/ directory for all Python tests. Mirror the module path when
possible: python/chaos_game.py → tests/test_chaos_game.py.
Required tests
Every Python module must have tests covering:
- Happy path — typical input produces expected output.
- Boundary — empty input, zero, maximum, or minimum values.
- Error path — malformed input raises the documented exception.
- No-Float drift — any function that returns a fixed-point value must roundtrip through the canonical Q16_16 representation without loss.
Example
# tests/test_q16_canonical.py
from python.q16_canonical import q16_from_float, q16_to_float
def test_q16_roundtrip():
for x in [0.0, 1.0, -1.0, 3.1415926535, -65535.999]:
raw = q16_from_float(x)
assert abs(q16_to_float(raw) - x) < 1.5e-5
Running Python tests
pytest tests/ -v
python3 -m py_compile python/*.py qubo/*.py
4. Integration tests
Integration tests live in tests/integration/ and exercise end-to-end flows:
test_receipt_roundtrip.py— generate a receipt, serialize to JSON, deserialize, verify equality.test_chaos_to_q16.py— run the chaos game, produce addresses, and assert they are valid Sidon labels.test_finsler_qubo.py— build a Finsler metric, convert to QUBO, solve, and check that the returned path is feasible.
Integration tests may be slow; CI runs them but they are allowed to be skipped
locally with pytest -m 'not slow'.
5. Documentation tests
Documentation is part of the contract and is tested:
- Glossary lint — warns when a domain term appears repeatedly in docs but is
not defined in
docs/GLOSSARY.md.python3 .github/scripts/glossary_lint.py - CFF validation —
CITATION.cffmust remain valid YAML.python3 -c "import yaml; yaml.safe_load(open('CITATION.cff'))" - Doc sync check — README, PORTING_MAP, and AGENTS must mention every
top-level directory.
python3 .github/scripts/check_doc_sync.py
6. CI gates
Every push and pull request must pass:
lake build— default target builds.lake build SilverSightFormal— formal library builds.pytest tests/ -v— Python tests pass.python3 -m py_compileon touched.pyfiles.python3 .github/scripts/glossary_lint.py— no undefined repeated terms.python3 .github/scripts/check_doc_sync.py— README matches tree.rg "sorry|admit" formal/ Core/— no committed placeholders.python3 -c "import yaml; yaml.safe_load(open('CITATION.cff'))"— CFF valid.
7. Test-driven porting checklist
When porting a Research Stack module to SilverSight:
- Module builds (
lake build CoreFormalism.X). - No
sorryoradmitin the ported surface. - At least one
#evalwitness orexampleblock added. - Python shim (if any) has a matching unit test.
- New terms added to
docs/GLOSSARY.mdordocs/GLOSSARY_ALLOWLIST.md. PORTING_MAP.mdstatus updated.AGENTS.mdupdated if boundaries changed.