mirror of
https://github.com/donlucasx/xscapes.git
synced 2026-10-20 08:43:32 +02:00
stillFor() is right that the ask, the knock and the worry all stand still. What "still" was implemented as is the defect: pace() returned 0, and 0 is HOME -- the column nearest the frame edge. drawScene draws the companion at lay.CatX + round(dx), so at the exact frame the agent starts asking for something, the companion teleported OUTWARD, away from the reader it is trying to reach. Measured on the rendered frame in notes/s28-pace, which SYMLINKS pace.go rather than copying its arithmetic so it cannot go stale: 6 cells at 111/124/143/153, 5 at 80, 2 at 40, with Steps and StepAge unchanged either side -- the pose is the only thing that moved. Over 68 (width, step count) transitions, 56 move the companion and every one of them moves it outward. It is TWO teleports per ask, and the second was never written down: answering starts a tool, ToolStart both clears needsInput and takes a step, so it snaps straight back inward. ⚠ AND FIXING IT ALONE RE-BREAKS THE BALLOON. live.go anchored the pointer with lay.CatX+cat.HeadCol() -- HOME, not the drawn catX. That was correct only BECAUSE of this defect: every pose that raises a balloon is a held pose, so dx was always 0. With the pace fixed and live.go left alone, TestTheBalloonPointsAtTheCompanion fails 9 of 20 combinations -- the bare-sand aim s27 just fixed. The anchor moves to the drawn column in the same commit. ⚠ That test could never have caught it: it builds its state from demoState(), which leaves Steps at 0, so dx is 0 whatever pace() does. It now gets a real step count, which is what turns it into a guard. TestTheHeldPosesDoNotPace asserted dx == 0 for the three held poses. That assertion IS the defect written down, so it now compares against the offset the same state would have had while working. ⚠ Found and NOT fixed here: pace() calls paceSpan(w) unconditionally, but compose() sets PaceSpan = 0 in the unmirrored layout, where CatX is 5 and "inward" is the wrong direction. At 124 columns -mirror=false draws the companion at column -1, clipped by the left edge, while it works. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FpWuRRqmoTMo6ayCkx9yYZ
119 lines
4.5 KiB
Go
119 lines
4.5 KiB
Go
package main
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/donlucasx/xscapes/internal/companion"
|
|
"github.com/donlucasx/xscapes/internal/event"
|
|
"github.com/donlucasx/xscapes/internal/reduce"
|
|
)
|
|
|
|
// The companion paces INWARD, one step per MAIN-THREAD tool event.
|
|
//
|
|
// His two notes are the spec. "Should be tied up to an actual agent action so
|
|
// its not random" -- so the step count comes from events, never from a clock.
|
|
// And "the companion should move towards the center of the screen instead of
|
|
// the far edge (right) where theres barely any margin" -- so the offset is
|
|
// never positive, because outward is a wall.
|
|
func TestThePaceGoesInwardAndIsDrivenByEvents(t *testing.T) {
|
|
for _, w := range []int{40, 80, 124, 200} {
|
|
span := paceSpan(w)
|
|
if span < 1 {
|
|
t.Fatalf("w=%d: span %d leaves nowhere to pace", w, span)
|
|
}
|
|
// Every step of a long walk, at every phase of the stride.
|
|
for n := 0; n < 4*span+3; n++ {
|
|
for _, since := range []float64{0, stepDur / 3, stepDur * 0.99, stepDur, 5} {
|
|
dx, _ := paceAt(n, since, span)
|
|
if dx > 0 {
|
|
t.Fatalf("w=%d n=%d since=%.2f: dx=%.2f is OUTWARD, into the margin", w, n, since, dx)
|
|
}
|
|
if dx < -float64(span) {
|
|
t.Fatalf("w=%d n=%d: dx=%.2f goes past the reserved strip (%d)", w, n, dx, span)
|
|
}
|
|
}
|
|
}
|
|
// A triangle comes home: at 2*span steps it is back where it started.
|
|
if dx, _ := paceAt(2*span, stepDur, span); dx != 0 {
|
|
t.Errorf("w=%d: after a full there-and-back the companion is at %.2f, not home", w, dx)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The sand and the litter keep out of the strip the companion walks.
|
|
func TestNothingIsDrawnInThePacingStrip(t *testing.T) {
|
|
for _, w := range []int{40, 80, 124, 200} {
|
|
lay := compose(w, 12, true)
|
|
reach := lay.CatX - lay.PaceSpan
|
|
if lay.SandTo >= reach {
|
|
t.Errorf("w=%d: the sand runs to %d but the companion reaches %d", w, lay.SandTo, reach)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A pose that holds its ground HOLDS ITS GROUND: it keeps the column it is
|
|
// standing on and drops the stride pose, because a raised claw that is also
|
|
// walking is noise.
|
|
//
|
|
// ⚠ THIS TEST USED TO ASSERT THE DEFECT. It read `dx != 0 || moving` and
|
|
// called that "it should hold its ground" -- but dx = 0 is HOME, the column
|
|
// nearest the frame edge, so what it was really pinning down was a teleport of
|
|
// up to paceSpan(w) cells OUTWARD at the frame the agent asks for something.
|
|
// See the comment on pace(). The guarantee below is the one the old name
|
|
// always meant, and near_test.go states it again on the RENDERED frame.
|
|
func TestTheHeldPosesHoldTheirGround(t *testing.T) {
|
|
for _, st := range []reduce.State{
|
|
{Pose: companion.NeedsYou, Steps: 9, StepAge: 0.1},
|
|
{Pose: companion.Done, Steps: 9, StepAge: 0.1},
|
|
{Pose: companion.Worried, Steps: 9, StepAge: 0.1},
|
|
} {
|
|
dx, moving := pace(st, 124)
|
|
if moving {
|
|
t.Errorf("pose %v took the stride pose; a held pose does not walk", st.Pose)
|
|
}
|
|
// Where a WORKING companion with the same numbers would be standing.
|
|
want, _ := paceAt(st.Steps, st.StepAge, paceSpan(124))
|
|
if dx != want {
|
|
t.Errorf("pose %v is at %.2f but it was standing at %.2f -- it moved %.2f cells "+
|
|
"for no reason but the pose changing", st.Pose, dx, want, dx-want)
|
|
}
|
|
if dx == 0 {
|
|
t.Errorf("pose %v is at home (0); with Steps=%d it should be mid-strip, "+
|
|
"and a test that passes at 0 cannot tell holding from teleporting",
|
|
st.Pose, st.Steps)
|
|
}
|
|
}
|
|
// And a working companion with the same numbers does move, so the test
|
|
// above cannot pass by the pace being broken everywhere.
|
|
if dx, _ := pace(reduce.State{Pose: companion.Working, Steps: 9, StepAge: 0.1}, 124); dx == 0 {
|
|
t.Error("a working companion did not pace at all")
|
|
}
|
|
}
|
|
|
|
// SUBAGENT tool events do not move the parent. Those belong to the litter, and
|
|
// one event spending two channels is exactly what the encoding rule forbids.
|
|
func TestOnlyMainThreadToolEventsStepTheCompanion(t *testing.T) {
|
|
now := time.Now()
|
|
r := reduce.New("test")
|
|
main := event.Event{Kind: event.ToolStart, ID: "a", Tool: "Edit"}
|
|
sub := event.Event{Kind: event.ToolStart, ID: "b", Tool: "Edit", Agent: "sub-1"}
|
|
|
|
r.Apply(main, now)
|
|
r.Apply(sub, now)
|
|
r.Apply(sub, now)
|
|
r.Apply(sub, now)
|
|
got := r.State(now).Steps
|
|
if got != 1 {
|
|
t.Fatalf("one main-thread event and three subagent events gave %d steps, want 1 -- "+
|
|
"a subagent moving the parent spends the same event on two channels", got)
|
|
}
|
|
|
|
// And the age is measured from the last MAIN-thread one.
|
|
st := r.State(now.Add(2 * time.Second))
|
|
if math.Abs(st.StepAge-2) > 0.01 {
|
|
t.Errorf("StepAge %.2f, want ~2s since the main-thread event", st.StepAge)
|
|
}
|
|
}
|