feat(graph/mutation): implement removeTask, removeDependency, updateTask, updateEdgeAttributes

This commit is contained in:
2026-04-27 11:51:57 +00:00
parent 9ad0ec902c
commit 5adc712193
4 changed files with 508 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
---
id: graph/mutation
name: Implement TaskGraph mutation methods (remove, update, updateEdgeAttributes)
status: pending
status: completed
depends_on:
- graph/taskgraph-class
scope: narrow
@@ -16,12 +16,12 @@ Implement mutation methods in `src/graph/mutation.ts` and integrate on `TaskGrap
## Acceptance Criteria
- [ ] `removeTask(id: string): void` — No-op if node doesn't exist. Removes node and cascades edge removal (graphology handles this automatically).
- [ ] `removeDependency(prerequisite: string, dependent: string): void` — No-op if edge doesn't exist. Uses deterministic edge key `${prerequisite}->${dependent}` to identify the edge.
- [ ] `updateTask(id: string, attributes: Partial<TaskGraphNodeAttributes>): void` — Throws `TaskNotFoundError` if ID doesn't exist. Uses `mergeNodeAttributes` for shallow merge of provided attributes.
- [ ] `updateEdgeAttributes(prerequisite: string, dependent: string, attrs: Partial<TaskGraphEdgeAttributes>): void` — Throws `TaskNotFoundError` (actually `TaskNotFoundError` for the edge itself, but per the spec, edge attributes need both endpoints to exist) if the edge doesn't exist. Uses `mergeEdgeAttributes` for shallow merge.
- [ ] All mutations maintain the deterministic edge key format
- [ ] Unit tests: remove nonexistent node/edge is no-op, update nonexistent throws, partial updates merge correctly
- [x] `removeTask(id: string): void` — No-op if node doesn't exist. Removes node and cascades edge removal (graphology handles this automatically).
- [x] `removeDependency(prerequisite: string, dependent: string): void` — No-op if edge doesn't exist. Uses deterministic edge key `${prerequisite}->${dependent}` to identify the edge.
- [x] `updateTask(id: string, attributes: Partial<TaskGraphNodeAttributes>): void` — Throws `TaskNotFoundError` if ID doesn't exist. Uses `mergeNodeAttributes` for shallow merge of provided attributes.
- [x] `updateEdgeAttributes(prerequisite: string, dependent: string, attrs: Partial<TaskGraphEdgeAttributes>): void` — Throws `TaskNotFoundError` (actually `TaskNotFoundError` for the edge itself, but per the spec, edge attributes need both endpoints to exist) if the edge doesn't exist. Uses `mergeEdgeAttributes` for shallow merge.
- [x] All mutations maintain the deterministic edge key format
- [x] Unit tests: remove nonexistent node/edge is no-op, update nonexistent throws, partial updates merge correctly
## References
@@ -31,8 +31,16 @@ Implement mutation methods in `src/graph/mutation.ts` and integrate on `TaskGrap
## Notes
> To be filled by implementation agent
Implementation follows the architecture spec precisely:
- Standalone functions in `mutation.ts` take `TaskGraphInner` as first arg
- TaskGraph class methods delegate to standalone functions
- `removeTask`/`removeDependency` are no-ops on missing targets (idempotent removal)
- `updateTask`/`updateEdgeAttributes` throw `TaskNotFoundError` on missing targets
- Deterministic edge key format `${prerequisite}->${dependent}` used throughout
## Summary
> To be filled on completion
Implemented all four TaskGraph mutation methods with standalone functions and class integration.
- Created: `test/mutation.test.ts` (27 tests)
- Modified: `src/graph/mutation.ts`, `src/graph/construction.ts`
- Tests: 284 total, all passing (27 new mutation tests)