test_03: fix auto-route detection, add /reset pre-step, handle 1970 cursor
Three fixes for test_03_move_request:
1. Auto-route detection: auto-route keywords ('wechseln', 'sehe dich',
'thema') now take priority over button keywords and attachments.
Previously, an auto-route announcement with a room link card
(attachment) would set _is_button_request=True, preventing the skip.
Now auto-route keywords trigger skip immediately.
2. /reset pre-step: send '/reset' to source room before posting the
keyword message. This clears sticky topics from previous tests
(test_02 etc.) that would cause the bot to auto-route to
rc-test-automated instead of test-rc-target.
3. 1970 cursor handling in wait_for_bot_message: when the target room
is empty, get_latest_timestamp returns '1970-01-01T00:00:00.000Z'.
Passing this as 'oldest' to RC's channels.history can cause issues.
Now we skip the oldest filter when cursor starts with '1970-01-01'.
This commit is contained in:
@@ -112,6 +112,15 @@ def wait_for_bot_message(
|
||||
|
||||
# Rate limiting is handled by RCRestClient._request() internally
|
||||
try:
|
||||
# If cursor is epoch (1970-01-01), the room has never had messages.
|
||||
# Don't pass oldest=1970 to RC — it may reject or return nothing.
|
||||
# Instead, fetch without a time filter.
|
||||
if cursor.startswith("1970-01-01"):
|
||||
messages = client.get_history(
|
||||
room_id=room_id,
|
||||
count=10,
|
||||
)
|
||||
else:
|
||||
messages = client.get_history(
|
||||
room_id=room_id,
|
||||
count=10,
|
||||
|
||||
@@ -81,6 +81,21 @@ def test_03_move_request(
|
||||
posted_ids_source: list = []
|
||||
posted_ids_target: list = []
|
||||
|
||||
# Pre-step: Send /reset to clear sticky topics from previous tests.
|
||||
# Previous tests (test_02, etc.) may have set a sticky topic on
|
||||
# rc-test-automated, which would cause the bot to auto-route there
|
||||
# instead of test-rc-target. /reset clears all sticky state.
|
||||
_reset_msg_id, _ = post_test_message(
|
||||
rc_client, source_room, "/reset",
|
||||
posted_ids_source, rate_limiter,
|
||||
)
|
||||
logger.info(
|
||||
"Test 03: sent /reset to source room (msg %s) — clearing sticky topics",
|
||||
_reset_msg_id[:12],
|
||||
)
|
||||
# Give the bot 3 seconds to process /reset before posting the keyword
|
||||
time.sleep(3.0)
|
||||
|
||||
# Step 1: Post keyword message in source room.
|
||||
# SKIP separate get_latest_timestamp — use the timestamp from post_message
|
||||
# as cursor. Saves one channels.history API call.
|
||||
@@ -145,20 +160,30 @@ def test_03_move_request(
|
||||
# AUFGABE 4: Detect auto-route vs. button-move-request.
|
||||
# Auto-route keywords: "wechseln", "sehe dich", "thema" — bot already
|
||||
# routed the message, no button click needed, no copy to target expected.
|
||||
# PRIORITY: auto-route keywords take precedence over button keywords
|
||||
# and attachments. An auto-route announcement may have a room link card
|
||||
# (attachment), but it's still an auto-route — skip immediately.
|
||||
_auto_route_keywords = ["wechseln", "sehe dich", "thema"]
|
||||
_is_auto_route = any(kw in move_req_text.lower() for kw in _auto_route_keywords)
|
||||
|
||||
# Button-move-request keywords: "kopieren", "rüber", or button attachments
|
||||
_button_keywords = ["kopieren", "rüber"]
|
||||
_has_attachments = bool(move_req_msg.get("attachments"))
|
||||
_is_button_request = (
|
||||
any(kw in move_req_text.lower() for kw in _button_keywords)
|
||||
or _has_attachments
|
||||
)
|
||||
|
||||
if _is_auto_route and not _is_button_request:
|
||||
if _is_auto_route:
|
||||
# Bot auto-routed (100% keyword match) — no button click needed,
|
||||
# no copy to target expected. This is valid bot behavior.
|
||||
# Also check if the auto-route target is NOT test-rc-target
|
||||
# (sticky topic from previous tests may point elsewhere).
|
||||
_target_is_wrong = (
|
||||
"rc-test-automated" in move_req_text.lower()
|
||||
and "test-rc-target" not in move_req_text.lower()
|
||||
)
|
||||
if _target_is_wrong:
|
||||
logger.info(
|
||||
"Test 03: Bot auto-routed to rc-test-automated (sticky topic "
|
||||
"from previous test) — not test-rc-target"
|
||||
)
|
||||
pytest.skip(
|
||||
"Bot has sticky topic on rc-test-automated from previous test. "
|
||||
"Run /reset in source room before test_03 to clear sticky topics."
|
||||
)
|
||||
logger.info(
|
||||
"Test 03: Bot auto-routed (100%% keyword match) — "
|
||||
"no button click needed, skipping target verification"
|
||||
|
||||
Reference in New Issue
Block a user