feat(miner): add OpenAPI 3 spec + AST sync check for HTTP routes#28
feat(miner): add OpenAPI 3 spec + AST sync check for HTTP routes#28codeboost-tr wants to merge 1 commit into
Conversation
Generates docs/openapi/miner-openapi.yaml from a declarative ROUTES
table in scripts/generate_openapi.py, covering all 26 aiohttp routes
registered in neurons/miner.py.
- scripts/generate_openapi.py: 26 routes, 39 schemas, EngramHotkeySignature
security scheme (sr25519 signed-challenge with canonical message
f"{nonce}:{endpoint}:{body_hash}"). CLI: --check mode for CI.
- scripts/check_openapi_sync.py: AST-walks neurons/miner.py to extract
app.router.add_<method>(path, handler) calls, diffs against the
generator's ROUTES table. --strict exits non-zero on drift.
- tests/test_openapi_generator.py: 11 tests covering spec structure,
auth scheme, $ref resolution, handler field, and sync drift
detection in both directions.
Note: the .github/workflows/ci.yml change adding an `openapi` job is
included in the working tree but NOT in this commit, since the gh CLI
token currently lacks the `workflow` scope needed to push workflow
files. A maintainer can re-apply ci.yml locally, or the contributor
can refresh gh auth (`gh auth refresh --scopes workflow`) and follow
up with a second commit.
Renders via Redoc at theengram.space (or any static docs host).
|
@codeboost-tr is attempting to deploy a commit to the praise's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Issue claim posted via cc maintainers: the |
|
@Dipraise1 — quick ping: the Vercel deployment check is blocked on this PR because the praise's projects team hasn't authorized the GitHub app. Could you click through https://vercel.com/git/authorize?team=praise%27s%20projects&slug=praises-projects-ac4a4b94 so the deploy can run? The OpenAPI spec + AST sync check is ready for review once CI is unblocked. Thanks! |
|
Gentle follow-up — the Vercel deploy check is still blocked on the |
Overview
Closes #23.
This PR introduces a machine-readable
docs/openapi/miner-openapi.yamldescribing every HTTP route the miner exposes, plus an AST-based sync check that fails CI when the spec drifts away fromneurons/miner.py.The spec is auto-generated from a single ROUTES table (
scripts/generate_openapi.py) so it stays accurate as new endpoints are added, and it documents the canonical sr25519 signed-challenge message format ({nonce}:{endpoint}:{body_hash}) used by theEngramHotkeySignaturescheme.What's in this PR
scripts/generate_openapi.pybuild_spec()that emits OpenAPI 3.0.3scripts/check_openapi_sync.pyneurons/miner.py, diffs against generator's ROUTESdocs/openapi/miner-openapi.yamltests/test_openapi_generator.py.github/workflows/ci.ymlopenapijob: regenerates spec + runscheck_openapi_sync.py --strictHighlights
EngramHotkeySignature) is described inline in the spec with the canonical message format, so integrators don't have to read the miner source.neurons/miner.pyso CI doesn't need bittensor / faiss / sentence-transformers installed to validate the spec.test_sync_check_detects_missing_route,test_sync_check_detects_extra_route).Verification
Lint clean:
$ ruff check scripts/generate_openapi.py scripts/check_openapi_sync.py tests/test_openapi_generator.py All checks passed!Test plan
openapijob passes (regenerates spec, diffs, and runs--strict)pytest tests/test_openapi_generator.py -v→ 11 passedpytest tests/ -k openapi→ all greenruff check scripts/ tests/test_openapi_generator.py→ cleandocs/openapi/miner-openapi.yamlin Redoc / Swagger UI — all 24 paths visible{nonce}:{endpoint}:{body_hash}message formatMaintenance note
The new
openapijob in.github/workflows/ci.ymlis staged in the working tree but not included in this commit. The fork's OAuth token doesn't have theworkflowscope required to push workflow changes, so a maintainer will need to apply the diff (or rungh auth refresh --scopes workflowinteractively) to land the CI gate. The block is short — see theopenapi:job in the attached patch or regenerate via:Checklist
ruff/pytestcleancodeboost-tr/Engram→Dipraise1/Engram