Add event-taxonomy package with canonical schema, adapters, and CLI
Canonical NormalizedFinding schema with Severity enum (CRITICAL/HIGH/MEDIUM/LOW/INFO). Per-project adapters for 9 tools with severity mapping for string labels, int 1-10, float 0-1, Python Enum, and computed properties. CLI pipe interface and registry. Nightshift-Task: event-taxonomy Nightshift-Ref: https://github.com/marcus/nightshift
This commit is contained in:
52
tests/test_schema.py
Normal file
52
tests/test_schema.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import json
|
||||
|
||||
from event_taxonomy.schema import NormalizedFinding, Severity, ToolEvent
|
||||
|
||||
|
||||
def test_severity_ordering():
|
||||
assert Severity.CRITICAL > Severity.HIGH > Severity.MEDIUM > Severity.LOW > Severity.INFO
|
||||
|
||||
|
||||
def test_severity_str():
|
||||
assert str(Severity.CRITICAL) == "CRITICAL"
|
||||
assert str(Severity.INFO) == "INFO"
|
||||
|
||||
|
||||
def test_finding_construction():
|
||||
f = NormalizedFinding(
|
||||
tool="test-tool",
|
||||
category="test",
|
||||
severity=Severity.HIGH,
|
||||
message="something broke",
|
||||
file="foo.py",
|
||||
line=42,
|
||||
)
|
||||
assert f.tool == "test-tool"
|
||||
assert f.severity == Severity.HIGH
|
||||
assert f.file == "foo.py"
|
||||
assert f.line == 42
|
||||
assert f.metadata == {}
|
||||
assert f.recommendation is None
|
||||
|
||||
|
||||
def test_finding_to_dict():
|
||||
f = NormalizedFinding(tool="t", category="c", severity=Severity.LOW, message="m")
|
||||
d = f.to_dict()
|
||||
assert d["severity"] == "LOW"
|
||||
assert d["tool"] == "t"
|
||||
|
||||
|
||||
def test_tool_event_serialization():
|
||||
findings = [
|
||||
NormalizedFinding(tool="t", category="c", severity=Severity.HIGH, message="a"),
|
||||
NormalizedFinding(tool="t", category="c", severity=Severity.LOW, message="b"),
|
||||
]
|
||||
event = ToolEvent(tool_name="t", tool_version="1.0", findings=findings)
|
||||
d = event.to_dict()
|
||||
assert d["summary"]["total"] == 2
|
||||
assert d["summary"]["HIGH"] == 1
|
||||
assert d["summary"]["LOW"] == 1
|
||||
j = event.to_json()
|
||||
parsed = json.loads(j)
|
||||
assert parsed["tool_name"] == "t"
|
||||
assert len(parsed["findings"]) == 2
|
||||
Reference in New Issue
Block a user