Skip to content

Medium35 training campaign monitor in cockpit-admin#78

Merged
electron-rare merged 1 commit into
mainfrom
feat/medium35-campaign-page
May 19, 2026
Merged

Medium35 training campaign monitor in cockpit-admin#78
electron-rare merged 1 commit into
mainfrom
feat/medium35-campaign-page

Conversation

@electron-rare
Copy link
Copy Markdown
Contributor

Summary

New page admin.ailiance.fr/training/campaign to monitor and control the
gateway-orchestrated medium35 training campaign live.

  • FastAPI proxy (apps/api/src/.../routers/admin/campaign.py +
    services/gateway_admin.py): proxies the gateway's /admin/training/*
    endpoints behind the existing require_tailscale_user auth. Admin token
    read from env (COCKPIT_AILIANCE_ADMIN_TOKEN), never exposed to the
    browser.
  • React page (apps/cockpit-admin/src/routes/training.campaign.tsx):
    live status card (auto-refresh 30s), per-domain verdict grid, Start dialog
    with multi-select of the 28 hardware-first domains, Abort confirm, log
    tail of the current domain via the existing LogTail component.
  • Companion in ailiance/ailiance PR #113 adds the gateway log endpoint
    this page consumes.

Known follow-up

The 28-domain list is hardcoded in CampaignControls.tsx. A future small
addition could expose the list via the gateway and fetch it dynamically.

Test plan

  • 7 new API tests pass, full API suite 125 tests green
  • pnpm -F cockpit-admin build clean

Context: the gateway exposes /admin/training/{status,start,abort,log}
endpoints that drive the medium35 training campaign across 28+
hardware-first and generalist domains. Operators had no UI to drive
them — only curl with an X-Admin-Token header.

Approach: proxy the four endpoints through cockpit-api so the admin
token stays server-side, then build a dedicated /training/campaign
page in cockpit-admin with live status, controls, and log tail.

Changes:
- apps/api: services/gateway_admin.py async httpx client with
  X-Admin-Token injection, shared AsyncClient, upstream-status
  HTTPException remap.
- apps/api: routers/admin/campaign.py FastAPI router gated by
  require_tailscale_user (matches existing admin pattern).
- apps/api: 7 new tests covering status / start / abort / log paths
  including tail clamping and auth gating.
- apps/cockpit-admin: 4 TanStack Query hooks (status auto-refresh
  30s, log auto-refresh 30s skipped when no current domain, plus
  start/abort mutations).
- apps/cockpit-admin: CampaignStatusCard (progress bars overall +
  current), CampaignDomainGrid (verdict badges), CampaignControls
  (Start modal with 28-domain checkbox, Abort confirm dialog).
- apps/cockpit-admin: /training/campaign route reusing LogTail for
  the live tail of the current domain.
- deploy: COCKPIT_AILIANCE_ADMIN_TOKEN piped from host env into api
  container (never hardcoded).

Impact: operators can launch, monitor, and abort medium35 training
campaigns from admin.ailiance.fr without shell access to the
gateway, and the X-Admin-Token never reaches the browser.
Copilot AI review requested due to automatic review settings May 19, 2026 22:18
@electron-rare electron-rare merged commit ffea9d2 into main May 19, 2026
2 of 3 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new cockpit-admin page for live monitoring and control of the gateway-orchestrated “medium35” training campaign, backed by new cockpit-api proxy endpoints that inject the admin token server-side (so the browser never sees it).

Changes:

  • Added FastAPI proxy router + async gateway client for /admin/training/* campaign endpoints (status/start/abort/log), protected by existing Tailscale auth.
  • Added new cockpit-admin route /training/campaign with status, per-domain verdict table, start/abort controls, and log tail display (auto-refresh).
  • Added unit tests covering the new campaign proxy endpoints.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
deploy/docker-compose.yml Adds COCKPIT_AILIANCE_ADMIN_TOKEN env wiring for the API container.
apps/cockpit-admin/src/routeTree.gen.ts Registers the new /training/campaign route (generated).
apps/cockpit-admin/src/routes/training.index.tsx Adds a link from training runs to the new campaign page.
apps/cockpit-admin/src/routes/training.campaign.tsx New campaign monitoring page (status + verdicts + log tail).
apps/cockpit-admin/src/hooks/useStartCampaign.ts React Query mutation to start the campaign.
apps/cockpit-admin/src/hooks/useCampaignStatus.ts React Query polling for campaign status.
apps/cockpit-admin/src/hooks/useCampaignLog.ts React Query polling for plain-text log tail.
apps/cockpit-admin/src/hooks/useAbortCampaign.ts React Query mutation to abort the campaign.
apps/cockpit-admin/src/components/CampaignStatusCard.tsx UI card for campaign status + progress bars.
apps/cockpit-admin/src/components/CampaignDomainGrid.tsx Verdict table for per-domain results (and active domain).
apps/cockpit-admin/src/components/CampaignControls.tsx Start/abort controls with dialogs and domain selection.
apps/api/tests/unit/test_admin_campaign.py New unit tests for the campaign proxy router.
apps/api/src/ailiance_demo/services/gateway_admin.py New async client to call gateway admin campaign endpoints.
apps/api/src/ailiance_demo/routers/admin/campaign.py New authenticated proxy router under /api/admin/training/campaign.
apps/api/src/ailiance_demo/main.py Wires the new router into the FastAPI app.
Comments suppressed due to low confidence (1)

apps/cockpit-admin/src/components/CampaignControls.tsx:121

  • For accessibility, the role="dialog"/aria-modal should describe the dialog surface, not the full-screen overlay (which also has click-to-dismiss). Move the dialog role attributes onto the inner panel and wire aria-labelledby to the dialog title so screen readers announce it correctly (same applies to the abort dialog below).
        <div
          role="dialog"
          aria-modal="true"
          className="fixed inset-0 z-40 flex items-center justify-center bg-black/50"
          onClick={() => setStartOpen(false)}
        >
          <div
            className="max-h-[80vh] w-full max-w-2xl overflow-y-auto rounded bg-white p-6 shadow-lg"
            onClick={(e) => e.stopPropagation()}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +42 to +45
@router.get("/log/{domain}", response_class=PlainTextResponse)
async def get_domain_log(domain: str, tail: int = 100) -> str:
tail = max(1, min(tail, 1000))
return await gateway_admin.get_domain_log(domain, tail)
Comment on lines +32 to +39
# Shared async client. Reused across calls to keep connection pooling.
_client: httpx.AsyncClient | None = None


def _get_client() -> httpx.AsyncClient:
global _client
if _client is None:
_client = httpx.AsyncClient(base_url=_GATEWAY_URL.rstrip("/"))
Comment on lines +86 to +94
<button
type="button"
onClick={() => setStartOpen(true)}
disabled={startDisabled}
title={startDisabled ? 'campagne déjà active' : 'Démarrer la campagne'}
className="inline-flex items-center gap-2 rounded bg-emerald-600 px-3 py-1 text-sm text-white hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-slate-300"
>
<Play size={14} /> Start
</button>
Comment on lines +13 to +14
const url = `/api/admin/training/campaign/log/${domain}?tail=${tail}`;
const response = await fetch(url, { signal });
Comment on lines +24 to +32
function ProgressBar({ value, max }: { value: number; max: number }) {
const pct = max > 0 ? Math.min(100, Math.round((value / max) * 100)) : 0;
return (
<div className="h-2 rounded bg-slate-200 overflow-hidden" aria-label={`${pct}%`}>
<div
className="h-full bg-violet-500 transition-all"
style={{ width: `${pct}%` }}
/>
</div>

router = APIRouter(
prefix="/api/admin/training/campaign",
tags=["campaign"],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants