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.
77 lines
2.2 KiB
TypeScript
77 lines
2.2 KiB
TypeScript
// Merging workflow definitions with their run statistics.
|
|
//
|
|
// The rows used to come from the definition list alone, so a workflow that had
|
|
// run but was no longer in that list (or a definitions fetch that came back
|
|
// empty while the stats fetch succeeded) produced no rows at all. The page then
|
|
// showed "No workflow runs yet" directly above the stage tables listing those
|
|
// very runs (archie-core-rcbf).
|
|
//
|
|
// A run is evidence the workflow exists. Anything with either a definition or
|
|
// statistics gets a row.
|
|
|
|
/** A workflow's run statistics, as the stats endpoint reports them. */
|
|
export interface WorkflowStats {
|
|
workflow: string;
|
|
runs?: number;
|
|
merged?: number;
|
|
completed?: number;
|
|
avg_tokens?: number;
|
|
avg_steps?: number;
|
|
origin?: string;
|
|
}
|
|
|
|
/** A workflow definition, as the definitions endpoint reports it. */
|
|
export interface WorkflowDefinition {
|
|
id: string;
|
|
name?: string;
|
|
origin?: string;
|
|
enabled?: boolean;
|
|
}
|
|
|
|
/** One table row: a definition, its statistics, or both. */
|
|
export interface WorkflowRow {
|
|
id: string;
|
|
name?: string;
|
|
workflow: string;
|
|
runs?: number;
|
|
merged?: number;
|
|
completed?: number;
|
|
avg_tokens?: number;
|
|
avg_steps?: number;
|
|
origin?: string;
|
|
}
|
|
|
|
/**
|
|
* workflowRows returns one row per known workflow, definitions first and in
|
|
* their declared order, then any workflow seen only in the statistics.
|
|
*/
|
|
export function workflowRows(
|
|
workflows: WorkflowStats[] | null | undefined,
|
|
definitions: WorkflowDefinition[] | null | undefined,
|
|
): WorkflowRow[] {
|
|
const stats = new Map((workflows || []).map((w) => [w.workflow, w]));
|
|
const rows: WorkflowRow[] = [];
|
|
const claimed = new Set<string>();
|
|
|
|
for (const definition of definitions || []) {
|
|
claimed.add(definition.id);
|
|
rows.push({
|
|
...definition,
|
|
...(stats.get(definition.id) || {
|
|
workflow: definition.id,
|
|
runs: 0,
|
|
merged: 0,
|
|
completed: 0,
|
|
}),
|
|
});
|
|
}
|
|
|
|
for (const workflow of workflows || []) {
|
|
if (claimed.has(workflow.workflow)) continue;
|
|
// No definition to describe it, so the id is the only name it has.
|
|
rows.push({ id: workflow.workflow, name: workflow.workflow, ...workflow });
|
|
}
|
|
|
|
return rows;
|
|
}
|