patchwise-agent-studio / web /src /domain /homeStats.test.ts
EnergyVenom's picture
Astra: AR and gap business actions, usage fixes, client report coverage, health check, backups and alerts, cancel_invoice fix (d52c9b976774)
cdfb5de verified
Raw History Blame Contribute Delete
1.59 kB
import { describe, expect, it } from 'vitest';
import type { Schemas } from '../api/client';
import { effortSavedHours, regressionToDate, updateCycles } from './homeStats';
const run = (id: string, status: string, created_at: string, counts: Record<string, number>, patch_id: string | null = '26D') =>
({ run_id: id, status, created_at, counts, patch_id, modules: ['AP'], decisions: {} }) as unknown as Schemas['RunSummary'];
describe('home numbers', () => {
const runs = [
run('a', 'completed', '2026-11-18T10:00:00Z', { passed: 7, failed: 1, skipped: 2 }),
run('b', 'waiting_review', '2026-11-19T10:00:00Z', { passed: 5, failed: 2 }),
run('c', 'cancelled', '2026-11-10T10:00:00Z', { passed: 0, failed: 0 }, '26C'),
run('d', 'completed', '2026-11-01T10:00:00Z', { passed: 3, failed: 0 }, null),
];
it('counts only runs that executed scenarios as test cycles', () => {
expect(regressionToDate(runs)).toEqual({ passed: 15, failed: 3, skipped: 2, executed: 18, cycles: 3, passRate: 83 });
expect(regressionToDate([]).passRate).toBeNull();
});
it('states effort saved from the scenarios executed', () => {
expect(effortSavedHours(18)).toBe(6);
expect(effortSavedHours(0)).toBe(0);
});
it('gives each update its stage from its newest run, newest update first', () => {
expect(updateCycles(runs)).toEqual([
{ patch: '26D', stage: 'in_progress', runs: 2, passed: 12, failed: 3, last: '2026-11-19T10:00:00Z' },
{ patch: '26C', stage: 'stopped', runs: 1, passed: 0, failed: 0, last: '2026-11-10T10:00:00Z' },
]);
});
});