Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed unknown workflow operator actions crashing the dashboard action bar. (#7427) (@houko)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from "vitest";
import { describeAction } from "./OperatorActionBar";

const translate = (
_key: string,
fallback: string,
_options?: Record<string, unknown>,
) => fallback;

describe("describeAction", () => {
it("rejects unknown string verbs instead of treating them as objects", () => {
expect(describeAction("future_action", translate)).toBeNull();
});

it("rejects malformed object descriptors", () => {
expect(describeAction({}, translate)).toBeNull();
expect(describeAction({ provide_input: null }, translate)).toBeNull();
expect(describeAction({ provide_input: {} }, translate)).toBeNull();
});

it("preserves valid provide-input descriptors", () => {
expect(
describeAction({ provide_input: { field: "ticket_id" } }, translate),
).toMatchObject({
verb: "provide_input",
field: "ticket_id",
needsPayload: true,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Badge } from "./ui/Badge";
import { useWorkflowOperatorPause } from "../lib/queries/workflows";
import { useResolveOperatorStep } from "../lib/mutations/workflows";
import { ApiError } from "../lib/http/client";
import type { OperatorActionDescriptor, OperatorActionVerb } from "../api";
import type { OperatorActionVerb } from "../api";

interface Props {
runId: string;
Expand All @@ -29,8 +29,8 @@ interface Props {
* here so the action list, button labels, and resolve POST stay in
* lockstep — adding a verb in `OperatorAction` (Rust) requires updating
* exactly this function on the dashboard. */
function describeAction(
action: OperatorActionDescriptor,
export function describeAction(
action: unknown,
t: (key: string, fallback: string, options?: Record<string, unknown>) => string,
): {
verb: OperatorActionVerb;
Expand All @@ -39,7 +39,7 @@ function describeAction(
field?: string;
variant: "primary" | "secondary" | "danger" | "ghost";
icon: React.ComponentType<{ className?: string }>;
} {
} | null {
if (typeof action === "string") {
switch (action) {
case "approve":
Expand All @@ -51,8 +51,20 @@ function describeAction(
case "freeform_input":
return { verb: "freeform_input", label: t("workflows.operator.freeform_input", "Freeform input"), needsPayload: true, variant: "secondary", icon: MessageSquare };
}
return null;
}
// ProvideInput carries a `field` name — labelled on the button.
if (
typeof action !== "object" ||
action === null ||
!("provide_input" in action) ||
typeof action.provide_input !== "object" ||
action.provide_input === null ||
!("field" in action.provide_input) ||
typeof action.provide_input.field !== "string"
) {
return null;
}
return {
verb: "provide_input",
label: t("workflows.operator.provide_field", "Provide '{{field}}'", { field: action.provide_input.field }),
Expand Down Expand Up @@ -141,6 +153,7 @@ export function OperatorActionBar({ runId }: Props) {
<div className="flex flex-wrap gap-1.5">
{pause.actions.map((action, idx) => {
const desc = describeAction(action, t);
if (!desc) return null;
const key = `${desc.verb}:${desc.field ?? ""}`;
const Icon = desc.icon;
const isOpen = openVerb === key;
Expand Down