fix(formula): address code review findings

Fixes from self-review of formula parser and bd cook:

1. Atomicity: Add cleanup on failure in cookFormula - if labels/deps
   transaction fails, delete the already-created issues

2. Validation: Add recursive depends_on validation for child steps
   and validate priority ranges for children

3. Documentation: Mark unimplemented fields (Expand, ExpandVars,
   Condition, Gate) with TODO(future) comments

4. Thread safety: Add note that Parser is NOT thread-safe

5. Error messages: Track first definition location for duplicate ID
   errors (e.g., "duplicate id at steps[1], first defined at steps[0]")

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-24 13:50:19 -08:00
parent 4fdcda4568
commit d1c4526e6e
4 changed files with 118 additions and 20 deletions

View File

@@ -198,6 +198,52 @@ func TestValidate_ChildSteps(t *testing.T) {
}
}
func TestValidate_ChildStepsInvalidDependsOn(t *testing.T) {
formula := &Formula{
Formula: "mol-bad-child-dep",
Version: 1,
Type: TypeWorkflow,
Steps: []*Step{
{
ID: "epic1",
Title: "Epic 1",
Children: []*Step{
{ID: "child1", Title: "Child 1"},
{ID: "child2", Title: "Child 2", DependsOn: []string{"nonexistent"}},
},
},
},
}
err := formula.Validate()
if err == nil {
t.Error("Validate should fail for child depends_on referencing unknown step")
}
}
func TestValidate_ChildStepsInvalidPriority(t *testing.T) {
p := 10 // invalid
formula := &Formula{
Formula: "mol-bad-child-priority",
Version: 1,
Type: TypeWorkflow,
Steps: []*Step{
{
ID: "epic1",
Title: "Epic 1",
Children: []*Step{
{ID: "child1", Title: "Child 1", Priority: &p},
},
},
},
}
err := formula.Validate()
if err == nil {
t.Error("Validate should fail for child with invalid priority")
}
}
func TestValidate_BondPoints(t *testing.T) {
formula := &Formula{
Formula: "mol-compose",