Skip to content

Commit 4e72334

Browse files
committed
fix(academy): validate condition branch handles in edge_exists rules
- Add sourceHandle field to edge_exists ValidationRule type - Check sourceHandle in validation.ts when specified - Require both condition-if and condition-else branches to be connected in the branching and final project exercises
1 parent 67ef00c commit 4e72334

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

apps/sim/lib/academy/content/courses/sim-foundations.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,15 @@ export const simFoundations: Course = {
470470
type: 'edge_exists',
471471
sourceType: 'condition',
472472
targetType: 'agent',
473-
label: 'Connect the Condition to at least one Agent',
473+
sourceHandle: 'condition-if',
474+
label: 'Connect the Condition true branch (top handle) to an Agent',
475+
},
476+
{
477+
type: 'edge_exists',
478+
sourceType: 'condition',
479+
targetType: 'agent',
480+
sourceHandle: 'condition-else',
481+
label: 'Connect the Condition false branch (bottom handle) to an Agent',
474482
},
475483
],
476484
hints: [
@@ -683,7 +691,15 @@ export const simFoundations: Course = {
683691
type: 'edge_exists',
684692
sourceType: 'condition',
685693
targetType: 'agent',
686-
label: 'Connect the Condition to at least one branch Agent',
694+
sourceHandle: 'condition-if',
695+
label: 'Connect the Condition true branch to an Agent',
696+
},
697+
{
698+
type: 'edge_exists',
699+
sourceType: 'condition',
700+
targetType: 'agent',
701+
sourceHandle: 'condition-else',
702+
label: 'Connect the Condition false branch to an Agent',
687703
},
688704
],
689705
hints: [

apps/sim/lib/academy/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export type ValidationRule = { label?: string } & (
114114
valueNotEmpty?: boolean
115115
valuePattern?: string
116116
}
117-
| { type: 'edge_exists'; sourceType: string; targetType: string }
117+
| { type: 'edge_exists'; sourceType: string; targetType: string; sourceHandle?: string }
118118
| { type: 'block_count_min'; count: number }
119119
| { type: 'block_count_max'; count: number }
120120
| { type: 'custom'; validatorId: string; params?: Record<string, unknown> }

apps/sim/lib/academy/validation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ function checkRule(
5858
return edges.some((e) => {
5959
const source = blockMap.get(e.source)
6060
const target = blockMap.get(e.target)
61-
return source?.type === rule.sourceType && target?.type === rule.targetType
61+
if (source?.type !== rule.sourceType || target?.type !== rule.targetType) return false
62+
if (rule.sourceHandle && e.sourceHandle !== rule.sourceHandle) return false
63+
return true
6264
})
6365
}
6466

0 commit comments

Comments
 (0)