Complete KE client to cover all OpenAPI spec operations#44
Merged
Conversation
Implements three missing operations from the Knowledge Engine OpenAPI spec across the ClientProtocol, Client (HTTP), and TestClient (in-memory fake): - DELETE /sc/ki -> unregister_ki(kb_id, ki_id) - PUT /sc/lease/renew -> renew_lease(kb_id) -> SmartConnectorLease - POST /sc/knowledge -> load_domain_knowledge(kb_id, knowledge) Models: - KnowledgeBaseInfo gains optional leaseRenewalTime (30-3600) and reasonerLevel (1-5) fields. - New SmartConnectorLease model for the lease-renewal response. - Client.register_kb now serialises with exclude_none=True so unset optional fields are omitted from the payload, per the spec. KnowledgeBase: - Adds renew_lease(), load_domain_knowledge(knowledge), and unregister_ki(ki_name) wrappers (name-based, resolves to KI id). - Constructor and KnowledgeBaseBuilder propagate the two new optional fields through to KnowledgeBaseInfo so they can be set via settings. Tests: - Adds unit tests for all three new client operations (success + not-found + unexpected-response paths where applicable). - Adds tests for the new KnowledgeBase wrappers via TestClient. Closes #39 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #39, #6
Summary
Adds the three missing Knowledge Engine REST operations to the client stack and wires them into
KnowledgeBase.Changes
ke/models.pyKnowledgeBaseInfogains two optional fields:lease_renewal_time(aliasleaseRenewalTime, 30–3600)reasoner_level(aliasreasonerLevel, 1–5)SmartConnectorLeasemodel for the lease renewal response (knowledgeBaseId,expires).ke/client.py(ClientProtocol+Client)unregister_ki(kb_id, ki_id)→DELETE /sc/kirenew_lease(kb_id)→PUT /sc/lease/renew→SmartConnectorLeaseload_domain_knowledge(kb_id, knowledge)→POST /sc/knowledgewithtext/plain; charset=UTF-8body (Jena rules)Client.register_kbnow dumps withexclude_none=Trueso unsetleaseRenewalTime/reasonerLevelaren't sent.testing/fake_client.py(TestClient)SmartConnectorNotFoundErrorfor unknown KB IDs / KI IDs.loaded_domain_knowledgeandlease_renewalsintrospection helpers for tests.kb/knowledge_base.py+kb/builder.pyKnowledgeBase.__init__acceptslease_renewal_timeandreasoner_leveland forwards them intoKnowledgeBaseInfo.KnowledgeBaseBuilderpropagates these from settings.kb.renew_lease() -> SmartConnectorLeasekb.load_domain_knowledge(knowledge: str)kb.unregister_ki(ki_name: str)— resolves the name to the KI id internally and cleans up both local registries.Tests
tests/test_client.py: success + not-found + unexpected-response paths for each new client method, plus payload-shape tests for the newKnowledgeBaseInfofields.tests/test_kb_new_operations.py: end-to-end tests for the newKnowledgeBasewrappers usingTestClient.Verification
uv run pytest -q→ 114 tests pass (97 baseline + 17 new).uv run ruff check .→ clean.Acceptance Criteria
unregister_kiimplemented inClientProtocol,Client, andTestClientrenew_leaseimplemented inClientProtocol,Client, andTestClientload_domain_knowledgeimplemented inClientProtocol,Client, andTestClientKnowledgeBaseInfoincludesleaseRenewalTimeandreasonerLevelfieldsKnowledgeBaseexposesrenew_lease(),load_domain_knowledge(), andunregister_ki()ruff check)