Skip to content

Implement TaskNodeBehavior #132

Closed
Closed

Description

@malibio

Overview

Implement the TaskNodeBehavior for handling task nodes with status tracking, due dates, and priority management.

Prerequisites

Before starting this issue:

Implementation Tasks

  • Create TaskNodeBehavior struct implementing NodeBehavior trait
  • Implement validation for task status (pending, in-progress, completed, cancelled)
  • Add due_date format validation (ISO date string)
  • Implement priority validation (1-4 range)
  • Validate required task description in content
  • Set default metadata for tasks
  • Implement deletion behavior (orphan children/subtasks)
  • Add comprehensive unit tests for task validation

Acceptance Criteria

  • TaskNodeBehavior properly implements all NodeBehavior trait methods
  • Status validation restricts to valid states
  • Due date validation ensures proper ISO format
  • Priority validation enforces 1-4 range (1=low, 2=medium, 3=high, 4=urgent)
  • Empty task descriptions are rejected
  • Default metadata includes status=pending, priority=2, due_date=null
  • Deletion orphans subtasks (doesn't cascade delete)
  • Unit tests cover all validation rules and edge cases
  • Code follows Rust best practices and passes cargo clippy

Technical Specifications

Implementation Pattern:

pub struct TaskNodeBehavior;

impl NodeBehavior for TaskNodeBehavior {
    fn type_name(&self) -> &'static str {
        "task"
    }

    fn validate(&self, node: &Node) -> Result<(), ValidationError> {
        // Validate non-empty description
        // Validate status in [pending, in-progress, completed, cancelled]
        // Validate due_date format if present
        // Validate priority in 1-4 range if present
    }

    fn can_have_children(&self) -> bool {
        true // Tasks can have subtasks
    }

    fn supports_markdown(&self) -> bool {
        false // Tasks are single-line descriptions
    }

    fn default_metadata(&self) -> Value {
        json\!({
            "status": "pending",
            "priority": 2,  // medium priority
            "due_date": null,
            "assignee_id": null,
            "estimated_hours": null
        })
    }

    fn on_delete(&self, _node: &Node) -> Result<Vec<DeletionAction>, ProcessingError> {
        Ok(vec\![
            DeletionAction::DeleteMentions,
            DeletionAction::OrphanChildren, // Subtasks become orphaned
        ])
    }
}

Metadata Schema:

{
  "status": "pending" | "in-progress" | "completed" | "cancelled",
  "priority": 1 | 2 | 3 | 4,
  "due_date": "YYYY-MM-DD" | null,
  "assignee_id": "node-id" | null,
  "estimated_hours": number | null
}

Validation Rules:

  • Content: Must be non-empty string
  • Status: Must be one of: pending, in-progress, completed, cancelled
  • Due date: If present, must be valid ISO date string (YYYY-MM-DD)
  • Priority: If present, must be integer 1-4
  • Assignee: If present, should be valid node ID (basic string check)

Dependencies:

Testing Requirements:

  • Test valid task with all fields
  • Test minimal task (only content)
  • Test invalid status values
  • Test invalid priority values (0, 5, -1)
  • Test invalid due_date formats
  • Test empty content rejection
  • Test default metadata generation
  • Test deletion behavior

Related Issues

Implementation Notes

  • Embeddings: Leave embedding_vector as None - NLP integration comes later
  • Complementary table: Tasks have a complementary tasks table for indexed queries (created in Initialize database schema (Pure JSON, no migrations) #102)
  • Status transitions: This issue only validates status values; status transition logic comes later
  • Subtasks: Orphaned on parent deletion (don't auto-delete) to preserve work

This provides the foundation for task management in NodeSpace.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions