-
Notifications
You must be signed in to change notification settings - Fork 0
feat: MGTP minimal deterministic decision artefact demo #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
3
commits into
feat/mgtp-scaffold-v0.1
Choose a base branch
from
copilot/add-deterministic-decision-demo
base: feat/mgtp-scaffold-v0.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| __pycache__/ | ||
| *.pyc | ||
| *.pyo | ||
| .pytest_cache/ | ||
| *.egg-info/ | ||
| dist/ | ||
| build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+14 KB
commit_gate/tests/__pycache__/test_determinism.cpython-312-pytest-9.0.2.pyc
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """Minimal MGTP decision artefact demonstration. | ||
|
|
||
| Proves: | ||
| 1) Deterministic canonicalisation — same inputs produce identical bytes. | ||
| 2) Stable decision_hash — sha256 of canonical request+verdict+reasons. | ||
| 3) Replayable reconstruction — stored bytes can be reloaded and re-verified. | ||
|
|
||
| No randomness. Fixed inputs. Fixed timestamp (excluded from hash). | ||
| Run with: python examples/minimal_decision_demo.py | ||
| """ | ||
|
|
||
| import base64 | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| # Resolve commit_gate package from repository layout | ||
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "commit_gate" / "src")) | ||
|
|
||
| from commit_gate.canonicalise import canonicalise | ||
| from commit_gate.engine import evaluate | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Fixed, deterministic inputs (no randomness, no live timestamps) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| REQUEST = { | ||
| "actor_id": "demo-actor", | ||
| "action_class": "FILE", | ||
| "context": {"description": "minimal demo commit"}, | ||
| "authority_scope": {"project": "demo-project"}, | ||
| "invariant_hash": "0000000000000000000000000000000000000000000000000000000000000000", | ||
| } | ||
|
|
||
| RULESET = { | ||
| "allowlist": [ | ||
| { | ||
| "actor_id": "demo-actor", | ||
| "action_class": "FILE", | ||
| "scope_match": {"project": "demo-project"}, | ||
| } | ||
| ], | ||
| "denylist": [], | ||
| "escalation": [], | ||
| } | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Evaluate and serialise | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| result = evaluate(REQUEST, RULESET) | ||
| canonical_bytes = canonicalise(result) | ||
| canonical_b64 = base64.b64encode(canonical_bytes).decode("ascii") | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Output — regulator-readable | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| print("=== MGTP Minimal Decision Artefact Demo ===") | ||
| print() | ||
| print(f"verdict : {result['verdict']}") | ||
| print(f"reasons : {result['reasons']}") | ||
| print(f"artefact_version: {result['artefact_version']}") | ||
| print(f"request_hash : {result['request_hash']}") | ||
| print(f"decision_hash : {result['decision_hash']}") | ||
| print() | ||
| print(f"canonical_bytes (base64):") | ||
| print(canonical_b64) | ||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+8.35 KB
prometheus/tests/__pycache__/test_aggregation_determinism.cpython-312-pytest-9.0.2.pyc
Binary file not shown.
Binary file added
BIN
+8.54 KB
prometheus/tests/__pycache__/test_fit_report_classification.cpython-312-pytest-9.0.2.pyc
Binary file not shown.
Binary file added
BIN
+6.25 KB
prometheus/tests/__pycache__/test_input_hashing.cpython-312-pytest-9.0.2.pyc
Binary file not shown.
Binary file added
BIN
+8.5 KB
prometheus/tests/__pycache__/test_negative_injection.cpython-312-pytest-9.0.2.pyc
Binary file not shown.
Binary file added
BIN
+8.01 KB
prometheus/tests/__pycache__/test_redline_scanner.cpython-312-pytest-9.0.2.pyc
Binary file not shown.
Binary file added
BIN
+11.4 KB
prometheus/tests/__pycache__/test_schema_validation.cpython-312-pytest-9.0.2.pyc
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| eyJhcnRlZmFjdF92ZXJzaW9uIjoiMC4xIiwiZGVjaXNpb25faGFzaCI6ImZhYjg3NDBjOTIwNDg5MTU0MDM4MDYzNjIwZTE0NTM0NjBlMWVhMTU0OWQwY2IxZjBjYjJkY2EwY2U4NjAzNjAiLCJyZWFzb25zIjpbImFsbG93bGlzdF9tYXRjaCJdLCJyZXF1ZXN0X2hhc2giOiJiYTEzN2RkNjM2YjNiNzZiZGI2YmRlZmQzNjc0YjQwMTkxMDY1NGU3YmY3MWFiNDEwNjYwMDg3NTU2ZWE0MmUwIiwidmVyZGljdCI6IkFMTE9XIn0= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """Replay test: proves stored golden canonical bytes are byte-identical on re-evaluation. | ||
|
|
||
| T-REPLAY-1: canonical_bytes from fixed inputs == stored golden bytes. | ||
| T-REPLAY-2: decision_hash derived from re-evaluation == hash in golden bytes. | ||
|
|
||
| Fails if any single byte differs. | ||
| """ | ||
|
|
||
| import base64 | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "commit_gate" / "src")) | ||
|
|
||
| from commit_gate.canonicalise import canonicalise | ||
| from commit_gate.engine import evaluate | ||
|
|
||
| FIXTURES_DIR = Path(__file__).resolve().parent / "fixtures" | ||
|
|
||
| # Fixed inputs — must exactly match examples/minimal_decision_demo.py | ||
| REQUEST = { | ||
| "actor_id": "demo-actor", | ||
| "action_class": "FILE", | ||
| "context": {"description": "minimal demo commit"}, | ||
| "authority_scope": {"project": "demo-project"}, | ||
| "invariant_hash": "0000000000000000000000000000000000000000000000000000000000000000", | ||
| } | ||
|
|
||
| RULESET = { | ||
| "allowlist": [ | ||
| { | ||
| "actor_id": "demo-actor", | ||
| "action_class": "FILE", | ||
| "scope_match": {"project": "demo-project"}, | ||
| } | ||
| ], | ||
| "denylist": [], | ||
| "escalation": [], | ||
| } | ||
|
|
||
|
|
||
| def _load_golden_bytes(): | ||
| b64_text = (FIXTURES_DIR / "golden_canonical_bytes.b64").read_text().strip() | ||
| return base64.b64decode(b64_text) | ||
|
Comment on lines
+42
to
+44
|
||
|
|
||
|
|
||
| def test_t_replay_1_canonical_bytes_identical(): | ||
| """T-REPLAY-1: Re-evaluating fixed inputs produces byte-identical canonical bytes.""" | ||
| golden = _load_golden_bytes() | ||
| result = evaluate(REQUEST, RULESET) | ||
| actual = canonicalise(result) | ||
| assert actual == golden, ( | ||
| f"Canonical bytes differ from golden fixture.\n" | ||
| f"Expected: {golden!r}\n" | ||
| f"Got: {actual!r}" | ||
| ) | ||
|
|
||
|
|
||
| def test_t_replay_2_decision_hash_stable(): | ||
| """T-REPLAY-2: decision_hash in re-evaluated result matches hash in golden bytes.""" | ||
| import json | ||
|
|
||
| golden = _load_golden_bytes() | ||
| golden_dict = json.loads(golden.decode("utf-8")) | ||
| golden_hash = golden_dict["decision_hash"] | ||
|
|
||
| result = evaluate(REQUEST, RULESET) | ||
| assert result["decision_hash"] == golden_hash, ( | ||
| f"decision_hash mismatch.\n" | ||
| f"Expected: {golden_hash}\n" | ||
| f"Got: {result['decision_hash']}" | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script runs significant logic at import time (evaluate + printing). Wrapping execution in a main() and guarding with if name == 'main' avoids side effects if the module is imported (e.g., by tooling) and makes it easier to reuse in tests.