fix: validate decision nodes have at least 2 children in frontend and AI builder
The frontend validate button was not checking that decision nodes with children have at least 2 branches, so it would pass validation but the backend publish check would reject with a 422. The AI tree validator also only checked options count, not children count — so AI-generated trees with 2 options pointing to the same single child would pass generation validation but fail at publish time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -710,7 +710,17 @@ export const useTreeEditorStore = create<TreeEditorState>()(
|
||||
message: `Decision node "${node.id}" requires at least one option`,
|
||||
severity: 'error'
|
||||
})
|
||||
} else {
|
||||
}
|
||||
// Decision nodes with children must have at least 2 branches
|
||||
if (node.children && node.children.length > 0 && node.children.length < 2) {
|
||||
errors.push({
|
||||
nodeId: node.id,
|
||||
field: 'children',
|
||||
message: `Decision node "${node.id}" must have at least 2 branches`,
|
||||
severity: 'error'
|
||||
})
|
||||
}
|
||||
if (node.options && node.options.length > 0) {
|
||||
// Validate options
|
||||
node.options.forEach((opt, i) => {
|
||||
if (!opt.label?.trim()) {
|
||||
|
||||
Reference in New Issue
Block a user