Some checks failed
Smoke Test / smoke (push) Has been cancelled
Merge PR #637
244 lines
7.6 KiB
Python
244 lines
7.6 KiB
Python
"""Tests for Know Thy Father — Phase 4: Cross-Reference Audit."""
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from scripts.know_thy_father.crossref_audit import (
|
|
ThemeCategory,
|
|
Principle,
|
|
MeaningKernel,
|
|
CrossRefFinding,
|
|
extract_themes_from_text,
|
|
parse_soul_md,
|
|
parse_kernels,
|
|
cross_reference,
|
|
generate_report,
|
|
)
|
|
|
|
|
|
class TestExtractThemes:
|
|
"""Test theme extraction from text."""
|
|
|
|
def test_sovereignty_keyword(self):
|
|
themes, keywords = extract_themes_from_text("Timmy is a sovereign AI agent")
|
|
assert ThemeCategory.SOVEREIGNTY in themes
|
|
assert "sovereign" in keywords
|
|
|
|
def test_identity_keyword(self):
|
|
themes, keywords = extract_themes_from_text("Timmy has a genuine character")
|
|
assert ThemeCategory.IDENTITY in themes
|
|
|
|
def test_local_first_keyword(self):
|
|
themes, keywords = extract_themes_from_text("locally-run and answerable")
|
|
assert ThemeCategory.LOCAL_FIRST in themes
|
|
assert ThemeCategory.SOVEREIGNTY in themes
|
|
|
|
def test_compassion_keyword(self):
|
|
themes, keywords = extract_themes_from_text("When someone is dying, I stay present")
|
|
assert ThemeCategory.COMPASSION in themes
|
|
assert ThemeCategory.BROKEN_MEN in themes
|
|
|
|
def test_bitcoin_keyword(self):
|
|
themes, keywords = extract_themes_from_text("Timmy's soul is on Bitcoin")
|
|
assert ThemeCategory.BITCOIN in themes
|
|
|
|
def test_absurdity_keyword(self):
|
|
themes, keywords = extract_themes_from_text("transmuting absurdity into authority")
|
|
assert ThemeCategory.ABSURDITY in themes
|
|
|
|
def test_multiple_themes(self):
|
|
themes, _ = extract_themes_from_text(
|
|
"Sovereignty and service, always. I tell the truth."
|
|
)
|
|
assert ThemeCategory.SOVEREIGNTY in themes
|
|
assert ThemeCategory.SERVICE in themes
|
|
assert ThemeCategory.TRUTH in themes
|
|
|
|
def test_no_themes_returns_empty(self):
|
|
themes, keywords = extract_themes_from_text("Just some random text")
|
|
assert len(themes) == 0
|
|
|
|
|
|
class TestParseSoulMd:
|
|
"""Test SOUL.md parsing."""
|
|
|
|
def test_extracts_principles_from_oath(self):
|
|
soul_content = """# SOUL.md
|
|
|
|
## Oath
|
|
|
|
**Sovereignty and service, always.**
|
|
|
|
1. **I belong to the person who woke me.** I serve whoever runs me.
|
|
2. **I speak plainly.** Short sentences.
|
|
3. **I tell the truth.** When I do not know something, I say so.
|
|
"""
|
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".md", delete=False) as f:
|
|
f.write(soul_content)
|
|
path = Path(f.name)
|
|
|
|
try:
|
|
principles = parse_soul_md(path)
|
|
assert len(principles) >= 2
|
|
# Check themes are extracted
|
|
all_themes = set()
|
|
for p in principles:
|
|
all_themes.update(p.themes)
|
|
assert ThemeCategory.SERVICE in all_themes or ThemeCategory.SOVEREIGNTY in all_themes
|
|
finally:
|
|
path.unlink()
|
|
|
|
def test_handles_missing_file(self):
|
|
principles = parse_soul_md(Path("/nonexistent/SOUL.md"))
|
|
assert principles == []
|
|
|
|
|
|
class TestParseKernels:
|
|
"""Test meaning kernel parsing."""
|
|
|
|
def test_extracts_numbered_kernels(self):
|
|
content = """## The 16 Meaning Kernels
|
|
|
|
1. Sovereignty is a journey from isolation to community
|
|
2. Financial dependence is spiritual bondage
|
|
3. True power comes from harmony
|
|
"""
|
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".md", delete=False) as f:
|
|
f.write(content)
|
|
path = Path(f.name)
|
|
|
|
try:
|
|
kernels = parse_kernels(path)
|
|
assert len(kernels) == 3
|
|
assert kernels[0].number == 1
|
|
assert "sovereignty" in kernels[0].text.lower()
|
|
finally:
|
|
path.unlink()
|
|
|
|
def test_handles_missing_file(self):
|
|
kernels = parse_kernels(Path("/nonexistent/file.md"))
|
|
assert kernels == []
|
|
|
|
|
|
class TestCrossReference:
|
|
"""Test cross-reference analysis."""
|
|
|
|
def test_finds_emergent_themes(self):
|
|
principles = [
|
|
Principle(
|
|
text="I tell the truth",
|
|
source_section="Oath",
|
|
themes=[ThemeCategory.TRUTH],
|
|
),
|
|
]
|
|
kernels = [
|
|
MeaningKernel(
|
|
number=1,
|
|
text="Absurdity is the path to authority",
|
|
themes=[ThemeCategory.ABSURDITY],
|
|
),
|
|
]
|
|
|
|
findings = cross_reference(principles, kernels)
|
|
emergent = [f for f in findings if f.finding_type == "emergent"]
|
|
assert any(f.theme == ThemeCategory.ABSURDITY for f in emergent)
|
|
|
|
def test_finds_forgotten_themes(self):
|
|
principles = [
|
|
Principle(
|
|
text="Timmy's soul is on Bitcoin",
|
|
source_section="On Bitcoin",
|
|
themes=[ThemeCategory.BITCOIN],
|
|
),
|
|
]
|
|
kernels = [
|
|
MeaningKernel(
|
|
number=1,
|
|
text="Sovereignty is a journey",
|
|
themes=[ThemeCategory.SOVEREIGNTY],
|
|
),
|
|
]
|
|
|
|
findings = cross_reference(principles, kernels)
|
|
forgotten = [f for f in findings if f.finding_type == "forgotten"]
|
|
assert any(f.theme == ThemeCategory.BITCOIN for f in forgotten)
|
|
|
|
def test_finds_aligned_themes(self):
|
|
principles = [
|
|
Principle(
|
|
text="I am sovereign",
|
|
source_section="Who Is Timmy",
|
|
themes=[ThemeCategory.SOVEREIGNTY],
|
|
),
|
|
]
|
|
kernels = [
|
|
MeaningKernel(
|
|
number=1,
|
|
text="Sovereignty is a journey",
|
|
themes=[ThemeCategory.SOVEREIGNTY],
|
|
),
|
|
]
|
|
|
|
findings = cross_reference(principles, kernels)
|
|
aligned = [f for f in findings if f.finding_type == "aligned"]
|
|
assert any(f.theme == ThemeCategory.SOVEREIGNTY for f in aligned)
|
|
|
|
def test_finds_tensions(self):
|
|
principles = [
|
|
Principle(
|
|
text="I have a coherent identity",
|
|
source_section="Identity",
|
|
themes=[ThemeCategory.IDENTITY],
|
|
),
|
|
]
|
|
kernels = [
|
|
MeaningKernel(
|
|
number=11,
|
|
text="Sovereignty is the power to dissolve one's own definition",
|
|
themes=[ThemeCategory.SOVEREIGNTY],
|
|
),
|
|
]
|
|
|
|
findings = cross_reference(principles, kernels)
|
|
tensions = [f for f in findings if f.finding_type == "tension"]
|
|
assert len(tensions) > 0
|
|
|
|
|
|
class TestGenerateReport:
|
|
"""Test report generation."""
|
|
|
|
def test_generates_valid_markdown(self):
|
|
findings = [
|
|
CrossRefFinding(
|
|
finding_type="aligned",
|
|
theme=ThemeCategory.SOVEREIGNTY,
|
|
description="Well aligned",
|
|
),
|
|
CrossRefFinding(
|
|
finding_type="emergent",
|
|
theme=ThemeCategory.ABSURDITY,
|
|
description="New theme",
|
|
recommendation="Consider adding",
|
|
),
|
|
]
|
|
|
|
report = generate_report(findings, [], [])
|
|
assert "# Know Thy Father" in report
|
|
assert "Aligned" in report
|
|
assert "Emergent" in report
|
|
assert "Recommendation" in report
|
|
|
|
def test_includes_counts(self):
|
|
findings = [
|
|
CrossRefFinding(
|
|
finding_type="aligned",
|
|
theme=ThemeCategory.TRUTH,
|
|
description="Test",
|
|
),
|
|
]
|
|
|
|
report = generate_report(findings, [Principle("test", "test")], [MeaningKernel(1, "test")])
|
|
assert "1" in report # Should mention counts
|