Complete source 6 engineering workflows and preserve release validation evidence
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Refresh the closed semantic OpenAPI catalog from the frozen Rust leaf table.
|
||||
|
||||
Run from any directory with Python 3: semantic_schema.py [--check].
|
||||
Run from any directory with Python 3: semantic_schema.py [--check] [--validate].
|
||||
--validate additionally runs source-6 structural fixtures with jsonschema.
|
||||
This generates documentation only, never runtime selectors or model mutations.
|
||||
"""
|
||||
import copy
|
||||
@@ -15,6 +16,7 @@ spec = json.loads(PATH.read_text(encoding="utf-8"))
|
||||
schemas = spec["components"]["schemas"]
|
||||
types = (ROOT / "crates/oa-core/src/semantic/types.rs").read_text(encoding="utf-8")
|
||||
model = (ROOT / "crates/oa-core/src/model.rs").read_text(encoding="utf-8")
|
||||
views = (ROOT / "crates/oa-core/src/view_options.rs").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def ref(name):
|
||||
@@ -47,6 +49,7 @@ def variant(name, value):
|
||||
|
||||
|
||||
def typed(name):
|
||||
name = name.replace("crate::view_options::", "")
|
||||
if name.startswith("Option<"):
|
||||
return optional(typed(name[7:-1]))
|
||||
if name.startswith("Vec<"):
|
||||
@@ -59,6 +62,7 @@ def typed(name):
|
||||
|
||||
|
||||
def reviewed(name):
|
||||
name = name.replace("crate::view_options::", "")
|
||||
key = "Reviewed" + re.sub(r"[^A-Za-z0-9]", "", name)
|
||||
observation = {"oneOf": [enum(["NotApplicable"]), variant("Value", typed(name))]}
|
||||
schemas[key] = obj({"oa": observation, "sa": copy.deepcopy(observation)})
|
||||
@@ -74,8 +78,9 @@ def keypair(name):
|
||||
for name in ["DataConstructor", "PortConstructor", "OccurrenceConstructor", "EventConstructor",
|
||||
"MessageConstructor", "ReferenceCollection", "OrderedCollection", "IncidentEnd",
|
||||
"ArtifactFacet", "ComponentPortKind", "ComponentPortOrientation", "PortDirection",
|
||||
"FragmentOperator", "StateActionKind", "ArtifactRelation"]:
|
||||
source = types if f"pub enum {name}" in types else model
|
||||
"FragmentOperator", "StateActionKind", "ArtifactRelation", "ExchangeFamily",
|
||||
"Coverage", "ExchangeLabels", "Kind", "RelationKind"]:
|
||||
source = next(s for s in [types, model, views] if f"pub enum {name}" in s)
|
||||
body = re.search(r"pub enum " + name + r"\s*\{([^}]+)\}", source).group(1)
|
||||
body = re.sub(r"//[^\n]*|#\[[^\]]*\]", "", body)
|
||||
names = [value.strip() for value in body.split(",") if value.strip()]
|
||||
@@ -84,17 +89,17 @@ for name in ["DataConstructor", "PortConstructor", "OccurrenceConstructor", "Eve
|
||||
|
||||
catalog = types.split("macro_rules! scalar_families", 1)[1].split("pub(super) use", 1)[0]
|
||||
families = re.findall(r"(\w+), (\w+), (\w+) \{([^}]+)\}", catalog)
|
||||
assert len(families) == 13
|
||||
assert len(families) == 14
|
||||
selectors, reviews = [], []
|
||||
leaf_count = 0
|
||||
for family, selector, review, body in families:
|
||||
leaves = re.findall(r"(\w+): ([\w<>]+)", body)
|
||||
leaves = re.findall(r"(\w+): ([\w:<>]+)", body)
|
||||
leaf_count += len(leaves)
|
||||
schemas[selector] = enum([leaf for leaf, _ in leaves])
|
||||
schemas[review] = {"oneOf": [variant(leaf, reviewed(value)) for leaf, value in leaves]}
|
||||
selectors.append(variant(family, ref(selector)))
|
||||
reviews.append(variant(family, ref(review)))
|
||||
assert leaf_count == 84
|
||||
assert leaf_count == 85
|
||||
schemas["AnnotationKey"] = obj({"path": array(ref("Id")), "field": ref("Id")})
|
||||
id_keys, text_keys, annotation_keys = keypair("Id"), keypair("String"), keypair("AnnotationKey")
|
||||
artifact_types = {"Presence": "bool", "Name": "String", "Description": "String", "Owner": "Id",
|
||||
@@ -119,13 +124,49 @@ schemas["FacetReview"] = {"oneOf": reviews}
|
||||
schemas["SemanticBaseline"] = obj({"facets": array(ref("FacetReview"))})
|
||||
schemas["TraceBaseline"]["properties"]["semantic"] = {**optional(ref("SemanticBaseline")), "default": None,
|
||||
"description": "Absent/null means Unreviewed. Historical typed facts never become live graph references."}
|
||||
schemas["Project"]["properties"]["schema_version"]["const"] = 5
|
||||
schemas["MigrationReport"]["properties"]["from_schema"]["enum"] = [1, 2, 3, 4]
|
||||
schemas["MigrationReport"]["properties"]["to_schema"]["const"] = 5
|
||||
schemas["MigrationReport"]["description"] = schemas["MigrationReport"]["description"].replace("V1/V2/V3 to V4", "V1/V2/V3/V4 to V5")
|
||||
spec["info"]["description"] = spec["info"]["description"].replace("schema-4", "schema-5")
|
||||
spec["paths"]["/api/v1/projects/import"]["post"]["description"] = "Schema-5 native JSON is described below. Schema-1/2/3/4 JSON and source are accepted through explicit frozen readers and migration, also on replacement and candidate validation. Prior prose reviews remain intact; absent semantic review stays Unreviewed. Export emits schema 5 / arcadia 5. See docs/language.rst."
|
||||
schemas["SourceBundle"]["description"] = schemas["SourceBundle"]["description"].replace("source4 workspace (source3 migrates explicitly)", "source5 workspace (source3/4 migrate explicitly)")
|
||||
schemas["Project"]["properties"]["schema_version"]["const"] = 6
|
||||
schemas["MigrationReport"]["properties"]["from_schema"]["enum"] = [1, 2, 3, 4, 5]
|
||||
schemas["MigrationReport"]["properties"]["to_schema"]["const"] = 6
|
||||
schemas["MigrationReport"]["description"] = re.sub(r"V1(?:/V[2-5])+ to V[4-6]", "V1/V2/V3/V4/V5 to V6", schemas["MigrationReport"]["description"])
|
||||
spec["info"]["description"] = re.sub(r"schema-[45]", "schema-6", spec["info"]["description"])
|
||||
spec["paths"]["/api/v1/projects/import"]["post"]["description"] = "Schema-6 native JSON is described below. Schema-1/2/3/4/5 JSON and source are accepted through explicit frozen readers and migration, also on replacement and candidate validation. Earlier versions reject source-6 constructors and saved view fields. Prior prose and typed reviews remain intact; absent semantic review stays Unreviewed. Export emits schema 6 / arcadia 6. See docs/language.rst."
|
||||
schemas["SourceBundle"]["description"] = re.sub(r"source[45] workspace \(source[^)]+\)", "source6 workspace (source3/4/5 migrate explicitly)", schemas["SourceBundle"]["description"])
|
||||
|
||||
# Source-6 additions are closed serde records; selectors with an empty payload
|
||||
# remain explicit selections rather than reverting to their omitted defaults.
|
||||
schemas["EdgeKind"] = {"oneOf": [enum(["Trace"]), variant("Relation", ref("RelationKind"))]}
|
||||
schemas["RelationKinds"] = {"oneOf": [enum(["All"]), variant("Only", array(ref("EdgeKind")))]}
|
||||
for selection in ["CategorySelection", "ContextSelection"]:
|
||||
schemas[selection] = {"oneOf": [enum(["All"]), variant("Any", array(ref("Id")))]}
|
||||
schemas["ViewOptions"] = obj({
|
||||
"hidden_edges": {**array(ref("Id")), "default": []},
|
||||
"relation_kinds": {**ref("RelationKinds"), "default": "All"},
|
||||
"work_categories": {**ref("CategorySelection"), "default": "All"},
|
||||
"participant_categories": {**ref("CategorySelection"), "default": "All"},
|
||||
"coverage": {**ref("Coverage"), "default": "All"},
|
||||
"work_contexts": {**ref("ContextSelection"), "default": "All"},
|
||||
"exchange_labels": {**ref("ExchangeLabels"), "default": "Name"}}, [])
|
||||
schemas["ViewOptions"]["description"] = "Presentation only. Independent predicates intersect; category members union within a family. Only([]) hides all relations and traces. Any([]) remains an explicit empty selection. Traceability permits both-layer hidden/category/context references; ordinary projections require the diagram layer. Filtering preserves unfiltered automatic port positions."
|
||||
schemas["Diagram"]["properties"]["view_options"] = {**ref("ViewOptions"), "default": {}}
|
||||
|
||||
def upsert_variant(variants, name, value):
|
||||
variants[:] = [v for v in variants if name not in v.get("properties", {})]
|
||||
variants.append(variant(name, value))
|
||||
|
||||
upsert_variant(schemas["RelationBody"]["oneOf"], "CommunicationMean", obj({
|
||||
"source": ref("Id"), "target": ref("Id"), "oriented": typed("bool"), "items": array(ref("Id"))}))
|
||||
upsert_variant(schemas["SharedBody"]["oneOf"][1]["oneOf"], "ExchangeCategory", obj({
|
||||
"family": ref("ExchangeFamily"), "exchanges": array(ref("Id"))}))
|
||||
schemas["CommunicationPortChoice"] = {"oneOf": [
|
||||
variant("Reuse", obj({"port": ref("Id")})),
|
||||
variant("Create", obj({"id": ref("Id"), "alias": typed("String"), "name": typed("String"),
|
||||
"description": typed("String"), "kind": ref("ComponentPortKind"),
|
||||
"orientation": ref("ComponentPortOrientation")}))]}
|
||||
schemas["CommunicationEndpointDecision"] = obj({"source": ref("Id"),
|
||||
"source_port": ref("CommunicationPortChoice"), "target_port": ref("CommunicationPortChoice")})
|
||||
schemas["TransitionRequest"]["properties"]["communication_endpoints"] = {
|
||||
**array(ref("CommunicationEndpointDecision"), 200), "default": [],
|
||||
"description": "Explicit SA component-port pair per selected OA CommunicationMean. Reuse or Create only. Owners follow reviewed participant mappings; no participant-to-port substitution or automatic interface allocation."}
|
||||
schemas["Drift"] = enum(["Unreviewed", "Unchanged", "OaChanged", "SaChanged", "BothChanged"])
|
||||
schemas["FacetDrift"] = obj({"selector": ref("FacetSelector"), "current": ref("FacetReview"), "drift": ref("Drift")})
|
||||
schemas["SemanticDrift"] = obj({"own": ref("Drift"), "linked": ref("Drift"),
|
||||
@@ -197,6 +238,70 @@ def check_refs(value):
|
||||
|
||||
|
||||
check_refs(spec)
|
||||
|
||||
if "--validate" in sys.argv:
|
||||
from jsonschema import Draft202012Validator, FormatChecker
|
||||
|
||||
for schema in schemas.values():
|
||||
Draft202012Validator.check_schema(schema)
|
||||
|
||||
fixture_count = 0
|
||||
|
||||
def accepts(name, value, expected=True):
|
||||
global fixture_count
|
||||
validator = Draft202012Validator({**ref(name), "components": spec["components"]},
|
||||
format_checker=FormatChecker())
|
||||
errors = list(validator.iter_errors(value))
|
||||
assert (not errors) == expected, (name, value, [e.message for e in errors])
|
||||
fixture_count += 1
|
||||
|
||||
a, b = "00000000-0000-4000-8000-000000000001", "00000000-0000-4000-8000-000000000002"
|
||||
mean = {"source": a, "target": b, "oriented": False, "items": []}
|
||||
accepts("RelationBody", {"CommunicationMean": mean})
|
||||
accepts("RelationBody", {"CommunicationMean": {**mean, "typo": True}}, False)
|
||||
for field in mean:
|
||||
accepts("RelationBody", {"CommunicationMean": {k: v for k, v in mean.items() if k != field}}, False)
|
||||
category = {"family": "Participant", "exchanges": [a]}
|
||||
accepts("SharedBody", {"ExchangeCategory": category})
|
||||
accepts("SharedBody", {"ExchangeCategory": {**category, "family": "Future"}}, False)
|
||||
accepts("SharedBody", {"ExchangeCategory": {**category, "typo": []}}, False)
|
||||
accepts("ViewOptions", {})
|
||||
options = {"hidden_edges": [a], "relation_kinds": {"Only": ["Trace", {"Relation": "CommunicationMean"}]},
|
||||
"work_categories": {"Any": []}, "participant_categories": {"Any": [b]},
|
||||
"coverage": "OutsideBehavior", "work_contexts": {"Any": []}, "exchange_labels": "NameAndItems"}
|
||||
accepts("ViewOptions", options)
|
||||
accepts("ViewOptions", {**options, "relation_kinds": {"Only": []}})
|
||||
for field, value in [("typo", []), ("coverage", "Unknown"), ("hidden_edges", ["not-an-id"]),
|
||||
("relation_kinds", {"Only": [], "typo": []}),
|
||||
("relation_kinds", {"Only": [{"Relation": "Future"}]}),
|
||||
("work_contexts", {"Any": [], "typo": []}),
|
||||
("exchange_labels", "Names")]:
|
||||
accepts("ViewOptions", {**options, field: value}, False)
|
||||
create = {"id": a, "alias": "radio", "name": "Radio", "description": "",
|
||||
"kind": "Standard", "orientation": "Unset"}
|
||||
accepts("CommunicationPortChoice", {"Create": create})
|
||||
accepts("CommunicationPortChoice", {"Reuse": {"port": a}})
|
||||
accepts("CommunicationPortChoice", "Auto", False)
|
||||
accepts("CommunicationPortChoice", {"Reuse": {"port": a, "owner": b}}, False)
|
||||
for field in create:
|
||||
accepts("CommunicationPortChoice", {"Create": {k: v for k, v in create.items() if k != field}}, False)
|
||||
pair = {"source": a, "source_port": {"Create": create}, "target_port": {"Reuse": {"port": b}}}
|
||||
accepts("CommunicationEndpointDecision", pair)
|
||||
accepts("CommunicationEndpointDecision", {k: v for k, v in pair.items() if k != "target_port"}, False)
|
||||
request = {"direction": "OaToSa", "sources": [a], "scope": "SelectedOnly", "mappings": [],
|
||||
"fields": [], "resolutions": [], "destination_diagram": None}
|
||||
accepts("TransitionRequest", request)
|
||||
accepts("TransitionRequest", {**request, "communication_endpoints": [pair]})
|
||||
accepts("TransitionRequest", {**request, "communication_endpoints": [pair] * 200})
|
||||
accepts("TransitionRequest", {**request, "communication_endpoints": [pair] * 201}, False)
|
||||
accepts("FacetSelector", {"Category": "Family"})
|
||||
accepts("FacetSelector", {"Category": "Unknown"}, False)
|
||||
accepts("FacetReview", {"Category": {"Family": {"oa": {"Value": "Work"}, "sa": {"Value": "Participant"}}}})
|
||||
accepts("FacetSelector", {"Member": {"collection": "CategoryExchanges", "keys": {"oa": a, "sa": b}}})
|
||||
assert schemas["Project"]["properties"]["schema_version"]["const"] == 6
|
||||
assert schemas["MigrationReport"]["properties"]["from_schema"]["enum"] == [1, 2, 3, 4, 5]
|
||||
print(f"Source-6 schema fixtures: {fixture_count} passed; all {len(schemas)} component schemas well-formed")
|
||||
|
||||
rendered = json.dumps(spec, indent=2, ensure_ascii=False) + "\n"
|
||||
if "--check" in sys.argv:
|
||||
assert json.loads(PATH.read_text(encoding="utf-8")) == spec, "Run semantic_schema.py to refresh OpenAPI"
|
||||
|
||||
Reference in New Issue
Block a user