Improve WebUI streaming and Python tooling

This commit is contained in:
武阳
2026-05-06 20:37:17 +08:00
parent a0da3c2423
commit 9ca675be0d
13 changed files with 930 additions and 147 deletions
+51
View File
@@ -74,6 +74,35 @@ class GuiServerTests(unittest.TestCase):
self.assertEqual(payload['account_id'], 'alice')
self.assertIn('/accounts/alice/sessions', payload['session_directory'])
self.assertIn('/accounts/alice/sessions', payload['upload_directory'])
self.assertIn('/accounts/alice/python/.venv', payload['python_env_directory'])
self.assertTrue((Path(payload['python_env_directory']) / 'bin' / 'python').exists())
def test_state_update_is_scoped_to_account(self) -> None:
with tempfile.TemporaryDirectory() as d:
client, _ = _build_client(Path(d))
updated = client.post(
'/api/state',
json={'account_id': 'alice', 'allow_shell': True, 'model': 'alice-model'},
)
self.assertEqual(updated.status_code, 200)
self.assertTrue(updated.json()['allow_shell'])
self.assertEqual(updated.json()['model'], 'alice-model')
alice = client.get('/api/state', params={'account_id': 'alice'}).json()
bob = client.get('/api/state', params={'account_id': 'bob'}).json()
default = client.get('/api/state').json()
self.assertEqual(alice['model'], 'alice-model')
self.assertTrue(alice['allow_shell'])
self.assertEqual(bob['model'], 'test-model')
self.assertFalse(bob['allow_shell'])
self.assertEqual(default['model'], 'test-model')
self.assertFalse(default['allow_shell'])
def test_run_locks_are_scoped_to_account(self) -> None:
with tempfile.TemporaryDirectory() as d:
_, 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'))
def test_state_update_rejects_missing_cwd(self) -> None:
with tempfile.TemporaryDirectory() as d:
@@ -132,6 +161,28 @@ class GuiServerTests(unittest.TestCase):
payload = response.json()
self.assertIsNone(payload['session_id'])
def test_chat_uses_account_scoped_model_config(self) -> None:
with tempfile.TemporaryDirectory() as d:
client, _ = _build_client(Path(d))
client.post(
'/api/state',
json={'account_id': 'alice', 'model': 'alice-model'},
)
response = client.post(
'/api/chat',
json={'prompt': '/status', 'account_id': 'alice'},
)
self.assertEqual(response.status_code, 200)
self.assertIn('- Model: alice-model', response.json()['final_output'])
bob = client.post(
'/api/chat',
json={'prompt': '/status', 'account_id': 'bob'},
)
self.assertEqual(bob.status_code, 200)
self.assertIn('- Model: test-model', bob.json()['final_output'])
def test_agent_session_store_uses_session_subdirectory(self) -> None:
with tempfile.TemporaryDirectory() as d:
root = Path(d)