Skip to content

Enforce the container-type check in move_node_unchecked (closes #3011) - #3085

Merged
malibio merged 2 commits into
mainfrom
issue-3011-move-unchecked-container
Sep 26, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3011-move-unchecked-container

Conversation

@malibio

@malibio malibio commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

move_node_unchecked skipped the can_have_children() check that move_node enforces, so the unchecked variant could place a node under a leaf type (query, code-block, …).

  • Extracted the shared hierarchy rules into validate_move (date nodes are immovable, parent must exist and be a container, no cycles). Both variants now call it, so they differ only in OCC.
  • Corrected the move_node_unchecked doc comment: it claimed imports/type-conversion use, but it has no production caller (the import path uses create_node_with_parent).
  • Updated both functions' # Errors docs.
  • Added test_move_node_unchecked_rejects_non_container_parent.

Testing

  • cargo test -p nodespace-core — all green, including the integration tests that call move_node_unchecked
  • Pre-push gate (full pyramid + e2e) passed

Closes #3011

🤖 Generated with Claude Code

move_node_unchecked skipped the can_have_children() check that move_node
enforces, so the unchecked variant could park a node under a leaf type.
Extract the shared hierarchy rules (date immovable, parent exists and is a
container, no cycle) into validate_move, called by both variants so they
differ only in OCC. Correct the doc comment that claimed import/type-
conversion use, and add a regression test.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio

malibio commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3085

Review Type: Initial Review

Summary

A small, well-scoped fix. The hierarchy rules for a move (date nodes can't move, the parent must exist and be a container, no cycles) now live in one private helper, validate_move. Both move_node and move_node_unchecked call it, so the only difference left between the two is OCC. That removes the duplication that let the two paths drift apart in the first place (DRY / single source of truth). The doc comments are fixed and a regression test is added. I ran the targeted tests and they pass: the lib move_node tests (5/5, including the new one), the collection tests (91/91, including the collection-not-root check that goes through move_node_unchecked), and the integration suites move_node_ordering_test, mentioning_containers_test, parent_task_completion_play_test and event_emission_test.

Requirements Check

  • ✅ move_node_unchecked now enforces can_have_children(). It returns NotAContainer, the same error move_node returns.
  • ✅ The doc comment no longer claims callers that don't exist (imports, type conversions). It now says the variant enforces the same rules and skips only OCC. The # Errors sections on both functions list the container rule.
  • ✅ Regression test test_move_node_unchecked_rejects_non_container_parent checks the error variant and that the child did not move.
  • ✅ No existing caller breaks. I checked every move_node_unchecked call site (packages/core/tests/*, benches/performance.rs, embedding.rs, mod.rs). All of them move under container types (text, task, date, or none), so the new check rejects nothing they do.
  • ✅ Project rules: no backward-compat code, no dead code, no issue numbers in comments. The test uses crate::services::InsertPosition the same way the tests around it do.

Code Review Findings

  1. 📁 packages/core/src/services/node_service/hierarchy.rs (validate_move, parent lookup), 🟢 Behavior change is fine: node_exists → get_node.
    The unchecked path used to call node_exists, which hits only the store. It now calls get_node, which also returns a virtual date node for a date ID that hasn't been persisted yet. So move_node_unchecked now accepts a not-yet-persisted date as the parent where it used to return InvalidParent. This is the right call: move_node already behaves this way, and it's the point of making the two variants differ only in OCC. No test depended on the old InvalidParent result for a virtual date.

  2. 📁 packages/core/src/services/node_service/hierarchy.rs (validate_move), 🟢 Nit: get_node also runs populate_mentions, which is an extra query, and the helper only needs node_type. This cost already existed in move_node and is negligible for a single move, so no change is needed. If moves ever get batched, a lighter type lookup would be the place to trim.

  3. 📁 packages/core/src/services/node_service/hierarchy.rs (doc on move_node_unchecked), 🟢 Nit: "it currently serves tests and benches that don't need OCC" is a statement about current callers, and it can go stale the same way the old "imports, type conversions" line did. Consider describing the contract instead of the callers (e.g. "for callers that don't hold a version"). Optional.

  4. 📁 packages/core/src/services/node_service/hierarchy.rs (move_node), 🟢 Ordering kept. The version/OCC check still runs before validate_move, so a stale version still returns a version conflict before any hierarchy error, as it did before. Good. The helper also takes &Node rather than an ID, so it doesn't fetch the node a second time.

  5. 📁 packages/core/src/services/node_service/mod.rs (new test), 🟢 Good test. It uses a real leaf type (query, where can_have_children() == false), checks the exact error variant, and also checks that the rejected move left no side effects (the child still has no parent). No mocking is needed at this level.

Recommendation

APPROVE. This is a net improvement: it closes the gap in the check, removes about 30 lines of duplicated validation, and leaves the docs accurate. All findings are optional nits.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

… callers

Skipped: lighter type-only parent lookup in validate_move — move_node
already paid the get_node cost and moves aren't batched; revisit if
bulk moves route through it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio

malibio commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

Address-review summary

Re-review: NOT needed — the only change is a one-line doc comment; no logic changed.

🤖 Generated with Claude Code

@malibio
malibio merged commit 5706915 into main Sep 26, 2026
@malibio
malibio deleted the issue-3011-move-unchecked-container branch September 26, 2026 14:03
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.

move_node_unchecked omits the container-type check its OCC-checked sibling move_node enforces

1 participant