Repository navigation
API: introduce InsertPosition enum across proto/gRPC + service (replace overloaded insert_after_node_id) - #1236
Conversation
Code Review — PR #1236: InsertPosition EnumSummaryThis is a well-executed, complete refactor. The core design is sound: the enum cleanly replaces a two-valued Option<&str> with three explicitly-named variants, eliminates the empty_to_none sentinel hack at the proto layer, and threads the change consistently through Rust core, proto/gRPC daemon, Tauri commands, and TypeScript frontend. Coverage is broad and the migration is thorough. The PR is a net positive and should be merged once the issues below are addressed. Findings[Improvement] Stale doc comments on move_node and CreateNodeParamspackages/core/src/services/node_service.rs line 4329 — the Arguments block for move_node still reads: This argument no longer exists; the parameter is now position: InsertPosition<'_>. A caller reading this doc will be confused. packages/core/src/services/node_service.rs line 419 — CreateNodeParams.position says: The field has no Default impl and the actual runtime default for omitted callers is End (commit message confirms this). The doc says the opposite. This will mislead every future caller of this struct. packages/core/src/services/node_service.rs line 2037 — doc block for create_node_with_parent still references insert_after_node_id by name in the Note: paragraph. packages/core/src/services/node_service.rs line 9567 — test comment reads to insert_after_node_id.is_none(): the narrowing guard is now matches!(position, InsertPosition::End); the comment describes old code. These are straightforward fixes, not blockers, but stale doc comments on a freshly-renamed API are especially harmful. [Improvement] End with no parent silently degrades to Beginning at the store layerIn resolve_insert_position (node_service.rs line 4522): When parent_id is None (making a node a root), End resolves to None, and SqliteStore::move_node maps None to before the first sibling (Beginning) at the root level. So move_node_unchecked(id, None, InsertPosition::End) does not actually append at the end of the root list — it prepends. The call sites in tests and benchmarks use InsertPosition::Beginning explicitly for this case, so they are self-consistent, but the semantics of End for root-level nodes are silently wrong. Add a comment documenting that End with no parent falls back to store-layer Beginning, so future callers are not surprised. [Improvement] Proto bool oneof — bool beginning = 8 / bool end = 9 is an unusual encodingUsing bool as the payload of a oneof variant works but is non-idiomatic and creates a subtle footgun: a client sending {beginning: false} would still set the beginning variant, which the daemon correctly decodes as InsertPositionOwned::Beginning (the value of the bool is ignored). The standard pattern for a unit-type variant in proto is either an empty message (message Beginning {}) or a proto enum. The current approach requires explicit documentation to prevent future proto authors from interpreting the bool value as meaningful. This is not a blocker for a greenfield project but worth tracking. [Nit] Inline type annotations on insertPosition field accesses in TypeScriptIn shared-node-store.svelte.ts lines 1415 and 1497, the inline cast uses { type: string; siblingId?: string } | null. This duplicates structure that the exported InsertPosition type already defines. Import and use it directly to avoid drift if the shape changes. [Nit] pending-operations.ts line 19 retains an insertAfterNodeId reference in a commentThe race-condition scenario comment still reads which references B as insertAfterNodeId. Should be updated to insertPosition. [Nit] shared-node-store.svelte.ts line 562 commentThe method docblock at line 562 still reads insertAfterNodeId hint — should be insertPosition. Acceptance Criteria StatusChecking against issue #1216:
VerdictApprove with recommendations. Fix the stale doc comment claiming Defaults to Beginning on CreateNodeParams.position (it says the opposite of the actual behavior) before merge. The End-with-no-parent silent degradation and the gRPC daemon test gap are improvements worth making as a fast follow. |
malibio
left a comment
There was a problem hiding this comment.
Reviewed. See full findings in the PR comment above. One doc-accuracy fix recommended before merge (CreateNodeParams.position claims 'Defaults to Beginning' but the actual default is End). Other findings are improvements/nits.
- Fix wrong doc comment on CreateNodeParams.position (said Beginning, is End) - Update 3 stale doc/comment references from insert_after_node_id to new API - Document resolve_insert_position limitation: End with no parent resolves to None which store-layer maps to Beginning (all root-move callers already pass Beginning explicitly, so no behavior change) - Add proto oneof documentation explaining bool-variant encoding and why the bool value is semantically meaningless (unit variant workaround) - Add gRPC round-trip test covering Beginning, End, and After proto decoding paths via CreateNode + ReorderNode RPCs - Use imported InsertPosition type in shared-node-store instead of inline structural casts - Update 2 stale insertAfterNodeId comment references in TS files Skipped: proto bool → empty message redesign — wire format change requires coordinated client updates; behavior is correct for all internal callers. Co-Authored-By: Claude <[email protected]>
Review Feedback AddressedAll 7 reviewer recommendations addressed. 1 skipped with justification. ✅ Addressed
⏭️ SkippedProto |
#1216) Replaces the overloaded `insert_after_node_id: Option<&str>` pattern with an explicit `InsertPosition` enum at every layer: **Core (packages/core)** - `InsertPosition<'a>` (borrowed) and `InsertPositionOwned` (for struct storage) added to `packages/core/src/services/mod.rs`, re-exported from crate root - `CreateNodeParams.position: InsertPositionOwned` replaces `insert_after_node_id` - `create_parent_edge`, `reorder_child`, `reorder_node`, `move_node`, `move_node_unchecked` all accept `InsertPosition<'_>` directly - `resolve_insert_position` helper converts `End` → last-child lookup at the service layer so `SqliteStore::move_node` still takes `Option<&str>` - Default semantic changed: `None`/unset = **End** (append); callers that want "insert above" must now pass `Beginning` explicitly **Proto + daemon (packages/proto, packages/daemon)** - `CreateNodeRequest`, `MoveNodeRequest`, `ReorderNodeRequest` replace the overloaded `string insert_after_node_id` field with a `oneof position` carrying `beginning`, `end`, or `after` variants; unset = End - Daemon `node_service.rs` decodes the oneof and maps to `InsertPosition<'_>`; `empty_to_none` translation deleted from the three affected RPCs **Tauri + TypeScript (packages/desktop-app)** - `InsertPositionInput` serde enum on the Rust side deserializes `{type:"beginning"|"end"|"after", siblingId?:string}` from the frontend - `CreateNodeInput`, `move_node`, `reorder_node` Tauri commands accept `insert_position: Option<InsertPositionInput>` instead of `insert_after_node_id` - TS `InsertPosition` discriminated union + `insertPosition` factory exported from `backend-adapter.ts`; all callers in `reactive-node-service` and `shared-node-store` migrated Co-Authored-By: Claude <[email protected]>
- Fix wrong doc comment on CreateNodeParams.position (said Beginning, is End) - Update 3 stale doc/comment references from insert_after_node_id to new API - Document resolve_insert_position limitation: End with no parent resolves to None which store-layer maps to Beginning (all root-move callers already pass Beginning explicitly, so no behavior change) - Add proto oneof documentation explaining bool-variant encoding and why the bool value is semantically meaningless (unit variant workaround) - Add gRPC round-trip test covering Beginning, End, and After proto decoding paths via CreateNode + ReorderNode RPCs - Use imported InsertPosition type in shared-node-store instead of inline structural casts - Update 2 stale insertAfterNodeId comment references in TS files Skipped: proto bool → empty message redesign — wire format change requires coordinated client updates; behavior is correct for all internal callers. Co-Authored-By: Claude <[email protected]>
cfffa9a to
2bef75c
Compare
…ode_ops (closes #1241) (#1244) - daemon: refactor create_node, update_node, delete_node to delegate to node_ops::{create_node,update_node,delete_node} — removes inline collection resolution, lifecycle defaulting, and version auto-fetch from the gRPC layer (B3+B4 from architectural audit #1228) - core/node_ops: fix update_node to skip the NodeUpdate call when no field changes are present (only collection ops) — prevents "Update contains no changes" error on collection-only updates - daemon/tests: add 3 parity tests asserting create+collection+lifecycle, auto-fetch version, and add/remove collection membership via gRPC - agent/tools: add missing id/position fields to CreateNodeInput struct (required after InsertPosition enum was introduced in #1236) Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
…ce overloaded insert_after_node_id) (#1236) * Introduce InsertPosition enum across proto/gRPC + service layer (closes #1216) Replaces the overloaded `insert_after_node_id: Option<&str>` pattern with an explicit `InsertPosition` enum at every layer: **Core (packages/core)** - `InsertPosition<'a>` (borrowed) and `InsertPositionOwned` (for struct storage) added to `packages/core/src/services/mod.rs`, re-exported from crate root - `CreateNodeParams.position: InsertPositionOwned` replaces `insert_after_node_id` - `create_parent_edge`, `reorder_child`, `reorder_node`, `move_node`, `move_node_unchecked` all accept `InsertPosition<'_>` directly - `resolve_insert_position` helper converts `End` → last-child lookup at the service layer so `SqliteStore::move_node` still takes `Option<&str>` - Default semantic changed: `None`/unset = **End** (append); callers that want "insert above" must now pass `Beginning` explicitly **Proto + daemon (packages/proto, packages/daemon)** - `CreateNodeRequest`, `MoveNodeRequest`, `ReorderNodeRequest` replace the overloaded `string insert_after_node_id` field with a `oneof position` carrying `beginning`, `end`, or `after` variants; unset = End - Daemon `node_service.rs` decodes the oneof and maps to `InsertPosition<'_>`; `empty_to_none` translation deleted from the three affected RPCs **Tauri + TypeScript (packages/desktop-app)** - `InsertPositionInput` serde enum on the Rust side deserializes `{type:"beginning"|"end"|"after", siblingId?:string}` from the frontend - `CreateNodeInput`, `move_node`, `reorder_node` Tauri commands accept `insert_position: Option<InsertPositionInput>` instead of `insert_after_node_id` - TS `InsertPosition` discriminated union + `insertPosition` factory exported from `backend-adapter.ts`; all callers in `reactive-node-service` and `shared-node-store` migrated Co-Authored-By: Claude <[email protected]> * Address review feedback from PR #1236 - Fix wrong doc comment on CreateNodeParams.position (said Beginning, is End) - Update 3 stale doc/comment references from insert_after_node_id to new API - Document resolve_insert_position limitation: End with no parent resolves to None which store-layer maps to Beginning (all root-move callers already pass Beginning explicitly, so no behavior change) - Add proto oneof documentation explaining bool-variant encoding and why the bool value is semantically meaningless (unit variant workaround) - Add gRPC round-trip test covering Beginning, End, and After proto decoding paths via CreateNode + ReorderNode RPCs - Use imported InsertPosition type in shared-node-store instead of inline structural casts - Update 2 stale insertAfterNodeId comment references in TS files Skipped: proto bool → empty message redesign — wire format change requires coordinated client updates; behavior is correct for all internal callers. Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
…ode_ops (closes #1241) (#1244) - daemon: refactor create_node, update_node, delete_node to delegate to node_ops::{create_node,update_node,delete_node} — removes inline collection resolution, lifecycle defaulting, and version auto-fetch from the gRPC layer (B3+B4 from architectural audit #1228) - core/node_ops: fix update_node to skip the NodeUpdate call when no field changes are present (only collection ops) — prevents "Update contains no changes" error on collection-only updates - daemon/tests: add 3 parity tests asserting create+collection+lifecycle, auto-fetch version, and add/remove collection membership via gRPC - agent/tools: add missing id/position fields to CreateNodeInput struct (required after InsertPosition enum was introduced in #1236) Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
Closes #1216