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

Function ValidateScopeBinding

internal/task/validate.go:1093–1124  ·  view source on GitHub ↗

ValidateScopeBinding enforces the canonical scope/workspace invariant shared by task-domain records.

(scope Scope, workspaceBinding string, path string, workspaceField string)

Source from the content-addressed store, hash-verified

1091
1092// ValidateScopeBinding enforces the canonical scope/workspace invariant shared by task-domain records.
1093func ValidateScopeBinding(scope Scope, workspaceBinding string, path string, workspaceField string) error {
1094 scopePath := nestedPath(path, "scope")
1095 if err := scope.Validate(scopePath); err != nil {
1096 return err
1097 }
1098
1099 workspacePath := nestedPath(path, workspaceField)
1100 switch scope.Normalize() {
1101 case ScopeGlobal:
1102 if strings.TrimSpace(workspaceBinding) != "" {
1103 return fmt.Errorf(
1104 "%w: %s must be empty when %s is %q",
1105 ErrInvalidScopeBinding,
1106 workspacePath,
1107 scopePath,
1108 ScopeGlobal,
1109 )
1110 }
1111 case ScopeWorkspace:
1112 if strings.TrimSpace(workspaceBinding) == "" {
1113 return fmt.Errorf(
1114 "%w: %s is required when %s is %q",
1115 ErrInvalidScopeBinding,
1116 workspacePath,
1117 scopePath,
1118 ScopeWorkspace,
1119 )
1120 }
1121 }
1122
1123 return nil
1124}
1125
1126// ValidateImmutableTaskFields reports whether an update attempted to change immutable task fields.
1127func ValidateImmutableTaskFields(current Task, next Task) error {

Callers 6

ValidateMethod · 0.70
ValidateMethod · 0.70
ValidateMethod · 0.70
ValidateMethod · 0.70
ValidateMethod · 0.70
TestValidateScopeBindingFunction · 0.70

Calls 3

nestedPathFunction · 0.70
ValidateMethod · 0.65
NormalizeMethod · 0.45

Tested by 1

TestValidateScopeBindingFunction · 0.56