2 Commits

Author SHA1 Message Date
iamlukethedev fcecece1c3 fix(test): correct same-cell astar assertion to match code behavior
The test expected [] for same-cell targets, but the code correctly
returns [{ x: ex, y: ey }] so the movement layer can make the final
fine-grained adjustment to the exact pixel.

Made-with: Cursor
2026-03-27 13:19:47 -05:00
robotica4us-collab 450f4873f6 fix(issue-3): astar() returns empty path on failure instead of raw destination (#21)
* fix(navigation): astar() returns [] on failure instead of raw destination

Issue #3: When A* could not find a route, it returned [{x: endX, y: endY}]
(the raw destination) as a one-element path. The movement layer treated
this as a valid waypoint and steered agents in a straight line toward the
target, letting them pass through walls and furniture.

Changes:
- navigation.ts: Both failure exits in astar() now return [] instead of
  [{x: ex, y: ey}]. This applies to:
    * findFree() returning null (start or end hopelessly blocked)
    * start and end resolving to the same free cell (already arrived)
    * open list exhausted with no route to the end
- RetroOffice3D.tsx: Movement-layer waypoint fallback changed from
  agent.targetX/Y to agent.x/agent.y when path is empty. An agent with
  no route now stays put rather than walking through obstacles.

Tests added (tests/unit/navigation.astarFallback.test.ts):
- astar returns [] for an unreachable destination (thick wall barrier)
- astar returns [] when the entire grid is blocked (findFree fails)
- astar returns a valid path for reachable destinations (regression)
- astar returns [] when start and end snap to the same grid cell
- movement-layer simulation: empty path keeps agent at current position

* fix(navigation): preserve final waypoint for same-cell reachable targets

astar() was returning [] for both true pathfinding failures and same-cell
reachable targets, causing the movement layer to treat both cases identically
(agent stays put). A destination within the same nav cell is still reachable
— the agent should take the final fine-grained step to the exact pixel.

Fix: return [{ x: ex, y: ey }] for same-cell case so the movement layer
can settle the agent onto the exact interaction point.

---------

Co-authored-by: Neo (subagent) <neo@openclaw.local>
Co-authored-by: Neo <neo@openclaw.ai>
2026-03-27 13:19:39 -05:00