From 956bd5dd2e11dd5efc9826331c5b6fb748af3bfb Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sat, 21 Feb 2026 17:01:37 -0700 Subject: [PATCH] Make constraint kind a typed enum, remove dead next_row handling, panic on invalid kinds --- cmd/qrunproxy/timeline.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/cmd/qrunproxy/timeline.go b/cmd/qrunproxy/timeline.go index f4c0941..2d706aa 100644 --- a/cmd/qrunproxy/timeline.go +++ b/cmd/qrunproxy/timeline.go @@ -55,30 +55,34 @@ func (c *TimelineCell) String() string { return fmt.Sprintf("%s/%s@%s:r%d", c.BlockID, c.Event, c.track.ID, c.row) } +type constraintKind string + +const ( + constraintSameRow constraintKind = "same_row" +) + type constraint struct { - kind string + kind constraintKind a *TimelineCell b *TimelineCell } func (c constraint) satisfied() bool { switch c.kind { - case "same_row": + case constraintSameRow: return c.a.row == c.b.row - case "next_row": - return c.b.row > c.a.row + default: + panic("invalid constraint kind: " + string(c.kind)) } - return true } func (c constraint) String() string { switch c.kind { - case "same_row": + case constraintSameRow: return fmt.Sprintf("same_row(%s, %s)", c.a, c.b) - case "next_row": - return fmt.Sprintf("next_row(%s -> %s)", c.a, c.b) + default: + panic("invalid constraint kind: " + string(c.kind)) } - return fmt.Sprintf("%s(%s, %s)", c.kind, c.a, c.b) } type exclusiveGroup struct { @@ -166,7 +170,7 @@ func BuildTimeline(show *Show) (Timeline, error) { return tl, nil } -func (tl *Timeline) addConstraint(kind string, a, b *TimelineCell) { +func (tl *Timeline) addConstraint(kind constraintKind, a, b *TimelineCell) { tl.constraints = append(tl.constraints, constraint{kind: kind, a: a, b: b}) } @@ -243,7 +247,7 @@ func (tl *Timeline) buildConstraints() { for _, target := range trigger.Targets { t := tl.findCell(target.Block, target.Hook) if source.track != t.track { - tl.addConstraint("same_row", source, t) + tl.addConstraint(constraintSameRow, source, t) source.Type = CellSignal } group.members = append(group.members, t) @@ -281,14 +285,14 @@ func (tl *Timeline) enforceConstraints() bool { continue } switch c.kind { - case "same_row": + case constraintSameRow: if c.a.row < c.b.row { tl.insertGap(c.a.track, c.a.row) } else { tl.insertGap(c.b.track, c.b.row) } - case "next_row": - tl.insertGap(c.b.track, c.b.row) + default: + panic("invalid constraint kind: " + string(c.kind)) } return true }