71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SKILL = ROOT / "skills" / "technical-doc-flow"
|
|
sys.path.insert(0, str(SKILL / "scripts"))
|
|
from harness_common import InputError, load_rules, validate_with_schema # noqa: E402
|
|
|
|
|
|
def test_all_bundled_json_and_schemas_parse() -> None:
|
|
paths = [*SKILL.rglob("*.json"), ROOT / "harness.json"]
|
|
assert paths
|
|
for path in paths:
|
|
value = json.loads(path.read_text(encoding="utf-8"))
|
|
assert isinstance(value, dict), path
|
|
|
|
|
|
def test_quality_rules_have_unique_ids_and_every_runtime_threshold() -> None:
|
|
rules = load_rules()
|
|
ids = [item["id"] for item in rules["rules"]]
|
|
assert len(ids) == len(set(ids))
|
|
assert {
|
|
"DOC-H001",
|
|
"DOC-M002",
|
|
"DOC-L003",
|
|
"DOC-T009",
|
|
"DOC-F005",
|
|
"DOC-M004",
|
|
"FNL-001",
|
|
} <= set(ids)
|
|
assert rules["thresholds"]["route"]["light"]["requires_existing_draft"] is True
|
|
assert rules["thresholds"]["finalization"]["max_change_rate"] == 0.0
|
|
|
|
|
|
def test_artifact_contract_schema_names_exist() -> None:
|
|
expected = {
|
|
"run.schema.json",
|
|
"sources.schema.json",
|
|
"reader-contract.schema.json",
|
|
"evidence-map.schema.json",
|
|
"logic-map.schema.json",
|
|
"term-ledger.schema.json",
|
|
"review.schema.json",
|
|
"lint-report.schema.json",
|
|
"final-report.schema.json",
|
|
"chunk-manifest.schema.json",
|
|
"quality-rules.schema.json",
|
|
"runtime-contract.schema.json",
|
|
}
|
|
actual = {path.name for path in (SKILL / "schemas").glob("*.json")}
|
|
assert expected <= actual
|
|
|
|
|
|
def test_reader_contract_rejects_whitespace_values_and_undeclared_fields() -> None:
|
|
fixture = ROOT / "tests" / "fixtures" / "good" / "reader-contract.json"
|
|
reader = json.loads(fixture.read_text(encoding="utf-8"))
|
|
reader["non_goals"] = [" "]
|
|
with pytest.raises(InputError):
|
|
validate_with_schema(reader, "reader-contract.schema.json", "reader")
|
|
|
|
reader = json.loads(fixture.read_text(encoding="utf-8"))
|
|
reader["undeclared"] = True
|
|
with pytest.raises(InputError):
|
|
validate_with_schema(reader, "reader-contract.schema.json", "reader")
|