Skip to content

test: add an offline OBP-API contract for the meta calls - #6

Open
hongwei1 wants to merge 10 commits into
OpenBankProject:mainfrom
hongwei1:test/obp-api-contract
Open

hongwei1 wants to merge 10 commits into
OpenBankProject:mainfrom
hongwei1:test/obp-api-contract

Conversation

@hongwei1

@hongwei1 hongwei1 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

This adds an OBP-API contract for the calls OBP-MCP makes on its own: obp-api-contract/contract.json lists each of them (root, glossary, resource docs and swagger, at the default DEFAULT_API_VERSION v7.0.0) with its source file, the text that makes the call and the response fields the code reads, and obp-api-contract/snapshot.json records what an OBP-API documents for those endpoints. tests/test_obp_api_contract.py checks offline, as part of uv run pytest, that every listed call is still in its file, that every string in src/, database/ and scripts/ that builds an OBP-API path belongs to a listed call, that the paths use DEFAULT_API_VERSION, that the snapshot matches the contract, and that every endpoint and every field read is documented; it fails when a new call is added without a contract entry or when a retaken snapshot shows an endpoint or field gone. Fields OBP-API returns but does not document (the resource-docs and swagger bodies) are listed in undocumented_fields, and the test fails once they become documented so the list shrinks.

To check a new OBP-API build, run python3 -I obp-api-contract/snapshot.py --base https://k8s.openbankproject.com (anonymous GETs of the public resource docs and root, standard library only) and rerun the tests. The generic call_obp_api tool is not listed, since its endpoint is chosen by the user from the index and its version is already moved up to v5.1.0 by the existing floor in src/tools/endpoint_index.py. .github/workflows/tests.yml runs the whole suite (124 tests) on every pull request with uv sync --frozen; the endpoint index tests now build their index from sample resource docs, because database/endpoint_index.json is generated from a running OBP-API and is not in the repository.

A literal path segment also matches a documented placeholder, so a call whose own endpoint is gone could match a neighbouring endpoint when the snapshot is retaken, and the tests would pass against the wrong fields. snapshot.py now compares each call's operation with the snapshot.json already on disk: if one differs it lists the calls and writes nothing, unless --accept-rebind is given. A path with no /obp/vX.Y.Z prefix is recorded as missing and unversioned instead of stopping the script. The file is the same in every repository that keeps an OBP-API contract.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant