Verify deterministic movement from observations

Co-authored-by: codegirl007 <codegirl-007@users.noreply.github.com>
This commit is contained in:
Cursor Agent
2026-08-17 16:49:37 +00:00
co-authored by codegirl007
parent 3037dbc2dd
commit c4f8dbeaaf
7 changed files with 154 additions and 23 deletions
+43 -1
View File
@@ -1,7 +1,11 @@
package agent
import (
"bytes"
"context"
"image"
"image/color"
"image/png"
"testing"
"agentbox/internal/environment"
@@ -19,7 +23,13 @@ func TestDeterministicSequence(t *testing.T) {
{"", true},
}
for index, expected := range want {
decision, err := controller.NextAction(context.Background(), "", nil, Observation{})
x := 20
if index >= 2 {
x = 140
}
decision, err := controller.NextAction(context.Background(), "", nil, Observation{
Screenshot: screenshotWithSquare(t, x),
})
if err != nil {
t.Fatalf("step %d: %v", index, err)
}
@@ -31,3 +41,35 @@ func TestDeterministicSequence(t *testing.T) {
}
}
}
func TestDeterministicRejectsMissingMovement(t *testing.T) {
controller := &Deterministic{}
for step := 0; step < 2; step++ {
if _, err := controller.NextAction(context.Background(), "", nil, Observation{
Screenshot: screenshotWithSquare(t, 20),
}); err != nil {
t.Fatal(err)
}
}
if _, err := controller.NextAction(context.Background(), "", nil, Observation{
Screenshot: screenshotWithSquare(t, 20),
}); err == nil {
t.Fatal("movement verification error = nil")
}
}
func screenshotWithSquare(t *testing.T, startX int) []byte {
t.Helper()
img := image.NewRGBA(image.Rect(0, 0, 240, 100))
green := color.RGBA{G: 255, B: 102, A: 255}
for y := 20; y < 60; y++ {
for x := startX; x < startX+40; x++ {
img.Set(x, y, green)
}
}
var output bytes.Buffer
if err := png.Encode(&output, img); err != nil {
t.Fatal(err)
}
return output.Bytes()
}