fix(tui): accept goal requests during active turns (#5981)
* fix(tui): accept goal requests during active turns * fix(goal): reuse live input routing and remove busy guards * test(goal): cover followup streams across iteration budgets * refactor(goal): expand slash commands into hidden agent input * fix(goal): keep generated input permission scoped to users * refactor(agent): encapsulate goal input permission scope * refactor(goal): preserve task text without prompt wrapper * test(goal): consolidate coverage and exercise restart recovery * test(goal): wait for recovery reply without task registry race
This commit is contained in:
1 parent
b46d4dfd7d
commit
99ba062a97
15 files changed
+613
-360
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from nanobot.agent.goal_permission import (
|
||||
GoalInputScope,
|
||||
goal_mutation_allowed,
|
||||
goal_mutation_permission,
|
||||
revoke_goal_mutation_permission,
|
||||
)
|
||||
from nanobot.bus.events import InboundMessage
|
||||
|
||||
|
||||
def goal_message(**overrides):
|
||||
fields = dict(
|
||||
channel="websocket", sender_id="user", chat_id="test", content="Execute the plan",
|
||||
metadata={"goal_requested": True},
|
||||
)
|
||||
fields.update(overrides)
|
||||
return InboundMessage(**fields)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("overrides", [
|
||||
{"channel": "system", "input_role": "user"},
|
||||
{"sender_id": "subagent"},
|
||||
{"input_role": "system"},
|
||||
{"metadata": {"goal_requested": True, "_internal_continuation": True}},
|
||||
{"metadata": {"goal_requested": True, "_cron_trigger": {"job_id": "job"}}},
|
||||
{"metadata": {"goal_requested": True, "_local_trigger": {"trigger_id": "trigger"}}},
|
||||
])
|
||||
def test_background_input_cannot_authorize_initial_or_injected_work(overrides):
|
||||
message = goal_message(**overrides)
|
||||
with goal_mutation_permission(True):
|
||||
with GoalInputScope(message) as scope:
|
||||
assert goal_mutation_allowed() is False
|
||||
scope.consume_inputs([message])
|
||||
assert goal_mutation_allowed() is False
|
||||
assert goal_mutation_allowed() is True
|
||||
|
||||
|
||||
def test_revoked_permission_requires_a_new_explicit_request_to_reauthorize():
|
||||
with GoalInputScope(goal_message()) as scope:
|
||||
assert goal_mutation_allowed() is True
|
||||
revoke_goal_mutation_permission()
|
||||
scope.consume_inputs([goal_message(content="ok", metadata={})])
|
||||
assert goal_mutation_allowed() is False
|
||||
scope.consume_inputs([goal_message(content="Execute another plan")])
|
||||
assert goal_mutation_allowed() is True
|
||||
assert goal_mutation_allowed() is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize("error", [RuntimeError, asyncio.CancelledError])
|
||||
def test_injected_permission_is_cleared_on_abnormal_exit(error):
|
||||
with pytest.raises(error):
|
||||
with GoalInputScope() as scope:
|
||||
assert goal_mutation_allowed() is False
|
||||
scope.consume_inputs([goal_message()])
|
||||
assert goal_mutation_allowed() is True
|
||||
raise error()
|
||||
assert goal_mutation_allowed() is False
|
||||
Reference in new issue
Block a user