mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-05-08 09:57:21 -05:00
LinkML schema at vault/schema/question_schema.yaml is the sole schema
source of truth. Pydantic models in vault_cli.models are currently
hand-authored to match; full LinkML codegen wires in Phase 2 with the
drift-check in CI.
Core modules:
vault_cli/models.py — Pydantic question model (closed enums, content-
format per field, schema_version=1 gate).
vault_cli/hashing.py — canonical content_hash over whitelisted fields;
release_hash Merkle with __policy__ and
__canon_version__ leaves (Chip N-H5).
vault_cli/yaml_io.py — hardened SafeLoader: 256KB cap, depth 10 cap,
aliases rejected, timeout (H-7).
vault_cli/paths.py — path-as-classification parser with lowercase +
enum enforcement (H-9).
vault_cli/loader.py — walks vault/questions/, returns loaded + errors
(never raises — aggregate reporting).
vault_cli/validator.py — tiered invariant engine; fast + structural tiers
implemented per ARCHITECTURE.md §5.
vault_cli/compiler.py — YAML → SQLite with release_metadata rows
(release_id, release_hash, policy_version,
schema_version, published_count).
vault_cli/policy.py — single filter predicate. No consumer
re-implements (H-21).
release-policy.yaml v1: status=published. Dropped require_validated in
the wake of 9199/8053 resolution — validation is implicit in the
maintainer-approval → status=published transition, not a separate flag.
Tests (19 pass): key-order hash invariance (Soumith M-NEW-4), policy
filter correctness (H-21 runtime check), YAML hardening (H-7).
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
"""Tests for the release-policy filter.
|
|
|
|
Critical invariant (REVIEWS.md H-21): every exporter must call the SAME
|
|
policy.filter_questions function. This test is the runtime analogue; CI's
|
|
import-graph check is the static-analysis complement.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from vault_cli.policy import filter_questions, is_published, policy_version
|
|
|
|
|
|
def _policy() -> dict:
|
|
return {
|
|
"policy_version": 1,
|
|
"include": {"status": ["published"], "require_validated": False},
|
|
"exclude_topics": [],
|
|
"exclude_ids": [],
|
|
}
|
|
|
|
|
|
def test_published_passes() -> None:
|
|
q = {"id": "x", "status": "published", "topic": "t"}
|
|
assert is_published(q, _policy()) is True
|
|
|
|
|
|
def test_draft_rejected() -> None:
|
|
q = {"id": "x", "status": "draft", "topic": "t"}
|
|
assert is_published(q, _policy()) is False
|
|
|
|
|
|
def test_exclude_id_wins() -> None:
|
|
p = _policy()
|
|
p["exclude_ids"] = ["x"]
|
|
q = {"id": "x", "status": "published", "topic": "t"}
|
|
assert is_published(q, p) is False
|
|
|
|
|
|
def test_exclude_topic_wins() -> None:
|
|
p = _policy()
|
|
p["exclude_topics"] = ["t"]
|
|
q = {"id": "x", "status": "published", "topic": "t"}
|
|
assert is_published(q, p) is False
|
|
|
|
|
|
def test_filter_returns_published_only() -> None:
|
|
qs = [
|
|
{"id": "a", "status": "published", "topic": "t"},
|
|
{"id": "b", "status": "draft", "topic": "t"},
|
|
{"id": "c", "status": "deprecated", "topic": "t"},
|
|
]
|
|
out = filter_questions(qs, _policy())
|
|
assert {q["id"] for q in out} == {"a"}
|
|
|
|
|
|
def test_policy_version_returns_int() -> None:
|
|
assert policy_version(_policy()) == 1
|