feat(mindmodel): add validator and tests

This commit is contained in:
2026-03-24 21:28:17 +01:00
parent 7bd7d0d18c
commit a74e6006f5
2 changed files with 178 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
import json
import os
from scripts.mindmodel import validator
def write_manifest(path, data: str):
p = path
p.write_text(data, encoding="utf-8")
return str(p)
def test_validate_ok(tmp_path):
# manifest with one constraint and evidence pointing to an existing file
evidence_file = tmp_path / "file.txt"
evidence_file.write_text("hello")
manifest = {
"constraints": [
{"id": "c1", "evidence": [{"file": "file.txt", "text": "complete content"}]}
]
}
manifest_path = tmp_path / "manifest.json"
manifest_path.write_text(json.dumps(manifest))
code, report = validator.validate_manifest(
str(manifest_path), base_dir=str(tmp_path)
)
assert code == 0
assert report["missing_files"] == []
assert report["secrets"] == []
def test_missing_file_flags_failure(tmp_path):
# manifest refers to missing file
manifest = {
"constraints": [{"id": "c2", "evidence": [{"file": "nope.txt", "text": "foo"}]}]
}
manifest_path = tmp_path / "manifest.json"
manifest_path.write_text(json.dumps(manifest))
code, report = validator.validate_manifest(
str(manifest_path), base_dir=str(tmp_path)
)
assert code == 2
assert "nope.txt" in report["missing_files"]
def test_truncated_produces_warning(tmp_path):
# evidence text is truncated -> warning
f = tmp_path / "manifest.json"
manifest = {
"constraints": [{"id": "c3", "evidence": [{"text": "This is truncated..."}]}]
}
f.write_text(json.dumps(manifest))
code, report = validator.validate_manifest(str(f), base_dir=str(tmp_path))
assert code == 1
assert report["truncated"] >= 1
def test_manifest_scanned_for_secrets(tmp_path):
# manifest text contains an api_key pattern
f = tmp_path / "manifest.json"
f.write_text('api_key = "secretVALUE1234"')
code, report = validator.validate_manifest(str(f), base_dir=str(tmp_path))
assert code == 2
assert any("secretVALUE1234" in s for s in report["secrets"]) or report["secrets"]