Add session scoped runs and cancellation

This commit is contained in:
武阳
2026-05-07 16:26:20 +08:00
parent a4a0677ce4
commit 9d7d496443
6 changed files with 542 additions and 76 deletions
+30 -1
View File
@@ -104,6 +104,14 @@ class GuiServerTests(unittest.TestCase):
_, state = _build_client(Path(d))
self.assertIs(state.run_lock_for('alice'), state.run_lock_for('alice'))
self.assertIsNot(state.run_lock_for('alice'), state.run_lock_for('bob'))
self.assertIs(
state.run_lock_for('alice', 's1'),
state.run_lock_for('alice', 's1'),
)
self.assertIsNot(
state.run_lock_for('alice', 's1'),
state.run_lock_for('alice', 's2'),
)
def test_state_update_rejects_missing_cwd(self) -> None:
with tempfile.TemporaryDirectory() as d:
@@ -166,7 +174,7 @@ class GuiServerTests(unittest.TestCase):
with tempfile.TemporaryDirectory() as d:
root = Path(d)
client, state = _build_client(root)
agent = state.agent_for('alice')
agent = state.agent_for('alice', 'pending-1')
def fake_run(
prompt: str,
@@ -209,6 +217,27 @@ class GuiServerTests(unittest.TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()['session_id'], 'pending-1')
def test_cancel_run_marks_latest_session_cancelled(self) -> None:
with tempfile.TemporaryDirectory() as d:
client, state = _build_client(Path(d))
record = state.run_manager.start('alice', 'thread-1')
self.assertFalse(record.cancel_event.is_set())
response = client.post(
'/api/runs/cancel',
json={'account_id': 'alice', 'session_id': 'thread-1'},
)
self.assertEqual(response.status_code, 200)
self.assertTrue(response.json()['cancelled'])
self.assertTrue(record.cancel_event.is_set())
latest = client.get(
'/api/runs/latest',
params={'account_id': 'alice', 'session_id': 'thread-1'},
)
self.assertEqual(latest.status_code, 200)
self.assertEqual(latest.json()['status'], 'cancelled')
def test_chat_uses_account_scoped_model_config(self) -> None:
with tempfile.TemporaryDirectory() as d:
client, _ = _build_client(Path(d))