{% import "macros.html" as m %}
<div class="ribbon ribbon--info pw-ribbon">ℹ <span>CI single-flight holds when the Woodpecker pipeline runs a test
  through the warden (<span class="mono">testctl run --origin ci</span>) — it joins the <b>same lease</b>, so a CI run
  and a local run of the same test can’t collide. Triggering a pipeline needs the warden-reachable CI host plus a
  trigger token, which this read-mostly console does not hold; start one from the CLI
  (<span class="mono">testctl ci start</span>). “Watch” deep-links into Woodpecker.</span></div>

<section class="card pw-panel">
  <div class="pw-panel__head"><span class="pw-panel__title">Watch in Woodpecker</span></div>
  <div class="pw-panel__body">
  {% if data.ci_repo_url %}
    <p class="muted">This project’s CI on the Woodpecker host:</p>
    <p><a class="pw-ciurl mono" href="{{ data.ci_repo_url }}" target="_blank" rel="noopener">{{ data.ci_repo_url }}</a></p>
    <p class="muted">Per-pipeline links (<span class="mono">…/pipeline/&lt;id&gt;</span>) need a pipeline id the run-record
      doesn’t yet carry — that arrives with <span class="mono">testctl ci start</span> + a CI-run store (spec §4.6).</p>
  {% else %}
    {{ m.empty('⚙', 'CI host not linked',
       'Add a [ci] section to fed-resources/source/project.toml (host defaults to ' ~ data.woodpecker ~ ',
        repo = the Woodpecker repo id) to deep-link Watch into this project’s pipelines.') }}
  {% endif %}
  </div>
</section>

<section class="card pw-panel">
  <div class="pw-panel__head"><span class="pw-panel__title">Recent CI runs</span><span class="pw-panel__note muted">CI runs that joined the lease — run-records with origin <span class="mono">ci</span></span></div>
  {% if not data.ci_runs %}
    {{ m.empty('∅', 'No CI runs yet',
       'When a Woodpecker pipeline runs a test through the warden (--from-ci) it joins the lease and
        appears here with a Watch link.') }}
  {% else %}
  <div class="pw-panel__body">
  {% for c in data.ci_runs %}
    <div class="pw-cirow">
      {{ m.status_chip(c.outcome) }}
      <div class="pw-cirow__main"><div class="mono">{{ c.test_id }}</div><div class="muted mono">{{ c.run_id }} · {{ c.started_hhmmss }}</div></div>
      <span class="origin-badge origin-badge--ci">joined lease</span>
      {% if data.ci_repo_url %}<a class="button button-secondary button-sm" href="{{ data.ci_repo_url }}" target="_blank" rel="noopener">Watch ↗</a>{% endif %}
    </div>
  {% endfor %}
  </div>
  {% endif %}
</section>
