{% extends "base.html" %}
{% set active_nav = "workers" %}
{% block title %}Test: {{ name }} — Loom Workshop{% endblock %}
{% block content %}
<hgroup>
    <h1>Test Bench: {{ name }}</h1>
    <p>Send a payload and see the raw LLM output with contract validation.</p>
</hgroup>

{% if available_backends %}
<div class="backend-badges" aria-label="Available LLM backends">
    <span class="backend-badges-label">Backends:</span>
    {% for b in available_backends %}
    <kbd class="backend-badge" data-backend="{{ b.name }}">{{ b.label }}</kbd>
    {% endfor %}
</div>
{% else %}
<div class="backend-badges backend-badges-empty" role="alert">
    <span class="backend-badges-label">No backends detected.</span>
    <small>Set ANTHROPIC_API_KEY, OLLAMA_URL, or OPENAI_API_KEY / OPENAI_BASE_URL.</small>
</div>
{% endif %}

{% if config.get('input_schema', {}).get('properties') %}
<details>
    <summary>Input Schema</summary>
    <pre><code>{{ config.input_schema | tojson(indent=2) }}</code></pre>
</details>
{% endif %}

<form hx-post="/workers/{{ name }}/test/run" hx-target="#test-result" hx-swap="innerHTML" hx-indicator="#spinner">
    <label for="payload">Payload (JSON)</label>
    <textarea name="payload" id="payload" rows="8" placeholder='{"text": "Hello world"}'>{}</textarea>

    <label for="tier">Tier</label>
    <select name="tier" id="tier">
        <option value="">Default ({{ config.get('default_model_tier', 'standard') }})</option>
        {% for t in available_tiers %}
        <option value="{{ t }}">{{ t }}</option>
        {% endfor %}
    </select>

    <button type="submit">Run Test</button>
    <span id="spinner" class="htmx-indicator" aria-busy="true" role="status">Running&hellip;</span>
</form>

<div id="test-result" aria-live="polite"></div>
{% endblock %}
