Skip to content

Commit 30cc89b

Browse files
authored
test(app): tolerate one stray motion tick in the held-key diagonal journey (#1628)
1 parent 3655957 commit 30cc89b

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

internal/app/heldmotion/controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
// TickInterval is the motion loop's period.
1919
const TickInterval = 10 * time.Millisecond
2020

21-
// maxTickDelta caps the time a late tick may integrate, so a stalled
21+
// MaxTickDelta caps the time a late tick may integrate, so a stalled
2222
// scheduler produces a stutter rather than a jump.
23-
const maxTickDelta = 4 * TickInterval
23+
const MaxTickDelta = 4 * TickInterval
2424

2525
type heldKey struct {
2626
group, key string
@@ -296,7 +296,7 @@ func (c *Controller) run(id uint64) {
296296
pos := integrator.Step(
297297
input.ramp.ParamsFor(input.step),
298298
input.dir,
299-
min(now.Sub(last), maxTickDelta),
299+
min(now.Sub(last), MaxTickDelta),
300300
)
301301
last = now
302302

internal/app/simulation_journey_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"fmt"
1111
"image"
12+
"math"
1213
"os"
1314
"path/filepath"
1415
"slices"
@@ -17,6 +18,7 @@ import (
1718
"testing"
1819
"time"
1920

21+
"github.com/y3owk1n/neru/internal/app/heldmotion"
2022
"github.com/y3owk1n/neru/internal/config"
2123
"github.com/y3owk1n/neru/internal/domain"
2224
"github.com/y3owk1n/neru/internal/domain/action"
@@ -1405,8 +1407,18 @@ func TestSimulation_HeldMotionDiagonal(t *testing.T) {
14051407
},
14061408
)
14071409

1410+
// The two presses and the two releases each land as separate events, so
1411+
// a tick can fire while only one key is held and move that axis alone.
1412+
// A late tick integrates up to the controller's cap, so the bound is that
1413+
// much travel at the base speed: under the defaults four fifths of a
1414+
// step. Anything past that is a real drift, since an autorepeat that got
1415+
// through moves a whole step.
1416+
_, step, _ := cfg.HeldRepeat.HeldMotion([]string{config.CmdMoveMouseRight})
1417+
tickShare := heldmotion.MaxTickDelta.Seconds() / cfg.HeldRepeat.Ramp().Interval.Seconds()
1418+
strayTick := int(math.Ceil(float64(step) * tickShare))
1419+
14081420
end := sim.cursor.position()
1409-
if end.X-start.X != end.Y-start.Y {
1421+
if drift := (end.X - start.X) - (end.Y - start.Y); drift < -strayTick || drift > strayTick {
14101422
t.Fatalf("diagonal drifted: start %v, end %v", start, end)
14111423
}
14121424

0 commit comments

Comments
 (0)