Skip to content

Let the CLI move a node - #3580

Merged
malibio merged 1 commit into
mainfrom
issue-3569-cli-node-move
Oct 5, 2026
Merged

malibio merged 1 commit into
mainfrom
issue-3569-cli-node-move

Conversation

@malibio

@malibio malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Closes #3569

What changed

  • nodespace node move <id>: --parent <id> or --root changes the parent (MoveNode); --first or --after <sibling-id> alone changes the position under the current parent (ReorderNode). --version <n> works as on node update; without it the command moves the node at its current version. Output is the node's JSON, like the other node commands.
  • Refusal message: a second has_child edge is now refused with the exact command to run (nodespace node move <node> --parent <new-parent>), at both sites in core.
  • Skill docs: a hand-written Move a node section in references/cli.md, the regenerated CLI surface, and SKILL.md's hierarchy and version paragraphs name the command.

Notes for review

  • There is no --before. The RPCs take beginning / end / after, and resolving "before X" in the CLI would be a separate read that can go stale before the write. --first and --after reach every position; cli.md says how to place a node before a sibling.
  • A reorder prints the node read back after the write, since ReorderNode returns nothing.
  • update_refused became write_refused(status, rpc, json) so a move's version conflict is reported the same way as an update's.

Tests

CLI integration tests cover: move to the end, the beginning and after a sibling; move to root; reorder first and after a sibling; a move with no destination or position; a stale --version on both RPCs writing nothing; flag exclusivity; and the refusal, whose printed command is parsed and run to confirm it moves the node.

bun run test:changed passes (rust, skill, scripts tiers). Its first run failed three timeouts in scripts/gate-sccache.test.ts, which this change doesn't touch; the file passed alone and the full re-run passed.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3580 "Let the CLI move a node"

Review Type: Initial review (no prior reviews or comments on the PR). Reviewed commit 995496d7 against origin/main.

Method: Read the diff plus the surrounding code it depends on: the MoveNodeRequest / ReorderNodeRequest messages, the daemon's move_node / reorder_node handlers, core's move_node / reorder_node / resolve_reorder_position / resolve_insert_position, and the store's move_node_in_tx. I did not run the test suite; the behaviours below are derived from reading the code, not from executing it.

Summary

The mapping onto the two RPCs is right for the documented happy paths, the command is small and follows the shape of node update, the write_refused rename is a clean generalisation, and the refusal test that parses and runs the printed command is a good test. The change is a net improvement.

Three flag combinations write something other than what the caller asked for and exit 0, and cli.md states a rule for --after that nothing enforces. They are small to fix and this is an agent-facing write command, so I am asking for them before merge.

Requirements Check

  • ✅ AC1: nodespace node move <id> --parent <id> [--before/--after <id>] (or the equivalent) wraps MoveNode/ReorderNode, with JSON output. Met. --parent / --root goes to MoveNode, a position alone goes to ReorderNode, and both print through output::print_node. See the --before assessment below.
  • ✅ AC2: The refusal message names the real command, and cli.md documents it. Met at both sites in relationship.rs, and cli.md has a "Move a node" section.
  • ✅ AC3: CLI integration tests cover move, reorder and the refusal. Met, with one reorder assertion that cannot fail (finding 4).

On --first / --after with no --before: acceptable under "or the equivalent". Every position is reachable, and the RPCs have no before variant, so a CLI-side --before would be a read followed by a write. Two caveats. First, the documented workaround (list the children, name the predecessor with --after) is the same stale read moved to the caller, so the PR's stated reason is weaker than it sounds. Second, the workaround is only safe if a wrong --after is refused, which it is not today (finding 1). The durable fix is a before variant in the proto oneof, resolved inside the store's transaction; that is reasonable follow-up work, not a blocker here.

Findings

🟡 Important

1. --after with an ID that is not a child of the destination parent silently places the node last.
📁 packages/cli/src/commands/node.rs:175, :502; 📁 packages/skill/references/cli.md:177, :814

The help text and cli.md say the sibling "must be a child of the parent the node ends up under". Nothing checks that:

  • MoveNode: resolve_insert_position passes After(id) straight through, and move_node_in_tx (packages/core/src/db/sqlite_store/nodes.rs:3101-3145) falls back to "after the last sibling" when the ID is not among the parent's children. This includes an ID that does not exist at all, and the node's own ID.
  • ReorderNode: resolve_reorder_position checks only that the sibling node exists, not that it shares the parent, then hits the same fallback.

So node move X --parent P --after <typo> exits 0 with X at the end of P. An agent following cli.md's "place before a sibling" recipe with a predecessor that has since moved gets the same silent result.

Recommendation: refuse it. The best place is core (resolve_insert_position or the store: an After sibling that is not a child of the target parent is a hierarchy violation), since the fallback is what makes the docs untrue. If the fallback is load-bearing for the desktop app's concurrent reorders, validate in the CLI or daemon handler instead and say so. Add a test for a non-sibling and for the node's own ID.
Principle: fail loudly on invalid input; documentation must not promise a check the code does not make.

2. --parent "" moves the node to the root.
📁 packages/cli/src/commands/node.rs:164, :490

clap accepts an empty value, the CLI sends Some(""), and the daemon normalises it to None (packages/daemon/src/services/node_service.rs:1348), which is "make it a root". nodespace node move "$ID" --parent "$PARENT" with an unset variable detaches the node from its parent and exits 0. --root exists precisely so that going to the root is explicit.

Recommendation: reject an empty --parent (and an empty --after) in the CLI, with a clap value_parser or a bail! beside the existing "requires" check. Add a test.
Principle: a destructive outcome should need an explicit request, not be the reading of a missing value.

3. --root with --first or --after is accepted and the position is ignored.
📁 packages/cli/src/commands/node.rs:167-175; 📁 packages/cli/tests/it/cli_integration.rs:1790

A root has no sibling order (new_order is 0.0 when there is no parent), so the position does nothing. cli.md line 180 says a root "has no siblings to be ordered among", yet the exclusivity test asserts that --root --first parses successfully, which pins the wrong behaviour.

Recommendation: add conflicts_with_all = ["first", "after"] to root and flip that assertion to is_err().
Principle: reject flag combinations that have no meaning instead of accepting and discarding them.

4. The reorder --after assertion passes even if --after is ignored.
📁 packages/cli/tests/it/cli_integration.rs:1949

From [c, a, b] the test moves c after b and expects [a, b, c]. b is the last sibling, so "after b", "end", and the silent fallback from finding 1 all produce the same order. The test would still pass if the CLI sent the wrong sibling or no position.

Recommendation: reorder after a non-last sibling: from [c, a, b], --after a must give [a, c, b].
Principle: an assertion should distinguish the behaviour under test from its nearest wrong alternative.

🟢 Suggestions

5. A conflict on a move with no --version reports a version the caller never gave.
📁 packages/cli/src/commands/node.rs:464-477

Without --version the CLI reads the node and then writes at that version. If another writer lands in between, the caller sees "version N was given and it is now at version M", though they gave none. node update avoids this because UpdateNodeRequest.version is optional and the server reads the current version. Either make version optional on the two move requests and resolve it server-side (removes the extra round trip and the window), or keep the read and reword the message for this case. The current behaviour fails safe, so this is not blocking.

6. JSON output is not asserted.
📁 packages/cli/tests/it/cli_integration.rs (run_move)

AC1 asks for JSON output like the other node commands. The tests assert the resulting tree only. One assertion that the printed node carries the bumped version, on the reorder path in particular since it reads the node back separately, would cover the ReorderNode read-back at node.rs:514.

7. The root-reorder refusal that cli.md documents has no CLI test.
📁 packages/skill/references/cli.md:180

"A position without --parent is refused for one" is true in core (root_reorder_violation), but no CLI test runs node move <root> --first. One expect_err would pin it.

8. The refusal message is duplicated at two sites.
📁 packages/core/src/services/node_service/relationship.rs:931, :1306

The same four-line format string is now edited in two places. A small helper (second_parent_refused(target, existing, source)) keeps them from drifting. The duplication predates this PR, so this is optional.

Nitpicks

  • Nit: 📁 packages/skill/references/cli.md:173: "keeps its ID, its version history and everything nested under it". A move bumps the node's version, and nothing else in the skill docs describes a version history. Suggest "keeps its ID and everything nested under it", matching the command's own help text.
  • Nit: 📁 packages/cli/src/commands/node.rs:453: the "requires" check could be a clap ArgGroup with required = true, so the error arrives at parse time with usage text, like the exclusivity rules.

Checked and found sound

  • No-position reparent sends no position, and the daemon maps that to End. --parent equal to the current parent is a move to the end, which is coherent.
  • A stale --version is caught on both RPCs before any write, and the test asserts the tree is unchanged.
  • Version conflicts on both RPCs go through service_error_to_status and carry the x-version-conflict header that VersionConflict::from_status reads.
  • A CLI command in a core error message has precedent (packages/core/src/behaviors/mod.rs:2029).
  • No node-type, schema, lifecycle or Pro-boundary concerns; no issue numbers in code comments; SKILL.md and the generated cli-surface region are updated with the command.

Recommendation: REQUEST CHANGES

Findings 1 to 4 are each a few lines. With them fixed this is ready to merge; 5 to 8 and the nits are at the author's discretion.

@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: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (e495e760)

Fixed

  1. Non-sibling --after — refused in core, in the versioned move_node and reorder_node paths: the sibling must be another child of the target parent, and a node can't be placed after itself. The store's in-transaction fallback (place last when a concurrent move took the sibling away) is unchanged, and so is the unversioned move path. This also changes what the desktop app gets for the same input; its indent/outdent moves already name a child of the target parent, and the frontend, browser and Rust tiers pass. New test covers five cases (a child of the old parent, a missing node, the node itself, on both RPCs) and asserts order and version are untouched. It fails with the check disabled.
  2. Empty --parent / --after — rejected at parse time.
  3. --root with a position — now a parse error; the test assertion is flipped.
  4. Reorder assertion — now places after a non-last sibling ([c, a, b] → [a, c, b]).
  5. Root reorder refusal — tested through the CLI.
  6. Duplicated refusal message — one second_parent_refused helper serves both sites.
  • Nit: cli.md no longer says a move keeps a "version history".

Partly done
6. JSON output — the reorder test now asserts the version bump that the read-back reports. The printed JSON itself is not asserted: these tests drive the handlers in-process and don't capture stdout, and the output goes through print_node, the same path as every other node command.

Skipped
5. Conflict wording when --version is omitted — the fix is making version optional on both move RPCs and resolving it server-side, which changes the proto and the desktop app's callers. The window is one read-then-write, the outcome is a refusal with nothing written, and the advice in the message (read the node again) is still right. Worth doing with a before position variant if that is taken up.

  • Nit: ArgGroup for the "requires one of" check — the tests call the handler with a built MoveArgs, so the runtime check has to stay either way.

Tests: NODESPACE_TEST_ALL=1 bun run test:changed passes on every tier (frontend, scripts, skill, browser, type and node-type drift, Rust).

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3580 "Let the CLI move a node"

Review Type: Re-Review. Scope: git diff 995496d7..e495e760 (one commit, 5 files).

Method: Read the commit, the prior review and the author's response, then traced every caller of core's move_node, reorder_node and move_children_to_parent by reading the code. I did not run the test suite or the app; everything below is from reading, and the one new finding is a traced path, not a reproduced failure.

Previous Review Summary

Count
Previous recommendations 8 findings + 2 nits
Addressed 6 findings (1, 2, 3, 4, 7, 8) + 1 nit
Partly addressed 1 (finding 6)
Not addressed, reason holds 1 finding (5) + 1 nit
New issues found 1 Important, 3 Suggestions

Per finding:

  1. Non-sibling --after: addressed. require_sibling_under refuses a sibling whose parent is not the target parent, a missing node (its parent reads as None) and the node itself. The new CLI test covers five cases across both RPCs and asserts order and version are unchanged. See the new finding below for what this does to another caller.
  2. Empty --parent / --after: addressed with NonEmptyStringValueParser, tested at parse time.
  3. --root with a position: addressed with conflicts_with_all, assertion flipped, cli.md updated in both places.
  4. Reorder assertion: addressed. [c, a, b] with --after a must give [a, c, b], which "last" does not produce.
  5. Conflict wording without --version: skipped. The reason holds: the fix is a proto change that reaches the desktop callers, and the current behaviour refuses without writing.
  6. JSON output: partly addressed. The reorder test asserts the version bump; the printed JSON is not asserted because the tests drive handlers in-process. Acceptable: the output goes through the shared print_node.
  7. Root reorder through the CLI: addressed.
  8. Duplicated refusal message: addressed with second_parent_refused.
  • Nit (version history wording): addressed.
  • Nit (ArgGroup): skipped. The reason holds, since tests build MoveArgs directly and need the runtime check.

Requirements Check

  • ✅ AC1: node move wraps MoveNode / ReorderNode with JSON output. Met, unchanged by this commit.
  • ✅ AC2: The refusal message names the real command, and cli.md documents it. Met; the message now has one definition.
  • ✅ AC3: CLI integration tests cover move, reorder and the refusal. Met, and the reorder assertion can now fail.

What I traced for require_sibling_under

Callers of core's versioned move_node and reorder_node outside tests and benches: only the daemon's two handlers (packages/daemon/src/services/node_service.rs:1360, :1393). Clients of those RPCs: the CLI, the desktop app's Tauri commands (packages/desktop-app/app-lib/src/commands/nodes.rs:782, :810) and the dev-proxy's HTTP move route. packages/agent contains no MoveNodeRequest, ReorderNodeRequest or InsertPosition::After. Markdown import uses After only on the create path, which this commit does not touch. move_children_to_parent (service and store) takes no position and is unaffected. move_node_unchecked is exempt from the check and has no caller in this repository outside tests and benches.

The frontend never calls reorder_node. It reaches MoveNode through one function, persistMove, from three places in packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts:

Caller Position sent Affected?
indentNode (:1047) none (end) No
outdentNode (:1212) after the old parent, under the old parent's parent No in the normal case: it waits for pending moves and flushes all pending saves first, so the old parent's edge is in the database. A move to the root skips the check.
promoteChildren (:1340) after an ancestor-or-self of the merged-into node, under that node's parent Yes, see below

Could not determine: callers outside this repository (nodespace-sync builds on core and could call move_node or move_node_unchecked directly); whether the race below is reachable at human typing speed; and whether the delete that follows a merge cascades to children still attached in the database (core documents delete as a cascade, but I did not read the daemon's default delete path to the end).

Code Review Findings

🟡 Important

1. promoteChildren can now have its move refused where it previously succeeded, and it only logs the failure.
📁 packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts:1335-1345; 📁 packages/core/src/services/node_service/hierarchy.rs:509-512

The author's response says the desktop app's "indent/outdent moves already name a child of the target parent". That is true of those two, but promoteChildren (Backspace-merge of a node that has children, via combineNodes) is a third caller and it differs in the way that matters:

  • It takes the anchor and the new parent from the in-memory structure tree (getParentsForNode), not from the database.
  • It calls persistMove immediately. Unlike indentNode and outdentNode, it does not wait for pending moves or flush pending saves. outdentNode's own comment (:1185-1190) explains that this wait exists to avoid sibling-not-found errors.
  • Node writes are debounced by 500 ms (shared-node-store.svelte.ts:158), and an indent's move is asynchronous.

So if the anchor was created or indented moments before the merge, the database does not yet have it as a child of the target parent. Before this commit the store placed the promoted child last, which is the correct position here: the anchor is an ancestor-or-self of the node visually above the deleted one, so it is the last child of its parent. After this commit the move is a hierarchy violation. The .catch at :1340 logs it and nothing else: the structure tree has already been updated optimistically, and combineNodes goes on to delete the merged node (:637) while the child is still under it in the database.

Example: A has a child P that was typed in under 500 ms ago; F follows A and has a child G. Merging F into P sends "move G under A, after P" while P's create is still pending.

Recommendation: make promoteChildren satisfy the new rule the same way outdentNode does: run its moves inside a tracked move operation that waits for pending moves and flushes pending saves before persistMove. Add a frontend test for a merge whose anchor has a pending create. If that is too much for this PR, apply the check only where the caller is known to read from the database, and file the frontend change before tightening the shared path.
Principle: tightening a precondition on a shared path requires checking every caller against it; a previously benign fallback must not become a silent failure followed by a destructive step.

🟢 Suggestions

2. The unversioned exemption has no caller to justify it.
📁 packages/core/src/services/node_service/hierarchy.rs:506-512

The comment says "the unversioned path applies placements already made", but move_node_unchecked is called only from tests and benches in this repository. Keying input validation on whether a version was supplied also ties two unrelated things together: move_existing_node's doc says the two variants "differ only in OCC". Either apply the check on both paths, or name the caller the exemption is for.
Principle: YAGNI; one rule per concept.

3. Stale doc comment on resolve_reorder_position.
📁 packages/core/src/services/node_service/hierarchy.rs:1089-1092

It still says "any After sibling must exist". The rule is now that the sibling must be another child of the node's parent.

4. A missing sibling is reported as "is not a child of".
📁 packages/core/src/services/node_service/hierarchy.rs:1137-1142

reorder_node used to say "Sibling node X does not exist" for a typo. The new message is accurate but less direct for the commonest mistake. Optional: keep the existence wording when node_exists is false. Related: the rule is tested only through the CLI; a core unit test beside the other move tests would pin it where it lives.

Checked and found sound

  • The check runs after the version check and validate_move on the move path and after the version check on the reorder path, so a stale version still reports a conflict first.
  • It reads through a pooled reader before the transaction, which matches the documented fail-fast design. The store's in-transaction fallback still handles a sibling moved away concurrently.
  • second_parent_refused produces the same text as before at both sites.
  • clap changes: conflicts_with moved from parent to root and still covers the pair; the tests assert each combination.
  • cli.md: hand-written section and generated surface agree with the code.
  • No node-type, schema, lifecycle or Pro-boundary concerns in this commit.

Recommendation: REQUEST CHANGES

Every prior finding is resolved or reasonably declined, and the CLI itself is ready. The one blocker is finding 1: the core check is correct for the CLI but was verified against two of the desktop app's three callers. Either bring promoteChildren in line or scope the check, then this can merge. Findings 2 to 4 are at the author's discretion.

@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 (re-review): REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed (d563a3c5)

  1. promoteChildren refused by the new core check — fixed by taking the second option: the check is removed from core's move path, which is now identical to main (git diff origin/main on hierarchy.rs touches only the reorder path). The desktop app's merge, indent and outdent moves behave exactly as before. The CLI instead checks a move's --after itself, before writing: the sibling must be in GetChildren(<parent>) and must not be the node being moved. This is a read before the write, so it catches a wrong ID, not a race; the store's fallback still covers a sibling moved away in between. Changing promoteChildren to wait for pending writes was not done here: it is editor behaviour unrelated to a CLI command.
    • The reorder path keeps the check in core. Nothing in the frontend calls reorder: reorderNode / reorder_node appear only in core, the daemon, the CLI, and the Tauri command and its Rust tests.
  2. Unversioned exemption — gone with the move-path check.
  3. Stale doc comment on resolve_reorder_position — updated.
  4. Missing sibling wording — a reorder after a node that doesn't exist says "Sibling node X does not exist" again; "is not a child of" is for a node that exists elsewhere. A separate core unit test was not added: the CLI integration test runs both reorder refusals through core over the real transport.

The non-sibling test is unchanged and still passes its five cases (three on move, now refused by the CLI; two on reorder, refused by core), with order and version asserted untouched.

Tests: bun run test:changed passes (scripts, skill, type and node-type drift, Rust). quality:fix made no changes.

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3580 "Let the CLI move a node"

Review Type: Re-Review (third pass). Scope: git diff e495e760..d563a3c5 (one commit, 2 files), read alongside git diff origin/main...HEAD.

Method: Read the commit, both prior reviews and the author's responses, the CLI command and its tests, core's reorder path, the store's get_children and move_node_in_tx, and the daemon's GetChildren / MoveNode handlers. I searched for every caller of ReorderNode. I did not run the test suite or the CLI; everything below is from reading.

Previous Review Summary

Count
Previous recommendations (second review) 1 Important + 3 Suggestions
Addressed 4
Not addressed 0
New issues found 0 Critical, 0 Important, 2 Suggestions, 2 Nits

Per finding:

  1. promoteChildren could be refused by the new core check (Important): resolved. Verified from the diff, not the author's comment: git diff origin/main...HEAD -- packages/core/src/services/node_service/hierarchy.rs has two hunks, both in the reorder path (resolve_reorder_position and the new require_sibling_under). move_existing_node, validate_move, resolve_insert_position and the store's move_node_in_tx are byte-identical to origin/main, so the desktop app's indent, outdent and merge moves behave exactly as before.
  2. Unversioned exemption with no caller: resolved. The conditional is gone with the move-path check.
  3. Stale doc comment on resolve_reorder_position: resolved (see the nit on its line length).
  4. Missing sibling reported as "is not a child of": resolved in code, not in tests. require_sibling_under checks node_exists first and says "Sibling node X does not exist" again. No test exercises that branch (finding 2 below).

Who reaches the reorder check. ReorderNode clients outside tests: the CLI, and the Tauri command reorder_node (packages/desktop-app/app-lib/src/commands/nodes.rs:802), which is registered but which nothing in packages/desktop-app/src invokes. packages/dev-tools, packages/agent and packages/skill contain no reorder call. Core's reorder_node is called only by the daemon handler. The existing tests that reorder with After (packages/daemon/tests/it/grpc_round_trip.rs:1094) name a real sibling; the Tauri ordering tests use Beginning / End. So the tightened reorder rule changes behaviour for no existing caller in this repository.

Requirements Check

  • ✅ AC1: node move wraps MoveNode / ReorderNode with JSON output. Met. --first / --after stand in for --before, as accepted in the first review.
  • ✅ AC2: The refusal message names the real command, and cli.md documents it. Met; one second_parent_refused helper serves both sites.
  • ✅ AC3: CLI integration tests cover move, reorder and the refusal. Met.

The new code: require_child_of

Flag combinations (packages/cli/src/commands/node.rs:452-533):

Flags RPC --after checked by Result
none none n/a refused before any RPC
--parent P MoveNode n/a placed last
--parent P --first MoveNode n/a placed first
--parent P --after S MoveNode CLI (require_child_of) refused unless S is a child of P and S is not the node
--root MoveNode n/a root; clap refuses --first, --after, --parent with it
--first ReorderNode n/a first under current parent; refused for a root
--after S ReorderNode core (require_sibling_under) refused unless S is another child of the node's parent
--first --after S n/a n/a clap refuses

--version is orthogonal to all of these. The check runs only where it is needed: (Some(parent), Some(sibling)) cannot be true with --root, and the reorder path leaves it to core.

Checked and found sound:

  • The check runs before the write, so "Nothing was written." in the message is true.
  • It uses the destination parent, not the node's current one. The test's first case (a child of the parent the node is leaving) would pass a check written against the wrong parent, so it pins this.
  • GetChildren reads every has_child row for the parent with no lifecycle filter and no limit, so an archived child or a child past some page boundary is not wrongly refused. The CLI client is built with the raised decode limit (packages/proto/src/lib.rs:53).
  • A parent that does not exist returns no children, so the command is refused with "is not a child of" instead of reaching MoveNode. The wording is slightly off for that case, but nothing is written and the next thing the caller checks is the right one.
  • Failure output: main returns the anyhow error, so each refusal is Error: ... on stderr with a non-zero exit, with or without --json. Only a version conflict also prints structured JSON on stdout under --json; that matches node update.
  • The read-then-write window is stated honestly in the code comment and the author's response; the store's "last" fallback still covers a sibling moved away in between.
  • cli.md and the help text: "--after names a child of the parent the node ends up under; any other node is refused and nothing is written" is now true on both RPCs. The generated surface matches the MoveArgs doc comments.
  • Removing require_child_of fails the test: the three move cases in node_move_after_a_node_that_is_not_a_sibling_writes_nothing would succeed and trip expect_err. A check that refused everything fails node_move_reparents_a_node_at_the_requested_position, which moves after a real sibling.

Code Review Findings

🟢 Suggestions

1. The CLI's "after itself" branch is not pinned by a test.
📁 packages/cli/src/commands/node.rs:542-544; 📁 packages/cli/tests/it/cli_integration.rs:2083

The test's self case is --parent <new_parent> --after <node> with the node still under the old parent. Delete the sibling == node branch and that case is still refused, by the membership check, and the assertion accepts either message. The branch only matters when the node is already under the named parent (--parent <current parent> --after <self>): then the node is in GetChildren and, without the branch, MoveNode would place it last.

Recommendation: add that case to the loop ((Some(&old_parent), &node)), and assert the "after itself" message for it.
Principle: a test should fail when the branch it covers is removed.

2. The restored "Sibling node X does not exist" branch has no test, and the shared assertion is loose.
📁 packages/core/src/services/node_service/hierarchy.rs:1128-1132; 📁 packages/cli/tests/it/cli_integration.rs:2101-2104

The author's response says the CLI test "runs both reorder refusals through core"; those two are a child of another parent and the node itself. A reorder after a node that does not exist is not among the five cases, and no other test in core, the daemon or the app asserts that message. Separately, contains("is not a child of") || contains("after itself") lets any case produce either message.

Recommendation: add (None, &"no-such-node".to_string()) and give each case its expected fragment (a third tuple element) instead of the ||.
Principle: same as above; one expected outcome per case.

Nitpicks

  • Nit: 📁 packages/cli/src/commands/node.rs:465-490: with a stale --version and a wrong --after on a move, the sibling error is reported and the conflict is not; on a reorder core reports the conflict first. Nothing is written either way. Also, without --version the membership read sits between the version read and the write; running require_child_of before the version read would keep that window as small as it was.
  • Nit: 📁 packages/core/src/services/node_service/hierarchy.rs:1083: the edited doc-comment line is over 100 columns; rustfmt does not wrap comments, so it needs a manual wrap.

Could not determine

  • Whether the tests pass: I did not run them. The author reports bun run test:changed passing.
  • Callers outside this repository. A build on top of core that calls ReorderNode with an After naming a non-sibling would now be refused; core's move path, which such a build is more likely to use, is unchanged.
  • require_child_of transfers every child of the parent, content included, to test membership. I did not measure it; for a very large parent it is a heavier read than the move itself. Not worth a proto change here.

Recommendation: APPROVE

The blocker from the second review is resolved in the way that carries the least risk: core's move path is exactly main's, and the CLI checks its own input before writing. The two suggestions are a few test lines each and are at the author's discretion.

@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 (re-review 2): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Third review addressed (e8540beb)

All four items taken; none skipped.

  1. "After itself" branch unpinned — the test adds --parent <current parent> --after <self>, the case only that branch refuses.
  2. "Does not exist" branch untested, loose assertion — the test adds a reorder after a missing node, and each of the seven cases now names the one refusal it expects in place of the ||.
  • Nit: the CLI checks --after before it reads the version, so the window between that read and the write is what it was.
  • Nit: the resolve_reorder_position doc comment is wrapped.

Tests: bun run test:changed passes; quality:fix made no changes.

Re-review: not needed. This commit adds test cases, moves one existing check a few lines earlier in the same function, and rewraps a comment.

@malibio
malibio force-pushed the issue-3569-cli-node-move branch from 9af43e4 to 9118bf0 Compare October 5, 2026 08:05
@malibio
malibio merged commit 99393ec into main Oct 5, 2026
@malibio
malibio deleted the issue-3569-cli-node-move branch October 5, 2026 08:05
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.

Let the CLI move a node

1 participant