Skip to content

Backend: Allow blank text nodes in validation #484

Closed

Description

@malibio

Problem

Phase 1 of #479 changed the frontend to persist blank nodes immediately (with 500ms debounce). However, the backend validation is rejecting these blank nodes with:

ValidationFailed(MissingField("Text nodes must have content"))

Current Behavior

Expected Behavior

Backend should allow blank text nodes since:

  1. Users can create blank nodes by pressing Enter
  2. Blank nodes are valid during editing
  3. The burden is on the user to maintain or delete these blank nodes

Implementation

Update backend validation to allow content: "" for text nodes. The validation rule "Text nodes must have content" should be removed or made optional.

Related Issues

Acceptance Criteria

  • Backend accepts blank text nodes (content: "")
  • POST /api/nodes with blank text node returns 200
  • Blank nodes can be created, updated, and persisted
  • No validation errors for blank content

Priority

High - Blocks testing of Phase 1 (#479)

Activity

  1. added
    bug
    on Nov 13, 2025
  2. self-assigned this
    on Nov 14, 2025
  3. malibio commented on Nov 14, 2025

    @malibio
    CollaboratorAuthor

    Issue Reopened - Integration Tests Failing

    Problem Found:
    While PR #502 updated the Rust model layer validation to allow blank text nodes, the HTTP endpoint is still rejecting blank nodes with 422 Unprocessable Entity.

    Evidence:

    • ✅ Rust unit tests pass: test_node_validation_accepts_blank_content
    • ❌ Integration tests fail: All 9 tests in blank-node-creation.test.ts fail with HTTP 422
    • ❌ Dev server returns: POST http://localhost:3001/api/nodes 422 (Unprocessable Entity)

    Root Cause:
    The model layer (packages/core/src/models/node.rs) allows blank content, but there's likely additional validation in the HTTP handler that's still enforcing the "content must not be empty" rule.

    Investigation Needed:

    1. Check HTTP endpoint handlers (likely src-tauri/src/handlers/nodes.rs or MCP handlers)
    2. Find where the 422 validation error originates
    3. Remove or update that validation check
    4. Verify all integration tests pass

    Test Command:

    bun run dev  # Start dev server
    bun run test:db  # Run integration tests with database mode

    Expected Result:
    All 9 integration tests in blank-node-creation.test.ts should pass.

  4. malibio commented on Nov 14, 2025

    @malibio
    CollaboratorAuthor

    Investigation Summary for Next Session

    Problem Confirmation

    The backend model layer allows blank text nodes (PR #502 ✅), but the HTTP endpoint layer is rejecting them with 422 Unprocessable Entity ❌.

    What Works

    • ✅ Rust unit test passes: test_node_validation_accepts_blank_content in packages/core/src/models/node.rs:1227
    • ✅ Model validation allows blank content: Node::validate() at packages/core/src/models/node.rs:397-400

    What's Broken

    • ❌ All 9 integration tests in packages/desktop-app/src/tests/integration/blank-node-creation.test.ts fail
    • ❌ HTTP endpoint returns: POST http://localhost:3001/api/nodes 422 (Unprocessable Entity)
    • ❌ Error occurs during database initialization in tests (blank node creation fails immediately)

    Test Output

    stderr: POST http://localhost:3001/api/nodes 422 (Unprocessable Entity)
    Error: Database initialization failed after 3 attempts: HTTP 422: Unprocessable Entity
    

    Where to Look

    The validation is likely happening in one of these locations:

    1. HTTP Handlers (most likely):

      • packages/desktop-app/src-tauri/src/handlers/nodes.rs or similar
      • packages/desktop-app/src-tauri/src/mcp/handlers/nodes.rs (MCP handlers)
      • Look for validation logic that checks content.is_empty() or similar
    2. Service Layer:

      • packages/core/src/services/node_service.rs
      • Check create_node() or validate_node_data() methods
    3. Schema Validation:

      • Any JSON schema validation that might enforce non-empty content
      • Check for request validation middleware

    How to Reproduce

    # 1. Start dev server
    bun run dev
    
    # 2. Wait for proxy to compile and start (check http://localhost:3001/health returns "OK")
    curl http://localhost:3001/health
    
    # 3. Run integration tests (will fail with 422 errors)
    bun run test:db
    
    # 4. Look specifically at blank-node-creation tests
    cd packages/desktop-app && TEST_USE_DATABASE=true bunx vitest run src/tests/integration/blank-node-creation.test.ts

    Expected Fix

    Find the HTTP handler validation that's rejecting blank content and either:

    1. Remove it (if redundant with model validation), OR
    2. Update it to allow blank content for text nodes (matching the model layer)

    Success Criteria

    bun run test:db  # All tests should pass, including 9 blank-node-creation tests

    Context Files to Read First

    1. packages/core/src/models/node.rs:397-400 - See how model layer allows blank content
    2. packages/desktop-app/src/tests/integration/blank-node-creation.test.ts - Understand what tests expect
    3. HTTP handler files (TBD - need to search for the 422 source)

    Quick Start Command for Next Session

    # Assign yourself and start
    bun run gh:assign 484 "@me"
    bun run gh:status 484 "In Progress"
    
    # Start investigation
    cd /Users/malibio/nodespace/nodespace-core
    bun run dev  # Terminal 1: Start dev server
    # Wait for health check to pass, then in another terminal:
    bun run test:db  # Terminal 2: Reproduce the failures
  5. 9 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions