Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(automations): leave draft test automations out of the overview tiles (#18393)

Engel Nyst91857411cb74
diff --git a/__tests__/routes/automations-dashboard.test.tsx b/__tests__/routes/automations-dashboard.test.tsx
index ed2443d690..c6c86dff84 100644
--- a/__tests__/routes/automations-dashboard.test.tsx
+++ b/__tests__/routes/automations-dashboard.test.tsx
@@ -402,6 +402,105 @@ describe("AutomationsList β€” manifest-declared dashboard", () => {
});
});
+describe("AutomationsList β€” draft test automations stay out of the overview", () => {
+ // Testing a saved draft materializes a hidden automation in the DRAFT
+ // state; the groups never list it, so the tiles must not count it either.
+ const draftTestAutomation = createAutomation({
+ id: "a-draft",
+ name: "Draft widget",
+ enabled: false,
+ state: "DRAFT",
+ });
+ const savedDraft = {
+ id: "draft-1",
+ endpoint: "/v1/preset/prompt" as const,
+ name: "Saved widget draft",
+ draft: { prompt: "Draft prompt" },
+ validationErrors: null,
+ dispatchable: true,
+ sourceAutomationId: null,
+ materializedAutomationId: "a-draft",
+ lastTestRunId: "run-draft",
+ createdAt: "2026-01-02T00:00:00Z",
+ updatedAt: "2026-01-02T00:00:00Z",
+ };
+
+ beforeEach(() => {
+ vi.mocked(AutomationService.getAutomationRuns).mockImplementation((id) => {
+ if (id === "a-draft") {
+ return Promise.resolve({ runs: [createRun({})], total: 9 });
+ }
+ return Promise.resolve({ runs: [createRun({})], total: 6 });
+ });
+ });
+
+ it("counts only the listed automations and their runs in the tiles", async () => {
+ // Arrange
+ vi.mocked(AutomationService.getAutomations).mockResolvedValue({
+ automations: [okAutomation, draftTestAutomation],
+ total: 2,
+ });
+
+ // Act
+ renderAt("/automations", <AutomationsList />);
+ await within(
+ await screen.findByTestId("automation-card-a-ok"),
+ ).findByTestId("run-status-icon-completed");
+
+ // Assert
+ const automationsTile = screen.getByTestId("overview-tile-automations");
+ expect(
+ within(automationsTile).getByText("1", { exact: true }),
+ ).toBeInTheDocument();
+ expect(within(automationsTile).getByText("1 live")).toBeInTheDocument();
+ const runsTile = screen.getByTestId("overview-tile-total-runs");
+ expect(
+ within(runsTile).getByText("6", { exact: true }),
+ ).toBeInTheDocument();
+ expect(screen.queryByTestId("automation-card-a-draft")).toBeNull();
+ });
+
+ it("shows the first-run empty state when only draft test automations exist", async () => {
+ // Arrange β€” the saved draft is gone, its test automation is not.
+ vi.mocked(AutomationService.getAutomations).mockResolvedValue({
+ automations: [draftTestAutomation],
+ total: 1,
+ });
+
+ // Act
+ renderAt("/automations", <AutomationsList />);
+
+ // Assert
+ expect(await screen.findByTestId("automations-empty")).toBeInTheDocument();
+ const automationsTile = screen.getByTestId("overview-tile-automations");
+ expect(
+ within(automationsTile).getByText("0", { exact: true }),
+ ).toBeInTheDocument();
+ });
+
+ it("keeps a saved draft listed when its test automation is the only automation", async () => {
+ // Arrange
+ vi.mocked(AutomationService.getAutomations).mockResolvedValue({
+ automations: [draftTestAutomation],
+ total: 1,
+ });
+ vi.mocked(AutomationService.listServerDrafts).mockResolvedValue({
+ drafts: [savedDraft],
+ total: 1,
+ });
+
+ // Act
+ renderAt("/automations", <AutomationsList />);
+
+ // Assert
+ expect(
+ await screen.findByTestId("automation-setup-draft-draft-1"),
+ ).toBeInTheDocument();
+ expect(screen.queryByTestId("automations-empty")).toBeNull();
+ expect(screen.queryByTestId("automations-filtered-empty")).toBeNull();
+ });
+});
+
describe("AutomationsList β€” created-by filter on cloud workspaces", () => {
const TEAM_ORG_ID = "org-team";
const CURRENT_USER_ID = "user-me";
diff --git a/src/routes/automations-list.tsx b/src/routes/automations-list.tsx
index 7e1833c7e7..4f387533d8 100644
--- a/src/routes/automations-list.tsx
+++ b/src/routes/automations-list.tsx
@@ -108,6 +108,12 @@ export const clientLoader = () => {
return null;
};
+function withoutDraftAutomations(
+ automations: readonly Automation[] | undefined,
+): Automation[] {
+ return (automations ?? []).filter((a) => !isDraftAutomation(a));
+}
+
function getDraftKind(draft: AutomationDraftApiResponse): AutomationSetupKind {
if (draft.endpoint === "/v1") return "custom";
if (draft.endpoint === "/v1/preset/plugin") return "plugin";
@@ -375,13 +381,21 @@ export default function AutomationsList() {
offset: 0,
enabled: isBackendHealthy,
});
+ // Testing a saved draft materializes a hidden DRAFT automation. The page
+ // lists saved drafts in their own group and never lists these test
+ // artifacts, so the groups, tiles, run summaries, and empty state all
+ // leave them out.
+ const listedAutomations = useMemo(
+ () => withoutDraftAutomations(data?.automations),
+ [data?.automations],
+ );
+ const orgAutomations = useMemo(
+ () => withoutDraftAutomations(orgData?.automations),
+ [orgData?.automations],
+ );
const runSummaryAutomations = useMemo(
- () =>
- uniqueById([
- ...(orgData?.automations ?? []),
- ...(data?.automations ?? []),
- ]),
- [orgData?.automations, data?.automations],
+ () => uniqueById([...orgAutomations, ...listedAutomations]),
+ [orgAutomations, listedAutomations],
);
// One runs query per automation in either list β€” dashboard mode only.
const runSummaries = useAutomationRunSummaries(runSummaryAutomations, {
@@ -397,14 +411,13 @@ export default function AutomationsList() {
const importMutation = useImportAutomation();
const visible = useMemo(() => {
- if (!data?.automations) return [];
if (!dashboardSpec) {
- return data.automations.filter((a) =>
+ return listedAutomations.filter((a) =>
matchesAutomationSearch(a, searchQuery),
);
}
return applyDashboardView(
- data.automations,
+ listedAutomations,
{
search: searchQuery,
status: statusFilter,
@@ -419,7 +432,7 @@ export default function AutomationsList() {
runSummaries,
);
}, [
- data?.automations,
+ listedAutomations,
dashboardSpec,
searchQuery,
statusFilter,
@@ -438,13 +451,10 @@ export default function AutomationsList() {
[draftsData?.drafts, searchQuery],
);
const activeAutomations = useMemo(
- () => visible.filter((a) => a.enabled && !isDraftAutomation(a)),
- [visible],
- );
- const inactive = useMemo(
- () => visible.filter((a) => !a.enabled && !isDraftAutomation(a)),
+ () => visible.filter((a) => a.enabled),
[visible],
);
+ const inactive = useMemo(() => visible.filter((a) => !a.enabled), [visible]);
const handleToggle = (id: string, currentEnabled: boolean) => {
const willEnable = !currentEnabled;
@@ -593,9 +603,12 @@ export default function AutomationsList() {
const overviewTiles = useMemo(() => {
if (!dashboardSpec) return [];
- const automations = orgData?.automations ?? [];
return dashboardSpec.overview.tiles.map((tile) => {
- const value = computeOverviewTile(tile.metric, automations, runSummaries);
+ const value = computeOverviewTile(
+ tile.metric,
+ orgAutomations,
+ runSummaries,
+ );
const template =
value.isZero && tile.zeroDetail ? tile.zeroDetail : tile.detail;
return {
@@ -606,7 +619,7 @@ export default function AutomationsList() {
Icon: MANIFEST_ICON_BY_SLUG[tile.icon],
};
});
- }, [dashboardSpec, orgData?.automations, runSummaries]);
+ }, [dashboardSpec, orgAutomations, runSummaries]);
const groupInsights = dashboard
? { spec: dashboard.spec.insights, byId: runSummaries }
@@ -637,8 +650,16 @@ export default function AutomationsList() {
const isListError = (isError && !data) || (isDraftsError && !draftsData);
// Whether the org has any automations comes from the unfiltered list, so an
// empty filtered response shows the filtered empty state with Clear filters.
+ // The server total includes hidden DRAFT test automations; subtract the ones
+ // loaded. Saved drafts keep the page out of the empty state, since their
+ // group lists them.
+ const orgDraftAutomationCount =
+ (orgData?.automations.length ?? 0) - orgAutomations.length;
const hasNoAutomations =
- !isListError && orgData?.total === 0 && (draftsData?.total ?? 0) === 0;
+ !isListError &&
+ orgData !== undefined &&
+ orgData.total - orgDraftAutomationCount === 0 &&
+ (draftsData?.total ?? 0) === 0;
// The previous filter's rows stand in while the next page loads; when none
// of them match, show loading rather than a no-match that is not final. An
// empty org keeps its empty state instead.