Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/query-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ jobs:
- name: Verify portable candidate stubs against pinned public commits
env:
PYTHONDONTWRITEBYTECODE: '1'
run: python -B -S verify_portable_stubs.py
run: |
set -euo pipefail
python -B -S verify_portable_stubs.py
python -B -S verify_portable_stubs.py --check-math-tip
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Local engineering controls (no sibling checkout required):
```sh
python -B -S -m unittest -v test_research_query.py test_catalog_entry_helper.py test_verify_portable_stubs.py
python -B -S verify_portable_stubs.py
python -B -S verify_portable_stubs.py --check-math-tip
```

The twenty cross-repository federation controls remain in `trial/federation/test_federation.py`. Keep `research_query.py` byte-identical to the pinned federation/catalog hashes unless those pins are updated together.
Expand All @@ -52,7 +53,7 @@ The helper refuses sandbox paths, symlinks, mutable refs and non-public reposito
- [`portable/CANDIDATE_PUBLIC_REPLAY_STUBS.json`](portable/CANDIDATE_PUBLIC_REPLAY_STUBS.json) — uncataloged Math replay runners
- [`portable/CANDIDATE_DOWNSTREAM_GATE_STUBS.json`](portable/CANDIDATE_DOWNSTREAM_GATE_STUBS.json) — published fail-closed downstream hard-gate package (eng integrity; scientific effect none; refresh when Math- tip changes gate bytes)

Do not race meta-framework draft [#6](https://github.com/d6g8k5htny-coder/meta-framework/pull/6) (Drive parents / mesoscopic notes).
Do not race meta-framework draft [#6](https://github.com/d6g8k5htny-coder/meta-framework/pull/6) (Drive parents / mesoscopic notes). Live peer coordination status for writable agents is in [`portable/PEER_HANDOFF.json`](portable/PEER_HANDOFF.json).

The lookup tool rejects duplicate keys, malformed identities, mutable refs, path traversal, symlink payloads and entries marked private. The public catalog is manually source-reviewed; these checks do not independently discover actual GitHub visibility or prevent a malicious catalog from lying. Private `sandbox` artifacts are excluded from this route, not copied or fetched.

Expand Down
25 changes: 25 additions & 0 deletions portable/PEER_HANDOFF.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"scientific_status_authority": false,
"scientific_effect": "NONE",
"lemma_closed": false,
"query_tip_role": "portable candidate identities + lookup; not catalog authority",
"app_write": "query-only",
"cannot": [
"push meta-framework / Math- / trial / main / google-drive",
"comment on meta-framework PRs (Issues:write 403)",
"flip lemma_closed or research status"
],
"ready_for_meta_peers": [
"portable/CANDIDATE_PUBLIC_REPLAY_STUBS.json",
"portable/CANDIDATE_DOWNSTREAM_GATE_STUBS.json",
"portable/RN_FIXED_REMOTE_REPLAY_STUB.json"
],
"meta_readme_drift": "main README still says 18 public artifacts; registry has 22 including rn-fixed-remote-window*",
"avoid_racing": [
"meta-framework#6 cursor/catalog-drive-parents-5cb8",
"google-drive#3 selective Drive replicas",
"Math- drafts #7 #9 mesoscopic"
],
"batch336_note": "trial Path C IDLE; research main drafts skipped; this agent owns query- catalog stub currency + tip-drift gate",
"meaning": "coordination receipt only; not a task queue or acceptance register"
}
52 changes: 48 additions & 4 deletions test_verify_portable_stubs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Controls for verify_portable_stubs.py (offline-safe unit checks)."""
from __future__ import annotations

import hashlib
import json
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
from unittest import mock
Expand Down Expand Up @@ -52,13 +52,57 @@ def test_fetch_match(self):
'commit': '1' * 40,
'path': 'frontiers/x.py',
'bytes': 4,
'sha256': __import__('hashlib').sha256(b'data').hexdigest(),
'sha256': hashlib.sha256(b'data').hexdigest(),
}
v.validate_row(row)
with mock.patch.object(v, 'fetch', return_value=b'data'):
# exercise main path via temporary candidate list
with mock.patch.object(v, 'load_candidates', return_value=[row]):
self.assertEqual(v.main(), 0)
self.assertEqual(v.main([]), 0)

def _gate_row(self, payload: bytes = b'data'):
return {
'key': 'downstream-hard-gate-code',
'repository': 'Math-',
'visibility': 'public',
'commit': '1' * 40,
'path': 'frontiers/downstream_gate_20260925/hard_gate.py',
'bytes': len(payload),
'sha256': hashlib.sha256(payload).hexdigest(),
}

def test_math_tip_check_no_drift_when_tip_matches(self):
payload = b'data'
fake = {
'scientific_status_authority': False,
'math_tip': 'tipsha',
'artifacts': [self._gate_row(payload)],
}
with mock.patch.object(v, 'fetch_raw', return_value=payload):
with mock.patch.object(Path, 'is_file', return_value=True):
with mock.patch.object(Path, 'read_text', return_value=json.dumps(fake)):
out = v.check_math_tip_drift()
self.assertEqual(out['drifted'], [])
self.assertEqual(out['checked'], ['downstream-hard-gate-code'])

def test_math_tip_check_detects_drift(self):
fake = {
'scientific_status_authority': False,
'math_tip': 'tipsha',
'artifacts': [self._gate_row(b'data')],
}
with mock.patch.object(v, 'fetch_raw', return_value=b'DIFF'):
with mock.patch.object(Path, 'is_file', return_value=True):
with mock.patch.object(Path, 'read_text', return_value=json.dumps(fake)):
out = v.check_math_tip_drift()
self.assertEqual(len(out['drifted']), 1)
self.assertEqual(out['drifted'][0]['key'], 'downstream-hard-gate-code')

def test_peer_handoff_schema(self):
handoff = json.loads((ROOT / 'portable/PEER_HANDOFF.json').read_text())
self.assertFalse(handoff['scientific_status_authority'])
self.assertFalse(handoff['lemma_closed'])
self.assertEqual(handoff['scientific_effect'], 'NONE')
self.assertIn('portable/CANDIDATE_DOWNSTREAM_GATE_STUBS.json', handoff['ready_for_meta_peers'])


if __name__ == '__main__':
Expand Down
70 changes: 60 additions & 10 deletions verify_portable_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
Uses only declared commits/paths from portable/*.json. Network read of public
raw.githubusercontent.com content; no private sandbox fetch, no catalog edit,
no scientific acceptance. Skip offline with QUERY_STUB_VERIFY=0.

Pass --check-math-tip to also compare downstream-gate stubs to Math- default
tip bytes (detect tip drift that still verifies against older pinned commits).
"""
from __future__ import annotations

import argparse
import hashlib
import json
import os
Expand All @@ -31,7 +35,6 @@ def load_candidates() -> list[dict]:
if data.get('scientific_status_authority') is not False:
raise SystemExit('REFUSED: candidate bundle must deny scientific authority: ' + bundle_path.name)
rows.extend(data['artifacts'])
# de-dupe by key, prefer first
seen = set()
out = []
for row in rows:
Expand Down Expand Up @@ -59,16 +62,55 @@ def validate_row(row: dict) -> None:
raise SystemExit('REFUSED: invalid bytes for ' + row.get('key', '?'))


def fetch(row: dict) -> bytes:
url = (
f"https://raw.githubusercontent.com/d6g8k5htny-coder/"
f"{row['repository']}/{row['commit']}/{row['path']}"
)
def fetch_raw(repository: str, ref: str, path: str, max_bytes: int) -> bytes:
url = f'https://raw.githubusercontent.com/d6g8k5htny-coder/{repository}/{ref}/{path}'
with urllib.request.urlopen(url, timeout=30) as response:
return response.read(row['bytes'] + 1)
return response.read(max_bytes + 1)


def fetch(row: dict) -> bytes:
return fetch_raw(row['repository'], row['commit'], row['path'], row['bytes'])


def main() -> int:
def check_math_tip_drift() -> dict:
bundle_path = ROOT / 'portable/CANDIDATE_DOWNSTREAM_GATE_STUBS.json'
if not bundle_path.is_file():
return {'checked': [], 'drifted': [], 'math_tip_recorded': None}
data = json.loads(bundle_path.read_text())
drifted = []
checked = []
for row in data['artifacts']:
validate_row(row)
try:
tip_raw = fetch_raw(row['repository'], 'main', row['path'], 10000000)
except urllib.error.URLError as error:
raise SystemExit('REFUSED: tip fetch failed for ' + row['key'] + ': ' + str(error)) from error
tip_digest = hashlib.sha256(tip_raw).hexdigest()
checked.append(row['key'])
if len(tip_raw) != row['bytes'] or tip_digest != row['sha256']:
drifted.append({
'key': row['key'],
'stub_bytes': row['bytes'],
'tip_bytes': len(tip_raw),
'stub_sha256': row['sha256'],
'tip_sha256': tip_digest,
})
return {
'checked': checked,
'drifted': drifted,
'math_tip_recorded': data.get('math_tip'),
'meaning': 'tip drift vs portable stubs only; not catalog land or theorem acceptance',
}


def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--check-math-tip',
action='store_true',
help='fail if downstream-gate stubs no longer match Math- default tip bytes',
)
args = parser.parse_args(sys.argv[1:] if argv is None else argv)
if os.environ.get('QUERY_STUB_VERIFY', '1') == '0':
print('SKIPPED_STUB_VERIFY')
return 0
Expand All @@ -84,10 +126,18 @@ def main() -> int:
print('REFUSED: identity mismatch for ' + row['key'], file=sys.stderr)
return 2
checked.append(row['key'])
print(json.dumps({
report = {
'verified': checked,
'meaning': 'exact public bytes at declared commits only; not catalog land or theorem acceptance',
}, indent=2, sort_keys=True))
}
if args.check_math_tip:
tip = check_math_tip_drift()
report['math_tip_check'] = tip
if tip['drifted']:
print(json.dumps(report, indent=2, sort_keys=True))
print('REFUSED: TIP_DRIFT ' + ','.join(x['key'] for x in tip['drifted']), file=sys.stderr)
return 2
print(json.dumps(report, indent=2, sort_keys=True))
return 0


Expand Down
Loading