observation: deliver one execution event sequence to stream and snapshot
This commit is contained in:
1 parent
f83d992c61
commit
404d559b86
97 files changed
+2672
-3128
No files matched your search
@@ -10,6 +10,7 @@ import pathlib
|
||||
import sys
|
||||
|
||||
from jsonschema import Draft202012Validator
|
||||
from referencing import Registry, Resource
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
||||
SCHEMA_DIR = ROOT / "spec" / "schemas"
|
||||
@@ -23,7 +24,9 @@ def load_schema(name):
|
||||
|
||||
|
||||
def validator(schema):
|
||||
return Draft202012Validator(schema)
|
||||
event = load_schema("observation-event.schema.json")
|
||||
registry = Registry().with_resource(event["$id"], Resource.from_contents(event))
|
||||
return Draft202012Validator(schema, registry=registry)
|
||||
|
||||
|
||||
def require_valid(schema_name, document, label):
|
||||
@@ -41,16 +44,16 @@ def require_invalid(schema_name, document, label):
|
||||
def main():
|
||||
if len(sys.argv) != 4:
|
||||
raise SystemExit(
|
||||
"usage: validate_protocols.py ANALYSIS.json TRACE.json TOOL.json"
|
||||
"usage: validate_protocols.py ANALYSIS.json OBSERVATION.json TOOL.json"
|
||||
)
|
||||
analysis_path, trace_path, tool_path = map(pathlib.Path, sys.argv[1:])
|
||||
analysis_path, observation_path, tool_path = map(pathlib.Path, sys.argv[1:])
|
||||
analysis = json.loads(analysis_path.read_text(encoding="utf-8"))
|
||||
trace = json.loads(trace_path.read_text(encoding="utf-8"))
|
||||
observation = json.loads(observation_path.read_text(encoding="utf-8"))
|
||||
tool = json.loads(tool_path.read_text(encoding="utf-8"))
|
||||
|
||||
analysis_schema = "analysis.schema.json"
|
||||
require_valid(analysis_schema, analysis, "analysis")
|
||||
require_valid("trace-v2.schema.json", trace, "trace")
|
||||
require_valid("observation-file.schema.json", observation, "observation")
|
||||
require_valid("cli-tool.schema.json", tool, "tool")
|
||||
|
||||
# Negative mutations: structure, version and traversal must fail closed.
|
||||
@@ -66,13 +69,16 @@ def main():
|
||||
bad["modules"][0]["resources"] = 3
|
||||
require_invalid(analysis_schema, bad, "analysis resources integer")
|
||||
|
||||
bad = copy.deepcopy(trace)
|
||||
bad = copy.deepcopy(observation)
|
||||
bad["events"][0]["seq"] = "zero"
|
||||
require_invalid("trace-v2.schema.json", bad, "trace event sequence type")
|
||||
require_invalid("observation-file.schema.json", bad, "observation event sequence type")
|
||||
|
||||
bad = copy.deepcopy(trace)
|
||||
bad["truncated"] = {"reason": "made_up", "limit": 1, "written": 1}
|
||||
require_invalid("trace-v2.schema.json", bad, "trace truncation reason")
|
||||
bad = copy.deepcopy(observation)
|
||||
bad["events"][0]["schema"] = "marqdo.execution-events"
|
||||
require_invalid("observation-file.schema.json", bad, "retired event format")
|
||||
bad = copy.deepcopy(tool)
|
||||
bad["requires"]["analysis"] = [3]
|
||||
require_invalid("cli-tool.schema.json", bad, "tool version requirement array")
|
||||
|
||||
bad = copy.deepcopy(tool)
|
||||
bad["entrypoint"] = "../outside"
|
||||
@@ -83,8 +89,8 @@ def main():
|
||||
require_invalid("cli-tool.schema.json", bad, "tool invalid version")
|
||||
|
||||
print(
|
||||
"validated analysis/trace/tool artifacts "
|
||||
f"({len(analysis['modules'])} modules, {len(trace['events'])} events)"
|
||||
"validated analysis/observation/tool artifacts "
|
||||
f"({len(analysis['modules'])} modules, {len(observation['events'])} events)"
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user