Simplify campaign list and add searchable status filters

This commit is contained in:
2026-10-06 16:21:38 -04:00
parent 7985f1202f
commit ba015ca4c7
6 changed files with 327 additions and 389 deletions
+21 -2
View File
@@ -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' });
});