fix(2-A3b): complete error-render path, fix link, add supervisor tests

- Add api_key_missing computation to adapters_edit_submit error re-render
  path so the warning and disabled checkbox appear on validation errors
- Fix broken /keys -> /api-keys link in adapters_edit.html template
- Add three supervisor tests:
  - test_start_adapter_refuses_when_required_key_missing
  - test_start_adapter_succeeds_after_key_added_and_clears_last_error
  - test_start_adapter_does_not_check_when_no_requires_api_key
- Add adapters_edit_submit error re-render test:
  - test_adapters_edit_submit_error_rerender_includes_api_key_missing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Matt Johnson 2026-05-19 02:17:29 +00:00
commit 4a209d3a03
3 changed files with 259 additions and 2 deletions

View file

@ -1666,6 +1666,17 @@ async def adapters_edit_submit(
api_key_rows = await conn.fetch("SELECT alias FROM config.api_keys ORDER BY alias")
api_keys = [{"alias": r["alias"]} for r in api_key_rows]
# Check if required API key is missing
api_key_missing = False
requires_api_key_alias = None
if adapter_cls and adapter_cls.requires_api_key is not None:
requires_api_key_alias = adapter_cls.requires_api_key
has_key = await conn.fetchval(
"SELECT 1 FROM config.api_keys WHERE alias = $1",
requires_api_key_alias,
)
api_key_missing = not has_key
csrf_token = request.state.csrf_token
response = templates.TemplateResponse(
request=request,
@ -1680,6 +1691,8 @@ async def adapters_edit_submit(
"form_data": form_data,
"tile_url": tile_url,
"tile_attribution": tile_attribution,
"api_key_missing": api_key_missing,
"requires_api_key_alias": requires_api_key_alias,
},
status_code=200,
)

View file

@ -28,7 +28,7 @@
{% if api_key_missing %}
<article aria-label="API Key Required" style="background-color: var(--pico-mark-background-color); margin-bottom: 1rem;">
<strong>⚠️ API Key Required:</strong> This adapter requires the <code>{{ requires_api_key_alias }}</code> API key to be configured before it can be enabled.
<a href="/keys">Configure API Keys</a>
<a href="/api-keys">Configure API Keys</a>
</article>
{% endif %}