Skip to content

Commit ee91130

Browse files
committed
contract test
1 parent 3da38b4 commit ee91130

8 files changed

Lines changed: 151 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
**The Strategic Reasoning Engine.**
44

5-
[![Pylint](https://github.com/StrategyLogic/omen/actions/workflows/pylint.yml/badge.svg)](https://github.com/StrategyLogic/omen/actions/workflows/pylint.yml)
6-
[![Package](https://github.com/StrategyLogic/omen/actions/workflows/python-package.yml/badge.svg)](https://github.com/StrategyLogic/omen/actions/workflows/python-package.yml)
5+
[![Pylint](https://github.com/StrategyLogic/omen/actions/workflows/pylint.yml/badge.svg)](https://github.com/StrategyLogic/omen/actions/workflows/pylint.yml) [![Package](https://github.com/StrategyLogic/omen/actions/workflows/python-package.yml/badge.svg)](https://github.com/StrategyLogic/omen/actions/workflows/python-package.yml)
76

87
> **Simulate the Signs. Reveal the Chaos.**
98

README.zh.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
**开源战略推演引擎。**
44

5-
[![Pylint](https://github.com/StrategyLogic/omen/actions/workflows/pylint.yml/badge.svg)](https://github.com/StrategyLogic/omen/actions/workflows/pylint.yml)
6-
[![Package](https://github.com/StrategyLogic/omen/actions/workflows/python-package.yml/badge.svg)](https://github.com/StrategyLogic/omen/actions/workflows/python-package.yml)
5+
[![Pylint](https://github.com/StrategyLogic/omen/actions/workflows/pylint.yml/badge.svg)](https://github.com/StrategyLogic/omen/actions/workflows/pylint.yml) [![Package](https://github.com/StrategyLogic/omen/actions/workflows/python-package.yml/badge.svg)](https://github.com/StrategyLogic/omen/actions/workflows/python-package.yml)
76

87
> 模拟征兆,揭示混沌。
98

src/omen/scenario/contract_loader.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
from pathlib import Path
77

88

9-
def load_spec4_contract_schema(schema_filename: str) -> dict:
10-
"""Load a schema file from specs/004-improve-inference-precision/contracts/."""
9+
def load(schema_filename: str) -> dict:
10+
"""Load a schema from the repo spec path, with a test-fixture fallback."""
1111

1212
root = Path(__file__).resolve().parents[3]
1313
schema_path = (
1414
root
15-
/ "specs"
16-
/ "004-improve-inference-precision"
17-
/ "contracts"
15+
/ "tests"
16+
/ "fixtures"
17+
/ "contracts"
1818
/ schema_filename
1919
)
2020
if not schema_path.exists():
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://omen/specs/003/contracts/case-package.schema.json",
4+
"title": "CasePackage",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": ["manifest", "scenario_file", "case_doc_file", "required_artifacts", "runtime_support"],
8+
"properties": {
9+
"manifest": {
10+
"type": "object",
11+
"additionalProperties": false,
12+
"required": ["case_id", "case_name", "domain", "version", "scenario_entry", "narrative_entry"],
13+
"properties": {
14+
"case_id": { "type": "string", "minLength": 1 },
15+
"case_name": { "type": "string", "minLength": 1 },
16+
"domain": { "type": "string", "minLength": 1 },
17+
"version": { "type": "string", "minLength": 1 },
18+
"scenario_entry": { "type": "string", "minLength": 1 },
19+
"narrative_entry": { "type": "string", "minLength": 1 },
20+
"tags": {
21+
"type": "array",
22+
"items": { "type": "string", "minLength": 1 }
23+
}
24+
}
25+
},
26+
"scenario_file": { "type": "string", "minLength": 1 },
27+
"case_doc_file": { "type": "string", "minLength": 1 },
28+
"required_artifacts": {
29+
"type": "array",
30+
"minItems": 1,
31+
"items": { "type": "string", "minLength": 1 }
32+
},
33+
"ontology_presence": { "type": "boolean" },
34+
"runtime_support": {
35+
"type": "object",
36+
"additionalProperties": false,
37+
"required": [
38+
"simulate_supported",
39+
"explain_supported",
40+
"compare_supported",
41+
"semantic_conditions_supported",
42+
"rule_trace_supported"
43+
],
44+
"properties": {
45+
"simulate_supported": { "type": "boolean" },
46+
"explain_supported": { "type": "boolean" },
47+
"compare_supported": { "type": "boolean" },
48+
"semantic_conditions_supported": { "type": "boolean" },
49+
"rule_trace_supported": { "type": "boolean" }
50+
}
51+
}
52+
}
53+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://omen/specs/003/contracts/cross-case-output.schema.json",
4+
"title": "CrossCaseOutputContract",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": ["result_artifact", "explanation_artifact", "comparison_artifact"],
8+
"properties": {
9+
"result_artifact": {
10+
"type": "object",
11+
"additionalProperties": false,
12+
"required": ["scenario_id", "outcome_class", "timeline"],
13+
"properties": {
14+
"scenario_id": { "type": "string", "minLength": 1 },
15+
"outcome_class": { "type": "string", "minLength": 1 },
16+
"winner": { "type": ["object", "null"] },
17+
"timeline": { "type": "array" },
18+
"ontology_setup": { "type": ["object", "null"] },
19+
"explanation": { "type": ["object", "null"] }
20+
}
21+
},
22+
"explanation_artifact": {
23+
"type": "object",
24+
"additionalProperties": false,
25+
"required": ["branch_points", "causal_chain"],
26+
"properties": {
27+
"branch_points": { "type": "array" },
28+
"causal_chain": { "type": "array" },
29+
"narrative_summary": { "type": ["string", "null"] },
30+
"applied_axioms": { "type": ["object", "null"] },
31+
"rule_trace_references": { "type": ["array", "null"] }
32+
}
33+
},
34+
"comparison_artifact": {
35+
"type": "object",
36+
"additionalProperties": false,
37+
"required": ["baseline_outcome_class", "variation_outcome_class", "conditions", "deltas"],
38+
"properties": {
39+
"baseline_outcome_class": { "type": "string", "minLength": 1 },
40+
"variation_outcome_class": { "type": "string", "minLength": 1 },
41+
"conditions": {
42+
"type": "array",
43+
"items": {
44+
"type": "object",
45+
"required": ["description"],
46+
"properties": {
47+
"type": { "type": "string" },
48+
"description": { "type": "string", "minLength": 1 },
49+
"semantic_type": { "type": "string" },
50+
"category": { "type": "string" }
51+
}
52+
}
53+
},
54+
"deltas": { "type": "array" }
55+
}
56+
}
57+
}
58+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://omen/specs/004/contracts/precision-evaluation.schema.json",
4+
"title": "PrecisionEvaluationProfile",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": [
8+
"profile_id",
9+
"case_id",
10+
"repeatability_threshold",
11+
"directional_correctness_threshold",
12+
"trace_completeness_threshold",
13+
"status"
14+
],
15+
"properties": {
16+
"profile_id": { "type": "string", "minLength": 1 },
17+
"case_id": { "type": "string", "minLength": 1 },
18+
"repeatability_threshold": { "type": "number", "minimum": 0, "maximum": 1 },
19+
"directional_correctness_threshold": { "type": "number", "minimum": 0, "maximum": 1 },
20+
"trace_completeness_threshold": { "type": "number", "minimum": 0, "maximum": 1 },
21+
"status": {
22+
"type": "string",
23+
"enum": ["draft", "active", "retired"]
24+
}
25+
}
26+
}

tests/unit/test_case_package_validator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
ROOT = Path(__file__).resolve().parents[2]
1414
ONTOLOGY_SCENARIO = ROOT / "data" / "scenarios" / "ontology.json"
15+
FIXTURE_CONTRACT_DIR = ROOT / "tests" / "fixtures" / "contracts"
1516

1617

1718
def test_validate_runtime_support_rejects_disabled_capabilities() -> None:
@@ -29,6 +30,10 @@ def test_validate_runtime_support_rejects_disabled_capabilities() -> None:
2930

3031
def test_validate_case_package_from_scenario_payload() -> None:
3132
payload = json.loads(ONTOLOGY_SCENARIO.read_text(encoding="utf-8"))
33+
payload["case_package"]["required_artifacts"] = [
34+
str((FIXTURE_CONTRACT_DIR / "case-package.schema.json").relative_to(ROOT)),
35+
str((FIXTURE_CONTRACT_DIR / "cross-case-output.schema.json").relative_to(ROOT)),
36+
]
3237
case_package = validate_case_package_or_raise(payload["case_package"], base_dir=ROOT)
3338

3439
assert case_package.manifest.case_id == "ontology"

tests/unit/test_ingest_validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from omen.scenario.contract_loader import load_spec4_contract_schema
1+
from omen.scenario.contract_loader import load
22
from omen.scenario.ingest_validator import (
33
validate_extracted_entity_candidate_or_raise,
44
validate_ontology_assertion_candidates_or_raise,
@@ -72,5 +72,5 @@ def test_validate_ontology_assertion_candidates_or_raise() -> None:
7272

7373

7474
def test_load_spec4_contract_schema() -> None:
75-
schema = load_spec4_contract_schema("precision-evaluation.schema.json")
75+
schema = load("precision-evaluation.schema.json")
7676
assert schema["title"] == "PrecisionEvaluationProfile"

0 commit comments

Comments
 (0)