Keep local reroutes bound to original edges within simplified guidance

This commit is contained in:
DCCONSTRUCTIONS
2026-10-09 20:43:44 +03:00
parent b2faab8ada
commit 3376b1a9e6
3 changed files with 117 additions and 15 deletions
+58
View File
@@ -224,3 +224,61 @@ def test_observed_detour_can_pass_advisory_joint_without_returning_to_line(condi
assert result["authority"] == "adjacent-route-intent-only; not-mission-arrival"
assert result["body"] == body
assert mission.confirm_corridor_transition(pose, 10., body) is None
@pytest.mark.parametrize('direction', ['forward', 'reverse', 'at-node'])
def test_local_blockage_keeps_original_graph_edge_and_nearby_return_node(direction):
from k1link.simulation.ai_polygon.route_feedback import blocked_route_piece
*_, inputs, _ = fixture()
if direction == 'reverse':
inputs['routing'].update(start_node='3', goal_nodes=['0'])
inputs['mission']['route_xy'] = [[0., 0.]]
segment = build_route(inputs)['legs'][0]['segments'][0]
pose = [2.8, .2] if direction == 'reverse' else ([8., 0.] if direction == 'at-node' else [9.2, .2])
hazard = [1.8, .1, 0.] if direction == 'reverse' else [10.2, .1, 0.]
edge, anchor, closed = blocked_route_piece(inputs['routing'], segment, [hazard], pose)
assert (edge['id'], anchor, closed) == (('0', '1', ['0']) if direction == 'reverse' else ('2', '2', ['2']))
def test_compressed_advisory_reroute_uses_nearby_branch_without_closing_the_passed_chain(monkeypatch):
from k1link.simulation.ai_polygon.route_mission import RoutedMission
*_, inputs, _ = fixture()
graph = inputs['routing']['map']
graph['nodes'].append(dict(id='6', xy=[8., 5.], z=0.))
graph['edges'].extend([
dict(id='6', start='2', end='6', half_width_m=1., bidirectional=True, cost_m=5.),
dict(id='7', start='6', end='5', half_width_m=1., bidirectional=True, cost_m=4.)])
graph['sha256'] = digest({k:v for k,v in graph.items() if k!='sha256'})
inputs.update(sensors={'schema_version':'missioncore.simulation-sensor-rig/v4'},
behavior={'max_speed_mps':1.})
mission = RoutedMission(inputs)
mission.route_observation([0.,0.,0.,0.,0.,0.,1.],0.)
pose = [9.2,.2,0.,0.,0.,0.,1.]
mission.route_observation(pose,10.)
mission.last_time, mission.last_pose = 10., tuple(pose)
receipt = dict(hazards_xyz=[[10.2,.1,0.],[10.2,.2,0.],[10.2,.3,0.]])
monkeypatch.setattr(mission.blockage, 'observe', lambda *args: receipt)
original = copy.deepcopy(mission.global_route)
event = mission.observe_navigation({},np.empty((0,3)),pose,10.)
assert event['status'] == 'ready' and event['anchor_node'] == '2'
assert mission.unavailable_edges == {'2'}
segments = mission.leg['segments']
assert segments[0]['start_xy'] == pose[:2]
assert segments[0]['end_xy'] == [8.,0.] and segments[0]['edge_ids'] == ['2']
assert segments[0]['return_to_anchor'] is True
assert segments[1]['end_xy'] == [8.,5.]
assert math.dist(pose[:2], mission.arrival_target()) < 1.3
assert mission.global_route == original # Preparation remains immutable.
assert mission.index == 0 and mission.segment_index == 0
assert not mission.confirm_arrival(pose,10.,0,admitted=False)
def test_component_chain_cannot_reverse_a_one_way_edge():
from k1link.simulation.ai_polygon.route_feedback import blocked_route_piece
*_, inputs, _ = fixture()
segment = build_route(inputs)['legs'][0]['segments'][0]
inputs['routing']['map']['edges'][1]['bidirectional'] = False
broken = {**segment,'start_xy':segment['end_xy'],'end_xy':segment['start_xy'],
'edge_ids':list(reversed(segment['edge_ids']))}
with pytest.raises(ValueError,match='oriented graph chain'):
blocked_route_piece(inputs['routing'],broken,[[1.,0.,0.]],[3.,0.])