Skip to content

Implement PersonNodeBehavior - #1401

Merged
malibio merged 4 commits into
mainfrom
worktree-issue-133-person-node-behavior
Jun 9, 2026
Merged

malibio merged 4 commits into
mainfrom
worktree-issue-133-person-node-behavior

Conversation

@malibio

@malibio malibio commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Closes #133

Michael Libio and others added 2 commits June 9, 2026 13:48
PersonNode is pure identity: name (optional) and email (optional,
format-validated when present). role and auth_status are explicitly
out of scope — they live on the has_role edge to DatabaseSettingsNode.

- Add person SchemaNode to core_schemas.rs (name, email, both optional)
- Add PersonNodeBehavior: validate email format, compute_display_name
  falls back to email then "Unknown", can_have_children = false
- Register PersonNodeBehavior in NodeBehaviorRegistry::new()
- 14 unit tests: schema present, behavior registered, email validation,
  empty/absent name valid, compute_content with/without name

Co-Authored-By: Claude <[email protected]>
Registers personNodePlugin in core-plugins.ts with a /person slash
command, PersonNode inline component, and PersonSchemaForm for editing
name and email. No custom viewer — BaseNodeViewer handles it. Updates
plugin count and slash command count tests (+1 each).

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review — PR #1401: Implement PersonNodeBehavior

Review Type: Initial Review


Requirements Check (Issue #133)

  • ✅ person schema entry exists with optional name and email only (core_schemas.rs)
  • ✅ PersonNodeBehavior implements all NodeBehavior methods and is registered in NodeBehaviorRegistry::new()
  • ✅ email format-checked when present; empty name is accepted (validate + tests)
  • ✅ 14 unit tests cover validation, computed content, and the empty-name path
  • ✅ Passes cargo clippy; no lint suppression
  • ✅ Frontend: PersonNode component, PersonSchemaForm, and plugin registered in core-plugins.ts
  • ✅ All 3848 frontend tests pass; all 14 Rust person-behavior tests pass

Overall Assessment

This is a clean, well-scoped implementation that correctly delivers the PersonNode identity primitive. The Rust backend is particularly well done: namespaced property access (properties.person.*), graceful fallback in compute_display_name, and thorough unit test coverage. Two issues need to be addressed before merge — one is a doc comment misplacement that surfaces incorrect documentation on a public type, and one is a frontend interface deviation that breaks the component contract established by all other node components.


Findings

[Improvement] Doc comment misplacement attaches NodeBehaviorRegistry thread-safety docs to PersonNodeBehavior

📁 packages/core/src/behaviors/mod.rs:2005–2035

The ///-comment block beginning at line 2005 (the thread-safety and fallback-behavior section) was originally the doc comment for NodeBehaviorRegistry. When PersonNodeBehavior was inserted at line 2035, it broke the comment chain: in Rust, a /// block attaches to the immediately following item. The entire thread-safety section (# Thread Safety, concurrent reads/registration guidance) now documents PersonNodeBehavior — a unit struct with no threading surface at all — instead of NodeBehaviorRegistry.

The fix is to insert a blank non-doc line between the NodeBehaviorRegistry docs and the PersonNodeBehavior doc:

// (end of NodeBehaviorRegistry thread-safety doc)
/// accessed concurrently during runtime, making external synchronization unnecessary

// ← insert a blank line or a non-/// separator here

/// Built-in behavior for person nodes
///
/// Person nodes are pure identity ...
pub struct PersonNodeBehavior;

Then the NodeBehaviorRegistry doc block (lines 2005–2028) needs to be moved to immediately precede pub struct NodeBehaviorRegistry (line 2140). Currently NodeBehaviorRegistry has only the # Examples block as its doc comment.

Engineering principle: Rust /// comment blocks are documentation, not decoration. Misattributed docs generate incorrect rustdoc output and mislead future readers about API contracts.


[Improvement] person-node.svelte defines an inline props type instead of implementing NodeComponentProps

📁 packages/desktop-app/src/lib/design/components/person-node.svelte:12–26

Every other node component (DateNode, TaskNode, HeaderNode, etc.) types its props using the shared NodeComponentProps interface from $lib/types/node-viewers.ts. PersonNode deviates by declaring an ad-hoc inline type that adds a metadata field not present in NodeComponentProps. This breaks the contract that allows BaseNodeViewer and the plugin system to mount any node component interchangeably.

Additionally, metadata is accepted as a prop but never passed to BaseNode or used in any logic — it is silently dropped.

// Current (inline, non-standard):
let {
  nodeId,
  nodeType = 'person',
  autoFocus = false,
  content = $bindable(''),
  children = [],
  metadata = {}          // ← not in NodeComponentProps, never used
}: { ... } = $props();

// Should be:
import type { NodeComponentProps } from '$lib/types/node-viewers.js';
let {
  nodeId,
  content = $bindable(''),
  autoFocus = false,
  nodeType = 'person',
  children = []
}: NodeComponentProps = $props();

Engineering principle: Interface consistency (Liskov Substitution / ISP) — components mounted via the same plugin slot must honour the same contract. Diverging prop signatures create invisible breakage when the registry iterates over plugins generically.


[Improvement] person-node.svelte wrapper <div> has a class name but no styles

📁 packages/desktop-app/src/lib/design/components/person-node.svelte:37

The component wraps BaseNode in <div class="person-node-wrapper"> but has no <style> block and no applied styling. Unlike TaskNode (which needs the wrapper for absolute-positioned action buttons) or DateNode (which adds flex layout for the calendar icon), PersonNode adds no DOM behaviour via this wrapper. The wrapper div adds a gratuitous DOM node and a dangling class name.

Either add the <style> block with intentional layout (e.g., to accommodate a future person-avatar icon) and document the intent, or remove the wrapper and render BaseNode directly. HeaderNode, CodeBlockNode, and OrderedListNode all render BaseNode directly without a wrapper.


Nit: person-node.svelte comment says "Renders inline with a person icon" but no icon is rendered

📁 packages/desktop-app/src/lib/design/components/person-node.svelte:4

The component comment says "Renders inline with a person icon" but there is no icon component in the template. Either remove the claim from the comment or add the icon (consistent with DateNode using Icon name="calendar"). If the icon is intentionally deferred, note that in the comment.


Nit: get_embeddable_content uses string equality to sentinel-check display name

📁 packages/core/src/behaviors/mod.rs:2091–2097

fn get_embeddable_content(&self, node: &Node) -> Option<String> {
    let display = self.compute_display_name(node);
    if display == "Unknown" {
        None
    } else {
        Some(display)
    }
}

The sentinel "Unknown" is a magic string that creates implicit coupling between compute_display_name and get_embeddable_content. If the fallback string is ever localised or changed, get_embeddable_content silently breaks. The cleaner approach is to let compute_display_name return Option<String> and have the caller decide on the "Unknown" default, or extract a private helper that returns Option<String> used by both methods.


Summary

Finding Severity File
Thread-safety docs misattributed to PersonNodeBehavior [Improvement] packages/core/src/behaviors/mod.rs:2005–2035
PersonNode doesn't implement NodeComponentProps interface + dead metadata prop [Improvement] packages/desktop-app/src/lib/design/components/person-node.svelte:12–26
Wrapper <div> with no styles [Improvement] packages/desktop-app/src/lib/design/components/person-node.svelte:37
Comment says "person icon" but no icon exists Nit packages/desktop-app/src/lib/design/components/person-node.svelte:4
Magic string sentinel in get_embeddable_content Nit packages/core/src/behaviors/mod.rs:2091–2097

Recommendation: REQUEST CHANGES — the NodeComponentProps interface deviation is a contract breakage that needs to be fixed before merge. The doc comment misplacement generates incorrect rustdoc. Both are straightforward to fix.

- Restore NodeBehaviorRegistry thread-safety doc block to its struct;
  PersonNodeBehavior now has its own clean doc comment
- PersonNode component uses NodeComponentProps interface, matching all
  other node components; removes dead metadata prop and wrapper div

Skipped: compute_display_name Option<String> refactor — the magic
string coupling is confined to one struct with full test coverage;
benefit does not outweigh the API churn at this stage.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

Review Addressed

✅ Addressed (2 of 2 important findings):

  • Doc comment misplacement — Restored the NodeBehaviorRegistry thread-safety doc block to its correct location. PersonNodeBehavior now has its own clean doc comment.
  • NodeComponentProps + dead metadata prop — PersonNode now uses the shared NodeComponentProps interface. Wrapper <div> removed; BaseNode is rendered directly (matching HeaderNode, CodeBlockNode, etc.).

⏭️ Skipped (1 nit):

  • compute_display_name returning Option<String> — The magic string coupling is real but confined to one struct with 14 tests covering the exact behavior. The refactor would change the public API and churn the tests for marginal gain at this stage. Can revisit if compute_display_name gains callers.

Construct-time seeding in NodeService::new: idempotently create one person
node (auth_status: "local", under properties["person"]) representing the
local user when none exists, so fresh and existing databases alike carry the
identity node. On Pro upgrade this node is bound to a Supabase identity
(nodespace-sync#125) via a single auth_identities row keyed on the node id,
not recreated. Name/email stay absent until the user fills them in.

Update PersonNodeBehavior doc to reflect auth_status on the node (role/
permission still lives on the member_of relationship). Add person_seed_test
covering fresh-install single-seed, the local auth_status, and idempotency.

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

Copy link
Copy Markdown
Contributor

Grafted the ADR-037 local-PersonNode seed (commit 003a328)

Consolidating issue #133 onto this PR (the parallel #1399 is now closed in favor of this one — it had a backend-only behavior with a different content=name shape; this PR's name/email identity model + frontend is the keeper).

Added here:

  • Construct-time seed in NodeService::new: idempotently creates exactly one local person node (auth_status: "local" under properties["person"]) when none exists — ADR-037 "every install seeds exactly one PersonNode: the local user." Construct-time (not schema-seed-gated) so existing databases are backfilled on next open too. Name/email stay absent until the user fills them (PersonNodeBehavior already allows empty/absent).
  • Doc update on PersonNodeBehavior to reflect auth_status living on the node (role/permission still lives on the member_of edge).
  • tests/person_seed_test.rs: fresh-install single-seed, the local auth_status, and re-open idempotency.

Why on the node (vs relationships)

ADR-037 §"PersonNode Seeding & Upgrade Continuity" requires auth_status on the PersonNode so a free install carries identity continuity; on Pro upgrade the node is bound (one auth_identities row keyed on node id, nodespace-sync#125), never recreated. The member_of edge still owns role/permission.

Tests

  • person_seed_test: 2/2 pass. behaviors::tests::person_*: 14/14 pass. Full lib: 951 pass; the only 2 failures (test_integration_schema_id_generation, test_update_schema_add_valid_title_template — slug hyphen/underscore) are pre-existing on the base branch, unrelated to PersonNode.

This unblocks nodespace-sync#125 (bind the seeded PersonNode → Supabase uid at sign-in) and #126 (auto-admin bootstrap).

@malibio
malibio merged commit d6ae248 into main Jun 9, 2026
@malibio
malibio deleted the worktree-issue-133-person-node-behavior branch June 9, 2026 14:28
mstomar125 added a commit that referenced this pull request Jun 10, 2026
- test_update_schema_add_valid_title_template created a "Person" base schema,
  which now collides with the core `person` schema (ADR-037 #1401) — rename the
  test entity to "Employee".
- test_integration_schema_id_generation asserted "customer-invoice" (hyphen),
  but normalize_schema_id joins on '_' (its dedicated unit tests confirm; the
  hyphenated core ids like code-block aren't generated through it) — assert
  "customer_invoice" and fix the stale "→ customer-profile" doc example.

cargo test -p nodespace-core --lib: 954 passed, 0 failed.

Co-authored-by: Mayank  Tomar <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
malibio added a commit that referenced this pull request Jun 22, 2026
* Implement PersonNodeBehavior and person schema (#133)

PersonNode is pure identity: name (optional) and email (optional,
format-validated when present). role and auth_status are explicitly
out of scope — they live on the has_role edge to DatabaseSettingsNode.

- Add person SchemaNode to core_schemas.rs (name, email, both optional)
- Add PersonNodeBehavior: validate email format, compute_display_name
  falls back to email then "Unknown", can_have_children = false
- Register PersonNodeBehavior in NodeBehaviorRegistry::new()
- 14 unit tests: schema present, behavior registered, email validation,
  empty/absent name valid, compute_content with/without name

Co-Authored-By: Claude <[email protected]>

* Add PersonNode frontend plugin, component, and property form (#133)

Registers personNodePlugin in core-plugins.ts with a /person slash
command, PersonNode inline component, and PersonSchemaForm for editing
name and email. No custom viewer — BaseNodeViewer handles it. Updates
plugin count and slash command count tests (+1 each).

Co-Authored-By: Claude <[email protected]>

* Address review: fix doc comment placement and NodeComponentProps

- Restore NodeBehaviorRegistry thread-safety doc block to its struct;
  PersonNodeBehavior now has its own clean doc comment
- PersonNode component uses NodeComponentProps interface, matching all
  other node components; removes dead metadata prop and wrapper div

Skipped: compute_display_name Option<String> refactor — the magic
string coupling is confined to one struct with full test coverage;
benefit does not outweigh the API churn at this stage.

Co-Authored-By: Claude <[email protected]>

* #133: seed one local PersonNode on every install (ADR-037)

Construct-time seeding in NodeService::new: idempotently create one person
node (auth_status: "local", under properties["person"]) representing the
local user when none exists, so fresh and existing databases alike carry the
identity node. On Pro upgrade this node is bound to a Supabase identity
(nodespace-sync#125) via a single auth_identities row keyed on the node id,
not recreated. Name/email stay absent until the user fills them in.

Update PersonNodeBehavior doc to reflect auth_status on the node (role/
permission still lives on the member_of relationship). Add person_seed_test
covering fresh-install single-seed, the local auth_status, and idempotency.

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

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude <[email protected]>
Co-authored-by: Mayank  Tomar <[email protected]>
malibio pushed a commit that referenced this pull request Jun 22, 2026
- test_update_schema_add_valid_title_template created a "Person" base schema,
  which now collides with the core `person` schema (ADR-037 #1401) — rename the
  test entity to "Employee".
- test_integration_schema_id_generation asserted "customer-invoice" (hyphen),
  but normalize_schema_id joins on '_' (its dedicated unit tests confirm; the
  hyphenated core ids like code-block aren't generated through it) — assert
  "customer_invoice" and fix the stale "→ customer-profile" doc example.

cargo test -p nodespace-core --lib: 954 passed, 0 failed.

Co-authored-by: Mayank  Tomar <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

Implement PersonNodeBehavior

2 participants