generated from coulomb/repo-seed
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
from infospace_bench.checks import run_collection_checks
|
|
from infospace_bench.inspection import export_mermaid, relationship_summary
|
|
from infospace_bench.models import KnowledgeArtifact, ViabilityThreshold
|
|
from infospace_bench.viability import evaluate_viability
|
|
|
|
|
|
def artifacts() -> list[KnowledgeArtifact]:
|
|
return [
|
|
KnowledgeArtifact(
|
|
id="source/a.md",
|
|
path="artifacts/sources/a.md",
|
|
kind="source",
|
|
title="A",
|
|
relationships=[{"type": "supports", "target": "generated/b.md"}],
|
|
),
|
|
KnowledgeArtifact(
|
|
id="generated/b.md",
|
|
path="artifacts/generated/b.md",
|
|
kind="generated",
|
|
title="B",
|
|
relationships=[{"type": "refines", "target": "source/a.md"}],
|
|
),
|
|
]
|
|
|
|
|
|
def test_collection_checks_produce_viability_metrics() -> None:
|
|
report = run_collection_checks(artifacts())
|
|
|
|
assert report.metrics["redundancy_ratio"] == 0
|
|
assert report.metrics["coverage_ratio"] == 1
|
|
assert report.metrics["coherence_components"] == 1
|
|
assert report.metrics["consistency_cycles"] == 1
|
|
assert report.metrics["granularity_entropy"] == 1
|
|
|
|
|
|
def test_viability_reports_per_threshold_and_overall_result() -> None:
|
|
report = evaluate_viability(
|
|
{"coverage_ratio": 0.75, "consistency_cycles": 1},
|
|
{
|
|
"coverage_ratio": ViabilityThreshold(min=0.5),
|
|
"consistency_cycles": ViabilityThreshold(max=0),
|
|
},
|
|
)
|
|
|
|
assert report.passed is False
|
|
assert report.results["coverage_ratio"].passed is True
|
|
assert report.results["consistency_cycles"].passed is False
|
|
|
|
|
|
def test_relationship_summary_and_mermaid_export() -> None:
|
|
summary = relationship_summary(artifacts())
|
|
|
|
assert summary.node_count == 2
|
|
assert summary.edge_count == 2
|
|
assert summary.relationship_types == {"refines": 1, "supports": 1}
|
|
|
|
mermaid = export_mermaid(summary)
|
|
assert "source/a.md -->|supports| generated/b.md" in mermaid
|
|
assert "generated/b.md -->|refines| source/a.md" in mermaid
|