Skip to content

Complete KE client to cover all OpenAPI spec operations#44

Merged
DaviddeBest-TNO merged 2 commits into
mainfrom
feat/complete-ke-client-issue-39
Jun 25, 2026
Merged

Complete KE client to cover all OpenAPI spec operations#44
DaviddeBest-TNO merged 2 commits into
mainfrom
feat/complete-ke-client-issue-39

Conversation

@DaviddeBest-TNO

@DaviddeBest-TNO DaviddeBest-TNO commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Closes #39, #6

Summary

Adds the three missing Knowledge Engine REST operations to the client stack and wires them into KnowledgeBase.

Changes

ke/models.py

  • KnowledgeBaseInfo gains two optional fields:
    • lease_renewal_time (alias leaseRenewalTime, 30–3600)
    • reasoner_level (alias reasonerLevel, 1–5)
  • New SmartConnectorLease model for the lease renewal response (knowledgeBaseId, expires).

ke/client.py (ClientProtocol + Client)

  • unregister_ki(kb_id, ki_id)DELETE /sc/ki
  • renew_lease(kb_id)PUT /sc/lease/renewSmartConnectorLease
  • load_domain_knowledge(kb_id, knowledge)POST /sc/knowledge with text/plain; charset=UTF-8 body (Jena rules)
  • Client.register_kb now dumps with exclude_none=True so unset leaseRenewalTime / reasonerLevel aren't sent.

testing/fake_client.py (TestClient)

  • In-memory implementations of all three new operations, raising SmartConnectorNotFoundError for unknown KB IDs / KI IDs.
  • New loaded_domain_knowledge and lease_renewals introspection helpers for tests.

kb/knowledge_base.py + kb/builder.py

  • KnowledgeBase.__init__ accepts lease_renewal_time and reasoner_level and forwards them into KnowledgeBaseInfo.
  • KnowledgeBaseBuilder propagates these from settings.
  • New high-level methods:
    • kb.renew_lease() -> SmartConnectorLease
    • kb.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 new KnowledgeBaseInfo fields.
  • tests/test_kb_new_operations.py: end-to-end tests for the new KnowledgeBase wrappers using TestClient.

Verification

  • uv run pytest -q → 114 tests pass (97 baseline + 17 new).
  • uv run ruff check . → clean.

Acceptance Criteria

  • unregister_ki implemented in ClientProtocol, Client, and TestClient
  • renew_lease implemented in ClientProtocol, Client, and TestClient
  • load_domain_knowledge implemented in ClientProtocol, Client, and TestClient
  • KnowledgeBaseInfo includes leaseRenewalTime and reasonerLevel fields
  • KnowledgeBase exposes renew_lease(), load_domain_knowledge(), and unregister_ki()
  • Tests exist for all three new operations
  • All existing tests still pass
  • Linting passes (ruff check)

DaviddeBest-TNO and others added 2 commits June 25, 2026 16:50
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>
@DaviddeBest-TNO DaviddeBest-TNO merged commit 8c1bd12 into main Jun 25, 2026
3 checks passed
@DaviddeBest-TNO DaviddeBest-TNO deleted the feat/complete-ke-client-issue-39 branch June 25, 2026 14:58
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.

Complete KE client to cover all OpenAPI spec operations

1 participant