π OpenHands: AI-Driven Development
fix(automations): show repositories and plugins stored in preset_metadata (#18041)
Engel Nyst3ccebab9f811
diff --git a/__tests__/api/automation-service.test.ts b/__tests__/api/automation-service.test.tsindex ede2e341df..8187d12b8f 100644--- a/__tests__/api/automation-service.test.ts+++ b/__tests__/api/automation-service.test.ts@@ -122,7 +122,6 @@ const mockAutomation: Automation = {prompt: "A test automation",trigger: { type: "schedule", schedule_human: "Daily at 09:00" },enabled: true,- repository: "acme/repo",model: "daily-profile",created_at: "2026-01-01T00:00:00Z",updated_at: "2026-01-02T00:00:00Z",@@ -178,6 +177,30 @@ describe("AutomationService", () => {expect(result).toEqual(response);});+ it("exposes the preset_metadata repositories and plugins of each listed automation", async () => {+ mockGet.mockResolvedValue({+ data: {+ automations: [+ {+ ...mockAutomation,+ preset_metadata: {+ repos: [{ url: "acme/repo", ref: "main" }],+ plugins: [{ source: "github:acme/plugin" }],+ },+ },+ ],+ total: 1,+ },+ });++ const { automations } = await AutomationService.listAutomations();++ expect(automations[0].repositories).toEqual([+ { url: "acme/repo", ref: "main" },+ ]);+ expect(automations[0].plugins).toEqual(["github:acme/plugin"]);+ });+it("uses default params when none provided", async () => {const response: AutomationsResponse = {automations: [],@@ -234,6 +257,86 @@ describe("AutomationService", () => {expect(mockGet).toHaveBeenCalledWith("/api/automation/v1/1");expect(result).toEqual(mockAutomation);});++ it("exposes the repository with its ref and the plugin stored in preset_metadata", async () => {+ mockGet.mockResolvedValue({+ data: {+ ...mockAutomation,+ preset_metadata: {+ preset_type: "plugin",+ repos: [+ { url: "https://github.com/qa-example/qa-repo", ref: "main" },+ ],+ plugins: [{ source: "github:qa-example/qa-plugin" }],+ },+ },+ });++ const result = await AutomationService.getAutomation("1");++ expect(result.repositories).toEqual([+ { url: "https://github.com/qa-example/qa-repo", ref: "main" },+ ]);+ expect(result.plugins).toEqual(["github:qa-example/qa-plugin"]);+ });++ it("keeps every repository and plugin entry stored in preset_metadata", async () => {+ mockGet.mockResolvedValue({+ data: {+ ...mockAutomation,+ preset_metadata: {+ repos: [+ { url: "https://github.com/qa-example/qa-repo", ref: "main" },+ { url: "qa-example/docs", provider: "github" },+ ],+ plugins: [+ { source: "github:qa-example/qa-plugin" },+ { source: "github:qa-example/other-plugin", ref: "v1" },+ ],+ },+ },+ });++ const result = await AutomationService.getAutomation("1");++ expect(result.repositories).toEqual([+ { url: "https://github.com/qa-example/qa-repo", ref: "main" },+ { url: "qa-example/docs" },+ ]);+ expect(result.plugins).toEqual([+ "github:qa-example/qa-plugin",+ "github:qa-example/other-plugin",+ ]);+ });++ it("adds no repositories or plugins when preset_metadata has none", async () => {+ mockGet.mockResolvedValue({+ data: { ...mockAutomation, preset_metadata: { preset_type: "prompt" } },+ });++ const result = await AutomationService.getAutomation("1");++ expect(result).not.toHaveProperty("repositories");+ expect(result).not.toHaveProperty("plugins");+ });++ it("falls back to a top-level repository, branch and plugins", async () => {+ mockGet.mockResolvedValue({+ data: {+ ...mockAutomation,+ repository: "acme/repo",+ branch: "develop",+ plugins: ["GitHub"],+ },+ });++ const result = await AutomationService.getAutomation("1");++ expect(result.repositories).toEqual([+ { url: "acme/repo", ref: "develop" },+ ]);+ expect(result.plugins).toEqual(["GitHub"]);+ });});describe("updateAutomation", () => {@@ -425,6 +528,17 @@ describe("AutomationService", () => {expect(result).toEqual(mockAutomation);});+ it("getAutomation exposes preset_metadata repositories from the cloud proxy response", async () => {+ mockCallCloudProxy.mockResolvedValue({+ ...mockAutomation,+ preset_metadata: { repos: [{ url: "acme/repo", ref: "main" }] },+ });++ const result = await AutomationService.getAutomation("abc");++ expect(result.repositories).toEqual([{ url: "acme/repo", ref: "main" }]);+ });+it("dispatchAutomation forwards method POST via callCloudProxy", async () => {mockCallCloudProxy.mockResolvedValue(mockRun);diff --git a/__tests__/components/automations/detail/configuration-section.test.tsx b/__tests__/components/automations/detail/configuration-section.test.tsxindex 5f634f8397..2575af413e 100644--- a/__tests__/components/automations/detail/configuration-section.test.tsx+++ b/__tests__/components/automations/detail/configuration-section.test.tsx@@ -17,8 +17,7 @@ const cronAutomation: Automation = {created_at: "2026-01-01T00:00:00Z",updated_at: "2026-01-01T00:00:00Z",model: "fast-model",- repository: "acme/app",- branch: "main",+ repositories: [{ url: "acme/app", ref: "main" }],timezone: "UTC",};@@ -36,8 +35,7 @@ const eventAutomation: Automation = {created_at: "2026-01-01T00:00:00Z",updated_at: "2026-01-01T00:00:00Z",model: "review-model",- repository: "acme/frontend-app",- branch: "main",+ repositories: [{ url: "acme/frontend-app", ref: "main" }],};const eventMultiPatternAutomation: Automation = {@@ -64,6 +62,41 @@ describe("ConfigurationSection", () => {expect(screen.getByText("acme/app")).toBeInTheDocument();});+ it("renders every repository as owner/repo with its branch badge", () => {+ const automation: Automation = {+ ...eventAutomation,+ repositories: [+ { url: "https://github.com/qa-example/qa-repo", ref: "main" },+ { url: "[email protected]:qa-example/docs.git", ref: "v2" },+ { url: "qa-example/tools" },+ ],+ };++ render(<ConfigurationSection automation={automation} />);++ expect(+ screen.getByText("AUTOMATIONS$DETAIL$REPOSITORIES"),+ ).toBeInTheDocument();+ const rows = screen.getAllByTestId("automation-repository");+ expect(rows.map((row) => row.textContent)).toEqual([+ "qa-example/qa-repomain",+ "qa-example/docsv2",+ "qa-example/tools",+ ]);+ });++ it("omits the repositories field when the automation has none", () => {+ render(+ <ConfigurationSection+ automation={{ ...eventAutomation, repositories: undefined }}+ />,+ );++ expect(+ screen.queryByText("AUTOMATIONS$DETAIL$REPOSITORIES"),+ ).not.toBeInTheDocument();+ });+it("renders event trigger with source, event type, and filter", () => {render(<ConfigurationSection automation={eventAutomation} />);diff --git a/__tests__/routes/automation-detail.test.tsx b/__tests__/routes/automation-detail.test.tsxindex 8e1be9d6dd..bb44181e3d 100644--- a/__tests__/routes/automation-detail.test.tsx+++ b/__tests__/routes/automation-detail.test.tsx@@ -21,6 +21,7 @@ import AutomationDetail from "#/routes/automation-detail";import type { Backend } from "#/api/backend-registry/types";import { AutomationRunStatus } from "#/types/automation";import type { Automation, AutomationRunsResponse } from "#/types/automation";+import { withPresetSources } from "#/utils/automation-preset-sources";import { packTarGzip } from "#/utils/tar-gzip";vi.mock("#/api/automation-service/automation-service.api", () => ({@@ -303,6 +304,37 @@ describe("AutomationDetail β backend-change guard", () => {});});+describe("AutomationDetail β repositories and plugins", () => {+ it("shows the repositories and plugins a preset response stores in preset_metadata", async () => {+ // Arrange β the automation service returns repos and plugins only inside+ // preset_metadata; the service layer maps them onto the automation.+ vi.mocked(AutomationService.getAutomation).mockResolvedValue(+ withPresetSources({+ ...automation,+ repository: undefined,+ preset_metadata: {+ preset_type: "plugin",+ repos: [+ { url: "https://github.com/qa-example/qa-repo", ref: "main" },+ ],+ plugins: [{ source: "github:qa-example/qa-plugin" }],+ },+ }),+ );++ // Act+ renderDetail();++ // Assert+ const [repository] = await screen.findAllByTestId("automation-repository");+ expect(repository).toHaveTextContent("qa-example/qa-repomain");+ expect(+ screen.getByText(I18nKey.AUTOMATIONS$DETAIL$PLUGINS),+ ).toBeInTheDocument();+ expect(screen.getByText("github:qa-example/qa-plugin")).toBeInTheDocument();+ });+});+describe("AutomationDetail β Automation Runs As", () => {const creatorId = "3f1c2a54-0b8e-4c1d-9a7e-5d2f6b8c9e01";const orgId = "0b93b5f2-5396-49f2-8d98-61f906184270";diff --git a/src/api/automation-service/automation-service.api.ts b/src/api/automation-service/automation-service.api.tsindex 8fbd7e2300..01ee4229c8 100644--- a/src/api/automation-service/automation-service.api.ts+++ b/src/api/automation-service/automation-service.api.ts@@ -36,6 +36,7 @@ import type {SetupRequestBody,ValidateDraftResponse,} from "#/manifests/types";+import { withPresetSources } from "#/utils/automation-preset-sources";import { downloadBlob } from "#/utils/utils";import type { Backend, ResolvedActiveBackend } from "../backend-registry/types";import {@@ -294,20 +295,26 @@ class AutomationService {const { limit = 50, offset = 0, createdBy } = params;const active = getActiveBackend().backend;+ let response: AutomationsResponse;if (active.kind === "cloud") {- return callCloudProxy<AutomationsResponse>({+ response = await callCloudProxy<AutomationsResponse>({backend: active,method: "GET",path: `${AUTOMATION_BASE_PATH}${getAutomationEndpoint("list")}?${buildListQuery(limit, offset, { created_by: createdBy })}`,headers: await buildAutomationRequestHeaders(),});+ } else {+ const { data } = await localAutomationAxios.get<AutomationsResponse>(+ `${AUTOMATION_BASE_PATH}${getAutomationEndpoint("list")}`,+ { params: { limit, offset, created_by: createdBy } },+ );+ response = data;}- const { data } = await localAutomationAxios.get<AutomationsResponse>(- `${AUTOMATION_BASE_PATH}${getAutomationEndpoint("list")}`,- { params: { limit, offset, created_by: createdBy } },- );- return data;+ return {+ ...response,+ automations: response.automations.map(withPresetSources),+ };}/**@@ -326,17 +333,20 @@ class AutomationService {const active = getActiveBackend().backend;const path = `${AUTOMATION_BASE_PATH}${getAutomationIdEndpoint("detail", id)}`;+ let automation: Automation;if (active.kind === "cloud") {- return callCloudProxy<Automation>({+ automation = await callCloudProxy<Automation>({backend: active,method: "GET",path,headers: await buildAutomationRequestHeaders(),});+ } else {+ const { data } = await localAutomationAxios.get<Automation>(path);+ automation = data;}- const { data } = await localAutomationAxios.get<Automation>(path);- return data;+ return withPresetSources(automation);}static async createAutomation(spec: AutomationSpec): Promise<Automation> {diff --git a/src/components/features/automations/detail/configuration-section.tsx b/src/components/features/automations/detail/configuration-section.tsxindex 532200161d..32385a9215 100644--- a/src/components/features/automations/detail/configuration-section.tsx+++ b/src/components/features/automations/detail/configuration-section.tsx@@ -13,6 +13,7 @@ import BellIcon from "#/icons/bell.svg?react";import CodeTagIcon from "#/icons/code-tag.svg?react";import LinkExternalIcon from "#/icons/link-external.svg?react";import { formatEventOn } from "#/utils/automation-schedule";+import { parseGitRemoteUrl } from "#/utils/parse-git-remote-url";import { SectionCard } from "./section-card";import { ConfigField } from "./config-field";import { BranchBadge } from "./branch-badge";@@ -81,15 +82,25 @@ export function ConfigurationSection({title={t(I18nKey.AUTOMATIONS$DETAIL$CONFIGURATION)}><div className="grid grid-cols-2 gap-x-4 gap-y-5">- {automation.repository && (+ {automation.repositories && automation.repositories.length > 0 && (<ConfigFieldicon={<GitBranchIcon className="size-3.5" />}label={t(I18nKey.AUTOMATIONS$DETAIL$REPOSITORIES)}>- <span className="flex items-center gap-1">- {automation.repository}- {automation.branch && <BranchBadge branch={automation.branch} />}- </span>+ <ul className="flex flex-col gap-1">+ {automation.repositories.map(({ url, ref }) => (+ <li+ key={`${url}@${ref ?? ""}`}+ data-testid="automation-repository"+ className="flex flex-wrap items-center gap-1"+ >+ <span className="break-all">+ {parseGitRemoteUrl(url)?.repository ?? url}+ </span>+ {ref && <BranchBadge branch={ref} />}+ </li>+ ))}+ </ul></ConfigField>)}diff --git a/src/types/automation.ts b/src/types/automation.tsindex 3afbf6718b..2f1377ff69 100644--- a/src/types/automation.ts+++ b/src/types/automation.ts@@ -21,6 +21,17 @@ export interface AutomationTrigger {filter?: string;}+/**+ * A repository an automation clones before it runs, as the preset API stores+ * it in `preset_metadata.repos[]` (the SDK's `RepoSource`).+ */+export interface AutomationRepository {+ /** Full git URL, or the `owner/repo` shorthand. */+ url: string;+ /** Branch, tag or commit to check out; absent uses the default branch. */+ ref?: string;+}+export interface Automation {id: string;name: string;@@ -55,6 +66,11 @@ export interface Automation {* automations even without `manage_automations`.*/user_id?: string;+ /**+ * Single repository in the import/export file's shape. The automation+ * service does not return it; read `repositories` for what an automation+ * clones.+ */repository?: string;/** Saved agent profile controlling model, tools, and selected secrets. */agent_profile_id?: string | null;@@ -76,15 +92,27 @@ export interface Automation {*/entrypoint?: string;branch?: string;+ /**+ * Every repository the automation clones. The service layer derives it on+ * read from `preset_metadata.repos` (or the top-level `repository`/`branch`+ * when there is no metadata); the service has no top-level field for it.+ */+ repositories?: AutomationRepository[];+ /**+ * Plugin sources (e.g. `github:owner/repo`). The service layer fills it on+ * read from `preset_metadata.plugins[].source`; a record without that+ * metadata keeps its own list.+ */plugins?: string[];notification?: string;timezone?: string;last_triggered_at?: string | null;/**- * Service-owned preset state, returned verbatim. The GUI reads only the+ * Service-owned preset state, returned verbatim. The GUI reads the* `template` provenance block inside it ({id, version, config}, written at- * setup time), and only through the guarded helper in- * `#/utils/automation-catalog`.+ * setup time) only through the guarded helper in+ * `#/utils/automation-catalog`, and `repos`/`plugins` only through+ * `#/utils/automation-preset-sources`.*/preset_metadata?: Record<string, unknown> | null;}@@ -96,6 +124,7 @@ export type AutomationSpec = Omit<| "updated_at"| "last_triggered_at"| "preset_metadata"+ | "repositories"| "entrypoint"| "disabled_reason"| "disabled_detail"diff --git a/src/utils/automation-export.test.ts b/src/utils/automation-export.test.tsindex d6e06ca0ac..0b43f30492 100644--- a/src/utils/automation-export.test.ts+++ b/src/utils/automation-export.test.ts@@ -5,6 +5,7 @@ import {parseAutomationFile,serializeAutomation,} from "./automation-export";+import { withPresetSources } from "./automation-preset-sources";const cronAutomation: Automation = {id: "automation-1",@@ -54,6 +55,31 @@ describe("automation export files", () => {expect(exported.spec).not.toHaveProperty("last_triggered_at");});+ it("exports the repository, ref and plugins read from preset_metadata", () => {+ const exported = serializeAutomation(+ withPresetSources({+ ...cronAutomation,+ repository: undefined,+ branch: undefined,+ plugins: undefined,+ preset_metadata: {+ repos: [+ { url: "https://github.com/qa-example/qa-repo", ref: "main" },+ ],+ plugins: [{ source: "github:qa-example/qa-plugin" }],+ },+ }),+ );++ expect(exported.spec).toMatchObject({+ repository: "https://github.com/qa-example/qa-repo",+ branch: "main",+ plugins: ["github:qa-example/qa-plugin"],+ });+ expect(exported.spec).not.toHaveProperty("repositories");+ expect(parseAutomationFile(exported)).toEqual(exported.spec);+ });+it("round-trips event trigger fields", () => {const exported = serializeAutomation({...cronAutomation,diff --git a/src/utils/automation-export.ts b/src/utils/automation-export.tsindex 57224d3212..fdfbd14171 100644--- a/src/utils/automation-export.ts+++ b/src/utils/automation-export.ts@@ -153,15 +153,19 @@ function validateTrigger(export function serializeAutomation(a: Automation): AutomationExportFile {const timezone = a.timezone ?? a.trigger.timezone;+ // The file carries a single repository: the first one the automation clones.+ const [primaryRepository] = a.repositories ?? [];+ const repository = primaryRepository?.url ?? a.repository;+ const branch = primaryRepository ? primaryRepository.ref : a.branch;const spec: AutomationSpec = {name: a.name,trigger: { ...a.trigger },enabled: a.enabled,prompt: a.prompt,- ...(a.repository !== undefined && { repository: a.repository }),+ ...(repository !== undefined && { repository }),...(a.model !== undefined && { model: a.model }),...(a.timeout != null && { timeout: a.timeout }),- ...(a.branch !== undefined && { branch: a.branch }),+ ...(branch !== undefined && { branch }),...(a.plugins !== undefined && { plugins: [...a.plugins] }),...(a.notification !== undefined && { notification: a.notification }),...(timezone !== undefined && { timezone }),diff --git a/src/utils/automation-preset-sources.ts b/src/utils/automation-preset-sources.tsnew file mode 100644index 0000000000..00095330ec--- /dev/null+++ b/src/utils/automation-preset-sources.ts@@ -0,0 +1,70 @@+import type { Automation, AutomationRepository } from "#/types/automation";++type UnknownRecord = Record<string, unknown>;++function isRecord(value: unknown): value is UnknownRecord {+ return typeof value === "object" && value !== null && !Array.isArray(value);+}++function readRecords(value: unknown): UnknownRecord[] {+ return Array.isArray(value) ? value.filter(isRecord) : [];+}++function readNonEmptyString(value: unknown): string | undefined {+ return typeof value === "string" && value.trim().length > 0+ ? value+ : undefined;+}++function readPresetRepositories(+ metadata: UnknownRecord,+): AutomationRepository[] {+ return readRecords(metadata.repos).flatMap((repo) => {+ const url = readNonEmptyString(repo.url);+ if (!url) return [];+ const ref = readNonEmptyString(repo.ref);+ return [{ url, ...(ref && { ref }) }];+ });+}++function readPresetPlugins(metadata: UnknownRecord): string[] {+ return readRecords(metadata.plugins).flatMap((plugin) => {+ const source = readNonEmptyString(plugin.source);+ return source ? [source] : [];+ });+}++/**+ * The automation service keeps an automation's repositories and plugins only+ * inside `preset_metadata` (`repos: [{url, ref?, provider?}]`,+ * `plugins: [{source, ref?, repo_path?}]`); its response has no top-level+ * fields for them. Lift them onto the `repositories` and `plugins` fields the+ * UI reads, falling back to the top-level `repository`/`branch`/`plugins` a+ * record without that metadata may carry. Fields with nothing to show stay+ * absent.+ */+export function withPresetSources(automation: Automation): Automation {+ const metadata = isRecord(automation.preset_metadata)+ ? automation.preset_metadata+ : {};++ const presetRepositories = readPresetRepositories(metadata);+ const legacyRepositories: AutomationRepository[] = automation.repository+ ? [+ {+ url: automation.repository,+ ...(automation.branch && { ref: automation.branch }),+ },+ ]+ : [];+ const repositories =+ presetRepositories.length > 0 ? presetRepositories : legacyRepositories;++ const presetPlugins = readPresetPlugins(metadata);++ return {+ ...automation,+ ...(repositories.length > 0 && { repositories }),+ ...(presetPlugins.length > 0 && { plugins: presetPlugins }),+ };+}