Skip to content

Backend: Allow blank text nodes in validation - #504

Merged
malibio merged 2 commits into
mainfrom
feature/issue-484-blank-text-nodes-http-validation
Nov 14, 2025
Merged

malibio merged 2 commits into
mainfrom
feature/issue-484-blank-text-nodes-http-validation

Conversation

@malibio

@malibio malibio commented Nov 14, 2025

Copy link
Copy Markdown
Collaborator

Closes #484

malibio and others added 2 commits November 15, 2025 00:34
…s (issue #484)

**Root Cause:**
PR #501 (SurrealDB migration) introduced a regression in the dev-proxy
`create_node` HTTP handler. It expected a full `Node` struct with `createdAt`,
`modifiedAt`, and `version` fields, but the frontend correctly sends partial
node data (via `BackendAdapter.createNode()`) without timestamps, expecting
the backend to add them automatically.

**Symptoms:**
- All 9 integration tests in `blank-node-creation.test.ts` failed with HTTP 422
- Error: "Unprocessable Entity" during database initialization
- Even non-blank sentinel nodes failed (proves it wasn't a blank content issue)

**Historical Behavior (Pre-Migration):**
- **Tauri commands**: Accept `CreateNodeInput` (no timestamps) → add in backend
- **MCP handlers**: Accept `MCPCreateNodeParams` (no timestamps) → add in backend
- **NodeOperations**: Creates full `Node` with timestamps at lines 675-689

**The Bug:**
Dev-proxy broke this contract by accepting `Json<Node>` instead of partial data.

**The Fix:**
1. Created `CreateNodeRequest` struct matching `CreateNodeInput` (no timestamps)
2. Updated `create_node` handler to accept `CreateNodeRequest`
3. Handler now adds `createdAt`, `modifiedAt`, `version` before calling NodeService
4. Matches established pattern from Tauri/MCP handlers

**Impact:**
- ✅ All 9 blank node integration tests now pass
- ✅ No regressions to existing 1538 passing tests
- ✅ Restores correct HTTP API contract (matches desktop mode behavior)

**Testing:**
```bash
bun run test:db src/tests/integration/blank-node-creation.test.ts
# Result: Test Files 1 passed (1), Tests 9 passed (9) ✅
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Enhanced the CreateNodeRequest struct documentation with:
- Clear field semantics for all 9 fields
- Validation process explanation (two-stage validation)
- JSON example showing typical usage
- Explicit notes on special cases (blank content, deterministic IDs, mentions vs mentioned_by)

This addresses Finding 2 from the code review - improving API contract clarity
at the critical HTTP endpoint boundary between frontend and backend.

Severity: 🟡 Important (Documentation improvement)

Related: Issue #484
@malibio

malibio commented Nov 14, 2025

Copy link
Copy Markdown
Collaborator Author

Code Review Feedback Addressed

✅ Implemented (1 recommendation)

🟡 Finding 2: Enhanced CreateNodeRequest Documentation

  • Commit: 35835c5
  • Changes:
    • Added comprehensive field-by-field documentation explaining semantics
    • Documented validation process (two-stage: behavior + schema)
    • Added JSON example showing typical usage
    • Clarified special cases:
  • Impact: Improved API contract clarity at critical HTTP boundary

⏭️ Skipped (2 recommendations)

🟡 Finding 1: Version Initialization Edge Case

  • Rationale: Premature optimization
    • Current implementation is correct for all active use cases
    • Blank text nodes use UUIDs (not deterministic IDs)
    • Date nodes with deterministic IDs created via different code paths
    • Optional id field exists for future extensibility only
    • If upsert semantics needed in future, should be separate endpoint (PUT vs POST)
  • Engineering Principle: Don't add complexity for hypothetical scenarios
  • Condition to Revisit: If Issue Phase 1: Eliminate ephemeral nodes during editing #479 or future issues require creating nodes with deterministic IDs via POST endpoint

🟢 Suggestion: Extract Conversion Helper Method

  • Rationale: Overkill for current needs
    • Only one location uses this conversion (POST /api/nodes)
    • No bulk create operations in roadmap
    • Conversion is straightforward (8 field mappings)
    • Would add indirection without clear benefit
  • Condition to Revisit: If a second endpoint needs this conversion (e.g., bulk create)

Summary: Addressed 1/3 recommendations using sound engineering judgment. Skipped 2 recommendations that would add unnecessary complexity without current benefits.

Tests: All quality checks pass ✅ (cargo clippy, cargo fmt, eslint, svelte-check)

Status: Ready for final review or merge

@malibio
malibio merged commit 4ee38f8 into main Nov 14, 2025
@malibio
malibio deleted the feature/issue-484-blank-text-nodes-http-validation branch November 14, 2025 23:47
malibio added a commit that referenced this pull request Feb 4, 2026
* Fix: Dev-proxy HTTP endpoint regression - accept partial node requests (issue #484)

**Root Cause:**
PR #501 (SurrealDB migration) introduced a regression in the dev-proxy
`create_node` HTTP handler. It expected a full `Node` struct with `createdAt`,
`modifiedAt`, and `version` fields, but the frontend correctly sends partial
node data (via `BackendAdapter.createNode()`) without timestamps, expecting
the backend to add them automatically.

**Symptoms:**
- All 9 integration tests in `blank-node-creation.test.ts` failed with HTTP 422
- Error: "Unprocessable Entity" during database initialization
- Even non-blank sentinel nodes failed (proves it wasn't a blank content issue)

**Historical Behavior (Pre-Migration):**
- **Tauri commands**: Accept `CreateNodeInput` (no timestamps) → add in backend
- **MCP handlers**: Accept `MCPCreateNodeParams` (no timestamps) → add in backend
- **NodeOperations**: Creates full `Node` with timestamps at lines 675-689

**The Bug:**
Dev-proxy broke this contract by accepting `Json<Node>` instead of partial data.

**The Fix:**
1. Created `CreateNodeRequest` struct matching `CreateNodeInput` (no timestamps)
2. Updated `create_node` handler to accept `CreateNodeRequest`
3. Handler now adds `createdAt`, `modifiedAt`, `version` before calling NodeService
4. Matches established pattern from Tauri/MCP handlers

**Impact:**
- ✅ All 9 blank node integration tests now pass
- ✅ No regressions to existing 1538 passing tests
- ✅ Restores correct HTTP API contract (matches desktop mode behavior)

**Testing:**
```bash
bun run test:db src/tests/integration/blank-node-creation.test.ts
# Result: Test Files 1 passed (1), Tests 9 passed (9) ✅
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

* Address review: Add comprehensive documentation to CreateNodeRequest

Enhanced the CreateNodeRequest struct documentation with:
- Clear field semantics for all 9 fields
- Validation process explanation (two-stage validation)
- JSON example showing typical usage
- Explicit notes on special cases (blank content, deterministic IDs, mentions vs mentioned_by)

This addresses Finding 2 from the code review - improving API contract clarity
at the critical HTTP endpoint boundary between frontend and backend.

Severity: 🟡 Important (Documentation improvement)

Related: Issue #484

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
* Fix: Dev-proxy HTTP endpoint regression - accept partial node requests (issue #484)

**Root Cause:**
PR #501 (SurrealDB migration) introduced a regression in the dev-proxy
`create_node` HTTP handler. It expected a full `Node` struct with `createdAt`,
`modifiedAt`, and `version` fields, but the frontend correctly sends partial
node data (via `BackendAdapter.createNode()`) without timestamps, expecting
the backend to add them automatically.

**Symptoms:**
- All 9 integration tests in `blank-node-creation.test.ts` failed with HTTP 422
- Error: "Unprocessable Entity" during database initialization
- Even non-blank sentinel nodes failed (proves it wasn't a blank content issue)

**Historical Behavior (Pre-Migration):**
- **Tauri commands**: Accept `CreateNodeInput` (no timestamps) → add in backend
- **MCP handlers**: Accept `MCPCreateNodeParams` (no timestamps) → add in backend
- **NodeOperations**: Creates full `Node` with timestamps at lines 675-689

**The Bug:**
Dev-proxy broke this contract by accepting `Json<Node>` instead of partial data.

**The Fix:**
1. Created `CreateNodeRequest` struct matching `CreateNodeInput` (no timestamps)
2. Updated `create_node` handler to accept `CreateNodeRequest`
3. Handler now adds `createdAt`, `modifiedAt`, `version` before calling NodeService
4. Matches established pattern from Tauri/MCP handlers

**Impact:**
- ✅ All 9 blank node integration tests now pass
- ✅ No regressions to existing 1538 passing tests
- ✅ Restores correct HTTP API contract (matches desktop mode behavior)

**Testing:**
```bash
bun run test:db src/tests/integration/blank-node-creation.test.ts
# Result: Test Files 1 passed (1), Tests 9 passed (9) ✅
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

* Address review: Add comprehensive documentation to CreateNodeRequest

Enhanced the CreateNodeRequest struct documentation with:
- Clear field semantics for all 9 fields
- Validation process explanation (two-stage validation)
- JSON example showing typical usage
- Explicit notes on special cases (blank content, deterministic IDs, mentions vs mentioned_by)

This addresses Finding 2 from the code review - improving API contract clarity
at the critical HTTP endpoint boundary between frontend and backend.

Severity: 🟡 Important (Documentation improvement)

Related: Issue #484

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
* Fix: Dev-proxy HTTP endpoint regression - accept partial node requests (issue #484)

**Root Cause:**
PR #501 (SurrealDB migration) introduced a regression in the dev-proxy
`create_node` HTTP handler. It expected a full `Node` struct with `createdAt`,
`modifiedAt`, and `version` fields, but the frontend correctly sends partial
node data (via `BackendAdapter.createNode()`) without timestamps, expecting
the backend to add them automatically.

**Symptoms:**
- All 9 integration tests in `blank-node-creation.test.ts` failed with HTTP 422
- Error: "Unprocessable Entity" during database initialization
- Even non-blank sentinel nodes failed (proves it wasn't a blank content issue)

**Historical Behavior (Pre-Migration):**
- **Tauri commands**: Accept `CreateNodeInput` (no timestamps) → add in backend
- **MCP handlers**: Accept `MCPCreateNodeParams` (no timestamps) → add in backend
- **NodeOperations**: Creates full `Node` with timestamps at lines 675-689

**The Bug:**
Dev-proxy broke this contract by accepting `Json<Node>` instead of partial data.

**The Fix:**
1. Created `CreateNodeRequest` struct matching `CreateNodeInput` (no timestamps)
2. Updated `create_node` handler to accept `CreateNodeRequest`
3. Handler now adds `createdAt`, `modifiedAt`, `version` before calling NodeService
4. Matches established pattern from Tauri/MCP handlers

**Impact:**
- ✅ All 9 blank node integration tests now pass
- ✅ No regressions to existing 1538 passing tests
- ✅ Restores correct HTTP API contract (matches desktop mode behavior)

**Testing:**
```bash
bun run test:db src/tests/integration/blank-node-creation.test.ts
# Result: Test Files 1 passed (1), Tests 9 passed (9) ✅
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

* Address review: Add comprehensive documentation to CreateNodeRequest

Enhanced the CreateNodeRequest struct documentation with:
- Clear field semantics for all 9 fields
- Validation process explanation (two-stage validation)
- JSON example showing typical usage
- Explicit notes on special cases (blank content, deterministic IDs, mentions vs mentioned_by)

This addresses Finding 2 from the code review - improving API contract clarity
at the critical HTTP endpoint boundary between frontend and backend.

Severity: 🟡 Important (Documentation improvement)

Related: Issue #484

---------

Co-authored-by: Claude <[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.

Backend: Allow blank text nodes in validation

1 participant