fix(feishu): restore assistant creation and pairing recovery
Refs NAN-239
This commit is contained in:
1 parent
cfb0f51e78
commit
2aa98677c6
36 files changed
+369
-47
No files matched your search
@@ -57,6 +57,55 @@ class TestGenerateCode:
|
||||
assert store.approve_code(code2) is None
|
||||
|
||||
|
||||
class TestDelivery:
|
||||
def test_failed_reply_can_retry_without_replacing_code_or_approving(self):
|
||||
code = store.generate_code("feishu", "alice")
|
||||
assert "delivery_status" not in store.list_pending()[0]
|
||||
store.record_delivery(code, "sending")
|
||||
assert store.list_pending()[0]["delivery_status"] == "sending"
|
||||
store.record_delivery(code, "failed")
|
||||
assert store.list_pending()[0]["delivery_status"] == "failed"
|
||||
assert store.generate_code("feishu", "alice") == code
|
||||
store.record_delivery(code, "sent")
|
||||
store.record_delivery(code, "failed")
|
||||
assert store.list_pending()[0]["delivery_status"] == "sent"
|
||||
assert not store.is_approved("feishu", "alice")
|
||||
|
||||
@pytest.mark.parametrize("action", [store.approve_code, store.deny_code])
|
||||
def test_late_delivery_does_not_revive_removed_request(self, action):
|
||||
code = store.generate_code("feishu", "alice")
|
||||
action(code)
|
||||
store.record_delivery(code, "sent")
|
||||
assert store.list_pending() == []
|
||||
|
||||
def test_expired_reply_is_not_revived(self, monkeypatch):
|
||||
monkeypatch.setattr(store.time, "time", lambda: 1000)
|
||||
code = store.generate_code("feishu", "alice", ttl=10)
|
||||
monkeypatch.setattr(store.time, "time", lambda: 1011)
|
||||
store.record_delivery(code, "sent")
|
||||
assert store.list_pending() == []
|
||||
assert store.approve_code(code) is None
|
||||
|
||||
def test_old_records_remain_usable(self):
|
||||
code = store.generate_code("feishu", "alice")
|
||||
data = store._load()
|
||||
data["pending"][code].pop("delivery_status", None)
|
||||
store._save(data)
|
||||
assert "delivery_status" not in store.list_pending()[0]
|
||||
store.record_delivery(code, "sent")
|
||||
assert store.approve_code(code) == ("feishu", "alice")
|
||||
|
||||
def test_bookkeeping_failure_preserves_store(self, monkeypatch):
|
||||
code = store.generate_code("feishu", "alice")
|
||||
before = store._store_path().read_bytes()
|
||||
with monkeypatch.context() as m:
|
||||
def fail(_data):
|
||||
raise OSError("disk unavailable")
|
||||
m.setattr(store, "_save", fail)
|
||||
store.record_delivery(code, "sent")
|
||||
assert store._store_path().read_bytes() == before
|
||||
|
||||
|
||||
class TestFormatPairingReply:
|
||||
def test_points_owner_to_webui_with_command_fallback(self) -> None:
|
||||
reply = store.format_pairing_reply("ABCD-EFGH")
|
||||
|
||||
@@ -13,12 +13,28 @@ from nanobot.config.loader import load_config, save_config
|
||||
from nanobot.config.schema import Config
|
||||
from nanobot.webui.settings_system import (
|
||||
coerce_channel_value,
|
||||
pairing_payload,
|
||||
save_channel_config_values,
|
||||
system_settings_payload,
|
||||
update_agent_system_settings,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", [None, "sending", "sent", "failed", "unknown", []])
|
||||
def test_pairing_payload_preserves_optional_delivery_state(status):
|
||||
item = {"code": "ABCD-EFGH", "channel": "feishu", "sender_id": "alice",
|
||||
"created_at": 1000, "expires_at": 1600}
|
||||
if status is not None:
|
||||
item["delivery_status"] = status
|
||||
[request] = pairing_payload(lambda: [item], now=1100)["requests"]
|
||||
assert request["code"] == "ABCD-EFGH"
|
||||
assert request["expires_in_seconds"] == 500
|
||||
if isinstance(status, str) and status in {"sending", "sent", "failed"}:
|
||||
assert request["delivery_status"] == status
|
||||
else:
|
||||
assert "delivery_status" not in request
|
||||
|
||||
|
||||
def test_system_domain_owns_runtime_dto_and_agent_updates(tmp_path, monkeypatch) -> None:
|
||||
monkeypatch.setattr("nanobot.webui.settings_system.COMMIT", "a" * 40)
|
||||
config = Config()
|
||||
|
||||
Reference in new issue
Block a user