Skip to content

Commit 4c69846

Browse files
author
Julio Berroa
committed
Add CI workflow: receipt generation + schema validation + hash chain verification
- Runs across Python 3.10/3.11/3.12 - Generates all 4 example receipts - Validates against schema.json - Verifies SHA-256 hash chains
1 parent 15a2f16 commit 4c69846

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

.github/workflows/ci.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
validate:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.10", "3.11", "3.12"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: pip install jsonschema
26+
27+
- name: Generate all example receipts
28+
run: |
29+
cd reference_impl
30+
python generate_receipt.py
31+
python scenario_cui_blocked.py
32+
python scenario_human_rejected.py
33+
python scenario_revoked.py
34+
35+
- name: Validate all receipts against schema
36+
run: |
37+
for f in examples/*.json; do
38+
echo "Validating $f..."
39+
python -m jsonschema -i "$f" schema.json
40+
echo " PASS: $f"
41+
done
42+
43+
- name: Verify hash chains
44+
run: |
45+
python -c "
46+
import json, hashlib
47+
48+
def verify(path):
49+
with open(path) as f:
50+
r = json.load(f)
51+
chain = r['integrity']['hash_chain']['chain']
52+
steps = r['execution']['steps']
53+
prev = '0' * 64
54+
for entry, step in zip(chain, steps):
55+
data = prev.encode() + json.dumps(step, sort_keys=True, separators=(',',':')).encode()
56+
h = hashlib.sha256(data).hexdigest()
57+
assert entry['hash'] == h, f'Hash mismatch at {entry[\"step_id\"]}'
58+
prev = h
59+
assert prev == r['integrity']['hash_chain']['final_hash']
60+
print(f' PASS: {path} ({len(chain)} steps)')
61+
62+
import glob
63+
for f in glob.glob('examples/*.json'):
64+
verify(f)
65+
"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ dist/
99
build/
1010
.DS_Store
1111
Thumbs.db
12-
.github/
12+

0 commit comments

Comments
 (0)