"""GET /api/plugins/enabled: the flat enabled-plugin-name list that drives
frontend route gating (ADR-009).

Pins two properties: the endpoint is reachable anonymously and returns a
plain array of names, and a disabled plugin's name drops out of that array
(so its frontend routes gate off), mirroring the search-disabled pattern.
"""


def test_enabled_anonymous_returns_array(client):
    """No auth required (jwt-optional): returns a flat array of name strings."""
    resp = client.get('/api/plugins/enabled')
    assert resp.status_code == 200, resp.get_json()
    data = resp.get_json()['data']
    assert isinstance(data, list)
    assert all(isinstance(name, str) for name in data)


def test_disabled_plugin_absent(app, client, monkeypatch):
    """A disabled plugin's name is missing; enabled ones remain present."""
    pm = app.extensions['plugin_manager']
    # Pretend printers is enabled but usb is not.
    monkeypatch.setattr(pm.registry, 'get_enabled_plugins',
                        lambda: ['printers', 'computers'])
    resp = client.get('/api/plugins/enabled')
    assert resp.status_code == 200, resp.get_json()
    data = resp.get_json()['data']
    assert 'printers' in data
    assert 'usb' not in data
