feat(mindmodel): add report-only validator skeleton, types, and tests
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.validators.mindmodel_validator import validate_manifest
|
||||
|
||||
|
||||
def _write_temp_manifest(contents: str) -> str:
|
||||
fd, path = tempfile.mkstemp(prefix="manifest_", suffix=".yaml")
|
||||
os.close(fd)
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(contents)
|
||||
return path
|
||||
|
||||
|
||||
def test_validator_reports_missing_file(tmp_path):
|
||||
# manifest referencing a non-existent file
|
||||
missing = str(tmp_path / "no_such_file.txt")
|
||||
manifest = f"""
|
||||
files:
|
||||
- path: {missing}
|
||||
"""
|
||||
mpath = _write_temp_manifest(manifest)
|
||||
try:
|
||||
report = validate_manifest(mpath)
|
||||
assert "missing_files" in report
|
||||
assert missing in report["missing_files"]
|
||||
finally:
|
||||
Path(mpath).unlink()
|
||||
|
||||
|
||||
def test_validator_detects_potential_secret(tmp_path):
|
||||
# manifest with evidence_excerpt containing PASSWORD
|
||||
evidence = "This shows a PASSWORD=hunter2 in the output"
|
||||
manifest = f'files:\n - path: some_file.txt\n evidence_excerpt: "{evidence}"\n'
|
||||
mpath = _write_temp_manifest(manifest)
|
||||
try:
|
||||
report = validate_manifest(mpath)
|
||||
assert "potential_secrets" in report
|
||||
items = report["potential_secrets"]
|
||||
assert any(evidence in (item.get("evidence_excerpt") or "") for item in items)
|
||||
finally:
|
||||
Path(mpath).unlink()
|
||||
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.validators.types import parse_manifest, Manifest
|
||||
|
||||
|
||||
def test_manifest_model_parses_sample(tmp_path: Path):
|
||||
sample = """
|
||||
files:
|
||||
- path: data/file1.txt
|
||||
evidence_excerpt: "some evidence"
|
||||
- file_path: data/file2.txt
|
||||
evidence_excerpt: "other evidence"
|
||||
"""
|
||||
p = tmp_path / "manifest.yaml"
|
||||
p.write_text(sample, encoding="utf-8")
|
||||
|
||||
manifest = parse_manifest(str(p))
|
||||
assert isinstance(manifest, Manifest)
|
||||
assert len(manifest.files) == 2
|
||||
assert manifest.files[0]["path"] == "data/file1.txt"
|
||||
assert manifest.files[1]["path"] == "data/file2.txt"
|
||||
Reference in New Issue
Block a user