去敏感提交
This commit is contained in:
@@ -9,7 +9,7 @@ from referee import FieldSpec, LocalSimulator, SimulatorClosed, Source, Spec
|
||||
|
||||
|
||||
def payload(request_id="e", **extra):
|
||||
return dict(arena_id="default", robot_id="2026001", request_id=request_id, **extra)
|
||||
return dict(arena_id="default", robot_id="TEAM-0001", request_id=request_id, **extra)
|
||||
|
||||
|
||||
def measure(request_id="m", x=0, y=0, channel=1):
|
||||
@@ -20,7 +20,7 @@ def measure(request_id="m", x=0, y=0, channel=1):
|
||||
def test_late_enter_and_deadline():
|
||||
now = [1400.25]
|
||||
sim = LocalSimulator([], clock=lambda: now[0], wall_clock=lambda: 1234.5,
|
||||
window_started_at=0)
|
||||
window_started_at=0, robot_id="TEAM-0001")
|
||||
response = sim.handle("/enter", payload())[1]
|
||||
assert response["remaining_real_duration_s"] == 99 # 窗口剩余取早
|
||||
assert response["real_timestamp_ms"] == 1234500
|
||||
@@ -35,28 +35,28 @@ def test_late_enter_and_deadline():
|
||||
|
||||
def test_program_deadline_and_subsecond_enter():
|
||||
now = [100]
|
||||
sim = LocalSimulator([], clock=lambda: now[0], window_started_at=0)
|
||||
sim = LocalSimulator([], clock=lambda: now[0], window_started_at=0, robot_id="TEAM-0001")
|
||||
assert sim.handle("/enter", payload())[1]["remaining_real_duration_s"] == 1200
|
||||
now[0] = 1300
|
||||
with pytest.raises(SimulatorClosed):
|
||||
sim.handle("/measure", measure())
|
||||
late = LocalSimulator([], clock=lambda: 1499.5, window_started_at=0)
|
||||
late = LocalSimulator([], clock=lambda: 1499.5, window_started_at=0, robot_id="TEAM-0001")
|
||||
assert late.handle("/enter", payload())[1]["remaining_real_duration_s"] == 0
|
||||
expired = LocalSimulator([], clock=lambda: 1500, window_started_at=0)
|
||||
expired = LocalSimulator([], clock=lambda: 1500, window_started_at=0, robot_id="TEAM-0001")
|
||||
with pytest.raises(SimulatorClosed):
|
||||
expired.handle("/enter", payload())
|
||||
|
||||
|
||||
def test_stress_mode_is_explicit():
|
||||
spec = Spec(field=FieldSpec(max_real_duration_s=1800))
|
||||
official = LocalSimulator([], spec=spec, clock=lambda: 0)
|
||||
stress = LocalSimulator([], spec=spec, clock=lambda: 0, stress_mode=True)
|
||||
official = LocalSimulator([], spec=spec, clock=lambda: 0, robot_id="TEAM-0001")
|
||||
stress = LocalSimulator([], spec=spec, clock=lambda: 0, stress_mode=True, robot_id="TEAM-0001")
|
||||
assert official.handle("/enter", payload())[1]["remaining_real_duration_s"] == 1200
|
||||
assert stress.handle("/enter", payload())[1]["remaining_real_duration_s"] == 1800
|
||||
|
||||
|
||||
def test_virtual_crossing_action_finishes_then_connection_closes():
|
||||
sim = LocalSimulator([])
|
||||
sim = LocalSimulator([], robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload())
|
||||
assert sim.handle("/measure", measure(x=1_800_000))[1]["virtual_time_s"] == 360005
|
||||
for path, body in [("/measure", measure("m2")), ("/exit", payload("x"))]:
|
||||
@@ -66,7 +66,7 @@ def test_virtual_crossing_action_finishes_then_connection_closes():
|
||||
|
||||
|
||||
def test_explicit_exit_closes_new_requests():
|
||||
sim = LocalSimulator([])
|
||||
sim = LocalSimulator([], robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload())
|
||||
assert sim.handle("/exit", payload("exit"))[1]["exit_reason"] == "user_exit"
|
||||
assert sim.closed_reason == "user_exit"
|
||||
@@ -76,7 +76,7 @@ def test_explicit_exit_closes_new_requests():
|
||||
|
||||
# ---------------------------------------------------------------- 量化与幂等
|
||||
def test_microseconds_accumulate_and_signed_zero_is_same_location():
|
||||
sim = LocalSimulator([Source(1, 1000, 0, 1500)])
|
||||
sim = LocalSimulator([Source(1, 1000, 0, 1500)], robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload())
|
||||
a = sim.handle("/measure", measure("a", 0.0))[1]
|
||||
b = sim.handle("/measure", measure("b", -0.0))[1]
|
||||
@@ -88,7 +88,7 @@ def test_microseconds_accumulate_and_signed_zero_is_same_location():
|
||||
|
||||
|
||||
def test_error_rejection_does_not_consume_id():
|
||||
sim = LocalSimulator([])
|
||||
sim = LocalSimulator([], robot_id="TEAM-0001")
|
||||
for bad in ["e\n", "e\u200b", "e\u0085", "e\ud800"]:
|
||||
assert sim.handle("/enter", payload(bad))[0] == 400
|
||||
assert not sim._idempotency
|
||||
@@ -96,7 +96,7 @@ def test_error_rejection_does_not_consume_id():
|
||||
|
||||
|
||||
def test_idempotent_replay_and_conflict():
|
||||
sim = LocalSimulator([])
|
||||
sim = LocalSimulator([], robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload("enter"))
|
||||
first = sim.handle("/measure", measure("m1", 100, 0))[1]
|
||||
replay = sim.handle("/measure", measure("m1", 100, 0))[1]
|
||||
@@ -108,7 +108,7 @@ def test_idempotent_replay_and_conflict():
|
||||
|
||||
|
||||
def test_idempotency_only_accepted_actions_occupy_id():
|
||||
sim = LocalSimulator([])
|
||||
sim = LocalSimulator([], robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload("enter"))
|
||||
# 未知字段:200 accepted=false,不占用 ID [题面 附件2 5.3]
|
||||
rejected = payload("m1", extra=1, position=dict(x=0, y=0), channel=1)
|
||||
@@ -118,7 +118,7 @@ def test_idempotency_only_accepted_actions_occupy_id():
|
||||
|
||||
def test_concurrent_registration_and_action_finishing_after_deadline():
|
||||
now = [0]
|
||||
sim = LocalSimulator([], clock=lambda: now[0])
|
||||
sim = LocalSimulator([], clock=lambda: now[0], robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload())
|
||||
started, release = Event(), Event()
|
||||
observe = sim._observe
|
||||
@@ -165,7 +165,7 @@ def test_concurrent_registration_and_action_finishing_after_deadline():
|
||||
|
||||
# ---------------------------------------------------------------- 校验与业务拒绝
|
||||
def test_huge_numeric_fields_return_bad_request():
|
||||
sim = LocalSimulator([])
|
||||
sim = LocalSimulator([], robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload())
|
||||
huge = 10 ** 400
|
||||
assert sim.handle("/measure", measure(x=huge))[0] == 400
|
||||
@@ -176,21 +176,21 @@ def test_huge_numeric_fields_return_bad_request():
|
||||
|
||||
|
||||
@pytest.mark.parametrize("body,expect", [
|
||||
(dict(arena_id="default", robot_id="2026001", request_id="e", extra=1), False),
|
||||
(dict(arena_id="other", robot_id="2026001", request_id="e"), False),
|
||||
(dict(arena_id="default", robot_id="TEAM-0001", request_id="e", extra=1), False),
|
||||
(dict(arena_id="other", robot_id="TEAM-0001", request_id="e"), False),
|
||||
(dict(arena_id="default", robot_id="someone-else", request_id="e"), False),
|
||||
])
|
||||
# pytest 参数化保留 expect 列(用例矩阵可读性),当前断言恒为 False,故不参与断言
|
||||
# pylint: disable-next=unused-argument
|
||||
def test_unknown_fields_and_mismatch_are_business_rejected(body, expect):
|
||||
sim = LocalSimulator([])
|
||||
sim = LocalSimulator([], robot_id="TEAM-0001")
|
||||
status, response = sim.handle("/enter", body)
|
||||
assert status == 200 and response["accepted"] is False
|
||||
assert response["virtual_time_s"] == 0
|
||||
|
||||
|
||||
def test_channel_and_position_validation():
|
||||
sim = LocalSimulator([])
|
||||
sim = LocalSimulator([], robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload())
|
||||
cases = [
|
||||
dict(position=dict(x=0, y=0), channel=0),
|
||||
@@ -210,7 +210,7 @@ def test_channel_and_position_validation():
|
||||
|
||||
|
||||
def test_actions_before_enter_are_business_rejected():
|
||||
sim = LocalSimulator([])
|
||||
sim = LocalSimulator([], robot_id="TEAM-0001")
|
||||
for path, body in [("/measure", measure()),
|
||||
("/clear", payload("c", position=dict(x=0, y=0), channel=1)),
|
||||
("/exit", payload("x"))]:
|
||||
@@ -220,7 +220,7 @@ def test_actions_before_enter_are_business_rejected():
|
||||
|
||||
def test_clear_rules():
|
||||
sim = LocalSimulator([Source(5, 10, 0, 1500), Source(6, 15, 0, 1500, directional=True,
|
||||
heading_deg=180)])
|
||||
heading_deg=180)], robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload())
|
||||
# 20m 内清除成功,且与定向朝向无关(源6 朝向 180°,机器人从西侧接近仍可清除)
|
||||
ok = sim.handle("/clear", payload("c5", position=dict(x=25, y=0), channel=5))[1]
|
||||
@@ -239,7 +239,7 @@ def test_measure_observation_matrix():
|
||||
sources = [Source(1, 1000, 0, 1500), # 全向,r_eff=1500
|
||||
Source(2, 100, 0, 1500, directional=True, heading_deg=0), # 定向朝东
|
||||
Source(3, 5000, 0, 1500)]
|
||||
sim = LocalSimulator(sources, error_half_deg=0.0)
|
||||
sim = LocalSimulator(sources, error_half_deg=0.0, robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload("enter"))
|
||||
# 超出有效接收半径
|
||||
assert sim.handle("/measure",
|
||||
@@ -264,7 +264,7 @@ def test_measure_observation_matrix():
|
||||
|
||||
|
||||
def test_svd_decimals_and_normalization():
|
||||
sim = LocalSimulator([Source(1, -10, 0, 1500)], error_half_deg=0.0)
|
||||
sim = LocalSimulator([Source(1, -10, 0, 1500)], error_half_deg=0.0, robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload())
|
||||
response = sim.handle("/measure", measure("m", 10, 0))[1]
|
||||
assert response["measure_result"] == "direction"
|
||||
@@ -272,7 +272,7 @@ def test_svd_decimals_and_normalization():
|
||||
|
||||
|
||||
def test_error_field_is_fixed_per_location():
|
||||
sim = LocalSimulator([Source(1, 1000, 0, 1500)], error_seed=7)
|
||||
sim = LocalSimulator([Source(1, 1000, 0, 1500)], error_seed=7, robot_id="TEAM-0001")
|
||||
sim.handle("/enter", payload())
|
||||
first = sim.handle("/measure", measure("m1", 500, 0))[1]["svd_deg"]
|
||||
sim.handle("/measure", measure("away", 300, 300))
|
||||
|
||||
Reference in New Issue
Block a user