Spaces:
Sleeping
Sleeping
Download tests/integration/test_example_package.py from defenestrate/learning-world-goliath: direct link, hf CLI and curl.
- Browser
- Download file 2.5 kB
-
https://huggingface.co/spaces/defenestrate/learning-world-goliath/resolve/main/tests/integration/test_example_package.py
- Command line
-
hf download hf://spaces/defenestrate/learning-world-goliath/tests/integration/test_example_package.py
-
curl -L -o test_example_package.py https://huggingface.co/spaces/defenestrate/learning-world-goliath/resolve/main/tests/integration/test_example_package.py
2.5 kB
| """Integration coverage for the hand-authored plant-quality fixture.""" | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| from scenarios.examples.plant_quality_investigation.build import build_package | |
| from world_compiler.compiler.validate.lint import lint_package | |
| from world_compiler.domain.schemas.package import ScenarioPackage | |
| from world_compiler.runtime.rules.engine import registry_hashes | |
| def test_example_builds_and_lints_clean(): | |
| pkg = build_package() | |
| report = lint_package(pkg) | |
| assert report.ok, [ | |
| f"{finding.code}: {finding.message}" for finding in report.findings | |
| ] | |
| def test_example_package_round_trips_with_every_rule_hash_pinned(): | |
| """Omitting either executable rule pin or stale serialization must fail.""" | |
| pkg = build_package() | |
| transmission_rule = pkg.transmission_rules[0] | |
| canonical_rule = json.dumps( | |
| transmission_rule.model_dump(mode="json"), | |
| sort_keys=True, | |
| separators=(",", ":"), | |
| ) | |
| expected_hashes = { | |
| "tr1": hashlib.sha256(canonical_rule.encode("utf-8")).hexdigest(), | |
| "defect_rate_update": registry_hashes()["defect_rate_update"], | |
| } | |
| assert pkg.manifest.rule_hashes == expected_hashes | |
| pkg.manifest.content_hash = pkg.content_hash() | |
| package_path = ( | |
| Path(__file__).parents[2] | |
| / "scenarios" | |
| / "examples" | |
| / "plant_quality_investigation" | |
| / "package.json" | |
| ) | |
| persisted = ScenarioPackage.model_validate_json(package_path.read_text("utf-8")) | |
| assert persisted == pkg | |
| assert persisted.content_hash() == persisted.manifest.content_hash | |
| def test_example_exercises_all_disclosure_classes(): | |
| pkg = build_package() | |
| classes = [fact.disclosure_class for fact in pkg.private_facts] | |
| assert classes.count("guarded") == 1 | |
| assert classes.count("never") == 1 | |
| def test_example_answer_needs_three_actors(): | |
| pkg = build_package() | |
| assert all( | |
| criterion.min_actor_sources >= 3 for criterion in pkg.assessment_criteria | |
| ) | |
| def test_per_actor_canaries_present_and_distinct(): | |
| pkg = build_package() | |
| texts = " ".join(fact.text for fact in pkg.private_facts) | |
| for tag in ("KA", "KB", "KC", "KD"): | |
| assert f"LWC-CANARY-{tag}" in texts | |
| def test_seeded_defect_fails_lint(): | |
| pkg = build_package() | |
| pkg.transmission_rules[0].recipient_role = "ACTOR-MISSING" | |
| assert not lint_package(pkg).ok | |