feat(workflows): pick a lane in the pipeline pass-rate panel
The panel aggregated every lane at once, which answers "does this stage get proved across the project" but never "does THIS lane prove it". A lane picker now narrows the same aggregation through ?lane=<id> on GET /api/lanes/pipeline-stats, counting that lane plus its own archived features — dropping the features would hide most of a lane's history the moment it starts its next one. The response carries a `lanes` array that the filter never narrows: it populates the picker, so it has to keep offering every other lane even while the counts show one. For the same reason the picker renders above the empty branch rather than inside the populated one — narrowing to a lane that has recorded nothing would otherwise be a one-way trip, with no control left to select anything else. A lane filter that is not a positive integer is rejected with 400 EBADLANE rather than silently aggregating everything.
This commit is contained in:
@@ -8,14 +8,14 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import { render, screen, fireEvent, within } from "@testing-library/react";
|
||||
import { render, screen, fireEvent, waitFor, within } from "@testing-library/react";
|
||||
import { LanePipelinePanel } from "../LanePipelinePanel";
|
||||
|
||||
const statsMock = vi.fn();
|
||||
|
||||
vi.mock("../../../lib/api", async (importOriginal) => {
|
||||
const actual = await importOriginal<Record<string, unknown>>();
|
||||
return { ...actual, api: { lanes: { pipelineStats: () => statsMock() } } };
|
||||
return { ...actual, api: { lanes: { pipelineStats: (id?: number | null) => statsMock(id) } } };
|
||||
});
|
||||
|
||||
const node = (id: string, over: Record<string, number> = {}) => ({
|
||||
@@ -45,6 +45,10 @@ const STATS = {
|
||||
},
|
||||
{ id: "hotfix", name: "Hotfix", runs: 1, nodes: [node("patch", { entered: 1, passed: 1 })] },
|
||||
],
|
||||
lanes: [
|
||||
{ id: 1, title: "api lane", cwd: "/w/api" },
|
||||
{ id: 2, title: "", cwd: "/w/ui" },
|
||||
],
|
||||
};
|
||||
|
||||
describe("LanePipelinePanel", () => {
|
||||
@@ -91,12 +95,42 @@ describe("LanePipelinePanel", () => {
|
||||
});
|
||||
|
||||
it("shows the CLI hint when nothing has been recorded", async () => {
|
||||
statsMock.mockResolvedValue({ pipelines: [] });
|
||||
statsMock.mockResolvedValue({ pipelines: [], lanes: [] });
|
||||
render(<LanePipelinePanel />);
|
||||
|
||||
expect(await screen.findByText(/ccam lanes add/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("refetches narrowed to the lane picked, and falls back to a cwd for an untitled one", async () => {
|
||||
statsMock.mockResolvedValue(STATS);
|
||||
render(<LanePipelinePanel />);
|
||||
|
||||
const picker = await screen.findByTestId("pipeline-stats-lane-picker");
|
||||
expect(within(picker).getByText("/w/ui")).toBeInTheDocument();
|
||||
expect(statsMock).toHaveBeenLastCalledWith(null);
|
||||
|
||||
fireEvent.change(picker, { target: { value: "2" } });
|
||||
expect(statsMock).toHaveBeenLastCalledWith(2);
|
||||
});
|
||||
|
||||
it("keeps the lane picker reachable when the picked lane recorded nothing", async () => {
|
||||
statsMock.mockResolvedValue(STATS);
|
||||
render(<LanePipelinePanel />);
|
||||
|
||||
// Without a picker in the empty branch, narrowing to a quiet lane would be
|
||||
// a one-way trip — no control left to select any other lane.
|
||||
statsMock.mockResolvedValue({ pipelines: [], lanes: STATS.lanes });
|
||||
fireEvent.change(await screen.findByTestId("pipeline-stats-lane-picker"), {
|
||||
target: { value: "1" },
|
||||
});
|
||||
|
||||
// Wait for the empty branch to take over, then re-query: the refetch swaps
|
||||
// the whole subtree, so a handle grabbed before it is already detached.
|
||||
await waitFor(() => expect(screen.queryByTestId("pipeline-stat-plan")).not.toBeInTheDocument());
|
||||
expect(screen.getByTestId("pipeline-stats-lane-picker")).toBeInTheDocument();
|
||||
expect(screen.queryByText(/ccam lanes add/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("surfaces a failed fetch", async () => {
|
||||
statsMock.mockRejectedValue(new Error("stats unreachable"));
|
||||
render(<LanePipelinePanel />);
|
||||
|
||||
Reference in New Issue
Block a user