coastwise / tests /test_submission.py
Stephen S. Lee
feat: source-derived Q&A with statewide CA ocean species coverage (#1)
c1b067e unverified
Raw
History Blame Contribute Delete
3.14 kB
"""Submission-readiness tests."""
import json
from coastwise.schemas import AwardTag, SubmissionPackage
from coastwise.source_cache import DEFAULT_SEED_CACHE_DIR, DEFAULT_SOURCE_CACHE_ROOT, load_seed_cache
from coastwise.source_registry import load_official_sources, statewide_source_coverage
from coastwise.submission import (
default_model_inventory,
validate_model_inventory,
validate_submission_package,
)
def test_default_model_inventory_documents_minicpm_under_hackathon_caps():
inventory = default_model_inventory()
assert inventory.entries[0].key == "minicpm5_1b"
assert inventory.all_under_32b
assert inventory.all_at_or_under_4b
assert not validate_model_inventory(inventory)
def test_model_inventory_declares_hosted_minicpm_interpreter_role():
from coastwise.schemas import ModelRole, RuntimeMode
entry = default_model_inventory().entries[0]
assert entry.runtime_mode is RuntimeMode.HOSTED_ENDPOINT
assert ModelRole.QUESTION_INTERPRETATION in entry.roles
def test_submission_package_validator_flags_missing_public_evidence():
inventory = default_model_inventory()
package = SubmissionPackage(
space_url="",
readme_has_frontmatter_tags=False,
target_tags=(AwardTag.OPENAI_CODEX, AwardTag.TINY_TITAN),
demo_video_url=None,
social_post_url=None,
model_inventory=inventory,
codex_evidence=None,
github_repo_visibility="private",
field_notes_url=None,
safety_limitations_documented=False,
source_freshness_policy_documented=False,
)
issues = validate_submission_package(package)
fields = {issue.field for issue in issues}
assert {"space_url", "demo_video_url", "social_post_url", "codex_evidence"} <= fields
def test_readme_documents_statewide_source_cache_policy_and_validation_limits():
readme = open("README.md", encoding="utf-8").read().casefold()
coverage = statewide_source_coverage()
assert "24 hours" in readme
assert "statewide official source registry" in readme
assert "structured answers for the reviewed validation set" in readme
assert "snippet fallback" in readme
assert "questions and optional beach/coastal-area text are not saved" in readme
assert "coastwise_llm_api_key" in readme
for source in load_official_sources():
if source.id in coverage.required_source_ids:
assert source.url.casefold() in readme
def test_seed_manifest_documents_statewide_coverage_and_24_hour_stale_policy():
manifest = json.loads((DEFAULT_SOURCE_CACHE_ROOT / "seed-manifest.json").read_text(encoding="utf-8"))
cache = load_seed_cache(DEFAULT_SEED_CACHE_DIR)
source_ids = set(cache.snapshots_by_source_id)
assert manifest["coverage_id"] == statewide_source_coverage().id
assert manifest["stale_after_hours"] == 24
assert set(statewide_source_coverage().required_source_ids) <= source_ids
assert {"lingcod_min_size", "dungeness_crab_bag_limit"} <= set(cache.facts_by_id)
assert {"cdph_annual_mussel_quarantine", "cdph_shellfish_verify"} <= set(cache.advisory_facts_by_id)