feat(plugin): add EntityUpdateClientProtocol and parent-aware get - #1064
feat(plugin): add EntityUpdateClientProtocol and parent-aware get#1064SandyChapman wants to merge 1 commit into
Conversation
|
The entity-client protocols describe a narrower surface than `EntityClient`
actually has, so a plugin needing more either declares a private protocol or
types against the concrete class. Two capabilities are missing:
- `update`, the read-modify-write against the `db_version` optimistic lock
- `get(..., parent=...)`, needed to address a child entity, which is unique
within (workspace, entity_type, parent, name) rather than by name alone
Add `EntityUpdateClientProtocol` as its own protocol rather than folding
`update` into `EntityClientProtocol`. Protocols are structural, so a new member
silently invalidates every existing implementer — including every test double —
even for services that never call it. Most services only create and read; they
keep their narrow surface, and a service needing both composes:
class Store(EntityClientProtocol[T], EntityUpdateClientProtocol[T], Protocol[T]):
...
`parent` is added to `EntityGetterProtocol.get` instead, because a second
protocol declaring a conflicting `get` could not compose with the first. It is
optional, so fetching a root entity is unchanged. The existing test doubles gain
the argument: each stands in for a client that already accepts it, so their
signature was simply inaccurate.
A static conformance assertion in the tests fails type-checking if the client and
the protocols ever drift apart, which is the situation this change exists to fix.
Signed-off-by: Sandy Chapman <schapman@nvidia.com>
9e5b4c1 to
29eabaf
Compare
📝 WalkthroughWalkthroughThe entity client contracts now support optional parent context for retrieval and a separate optimistic-locking update protocol. Public exports, protocol tests, and evaluator test fakes were updated to match the revised interfaces. ChangesEntity client contract alignment
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/nemo_platform_plugin/tests/entities/test_client_protocols.py (1)
11-11: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove postponed annotation evaluation.
from __future__ import annotationsmakes annotations string-based. All referenced types have normal imports. Remove this import.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/nemo_platform_plugin/tests/entities/test_client_protocols.py` at line 11, Remove the `from __future__ import annotations` import statement at the top of the test_client_protocols.py file. Since all type annotations in the module use properly imported types rather than requiring string-based deferred evaluation, this future import is unnecessary and should be deleted.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/nemo_platform_plugin/tests/entities/test_client_protocols.py`:
- Line 11: Remove the `from __future__ import annotations` import statement at
the top of the test_client_protocols.py file. Since all type annotations in the
module use properly imported types rather than requiring string-based deferred
evaluation, this future import is unnecessary and should be deleted.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 582832db-b1dd-4daf-8832-f8c52aa12bdd
📒 Files selected for processing (14)
packages/nemo_platform_plugin/src/nemo_platform_plugin/entities/__init__.pypackages/nemo_platform_plugin/src/nemo_platform_plugin/entities/base.pypackages/nemo_platform_plugin/src/nemo_platform_plugin/entity_client.pypackages/nemo_platform_plugin/tests/entities/test_client_protocols.pyplugins/nemo-evaluator/tests/api/service/test_metric_service.pyplugins/nemo-evaluator/tests/api/service/test_result_service.pyplugins/nemo-evaluator/tests/api/service/test_task_service.pyplugins/nemo-evaluator/tests/api/service/test_taskset_service.pyplugins/nemo-evaluator/tests/api/v2/test_metrics_routes.pyplugins/nemo-evaluator/tests/api/v2/test_results_routes.pyplugins/nemo-evaluator/tests/api/v2/test_tasks_routes.pyplugins/nemo-evaluator/tests/api/v2/test_tasksets_routes.pyplugins/nemo-evaluator/tests/test_metric_refs.pyplugins/nemo-evaluator/tests/test_task_refs.py
Problem
The entity-client protocols in
nemo_platform_plugindescribe a narrower surface thanEntityClientactually has, so a plugin needing more must declare a private protocol or type against the concrete class. Two capabilities are missing:update— the read-modify-write against thedb_versionoptimistic lock.get(..., parent=...)— needed to address a child entity, which is unique within(workspace, entity_type, parent, name)rather than by name alone.Approach
updatebecomes its own protocol, composed with the existing ones rather than folded into them:Folding it into
EntityClientProtocolwould be wrong: protocols are structural, so a new member silently invalidates every existing implementer — including every test double — even for services that never call it.MetricServiceonly creates and reads; it shouldn't be typed againstupdate, and its fakes shouldn't grow methods to satisfy a type.parentis added toEntityGetterProtocol.getrather than given its own protocol, because a second protocol declaring a conflictinggetcouldn't compose with the first. It's optional, so fetching a root entity is unchanged.That does require the existing test doubles to accept it — 10 fakes, one argument each. That's a correctness fix rather than churn: each stands in for a client that already accepts
parent, so their signature was simply inaccurate.Drift guard
The tests include a static conformance assertion:
tyfails here if the client and protocols ever diverge. Verified it actually catches drift — renamingupdatein the protocol produces:_ReadWriteStoreis itself the composition shown above, so the test doubles as proof that the pieces compose.Verification
nemo_platform_plugin+nemo-evaluator)tools/lint/lint-all.sh— 13/13tyacross both packages: 130 diagnostics before, 128 after — two fewer, none newContext
Prompted by review feedback on #1023, which had to declare a private
EntityStoreProtocolto publish entity revisions. That PR will drop its private copy and compose these instead. No evaluator-specific behavior is included here — the only evaluator changes are the test-double signatures the protocol change requires.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests