feat(graph/subgraph-and-validation): implement subgraph and validation methods

- Add subgraph() method using graphology-operators.subgraph (ADR-007: internal-only edges)
- Add validateSchema() using TypeBox Value.Check/Value.Errors
- Add validateGraph() detecting cycles and dangling references
- Add validate() combining both validations
- Define ValidationError, GraphValidationError, AnyValidationError types in error module
- Add standalone validation functions in src/graph/validation.ts
- Export validation module from src/graph/index.ts
- Add 43 unit tests for subgraph filtering and validation
This commit is contained in:
2026-04-27 12:41:51 +00:00
parent b0d943f4e6
commit c3649256cc
6 changed files with 869 additions and 5 deletions

View File

@@ -84,4 +84,55 @@ export class DuplicateEdgeError extends TaskgraphError {
this.prerequisite = prerequisite;
this.dependent = dependent;
}
}
}
// ---------------------------------------------------------------------------
// Validation error return types (validation never throws — returns arrays)
// ---------------------------------------------------------------------------
/**
* Schema validation error returned by `validateSchema()`.
*
* Represents a single field-level issue found by TypeBox `Value.Errors()`.
* Schema validation catches missing required fields, invalid enum values,
* type mismatches, etc.
*/
export interface ValidationError {
/** Discriminator: always "schema" */
type: 'schema';
/** Which task has the issue (if applicable) */
taskId?: string;
/** Which field is invalid */
field: string;
/** Human-readable description of the issue */
message: string;
/** The invalid value (if safe to include) */
value?: unknown;
}
/**
* Graph-level validation error returned by `validateGraph()`.
*
* Represents a structural graph issue (cycles, dangling references)
* rather than a per-field schema issue.
*/
export interface GraphValidationError {
/** Discriminator: always "graph" */
type: 'graph';
/** Category of graph issue */
category: 'cycle' | 'dangling-reference';
/** Which task is involved (for dangling references) */
taskId?: string;
/** Human-readable description */
message: string;
/** Additional details (e.g., cycle paths for cycle errors) */
details?: unknown;
}
/**
* Union type for any validation error (schema or graph).
*
* Used as the return type for `TaskGraph.validate()` which combines
* both `ValidationError[]` and `GraphValidationError[]`.
*/
export type AnyValidationError = ValidationError | GraphValidationError;