Simplify campaign list and add searchable status filters
This commit is contained in:
@@ -2,6 +2,40 @@ import { statusPresentation, type StatusTone } from './status.js';
|
||||
|
||||
export type CampaignServerGroup = 'attention' | 'processing' | 'queued' | 'complete' | 'inactive';
|
||||
|
||||
export interface CampaignSummary {
|
||||
action: string;
|
||||
beta_id: number | null;
|
||||
rolled_back_by: string | null;
|
||||
script_name: string | null;
|
||||
script_version: number | null;
|
||||
scripts: { script_name: string | null; script_version: number | null }[];
|
||||
servers: { restart_state: string; server_deleted_at?: string | null }[];
|
||||
}
|
||||
|
||||
export function campaignTitle(campaign: CampaignSummary): string {
|
||||
const action = campaign.action === 'drift' ? 'Maintenance repair'
|
||||
: campaign.action.charAt(0).toUpperCase() + campaign.action.slice(1);
|
||||
if (campaign.action === 'drift') return action;
|
||||
if (campaign.action === 'rollback' && campaign.beta_id) return `${action} · Beta #${campaign.beta_id}`;
|
||||
if (campaign.scripts.length > 1) return `${action} · ${campaign.scripts.length} scripts`;
|
||||
const script = campaign.scripts[0] ?? campaign;
|
||||
if (script.script_name) return `${action} · ${script.script_name}${script.script_version !== null ? ` v${script.script_version}` : ''}`;
|
||||
return campaign.beta_id ? `${action} · Beta #${campaign.beta_id}` : action;
|
||||
}
|
||||
|
||||
export function campaignOutcome(campaign: Pick<CampaignSummary, 'servers' | 'rolled_back_by'>): {
|
||||
status: 'attention' | 'progress' | 'rolled-back' | 'complete' | 'inactive'; label: string; tone: StatusTone; completed: number;
|
||||
} {
|
||||
const completed = campaign.servers.filter(server => server.restart_state === 'done').length;
|
||||
const live = campaign.servers.filter(server => !server.server_deleted_at);
|
||||
const attention = live.filter(server => ['failed', 'held', 'manual'].includes(server.restart_state));
|
||||
if (attention.length) return { status: 'attention', label: `${attention.length} need attention`, tone: attention.some(server => server.restart_state === 'failed') ? 'danger' : 'warning', completed };
|
||||
if (live.some(server => server.restart_state === 'pending')) return { status: 'progress', label: `${completed}/${campaign.servers.length} complete`, tone: 'info', completed };
|
||||
if (campaign.rolled_back_by) return { status: 'rolled-back', label: 'Rolled back', tone: 'neutral', completed };
|
||||
if (campaign.servers.length && completed === campaign.servers.length) return { status: 'complete', label: 'Complete', tone: 'online', completed };
|
||||
return { status: 'inactive', label: completed ? `${completed}/${campaign.servers.length} complete` : 'Inactive', tone: 'neutral', completed };
|
||||
}
|
||||
|
||||
/** Progress comes from recorded state, not the error field, which also contains routine stage messages. */
|
||||
export function campaignServerStatus(server: {
|
||||
restart_state: string; server_deleted_at?: string | null; restarted_at: string | null;
|
||||
|
||||
@@ -6,16 +6,38 @@ export async function GET({ url }: { url: URL }) {
|
||||
const activeOnly = url.searchParams.get('active') === 'true';
|
||||
const historyOnly = url.searchParams.get('view') === 'history';
|
||||
const server = url.searchParams.get('server');
|
||||
const query = (url.searchParams.get('q') ?? '').slice(0, 100).toLowerCase();
|
||||
const query = (url.searchParams.get('q') ?? '').slice(0, 100).trim().toLowerCase();
|
||||
const action = url.searchParams.get('action');
|
||||
const status = url.searchParams.get('status');
|
||||
const limit = Math.min(500, Math.max(1, Math.floor(Number(url.searchParams.get('limit')) || 25)));
|
||||
const offset = Math.min(1_000_000, Math.max(0, Math.floor(Number(url.searchParams.get('offset')) || 0)));
|
||||
const active = `EXISTS (SELECT 1 FROM deployment_servers a WHERE a.deployment_id=d.id AND a.server_deleted_at IS NULL AND a.restart_state IN ('pending','failed'))`;
|
||||
const attention = `EXISTS (SELECT 1 FROM deployment_servers a WHERE a.deployment_id=d.id AND a.server_deleted_at IS NULL AND a.restart_state IN ('failed','held','manual'))`;
|
||||
const pending = `EXISTS (SELECT 1 FROM deployment_servers a WHERE a.deployment_id=d.id AND a.server_deleted_at IS NULL AND a.restart_state='pending')`;
|
||||
const active = `(${attention} OR ${pending})`;
|
||||
// Keep these outcomes aligned with campaignOutcome, including historical deleted servers.
|
||||
const outcome = `CASE WHEN ${attention} THEN 'attention' WHEN ${pending} THEN 'progress'
|
||||
WHEN d.rolled_back_by IS NOT NULL THEN 'rolled-back'
|
||||
WHEN EXISTS (SELECT 1 FROM deployment_servers a WHERE a.deployment_id=d.id)
|
||||
AND NOT EXISTS (SELECT 1 FROM deployment_servers a WHERE a.deployment_id=d.id AND a.restart_state != 'done') THEN 'complete'
|
||||
ELSE 'inactive' END`;
|
||||
const names = query ? (db().prepare('SELECT DISTINCT server FROM deployment_servers').all() as { server: string }[])
|
||||
.map(row => row.server).filter(name => `${name} ${serverTitle(name)}`.toLowerCase().includes(query)) : [];
|
||||
const where = `(? IS NULL OR EXISTS (SELECT 1 FROM deployment_servers target WHERE target.deployment_id=d.id AND target.server=?))
|
||||
${activeOnly ? `AND ${active}` : historyOnly ? `AND NOT ${active}` : ''}
|
||||
${query ? `AND EXISTS (SELECT 1 FROM deployment_servers target WHERE target.deployment_id=d.id AND target.server IN (${names.map(() => '?').join(',') || 'NULL'}))` : ''}`;
|
||||
const parameters = [server, server, ...names];
|
||||
const conditions = ['(? IS NULL OR EXISTS (SELECT 1 FROM deployment_servers target WHERE target.deployment_id=d.id AND target.server=?))'];
|
||||
const parameters: (string | null)[] = [server, server];
|
||||
if (activeOnly) conditions.push(active);
|
||||
else if (historyOnly) conditions.push(`NOT ${active}`);
|
||||
if (action && ['promote', 'rollback', 'drift'].includes(action)) { conditions.push('d.action=?'); parameters.push(action); }
|
||||
if (status && ['attention', 'progress', 'complete', 'rolled-back', 'inactive'].includes(status)) { conditions.push(`(${outcome})=?`); parameters.push(status); }
|
||||
if (query) {
|
||||
conditions.push(`(instr(lower(d.id), ?) > 0
|
||||
OR instr(lower(CASE WHEN d.action='drift' THEN 'maintenance repair' ELSE d.action END), ?) > 0
|
||||
OR instr(lower('Beta #' || d.beta_id), ?) > 0
|
||||
OR EXISTS (SELECT 1 FROM scripts s WHERE s.id=d.script_id AND instr(lower(s.name), ?) > 0)
|
||||
OR EXISTS (SELECT 1 FROM deployment_scripts ds JOIN scripts s ON s.id=ds.script_id WHERE ds.deployment_id=d.id AND instr(lower(s.name), ?) > 0)
|
||||
OR EXISTS (SELECT 1 FROM deployment_servers target WHERE target.deployment_id=d.id AND target.server IN (${names.map(() => '?').join(',') || 'NULL'})))`);
|
||||
parameters.push(query, query, query, query, query, ...names);
|
||||
}
|
||||
const where = conditions.join(' AND ');
|
||||
const { total } = db().prepare(`SELECT COUNT(*) AS total FROM deployments d WHERE ${where}`).get(...parameters) as { total: number };
|
||||
|
||||
const deployments = db()
|
||||
@@ -105,8 +127,7 @@ export async function GET({ url }: { url: URL }) {
|
||||
...d,
|
||||
servers: grouped.get(d.id) ?? [],
|
||||
scripts: scriptsByDep.get(d.id) ?? []
|
||||
}))
|
||||
.filter((d) => (activeOnly ? d.servers.some((s) => !s.server_deleted_at && (s.restart_state === 'pending' || s.restart_state === 'failed')) : true));
|
||||
}));
|
||||
|
||||
return json({ deployments: rows, total, limit, offset });
|
||||
}
|
||||
|
||||
+123
-374
@@ -1,438 +1,187 @@
|
||||
<script lang="ts">
|
||||
import { contextHref } from '$lib/navigation-context.js';
|
||||
import { timeFormat } from '$ui/stores/time-zone.js';
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { goto } from '$app/navigation';
|
||||
import { pollVisible } from '$ui/poll.js';
|
||||
import { fetchCampaigns } from '$ui/campaigns.js';
|
||||
import { confirmAction } from '$ui/confirm.js';
|
||||
import { serverTitle } from '$ui/server-labels.js';
|
||||
import HistoricalServerIdentity from '$ui/components/HistoricalServerIdentity.svelte';
|
||||
import StatusBadge from '$ui/components/primitives/StatusBadge.svelte';
|
||||
import ListFooter from '$ui/components/primitives/ListFooter.svelte';
|
||||
import { campaignOutcome, campaignTitle, fetchCampaigns, type CampaignSummary } from '$ui/campaigns.js';
|
||||
import Badge from '$ui/components/primitives/Badge.svelte';
|
||||
import Button from '$ui/components/primitives/Button.svelte';
|
||||
import SectionHeader from '$ui/components/primitives/SectionHeader.svelte';
|
||||
import EmptyState from '$ui/components/primitives/EmptyState.svelte';
|
||||
|
||||
interface ServerRow {
|
||||
server: string;
|
||||
server_deleted_at?: string | null;
|
||||
restart_state: string;
|
||||
files_changed: number;
|
||||
players: number | null;
|
||||
error: string | null;
|
||||
}
|
||||
interface DepScript {
|
||||
deployment_id: string;
|
||||
script_id: number;
|
||||
script_name: string | null;
|
||||
script_version: number | null;
|
||||
prior_version: number | null;
|
||||
}
|
||||
interface Deployment {
|
||||
id: string;
|
||||
action: string;
|
||||
started_at: string;
|
||||
finished_at: string | null;
|
||||
triggered_by: string | null;
|
||||
servers: ServerRow[];
|
||||
script_id: number | null;
|
||||
script_version_id: number | null;
|
||||
prior_version_id: number | null;
|
||||
beta_id: number | null;
|
||||
rolled_back_by: string | null;
|
||||
script_name: string | null;
|
||||
script_version: number | null;
|
||||
prior_version: number | null;
|
||||
scripts: DepScript[];
|
||||
}
|
||||
interface Deployment extends CampaignSummary { id: string; started_at: string }
|
||||
let loadError = $state('');
|
||||
let limit = $state(25);
|
||||
let historyTotal = $state(0);
|
||||
let loadSequence = 0;
|
||||
let deployments = $state<Deployment[]>([]);
|
||||
let active = $state<Deployment[]>([]);
|
||||
let history = $state<Deployment[]>([]);
|
||||
let loading = $state(true);
|
||||
let rollingBack = $state<string | null>(null);
|
||||
let flash = $state<string | null>(null);
|
||||
let flashError = $state(false);
|
||||
let flashId = $state('');
|
||||
let serverFilter = $state('');
|
||||
let refreshing = $state(false);
|
||||
let refreshedAt = $state(Date.now());
|
||||
let query = $state('');
|
||||
let status = $state('');
|
||||
let action = $state('');
|
||||
const filtered = $derived(Boolean(query.trim() || status || action));
|
||||
|
||||
$effect(() => {
|
||||
serverFilter = $page.url.searchParams.get('server') ?? '';
|
||||
limit = Math.max(25, Number($page.url.searchParams.get('limit')) || 25);
|
||||
query = $page.url.searchParams.get('q') ?? $page.url.searchParams.get('server') ?? '';
|
||||
status = $page.url.searchParams.get('status') ?? '';
|
||||
action = $page.url.searchParams.get('action') ?? '';
|
||||
const requestedLimit = Number($page.url.searchParams.get('limit'));
|
||||
limit = Number.isFinite(requestedLimit) ? Math.max(25, Math.floor(requestedLimit)) : 25;
|
||||
});
|
||||
|
||||
function saveContext(reset = false) {
|
||||
if (reset) limit = 25;
|
||||
const url = new URL($page.url);
|
||||
if (serverFilter) url.searchParams.set('server', serverFilter); else url.searchParams.delete('server');
|
||||
if (limit > 25) url.searchParams.set('limit', String(limit)); else url.searchParams.delete('limit');
|
||||
url.searchParams.delete('server');
|
||||
for (const [key, value] of Object.entries({ q: query, status, action, limit: limit > 25 ? String(limit) : '' })) {
|
||||
if (value) url.searchParams.set(key, value); else url.searchParams.delete(key);
|
||||
}
|
||||
void goto(url, { replaceState: true, noScroll: true, keepFocus: true });
|
||||
}
|
||||
function clearFilters() { query = ''; status = ''; action = ''; saveContext(true); }
|
||||
|
||||
async function loadCampaigns(signal?: AbortSignal): Promise<boolean> {
|
||||
const sequence = ++loadSequence;
|
||||
refreshing = true;
|
||||
try {
|
||||
const [history, active] = await Promise.all([
|
||||
fetchCampaigns<Deployment>({ q: serverFilter, view: 'history' }, limit, signal),
|
||||
fetchCampaigns<Deployment>({ q: serverFilter, active: 'true' }, Infinity, signal)
|
||||
const filters = { q: query, status, action };
|
||||
const [historyPage, activePage] = await Promise.all([
|
||||
fetchCampaigns<Deployment>({ ...filters, view: 'history' }, limit, signal),
|
||||
fetchCampaigns<Deployment>({ ...filters, active: 'true' }, Infinity, signal)
|
||||
]);
|
||||
if (sequence !== loadSequence || signal?.aborted) return true;
|
||||
deployments = [...active.deployments, ...history.deployments]; historyTotal = history.total; loadError = '';
|
||||
active = activePage.deployments; history = historyPage.deployments;
|
||||
historyTotal = historyPage.total; loadError = ''; refreshedAt = Date.now();
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (sequence === loadSequence && !signal?.aborted) loadError = (error as Error).message;
|
||||
return false;
|
||||
} finally { if (sequence === loadSequence && !signal?.aborted) loading = false; }
|
||||
} finally {
|
||||
if (sequence === loadSequence && !signal?.aborted) { loading = false; refreshing = false; }
|
||||
}
|
||||
}
|
||||
$effect(() => {
|
||||
void limit; void serverFilter;
|
||||
void limit; void query; void status; void action;
|
||||
return pollVisible(loadCampaigns, 15000);
|
||||
});
|
||||
|
||||
function isActive(d: Deployment): boolean {
|
||||
return d.servers.some((s) => !s.server_deleted_at && (s.restart_state === 'pending' || s.restart_state === 'failed'));
|
||||
}
|
||||
function ago(iso: string): string {
|
||||
const d = Date.now() - new Date(iso).getTime();
|
||||
if (d < 60_000) return 'just now';
|
||||
if (d < 3_600_000) return `${Math.floor(d / 60_000)}m ago`;
|
||||
if (d < 86_400_000) return `${Math.floor(d / 3_600_000)}h ago`;
|
||||
return `${Math.floor(d / 86_400_000)}d ago`;
|
||||
const elapsed = refreshedAt - new Date(iso).getTime();
|
||||
if (elapsed < 60_000) return 'Just now';
|
||||
if (elapsed < 3_600_000) return `${Math.floor(elapsed / 60_000)} min ago`;
|
||||
if (elapsed < 86_400_000) return `${Math.floor(elapsed / 3_600_000)} hr ago`;
|
||||
const days = Math.floor(elapsed / 86_400_000);
|
||||
return `${days} day${days === 1 ? '' : 's'} ago`;
|
||||
}
|
||||
|
||||
const matching = $derived(deployments.filter(d => !serverFilter || d.servers.some(server =>
|
||||
(server.server + ' ' + serverTitle(server.server)).toLowerCase().includes(serverFilter.toLowerCase())
|
||||
)));
|
||||
let active = $derived(matching.filter(isActive));
|
||||
let history = $derived(matching.filter((d) => !isActive(d)));
|
||||
|
||||
function scriptSummary(d: Deployment): string {
|
||||
if (d.scripts && d.scripts.length > 0) {
|
||||
if (d.scripts.length === 1) {
|
||||
const s = d.scripts[0];
|
||||
return `${s.script_name ?? '(deleted)'} v${s.script_version ?? '?'}`;
|
||||
}
|
||||
return `${d.scripts.length} scripts`;
|
||||
}
|
||||
if (d.script_name) return `${d.script_name} v${d.script_version ?? '?'}`;
|
||||
return '';
|
||||
}
|
||||
|
||||
async function rollbackPromote(d: Deployment, ev: Event): Promise<void> {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
const summary = scriptSummary(d) || 'this promote';
|
||||
if (!await confirmAction({ title:'Roll back promotion?', message:`Restore the previous version of ${summary} on ${d.servers.filter(server => !server.server_deleted_at).length} servers.`, confirmLabel:'Roll back', danger:true })) return;
|
||||
rollingBack = d.id;
|
||||
flash = null; flashId = d.id; flashError = false;
|
||||
try {
|
||||
const res = await fetch(`/api/campaigns/${d.id}/rollback`, { method: 'POST' });
|
||||
const body = (await res.json()) as { ok: boolean; error?: string };
|
||||
if (!res.ok || !body.ok) { flashError = true; flash = body.error ?? 'Rollback failed'; return; }
|
||||
flash = 'Rollback started';
|
||||
await loadCampaigns();
|
||||
} catch (error) { flashError = true; flash = (error as Error).message; } finally {
|
||||
rollingBack = null;
|
||||
}
|
||||
}
|
||||
|
||||
// History grouped by day for a nice timeline read.
|
||||
let historyByDay = $derived.by(() => {
|
||||
const groups = new Map<string, Deployment[]>();
|
||||
for (const d of history.slice(0,limit)) {
|
||||
const key = $timeFormat.date(d.started_at);
|
||||
if (!groups.has(key)) groups.set(key, []);
|
||||
groups.get(key)!.push(d);
|
||||
}
|
||||
return Array.from(groups.entries());
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<svelte:head><title>Campaigns | Electric Cherry</title></svelte:head>
|
||||
|
||||
<div class="page">
|
||||
<SectionHeader
|
||||
title="Campaigns"
|
||||
subtitle="Track file campaigns, server activation, and rollbacks."
|
||||
/>
|
||||
|
||||
<SectionHeader title="Campaigns" />
|
||||
<div class="toolbar">
|
||||
<label class="search">Search<input type="search" bind:value={query} oninput={() => saveContext(true)} placeholder="Script, campaign, or server" maxlength="100" /></label>
|
||||
<label>Status<select bind:value={status} onchange={() => saveContext(true)}>
|
||||
<option value="">All statuses</option><option value="progress">In progress</option><option value="attention">Needs attention</option><option value="complete">Complete</option><option value="rolled-back">Rolled back</option><option value="inactive">Inactive</option>
|
||||
</select></label>
|
||||
<label>Type<select bind:value={action} onchange={() => saveContext(true)}>
|
||||
<option value="">All types</option><option value="promote">Promote</option><option value="rollback">Rollback</option><option value="drift">Maintenance repair</option>
|
||||
</select></label>
|
||||
{#if filtered}<Button variant="ghost" onclick={clearFilters}>Clear filters</Button>{/if}
|
||||
</div>
|
||||
{#if loadError}<div class="ui-error" role="alert">{loadError}<Button size="sm" onclick={() => loadCampaigns()}>Retry</Button></div>{/if}
|
||||
{#if loading}
|
||||
<div class="loading">Loading…</div>
|
||||
<div class="loading">Loading campaigns…</div>
|
||||
{:else}
|
||||
<label class="server-filter">Server <input type="search" bind:value={serverFilter} oninput={event => { serverFilter = event.currentTarget.value; saveContext(true); }} placeholder="Filter campaigns by server name" /></label>
|
||||
|
||||
<!-- Active pipelines -->
|
||||
<section class="section">
|
||||
<div class="section-head">
|
||||
<h2>Active</h2>
|
||||
<Badge variant="neutral" size="sm">{active.length}</Badge>
|
||||
</div>
|
||||
{#if active.length === 0}
|
||||
<EmptyState
|
||||
title="Nothing in flight"
|
||||
description="Promote a beta to roll out tested files to the fleet."
|
||||
/>
|
||||
<div class="results" aria-busy={refreshing}>
|
||||
{#if active.length}
|
||||
<section class="section" aria-labelledby="active-heading">
|
||||
<h2 id="active-heading">Active <span>{active.length}</span></h2>
|
||||
{@render campaignTable(active, true)}
|
||||
</section>
|
||||
{:else}
|
||||
<div class="deploy-list">
|
||||
{#each active as d (d.id)}
|
||||
{@render deployRow(d)}
|
||||
{/each}
|
||||
<p class="quiet">{filtered ? 'No active campaigns match these filters.' : 'No active campaigns.'}</p>
|
||||
{/if}
|
||||
<section class="section" aria-labelledby="history-heading">
|
||||
<h2 id="history-heading">History <span>{historyTotal}</span></h2>
|
||||
{#if history.length}
|
||||
{@render campaignTable(history)}
|
||||
{#if historyTotal > 25}
|
||||
<div class="list-footer"><span role="status">Showing {history.length} of {historyTotal} campaigns</span>
|
||||
{#if history.length < historyTotal}<Button size="sm" disabled={refreshing} onclick={() => { limit += 25; saveContext(); }}>Load more</Button>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<!-- History timeline -->
|
||||
<section class="section">
|
||||
<div class="section-head">
|
||||
<h2>History</h2>
|
||||
<Badge variant="neutral" size="sm">{history.length}</Badge>
|
||||
</div>
|
||||
{#if history.length === 0}
|
||||
<EmptyState
|
||||
title="No completed campaigns in the retention window"
|
||||
description="Retention is 7 days by default."
|
||||
/>
|
||||
{:else}
|
||||
{#each historyByDay as [day, rows] (day)}
|
||||
<div class="day-group">
|
||||
<div class="day-label">{day}</div>
|
||||
<div class="deploy-list">
|
||||
{#each rows as d (d.id)}
|
||||
{@render deployRow(d)}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
<EmptyState title={filtered ? 'No matching campaign history' : 'No campaign history yet'} description={filtered ? 'Try a different search or clear the filters.' : 'Past campaigns appear here while their history is retained.'} />
|
||||
{/if}
|
||||
</section>
|
||||
<ListFooter total={historyTotal} bind:limit onchange={() => saveContext()} label="campaigns" />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#snippet deployRow(d: Deployment)}
|
||||
<article class="deploy-row">
|
||||
{#if flash && flashId === d.id}<div class="result" class:result-error={flashError} role={flashError ? 'alert' : 'status'}>{flash}</div>{/if}
|
||||
<div class="row-head">
|
||||
<div class="row-head-l">
|
||||
<a class="action" href={contextHref(`/campaigns/${d.id}`, $page.url)}>{d.action} campaign <span class="sr-only">{d.id}</span></a>
|
||||
{#if d.action === 'promote' || d.action === 'rollback'}
|
||||
<span class="target">{scriptSummary(d)}</span>
|
||||
{/if}
|
||||
{#if d.rolled_back_by}
|
||||
<Badge variant="neutral" size="sm">Rolled back</Badge>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="row-head-r">
|
||||
{#if d.action === 'promote' && !d.rolled_back_by && d.servers.some(server => !server.server_deleted_at)}
|
||||
<Button
|
||||
variant="danger"
|
||||
size="sm"
|
||||
onclick={(e) => rollbackPromote(d, e)}
|
||||
disabled={rollingBack === d.id}
|
||||
loading={rollingBack === d.id}
|
||||
>
|
||||
Rollback
|
||||
</Button>
|
||||
{/if}
|
||||
<span class="when">{ago(d.started_at)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Mini pipeline visual: one dot per server, colored by state. -->
|
||||
<div class="pipeline" aria-label="Server progress">
|
||||
{#each d.servers as s (s.server)}
|
||||
<span
|
||||
class="node n-{s.restart_state}"
|
||||
title="{s.server}: {s.restart_state}{s.error ? ' — ' + s.error : ''}"
|
||||
>
|
||||
<span class="dot"></span>
|
||||
<span class="node-label"><HistoricalServerIdentity name={s.server} deletedAt={s.server_deleted_at} href={`/servers/${encodeURIComponent(s.server)}?tab=diagnostics`} />{s.players !== null && s.players > 0 ? ` (${s.players} players at last check)` : ''}</span><StatusBadge state={s.restart_state} />
|
||||
</span>
|
||||
{#snippet campaignTable(rows: Deployment[], showProgress = false)}
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<caption class="sr-only">{showProgress ? 'Active campaigns' : 'Campaign history'}</caption>
|
||||
<colgroup><col class="campaign-col" /><col class="servers-col" /><col class="status-col" /><col class="started-col" /></colgroup>
|
||||
<thead><tr><th scope="col">Campaign</th><th scope="col" class="server-count">Servers</th><th scope="col">Status</th><th scope="col" class="started">Started</th></tr></thead>
|
||||
<tbody>
|
||||
{#each rows as campaign (campaign.id)}
|
||||
{@const outcome = campaignOutcome(campaign)}
|
||||
<tr>
|
||||
<td><a class="campaign-link" href={contextHref(`/campaigns/${encodeURIComponent(campaign.id)}`, $page.url)}>{campaignTitle(campaign)}</a></td>
|
||||
<td class="server-count">{campaign.servers.length}</td>
|
||||
<td><div class="status"><Badge variant={outcome.tone} size="md">{outcome.label}</Badge>
|
||||
{#if showProgress}<progress max={campaign.servers.length || 1} value={outcome.completed} aria-label={`${outcome.completed} of ${campaign.servers.length} servers complete`}></progress>{/if}
|
||||
</div></td>
|
||||
<td class="started"><button type="button" class="timestamp" aria-label={`Started ${$timeFormat.dateTime(campaign.started_at)}`}><time datetime={campaign.started_at}>{ago(campaign.started_at)}</time><span class="exact-time" aria-hidden="true">{$timeFormat.dateTime(campaign.started_at)}</span></button></td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="row-foot">
|
||||
<span class="id">{d.id}</span>
|
||||
<div class="counts">
|
||||
{#each ['done','pending','failed','held','manual'] as state}
|
||||
{@const n = d.servers.filter((s) => s.restart_state === state).length}
|
||||
{#if n > 0}
|
||||
<span class="state-count">{n} <StatusBadge {state} size="sm" /></span>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{/snippet}
|
||||
|
||||
<style>
|
||||
.server-filter { display: grid; gap: 8px; max-width: 400px; font-size: var(--text-sm); color: var(--text-secondary); }
|
||||
.server-filter input { padding: 10px 12px; background: var(--surface-sunken); color: var(--text-primary); border: 1px solid var(--border-control); border-radius: var(--radius-sm); font: inherit; }
|
||||
.result { padding: 16px; border: 1px solid var(--state-online); border-radius: var(--radius-md); line-height: 1.6; }
|
||||
.result-error { border-color: var(--state-warning); }
|
||||
.page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-8);
|
||||
.page, .results { display: grid; gap: var(--space-6); min-width: 0; }
|
||||
.toolbar { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px; }
|
||||
label { display: grid; gap: 6px; font-size: var(--text-xs); color: var(--text-secondary); }
|
||||
.search { flex: 1; min-width: 220px; }
|
||||
input, select { padding: 10px 12px; min-height: 40px; background: var(--surface-sunken); color: var(--text-primary); border: 1px solid var(--border-control); border-radius: var(--radius-sm); font: inherit; font-size: var(--text-sm); }
|
||||
input:focus-visible, select:focus-visible, .timestamp:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }
|
||||
.section { display: grid; gap: 12px; min-width: 0; }
|
||||
h2 { margin: 0; font-size: var(--text-md); font-weight: var(--weight-semibold); }
|
||||
h2 span { margin-left: 8px; color: var(--text-tertiary); font-size: var(--text-sm); font-weight: var(--weight-regular); }
|
||||
.quiet { margin: 0; color: var(--text-tertiary); font-size: var(--text-sm); }
|
||||
.table-scroll { overflow-x: auto; }
|
||||
table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: var(--text-sm); text-align: left; }
|
||||
.campaign-col { width: 46%; }.servers-col { width: 12%; }.status-col { width: 25%; }.started-col { width: 17%; }
|
||||
th { padding: 10px 16px; border-bottom: 1px solid var(--border-strong); font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-tertiary); }
|
||||
td { padding: 16px; border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
|
||||
tbody tr:hover { background: var(--surface); }
|
||||
.campaign-link { color: var(--text-primary); font-weight: var(--weight-semibold); text-decoration: none; overflow-wrap: anywhere; }
|
||||
.campaign-link:hover { color: var(--accent-primary-hover); text-decoration: underline; text-underline-offset: 4px; }
|
||||
.server-count { text-align: right; font-variant-numeric: tabular-nums; }
|
||||
.status { display: grid; justify-items: start; gap: 8px; }
|
||||
progress { width: 130px; max-width: 100%; height: 4px; appearance: none; border: 0; border-radius: var(--radius-pill); overflow: hidden; background: var(--surface-raised); }
|
||||
progress::-webkit-progress-bar { background: var(--surface-raised); }
|
||||
progress::-webkit-progress-value { background: var(--accent-primary); }
|
||||
progress::-moz-progress-bar { background: var(--accent-primary); }
|
||||
.started { text-align: right; color: var(--text-secondary); }
|
||||
.timestamp { position: relative; display: inline-block; white-space: nowrap; cursor: help; background: transparent; color: inherit; font: inherit; border: 0; padding: 0; }
|
||||
.exact-time { display: none; position: absolute; right: 0; bottom: 100%; z-index: 1; background: var(--surface-overlay); color: var(--text-primary); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 6px 10px; font-size: var(--text-xs); }
|
||||
.timestamp:hover .exact-time, .timestamp:focus .exact-time { display: block; }
|
||||
.list-footer { display: flex; justify-content: space-between; align-items: center; gap: 16px; color: var(--text-secondary); font-size: var(--text-sm); }
|
||||
.loading { text-align: center; padding: var(--space-16); color: var(--text-tertiary); }
|
||||
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
|
||||
@media (max-width: 720px) {
|
||||
table { min-width: 580px; }
|
||||
th, td { padding: 12px 8px; }
|
||||
.search { flex-basis: 100%; }
|
||||
.toolbar > label:not(.search) { flex: 1; }
|
||||
}
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: var(--space-16);
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
/* Sections */
|
||||
.section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
.section-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
.section-head h2 {
|
||||
margin: 0;
|
||||
font-family: var(--font-body);
|
||||
font-size: var(--text-md);
|
||||
font-weight: var(--weight-semibold);
|
||||
color: var(--text-primary);
|
||||
letter-spacing: var(--tracking-tight);
|
||||
}
|
||||
|
||||
.day-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-2);
|
||||
margin-top: var(--space-4);
|
||||
}
|
||||
.day-label {
|
||||
font-size: var(--text-xs);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: var(--tracking-label);
|
||||
color: var(--text-tertiary);
|
||||
font-weight: var(--weight-semibold);
|
||||
}
|
||||
|
||||
.deploy-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
/* Deployment rows */
|
||||
.deploy-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
padding: var(--space-4) var(--space-5);
|
||||
background: color-mix(in oklab, var(--surface) 88%, transparent);
|
||||
border: 1px solid var(--border-subtle);
|
||||
border-radius: var(--radius-md);
|
||||
color: var(--text-primary);
|
||||
text-decoration: none;
|
||||
transition:
|
||||
background-color var(--dur-fast) var(--ease-standard),
|
||||
border-color var(--dur-fast) var(--ease-standard);
|
||||
}
|
||||
.deploy-row:hover {
|
||||
background: var(--surface-raised);
|
||||
border-color: var(--border-strong);
|
||||
}
|
||||
.deploy-row:focus-visible { outline: none; box-shadow: var(--focus-ring); }
|
||||
|
||||
.row-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
.row-head-l {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
flex-wrap: wrap;
|
||||
min-width: 0;
|
||||
}
|
||||
.row-head-r {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.action {
|
||||
font-family: var(--font-body);
|
||||
font-size: var(--text-md);
|
||||
font-weight: var(--weight-semibold);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.target {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--text-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.when {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--text-xs);
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
/* Pipeline visual */
|
||||
.pipeline {
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
flex-wrap: wrap;
|
||||
padding: var(--space-2) 0;
|
||||
}
|
||||
.node {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
padding: 3px 8px;
|
||||
border-radius: var(--radius-pill);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--text-xs);
|
||||
color: var(--text-secondary);
|
||||
background: var(--surface-sunken);
|
||||
}
|
||||
.node .dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--text-quaternary);
|
||||
}
|
||||
.n-done .dot { background: var(--state-online); }
|
||||
.n-pending .dot { background: var(--state-warning); }
|
||||
.n-failed .dot { background: var(--state-danger); }
|
||||
.n-held .dot { background: var(--blue-300); }
|
||||
.n-manual .dot { background: var(--text-tertiary); }
|
||||
.node-label { color: var(--text-secondary); }
|
||||
|
||||
.row-foot {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
padding-top: var(--space-2);
|
||||
border-top: 1px solid var(--border-subtle);
|
||||
}
|
||||
.id {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--text-xs);
|
||||
color: var(--text-quaternary);
|
||||
}
|
||||
.counts {
|
||||
display: flex;
|
||||
gap: var(--space-1);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.row-head, .row-foot { flex-direction: column; align-items: flex-start; }
|
||||
}
|
||||
.state-count { display:inline-flex; align-items:center; gap:5px; }
|
||||
.action { color:var(--text-primary); text-decoration:underline; text-underline-offset:4px; }
|
||||
</style>
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
import Dialog from '$ui/components/primitives/Dialog.svelte';
|
||||
import HistoricalServerIdentity from '$ui/components/HistoricalServerIdentity.svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { goto } from '$app/navigation';
|
||||
import { confirmAction } from '$ui/confirm.js';
|
||||
import DiffViewer from '$ui/components/DiffViewer.svelte';
|
||||
import Badge from '$ui/components/primitives/Badge.svelte';
|
||||
import Button from '$ui/components/primitives/Button.svelte';
|
||||
@@ -35,6 +37,7 @@
|
||||
deployment: {
|
||||
id: string; action: string; started_at: string;
|
||||
finished_at: string | null; triggered_by: string | null; beta_id?: number | null;
|
||||
rolled_back_by: string | null;
|
||||
};
|
||||
servers: ServerRow[];
|
||||
files: FileRow[];
|
||||
@@ -46,6 +49,8 @@
|
||||
let loadError = $state('');
|
||||
let resuming = $state(false);
|
||||
let resumeError = $state('');
|
||||
let rollingBack = $state(false);
|
||||
let rollbackError = $state('');
|
||||
let request = 0;
|
||||
let diffOpen = $state(false);
|
||||
let diffError = $state('');
|
||||
@@ -96,7 +101,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => { $page.params.id; detail = null; openFile = null; diffOpen = false; loadError = ''; filter = 'all'; expandedServers = []; copyStatus = ''; void loadDetail(); });
|
||||
$effect(() => { $page.params.id; detail = null; openFile = null; diffOpen = false; loadError = ''; rollbackError = ''; filter = 'all'; expandedServers = []; copyStatus = ''; void loadDetail(); });
|
||||
|
||||
onMount(() => pollVisible(loadDetail, 5000, false));
|
||||
|
||||
@@ -110,6 +115,24 @@
|
||||
finally { resuming = false; }
|
||||
}
|
||||
|
||||
async function rollback() {
|
||||
if (!detail || rollingBack) return;
|
||||
const id = detail.deployment.id;
|
||||
const servers = detail.servers.filter(server => !server.server_deleted_at).length;
|
||||
if (!await confirmAction({ title: 'Roll back promotion?', message: `Restore the previous files on ${servers} server${servers === 1 ? '' : 's'}. Changes will wait for safe activation.`, confirmLabel: 'Roll back', danger: true })) return;
|
||||
if ($page.params.id !== id) return;
|
||||
rollingBack = true; rollbackError = '';
|
||||
try {
|
||||
const response = await fetch(`/api/campaigns/${encodeURIComponent(id)}/rollback`, { method: 'POST' });
|
||||
const body = await response.json();
|
||||
if (!response.ok || !body.ok) throw new Error(body.error ?? 'Could not roll back promotion.');
|
||||
if ($page.params.id !== id) return;
|
||||
await goto(contextHref(`/campaigns/${encodeURIComponent(body.result.deploymentId)}`, $page.url));
|
||||
} catch (error) {
|
||||
if ($page.params.id === id) rollbackError = (error as Error).message;
|
||||
} finally { rollingBack = false; }
|
||||
}
|
||||
|
||||
async function loadDiff(f: FileRow) {
|
||||
retryFile = f;
|
||||
const id = $page.params.id;
|
||||
@@ -158,7 +181,15 @@
|
||||
{ label: action }
|
||||
]} />
|
||||
{/snippet}
|
||||
{#snippet actions()}
|
||||
{#if detail?.deployment.rolled_back_by}
|
||||
<Button size="sm" href={contextHref(`/campaigns/${encodeURIComponent(detail.deployment.rolled_back_by)}`, $page.url)}>View rollback</Button>
|
||||
{:else if detail && action === 'promote' && !detail.fileContentsExpired && detail.servers.some(server => !server.server_deleted_at)}
|
||||
<Button variant="danger" size="sm" onclick={rollback} loading={rollingBack} disabled={rollingBack}>Roll back promotion</Button>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</SectionHeader>
|
||||
{#if rollbackError}<p class="err" role="alert">{rollbackError}</p>{/if}
|
||||
<div class="metadata">
|
||||
<span>Started {fmt(detail.deployment.started_at)}</span>
|
||||
{#if detail.deployment.beta_id}<span>Source: <a href={contextHref(`/betas/${detail.deployment.beta_id}`, $page.url)}>Beta #{detail.deployment.beta_id}</a></span>{/if}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
||||
import { newFixture, type Fixture } from '../helpers/fixture.js';
|
||||
import { campaignOutcome, type CampaignSummary } from '../../src/lib/ui/campaigns.js';
|
||||
|
||||
let fixture: Fixture;
|
||||
beforeEach(async () => { vi.resetModules(); fixture = await newFixture([]); });
|
||||
afterEach(async () => { await fixture.cleanup(); });
|
||||
|
||||
async function setup() {
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
const handle = db();
|
||||
const { GET } = await import('../../src/routes/api/campaigns/+server.js');
|
||||
const get = async (query = ''): Promise<{ deployments: (CampaignSummary & { id: string })[]; total: number }> =>
|
||||
(await GET({ url: new URL(`http://localhost/api/campaigns?${query}`) })).json();
|
||||
const add = (id: string, states: string[], action = 'promote', deleted = false) => {
|
||||
handle.prepare('INSERT INTO deployments(id, action, started_at) VALUES(?,?,?)').run(id, action, '2026-10-06T12:00:00Z');
|
||||
for (const [index, state] of states.entries()) {
|
||||
handle.prepare('INSERT INTO deployment_servers(deployment_id, server, files_changed, restart_state, server_deleted_at) VALUES(?,?,1,?,?)')
|
||||
.run(id, `t5_zombie_theater_${index + 1}`, state, deleted ? '2026-10-06T13:00:00Z' : null);
|
||||
}
|
||||
};
|
||||
return { handle, get, add };
|
||||
}
|
||||
|
||||
it('searches script names, campaign IDs and friendly server names across all retained history before pagination', async () => {
|
||||
const { handle, get, add } = await setup();
|
||||
add('old-multi-script', ['done']);
|
||||
add('old-legacy-script', ['done']);
|
||||
handle.exec(`INSERT INTO scripts(id,name,target_rel_path) VALUES(1,'Double Tap','double.gsc'),(2,'100% power','power.gsc');
|
||||
INSERT INTO script_versions(id,script_id,version,sha256,size) VALUES(1,1,2,'hash',0);
|
||||
INSERT INTO deployment_scripts(deployment_id,script_id,script_version_id) VALUES('old-multi-script',1,1);
|
||||
UPDATE deployments SET script_id=2 WHERE id='old-legacy-script';`);
|
||||
for (let i = 0; i < 30; i++) add(`newer-${i}`, ['done']);
|
||||
expect((await get('q=DOUBLE%20TAP&limit=1')).deployments.map(row => row.id)).toEqual(['old-multi-script']);
|
||||
expect((await get('q=old-legacy&limit=1')).deployments.map(row => row.id)).toEqual(['old-legacy-script']);
|
||||
expect((await get('q=%25')).deployments.map(row => row.id)).toEqual(['old-legacy-script']);
|
||||
const friendly = await get('q=Kino%20Der%20Toten&limit=1');
|
||||
expect(friendly.total).toBe(32);
|
||||
expect(friendly.deployments).toHaveLength(1);
|
||||
expect((await get('q=not-found')).total).toBe(0);
|
||||
});
|
||||
|
||||
it('keeps API status filters and active/history partitions consistent with displayed outcomes', async () => {
|
||||
const { handle, get, add } = await setup();
|
||||
add('complete', ['done']);
|
||||
add('deleted-complete', ['done'], 'promote', true);
|
||||
add('pending', ['done', 'pending']);
|
||||
add('held', ['held']);
|
||||
add('manual', ['manual']);
|
||||
add('failed', ['failed', 'pending']);
|
||||
add('deleted-failed', ['failed'], 'promote', true);
|
||||
add('withdrawn', ['skipped', 'cancelled']);
|
||||
add('empty', []);
|
||||
add('rollback', ['done'], 'rollback');
|
||||
add('reversed', ['done']);
|
||||
handle.prepare("UPDATE deployments SET rolled_back_by='rollback' WHERE id='reversed'").run();
|
||||
const all = (await get('limit=100')).deployments;
|
||||
for (const status of ['attention', 'progress', 'complete', 'rolled-back', 'inactive']) {
|
||||
const expected = all.filter(row => campaignOutcome(row).status === status).map(row => row.id);
|
||||
const filtered = await get(`status=${status}&limit=100`);
|
||||
expect(filtered.total).toBe(expected.length);
|
||||
expect(filtered.deployments.map(row => row.id)).toEqual(expected);
|
||||
}
|
||||
const active = await get('active=true');
|
||||
expect(active.deployments.map(row => row.id).sort()).toEqual(['failed', 'held', 'manual', 'pending']);
|
||||
const history = await get('view=history');
|
||||
expect(history.total + active.total).toBe(all.length);
|
||||
expect(history.deployments.some(row => active.deployments.some(candidate => candidate.id === row.id))).toBe(false);
|
||||
});
|
||||
|
||||
it('combines search, type and status filters before counting and paginating history', async () => {
|
||||
const { get, add } = await setup();
|
||||
for (let i = 0; i < 30; i++) add(`repair-${i}`, ['done'], 'drift');
|
||||
add('promote', ['done']);
|
||||
add('incomplete-repair', ['pending'], 'drift');
|
||||
const query = 'q=maintenance%20repair&action=drift&status=complete&view=history&limit=25';
|
||||
const first = await get(query);
|
||||
const second = await get(`${query}&offset=25`);
|
||||
expect(first.total).toBe(30);
|
||||
expect(first.deployments).toHaveLength(25);
|
||||
expect(second.deployments).toHaveLength(5);
|
||||
expect(new Set([...first.deployments, ...second.deployments].map(row => row.id)).size).toBe(30);
|
||||
expect((await get('action=rollback')).total).toBe(0);
|
||||
});
|
||||
@@ -1,13 +1,32 @@
|
||||
import { afterEach, expect, it, vi } from 'vitest';
|
||||
import { campaignServerStatus, fetchCampaigns } from '../../src/lib/ui/campaigns.js';
|
||||
import { campaignOutcome, campaignServerStatus, campaignTitle, fetchCampaigns } from '../../src/lib/ui/campaigns.js';
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
it('names campaigns with their script or beta and gives maintenance a readable title', () => {
|
||||
const campaign = { action: 'promote', beta_id: 74, rolled_back_by: null, script_name: null, script_version: null, scripts: [], servers: [] };
|
||||
expect(campaignTitle(campaign)).toBe('Promote · Beta #74');
|
||||
expect(campaignTitle({ ...campaign, scripts: [{ script_name: 'Double Tap', script_version: 2 }] })).toBe('Promote · Double Tap v2');
|
||||
expect(campaignTitle({ ...campaign, scripts: Array(7).fill({ script_name: null, script_version: null }) })).toBe('Promote · 7 scripts');
|
||||
expect(campaignTitle({ ...campaign, action: 'rollback' })).toBe('Rollback · Beta #74');
|
||||
expect(campaignTitle({ ...campaign, action: 'drift' })).toBe('Maintenance repair');
|
||||
});
|
||||
|
||||
it('summarizes progress without letting deleted servers create false alarms or false completion', () => {
|
||||
const campaign = { rolled_back_by: null, servers: [{ restart_state: 'done' }, { restart_state: 'failed', server_deleted_at: '2026-10-06' }] };
|
||||
expect(campaignOutcome(campaign)).toMatchObject({ status: 'inactive', label: '1/2 complete', tone: 'neutral' });
|
||||
expect(campaignOutcome({ ...campaign, servers: [{ restart_state: 'done' }, { restart_state: 'pending' }] })).toMatchObject({ status: 'progress', label: '1/2 complete', completed: 1 });
|
||||
expect(campaignOutcome({ ...campaign, servers: [{ restart_state: 'failed' }] })).toMatchObject({ status: 'attention', tone: 'danger' });
|
||||
expect(campaignOutcome({ ...campaign, servers: [{ restart_state: 'held' }] })).toMatchObject({ status: 'attention', tone: 'warning' });
|
||||
expect(campaignOutcome({ ...campaign, rolled_back_by: 'rollback' })).toMatchObject({ status: 'rolled-back', label: 'Rolled back' });
|
||||
});
|
||||
|
||||
it('distinguishes queued work, file application, and health verification without treating stage messages as failures', () => {
|
||||
const server = { restart_state: 'pending', restarted_at: null, error: 'Queued to restart; waiting for another server to recover' };
|
||||
expect(campaignServerStatus(server, [{ apply_state: 'pending' }])).toEqual({ group: 'queued', label: 'Queued', tone: 'neutral' });
|
||||
expect(campaignServerStatus(server, [{ apply_state: 'applying' }])).toMatchObject({ group: 'processing', label: 'Applying files' });
|
||||
expect(campaignServerStatus({ ...server, restarted_at: '2026-10-06T20:08:29Z', error: 'Checking container state with host agent' }, [{ apply_state: 'applied' }]))
|
||||
const verifying = { ...server, restarted_at: '2026-10-06T20:08:29Z', error: 'Checking container state with host agent' };
|
||||
expect(campaignServerStatus(verifying, [{ apply_state: 'applied' }]))
|
||||
.toEqual({ group: 'processing', label: 'Verifying health', tone: 'info' });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user