The transition table moved the no-change outcomes to StatusCompleted, so a run that opens no pull request now ends in a status the per-workflow stats did not count at all: it was not merged, not in review, not parked, and the workflows page would have shown it as a run that went nowhere. The count travels the whole State Store path, since every dashboard consumer reads it through the gRPC client rather than the local store. - WorkflowStats filters `completed` beside merged and pr_open; the SQL is the count, so a wrong filter reads as zero rather than failing, and TestWorkflowStatsCountsCompletedRuns holds it against a real store. - storecontract.WorkflowStat gains Completed (json "completed"), the proto message gains field 9, and workflowStatProto/workflowStatValue carry it; TestWorkflowStatProtoCarriesEveryField round-trips every field by name. - The gateway's chat task report names the status. - The dashboard counts a completed run as delivered in GatePulseCard's totals and badge numerator, and the WorkflowStat/WorkflowStats/WorkflowRow interfaces carry the field. - TestOutcomeSitesAreTransitionsFromRunning is the guard that keeps the producer and the table agreeing: it re-reads this package's tc.Outcome assignment sites from source and requires each status to be one internal/taskstate allows from running, so a new or moved site has to be adjudicated against the table instead of discovered on a live run.
110 lines
3.3 KiB
TypeScript
110 lines
3.3 KiB
TypeScript
import { onMounted, ref } from "vue";
|
|
|
|
import { api } from "@/lib/api";
|
|
import { useLiveResource } from "@/stores/live-updates";
|
|
import type { ActivityDetailInput } from "./activity-detail";
|
|
import type { Setup } from "./setup-preference";
|
|
|
|
/**
|
|
* The dashboard's shared state.
|
|
*
|
|
* The health row, the throughput tiles, the token outlook and the activity
|
|
* table all read it, and the hero's actions read the task counts, so it lives
|
|
* in a module rather than being threaded down through a chain of props.
|
|
*/
|
|
|
|
export interface Summary {
|
|
statuses?: Record<string, number>;
|
|
tokens_by_day?: Array<{ tokens?: number }>;
|
|
}
|
|
|
|
export interface WorkflowStat {
|
|
workflow?: string;
|
|
runs?: number;
|
|
merged?: number;
|
|
completed?: number;
|
|
pr_open?: number;
|
|
parked?: number;
|
|
}
|
|
|
|
/** An event off the live stream: the payload the detail column reads, plus
|
|
* enough to point the row at the task it belongs to. */
|
|
export interface ActivityEvent extends ActivityDetailInput {
|
|
kind?: string;
|
|
type?: string;
|
|
task_id?: number | string;
|
|
repo?: string;
|
|
issue?: number | string;
|
|
at?: string | number;
|
|
}
|
|
|
|
/** A task, as far as the dashboard's links read it. */
|
|
export interface DashboardTask {
|
|
id: number | string;
|
|
status?: string;
|
|
owner?: string;
|
|
repo?: string;
|
|
issue_number?: number;
|
|
}
|
|
|
|
export const summary = ref<Summary | null>(null);
|
|
export const setup = ref<Setup | null>(null);
|
|
export const workflows = ref<{ workflows?: WorkflowStat[] } | null>(null);
|
|
// null means loading, [] means loaded.
|
|
export const tasks = ref<DashboardTask[] | null>(null);
|
|
export const error = ref<string | null>(null);
|
|
|
|
export const taskIDsBySource = ref(new Map<string, number>());
|
|
|
|
export async function loadDashboard(): Promise<void> {
|
|
error.value = null;
|
|
try {
|
|
const [nextSummary, nextSetup, nextWorkflows, nextTasks] =
|
|
await Promise.all([
|
|
api.summary<Summary>(),
|
|
api.setup<Setup>().catch(() => null),
|
|
api.workflows<{ workflows?: WorkflowStat[] }>().catch(() => null),
|
|
// Not defaulted to []: an empty list reads as "nothing needs you",
|
|
// which a failed fetch must never claim.
|
|
api.tasks<DashboardTask[]>(),
|
|
]);
|
|
const map = new Map<string, number>();
|
|
for (const task of nextTasks) {
|
|
if (task.owner && task.repo && task.issue_number) {
|
|
map.set(
|
|
`${task.owner}/${task.repo}#${task.issue_number}`,
|
|
Number(task.id),
|
|
);
|
|
}
|
|
}
|
|
taskIDsBySource.value = map;
|
|
summary.value = nextSummary;
|
|
setup.value = nextSetup;
|
|
workflows.value = nextWorkflows;
|
|
tasks.value = nextTasks;
|
|
} catch (err) {
|
|
error.value = String((err as Error).message || err);
|
|
}
|
|
}
|
|
|
|
export function taskIDForEvent(
|
|
event: ActivityEvent,
|
|
bySource: Map<string, number>,
|
|
): number {
|
|
if (Number(event.task_id) > 0) return Number(event.task_id);
|
|
if (!event.repo || !event.issue) return 0;
|
|
return Number(bySource.get(`${event.repo}#${event.issue}`)) || 0;
|
|
}
|
|
|
|
/** The task an activity row opens, or 0. An event carries the id, or a
|
|
* repo/issue pair the task list resolves. */
|
|
export function taskIDFor(event: ActivityEvent): number {
|
|
return taskIDForEvent(event, taskIDsBySource.value);
|
|
}
|
|
|
|
/** Owns the initial fetch and the event stream for the page's lifetime. */
|
|
export function useDashboard(): void {
|
|
useLiveResource("tasks", () => void loadDashboard(), 500);
|
|
onMounted(loadDashboard);
|
|
}
|