implement ops hub extension contract
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a053ff-1d6f-7fe2-ac1c-a6eb40a42a0c
This commit is contained in:
parent
9bbbf2032d
commit
75f4944144
14 changed files with 662 additions and 43 deletions
35
scripts/hub-core-conformance.py
Normal file
35
scripts/hub-core-conformance.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Run Ops Hub's package through a disposable hub-core reference runtime."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--hub-core-repo", type=Path, default=Path("../hub-core"))
|
||||
args = parser.parse_args()
|
||||
sys.path.insert(0, str(args.hub_core_repo.resolve()))
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from hub_core.conformance import ConformanceHarness
|
||||
from hub_core.runtime.app import create_app
|
||||
from hub_core.runtime.config import RuntimeSettings
|
||||
from hub_core.runtime.store import InMemoryPortStore
|
||||
from ops_hub.extension_contract import load_extension_package
|
||||
|
||||
settings = RuntimeSettings(environment="test", backend="memory", allow_ephemeral=True)
|
||||
target = TestClient(create_app(settings=settings, port_store=InMemoryPortStore()))
|
||||
harness = ConformanceHarness(target)
|
||||
harness.package = load_extension_package()
|
||||
report = harness.run()
|
||||
print(json.dumps(report.to_dict(), indent=2, sort_keys=True))
|
||||
return 0 if report.passed else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
50
scripts/hub-extension-check.py
Normal file
50
scripts/hub-extension-check.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Validate the owner package against hub-core's versioned schemas."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from jsonschema import Draft202012Validator, FormatChecker
|
||||
|
||||
from ops_hub.extension_contract import load_extension_package, validation_receipt
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--hub-core-repo", type=Path, default=Path("../hub-core"))
|
||||
args = parser.parse_args()
|
||||
|
||||
root = (
|
||||
args.hub_core_repo
|
||||
/ "hub_core"
|
||||
/ "contracts"
|
||||
/ "helixforge_hub_extension"
|
||||
/ "v0_1_0"
|
||||
)
|
||||
schemas = root / "schemas"
|
||||
package = load_extension_package()
|
||||
for key, schema_name in (
|
||||
("descriptor", "hub-descriptor.schema.json"),
|
||||
("manifest", "hub-manifest.schema.json"),
|
||||
):
|
||||
schema = json.loads((schemas / schema_name).read_text(encoding="utf-8"))
|
||||
Draft202012Validator.check_schema(schema)
|
||||
Draft202012Validator(schema, format_checker=FormatChecker()).validate(package[key])
|
||||
|
||||
catalog = json.loads((root / "catalogs" / "event-types.json").read_text(encoding="utf-8"))
|
||||
known_events = {entry["type"] for entry in catalog["event_types"]}
|
||||
declared_events = set(package["manifest"]["events_emitted"])
|
||||
declared_events.update(package["manifest"]["events_consumed"])
|
||||
unknown = sorted(declared_events - known_events)
|
||||
if unknown:
|
||||
raise SystemExit("events absent from hub-core catalog: " + ", ".join(unknown))
|
||||
|
||||
print(json.dumps(validation_receipt(), indent=2, sort_keys=True))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue