MCPcopy Create free account
hub / github.com/compozy/agh / Validate

Method Validate

internal/task/validate.go:412–466  ·  view source on GitHub ↗

Validate reports whether the task record contains the canonical persisted shape.

()

Source from the content-addressed store, hash-verified

410
411// Validate reports whether the task record contains the canonical persisted shape.
412func (t Task) Validate() error {
413 if strings.TrimSpace(t.ID) == "" {
414 return fmt.Errorf("%w: task.id is required", ErrValidation)
415 }
416 if err := ValidateScopeBinding(t.Scope, t.WorkspaceID, "task", "workspace_id"); err != nil {
417 return err
418 }
419 if strings.TrimSpace(t.ParentTaskID) != "" && strings.TrimSpace(t.ParentTaskID) == strings.TrimSpace(t.ID) {
420 return fmt.Errorf("%w: task.parent_task_id cannot equal task.id", ErrValidation)
421 }
422 if strings.TrimSpace(t.Title) == "" {
423 return fmt.Errorf("%w: task.title is required", ErrValidation)
424 }
425 if err := t.Status.Validate("task.status"); err != nil {
426 return err
427 }
428 if t.Status.Normalize() == TaskStatusDraft && !t.ClosedAt.IsZero() {
429 return fmt.Errorf("%w: task.closed_at must be empty while task.status is %q", ErrValidation, TaskStatusDraft)
430 }
431 if err := normalizePriorityOrDefault(t.Priority).Validate("task.priority"); err != nil {
432 return err
433 }
434 if err := validateTaskMaxAttempts(t.MaxAttempts, "task.max_attempts", true); err != nil {
435 return err
436 }
437 approvalPolicy := normalizeApprovalPolicyOrDefault(t.ApprovalPolicy)
438 if err := approvalPolicy.Validate("task.approval_policy"); err != nil {
439 return err
440 }
441 approvalState := normalizeApprovalStateOrDefault(approvalPolicy, t.ApprovalState)
442 if err := approvalState.Validate("task.approval_state"); err != nil {
443 return err
444 }
445 if err := ValidateApprovalSemantics(approvalPolicy, approvalState, "task"); err != nil {
446 return err
447 }
448 if err := t.CreatedBy.Validate("task.created_by"); err != nil {
449 return err
450 }
451 if err := validateNeedsAttention(t.NeedsAttention); err != nil {
452 return err
453 }
454 if err := t.Origin.Validate("task.origin"); err != nil {
455 return err
456 }
457 if t.Owner != nil {
458 if err := t.Owner.Validate("task.owner"); err != nil {
459 return err
460 }
461 }
462 if err := ValidateMetadataSize(t.Metadata, "task.metadata"); err != nil {
463 return err
464 }
465 return nil
466}
467
468func validateNeedsAttention(attention *NeedsAttention) error {
469 if attention == nil {

Callers 1

CreateTaskMethod · 0.95

Calls 11

validateTaskMaxAttemptsFunction · 0.85
validateNeedsAttentionFunction · 0.85
ValidateMetadataSizeFunction · 0.85
ValidateScopeBindingFunction · 0.70
ValidateMethod · 0.65
NormalizeMethod · 0.45
IsZeroMethod · 0.45

Tested by

no test coverage detected