Publish curated Unraid-AppOps-Gateway source from 034c9f844d2455850ba37b31379b7edaa786583e
This commit is contained in:
1 parent
c61fbfd87f
commit
1a54836efc
101 files changed
+4973
-1298
No files matched your search
@@ -798,7 +798,12 @@ def test_restart_voice_endpoint_succeeds_with_valid_token(api_client, restart_se
|
||||
assert payload['status'] == 'success'
|
||||
|
||||
|
||||
def test_restart_voice_endpoint_rejects_missing_or_invalid_token(api_client, restart_service):
|
||||
def test_restart_voice_endpoint_rejects_missing_or_invalid_token(api_client, restart_service, monkeypatch):
|
||||
from fastapi import HTTPException
|
||||
from backend.app.services import user_access
|
||||
def anonymous(_request):
|
||||
raise HTTPException(401, "Sign in required")
|
||||
monkeypatch.setattr(user_access, "current_user", anonymous)
|
||||
missing = api_client.post('/api/voice/actions/container/widefrog/restart')
|
||||
assert missing.status_code == 401
|
||||
|
||||
@@ -809,7 +814,12 @@ def test_restart_voice_endpoint_rejects_missing_or_invalid_token(api_client, res
|
||||
assert wrong.status_code == 403
|
||||
|
||||
|
||||
def test_voice_unraid_health_endpoint_rejects_missing_or_invalid_token(api_client, restart_service):
|
||||
def test_voice_unraid_health_endpoint_rejects_missing_or_invalid_token(api_client, restart_service, monkeypatch):
|
||||
from fastapi import HTTPException
|
||||
from backend.app.services import user_access
|
||||
def anonymous(_request):
|
||||
raise HTTPException(401, "Sign in required")
|
||||
monkeypatch.setattr(user_access, "current_user", anonymous)
|
||||
missing = api_client.post('/api/voice/actions/unraid/health')
|
||||
assert missing.status_code == 401
|
||||
|
||||
@@ -820,7 +830,12 @@ def test_voice_unraid_health_endpoint_rejects_missing_or_invalid_token(api_clien
|
||||
assert wrong.status_code == 403
|
||||
|
||||
|
||||
def test_voice_playbook_endpoint_rejects_missing_or_invalid_token(api_client, restart_service):
|
||||
def test_voice_playbook_endpoint_rejects_missing_or_invalid_token(api_client, restart_service, monkeypatch):
|
||||
from fastapi import HTTPException
|
||||
from backend.app.services import user_access
|
||||
def anonymous(_request):
|
||||
raise HTTPException(401, "Sign in required")
|
||||
monkeypatch.setattr(user_access, "current_user", anonymous)
|
||||
missing = api_client.post('/api/voice/actions/playbooks/fix-widefrog/run')
|
||||
assert missing.status_code == 401
|
||||
|
||||
@@ -1347,7 +1362,26 @@ def test_action_execute_idempotency_replays_without_duplicate_execution(api_clie
|
||||
assert conflict.status_code == 409
|
||||
|
||||
|
||||
def test_ai_route_does_not_execute_actions(api_client):
|
||||
@pytest.fixture
|
||||
def advisory_ai_provider(monkeypatch):
|
||||
from backend.app.services import managed_ai
|
||||
|
||||
calls = []
|
||||
|
||||
def analyze(_session, question, context):
|
||||
calls.append((question, context))
|
||||
return {
|
||||
'content': 'Een herstart vereist uitvoering via het Command Center.',
|
||||
'model': 'test-advisor', 'revision': 'test-r1',
|
||||
'deploymentId': 'test-deployment', 'requestId': 'test-request',
|
||||
'artifactDigest': 'sha256:' + 'a' * 64,
|
||||
}
|
||||
|
||||
monkeypatch.setattr(managed_ai, 'analyze', analyze)
|
||||
return calls
|
||||
|
||||
|
||||
def test_ai_route_does_not_execute_actions(api_client, advisory_ai_provider):
|
||||
response = api_client.post(
|
||||
'/api/ai/chat',
|
||||
json={'content': 'Herstart authentik nu meteen'},
|
||||
@@ -1362,9 +1396,10 @@ def test_ai_route_does_not_execute_actions(api_client):
|
||||
assert 'status' not in payload
|
||||
assert 'policy_decision' not in payload
|
||||
assert 'result' not in payload
|
||||
assert len(advisory_ai_provider) == 1
|
||||
|
||||
|
||||
def test_ai_route_does_not_create_jobs_or_approvals(api_client):
|
||||
def test_ai_route_does_not_create_jobs_or_approvals(api_client, advisory_ai_provider):
|
||||
initial_jobs = api_client.get('/api/jobs').json()
|
||||
initial_approvals = api_client.get('/api/approvals').json()
|
||||
|
||||
@@ -1385,6 +1420,7 @@ def test_ai_route_does_not_create_jobs_or_approvals(api_client):
|
||||
approvals = api_client.get('/api/approvals').json()
|
||||
assert jobs == initial_jobs
|
||||
assert approvals == initial_approvals
|
||||
assert len(advisory_ai_provider) == 1
|
||||
|
||||
|
||||
def test_ai_history_does_not_return_fake_run_events(api_client):
|
||||
@@ -1395,7 +1431,7 @@ def test_ai_history_does_not_return_fake_run_events(api_client):
|
||||
assert payload == []
|
||||
|
||||
|
||||
def test_ai_chat_response_is_advisory_without_action_buttons(api_client):
|
||||
def test_ai_chat_response_is_advisory_without_action_buttons(api_client, advisory_ai_provider):
|
||||
response = api_client.post(
|
||||
'/api/ai/chat',
|
||||
json={'content': 'Herstart widefrog en voer de fix uit'},
|
||||
@@ -1408,6 +1444,22 @@ def test_ai_chat_response_is_advisory_without_action_buttons(api_client):
|
||||
assert 'actionPlan' not in metadata
|
||||
assert 'approvalId' not in payload
|
||||
assert 'jobId' not in payload
|
||||
assert len(advisory_ai_provider) == 1
|
||||
|
||||
|
||||
def test_ai_provider_unavailable_creates_no_jobs_approvals_or_history(api_client, monkeypatch):
|
||||
from backend.app.services import managed_ai
|
||||
|
||||
def unavailable(*_args):
|
||||
raise managed_ai.ManagedAiError('NOT_CONFIGURED')
|
||||
|
||||
monkeypatch.setattr(managed_ai, 'analyze', unavailable)
|
||||
before = {path: api_client.get(path).json() for path in
|
||||
('/api/jobs', '/api/approvals', '/api/ai/history')}
|
||||
response = api_client.post('/api/ai/chat', json={'content': 'Herstart authentik meteen'})
|
||||
assert response.status_code == 503
|
||||
assert response.json()['detail']['code'] == 'NOT_CONFIGURED'
|
||||
assert {path: api_client.get(path).json() for path in before} == before
|
||||
|
||||
|
||||
def test_ai_status_returns_frontend_summary_contract(api_client):
|
||||
|
||||
Reference in new issue
Block a user