Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(agents): let workspace members view runtime capabilities (MUL-4427) (#5281)

Jiayuan Zhang05d929858237
diff --git a/packages/views/agents/components/tabs/mcp-config-tab.test.tsx b/packages/views/agents/components/tabs/mcp-config-tab.test.tsx
index 9d3d1da46e..d56f4b1515 100644
--- a/packages/views/agents/components/tabs/mcp-config-tab.test.tsx
+++ b/packages/views/agents/components/tabs/mcp-config-tab.test.tsx
@@ -4,7 +4,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import type { Agent } from "@multica/core/types";
+import type { Agent, AgentRuntime } from "@multica/core/types";
+import { ApiError } from "@multica/core/api";
import { I18nProvider } from "@multica/core/i18n/react";
import enCommon from "../../../locales/en/common.json";
import enAgents from "../../../locales/en/agents.json";
@@ -12,6 +13,19 @@ import { McpConfigTab } from "./mcp-config-tab";
const TEST_RESOURCES = { en: { common: enCommon, agents: enAgents } };
+const mockRuntimeCapabilities = vi.hoisted(() => vi.fn());
+
+// The tab reads discovery through runtimeCapabilitiesOptions; existing tests
+// render with runtime={null} so the query stays disabled and never fires.
+vi.mock("@multica/core/runtimes", () => ({
+ runtimeCapabilitiesOptions: (runtimeId: string | null) => ({
+ queryKey: ["runtime-capabilities", runtimeId],
+ queryFn: () => mockRuntimeCapabilities(runtimeId),
+ enabled: Boolean(runtimeId),
+ retry: false,
+ }),
+}));
+
vi.mock("sonner", () => ({
toast: {
error: vi.fn(),
@@ -58,12 +72,13 @@ function TestShell({ children }: { children: React.ReactNode }) {
function renderTab(
overrides: Partial<Agent> = {},
onSave = vi.fn().mockResolvedValue(undefined),
+ runtime: AgentRuntime | null = null,
) {
const result = render(
<TestShell>
<McpConfigTab
agent={{ ...baseAgent, ...overrides }}
- runtime={null}
+ runtime={runtime}
onSave={onSave}
/>
</TestShell>,
@@ -71,6 +86,24 @@ function renderTab(
return { ...result, onSave };
}
+const onlineRuntime: AgentRuntime = {
+ id: "runtime-1",
+ workspace_id: "ws-1",
+ daemon_id: "daemon-1",
+ name: "Claude (Mac)",
+ runtime_mode: "local",
+ provider: "claude",
+ launch_header: "",
+ status: "online",
+ device_info: "Mac",
+ metadata: {},
+ owner_id: "user-1",
+ visibility: "private",
+ last_seen_at: null,
+ created_at: "2026-07-11T00:00:00Z",
+ updated_at: "2026-07-11T00:00:00Z",
+};
+
describe("McpConfigTab", () => {
beforeEach(() => vi.clearAllMocks());
@@ -214,4 +247,47 @@ describe("McpConfigTab", () => {
expect(screen.getByRole("button", { name: /add server/i })).toBeDisabled();
expect(onSave).not.toHaveBeenCalled();
});
+
+ it("lists inherited MCP servers discovered from the assigned runtime", async () => {
+ mockRuntimeCapabilities.mockResolvedValue({
+ skills: [],
+ supported: true,
+ mcpServers: [
+ { name: "linear", transport: "http", source: "User config", enabled: true },
+ ],
+ mcpSupported: true,
+ });
+
+ renderTab({}, undefined, onlineRuntime);
+
+ expect(await screen.findByText("linear")).toBeInTheDocument();
+ });
+
+ it("shows a permission notice when capability discovery is forbidden", async () => {
+ mockRuntimeCapabilities.mockRejectedValue(
+ new ApiError("insufficient permissions", 403, "Forbidden"),
+ );
+
+ renderTab({}, undefined, onlineRuntime);
+
+ expect(
+ await screen.findByText(
+ "You don't have permission to view this runtime's MCP servers.",
+ ),
+ ).toBeInTheDocument();
+ });
+
+ it("shows a retry notice when capability discovery fails", async () => {
+ mockRuntimeCapabilities.mockRejectedValue(
+ new Error("daemon did not respond within 3 minutes"),
+ );
+
+ renderTab({}, undefined, onlineRuntime);
+
+ expect(
+ await screen.findByText(
+ "Couldn't discover runtime MCP servers. Try again.",
+ ),
+ ).toBeInTheDocument();
+ });
});
diff --git a/packages/views/agents/components/tabs/mcp-config-tab.tsx b/packages/views/agents/components/tabs/mcp-config-tab.tsx
index b09ab67f29..b35d0be398 100644
--- a/packages/views/agents/components/tabs/mcp-config-tab.tsx
+++ b/packages/views/agents/components/tabs/mcp-config-tab.tsx
@@ -12,6 +12,7 @@ import {
} from "lucide-react";
import { useQuery } from "@tanstack/react-query";
import type { Agent, AgentRuntime } from "@multica/core/types";
+import { ApiError } from "@multica/core/api";
import { runtimeCapabilitiesOptions } from "@multica/core/runtimes";
import {
AlertDialog,
@@ -222,7 +223,14 @@ export function McpConfigTab({
text={t(($) => $.tab_body.mcp_config.runtime_discovering)}
/>
) : runtimeQuery.isError ? (
- <McpNotice text={t(($) => $.tab_body.mcp_config.runtime_failed)} />
+ <McpNotice
+ text={
+ runtimeQuery.error instanceof ApiError &&
+ runtimeQuery.error.status === 403
+ ? t(($) => $.tab_body.mcp_config.runtime_forbidden)
+ : t(($) => $.tab_body.mcp_config.runtime_failed)
+ }
+ />
) : runtimeQuery.data?.mcpSupported !== true ? (
<McpNotice
text={t(($) => $.tab_body.mcp_config.runtime_unsupported)}
diff --git a/packages/views/agents/components/tabs/skills-tab.test.tsx b/packages/views/agents/components/tabs/skills-tab.test.tsx
index 8c7ef03a5e..6d82e9c8ca 100644
--- a/packages/views/agents/components/tabs/skills-tab.test.tsx
+++ b/packages/views/agents/components/tabs/skills-tab.test.tsx
@@ -17,6 +17,22 @@ const mockSetAgentSkillEnabled = vi.hoisted(() => vi.fn());
const mockRemoveAgentSkill = vi.hoisted(() => vi.fn());
const mockRuntimeCapabilities = vi.hoisted(() => vi.fn());
+// ApiError mirrors the production export. The tab branches on
+// `instanceof ApiError` for the 403 permission notice, so the class identity
+// must match the one the mocked query rejects with.
+const { ApiError } = vi.hoisted(() => {
+ class ApiError extends Error {
+ status: number;
+ statusText: string;
+ constructor(message: string, status: number, statusText: string) {
+ super(message);
+ this.status = status;
+ this.statusText = statusText;
+ }
+ }
+ return { ApiError };
+});
+
vi.mock("@multica/core/hooks", () => ({
useWorkspaceId: () => "ws-1",
}));
@@ -29,6 +45,7 @@ vi.mock("@multica/core/api", () => ({
setAgentSkillEnabled: (...args: unknown[]) => mockSetAgentSkillEnabled(...args),
removeAgentSkill: (...args: unknown[]) => mockRemoveAgentSkill(...args),
},
+ ApiError,
}));
vi.mock("@multica/core/runtimes", () => ({
@@ -74,6 +91,24 @@ const agent: Agent = {
archived_by: null,
};
+const onlineRuntime: AgentRuntime = {
+ id: "runtime-1",
+ workspace_id: "ws-1",
+ daemon_id: "daemon-1",
+ name: "Codex (Mac)",
+ runtime_mode: "local",
+ provider: "codex",
+ launch_header: "",
+ status: "online",
+ device_info: "Mac",
+ metadata: {},
+ owner_id: "user-1",
+ visibility: "private",
+ last_seen_at: null,
+ created_at: "2026-07-11T00:00:00Z",
+ updated_at: "2026-07-11T00:00:00Z",
+};
+
function renderSkillsTab(
agentOverrides: Partial<Agent> = {},
runtime: AgentRuntime | null = null,
@@ -159,27 +194,36 @@ describe("SkillsTab", () => {
mcpServers: [],
mcpSupported: true,
});
- const runtime: AgentRuntime = {
- id: "runtime-1",
- workspace_id: "ws-1",
- daemon_id: "daemon-1",
- name: "Codex (Mac)",
- runtime_mode: "local",
- provider: "codex",
- launch_header: "",
- status: "online",
- device_info: "Mac",
- metadata: {},
- owner_id: "user-1",
- visibility: "private",
- last_seen_at: null,
- created_at: "2026-07-11T00:00:00Z",
- updated_at: "2026-07-11T00:00:00Z",
- };
-
- renderSkillsTab({}, runtime);
+
+ renderSkillsTab({}, onlineRuntime);
expect(await screen.findByText("Local review")).toBeInTheDocument();
expect(screen.getByText("Host-level review workflow")).toBeInTheDocument();
});
+
+ it("shows a permission notice when capability discovery is forbidden", async () => {
+ mockRuntimeCapabilities.mockRejectedValue(
+ new ApiError("insufficient permissions", 403, "Forbidden"),
+ );
+
+ renderSkillsTab({}, onlineRuntime);
+
+ expect(
+ await screen.findByText(
+ "You don't have permission to view this runtime's skills.",
+ ),
+ ).toBeInTheDocument();
+ });
+
+ it("shows a retry notice when capability discovery fails", async () => {
+ mockRuntimeCapabilities.mockRejectedValue(
+ new Error("daemon did not respond within 3 minutes"),
+ );
+
+ renderSkillsTab({}, onlineRuntime);
+
+ expect(
+ await screen.findByText("Couldn't discover runtime skills. Try again."),
+ ).toBeInTheDocument();
+ });
});
diff --git a/packages/views/agents/components/tabs/skills-tab.tsx b/packages/views/agents/components/tabs/skills-tab.tsx
index f84d480e27..439bb23d00 100644
--- a/packages/views/agents/components/tabs/skills-tab.tsx
+++ b/packages/views/agents/components/tabs/skills-tab.tsx
@@ -16,7 +16,7 @@ import type {
AgentRuntime,
RuntimeLocalSkillSummary,
} from "@multica/core/types";
-import { api } from "@multica/core/api";
+import { api, ApiError } from "@multica/core/api";
import { useWorkspaceId } from "@multica/core/hooks";
import { runtimeCapabilitiesOptions } from "@multica/core/runtimes";
import {
@@ -231,7 +231,14 @@ export function SkillsTab({
text={t(($) => $.tab_body.skills.runtime_discovering)}
/>
) : runtimeQuery.isError ? (
- <RuntimeNotice text={t(($) => $.tab_body.skills.runtime_failed)} />
+ <RuntimeNotice
+ text={
+ runtimeQuery.error instanceof ApiError &&
+ runtimeQuery.error.status === 403
+ ? t(($) => $.tab_body.skills.runtime_forbidden)
+ : t(($) => $.tab_body.skills.runtime_failed)
+ }
+ />
) : runtimeQuery.data?.supported !== true ? (
<RuntimeNotice text={t(($) => $.tab_body.skills.runtime_unsupported)} />
) : runtimeSkills.length === 0 ? (
diff --git a/packages/views/locales/en/agents.json b/packages/views/locales/en/agents.json
index b692db5791..07a8e90edf 100644
--- a/packages/views/locales/en/agents.json
+++ b/packages/views/locales/en/agents.json
@@ -392,7 +392,8 @@
"runtime_missing": "Assign a local runtime to discover inherited MCP servers.",
"runtime_offline": "The local runtime is offline. Reconnect it to refresh inherited MCP servers.",
"runtime_discovering": "Discovering MCP servers from the local runtime…",
- "runtime_failed": "Couldn't discover runtime MCP servers. Try again when the runtime is online.",
+ "runtime_failed": "Couldn't discover runtime MCP servers. Try again.",
+ "runtime_forbidden": "You don't have permission to view this runtime's MCP servers.",
"runtime_unsupported": "This runtime version cannot report its MCP inventory yet.",
"runtime_empty": "No MCP servers were found in the runtime's user configuration.",
"edit_aria": "Edit MCP server",
@@ -495,7 +496,8 @@
"runtime_missing": "Assign a local runtime to discover inherited skills.",
"runtime_offline": "The local runtime is offline. Reconnect it to refresh inherited skills.",
"runtime_discovering": "Discovering skills from the local runtime…",
- "runtime_failed": "Couldn't discover runtime skills. Try again when the runtime is online.",
+ "runtime_failed": "Couldn't discover runtime skills. Try again.",
+ "runtime_forbidden": "You don't have permission to view this runtime's skills.",
"runtime_unsupported": "This runtime does not expose local skills.",
"runtime_empty": "No local skills were found for this runtime.",
"detail_title": "Skill details",
diff --git a/packages/views/locales/ja/agents.json b/packages/views/locales/ja/agents.json
index fe2a301932..a8335cd429 100644
--- a/packages/views/locales/ja/agents.json
+++ b/packages/views/locales/ja/agents.json
@@ -374,6 +374,7 @@
"runtime_offline": "ローカルランタイムはオフラインです。再接続すると更新できます。",
"runtime_discovering": "ローカルランタイムから MCP サーバーを検出中…",
"runtime_failed": "ランタイムの MCP サーバーを検出できませんでした。",
+ "runtime_forbidden": "このランタイムの MCP サーバーを表示する権限がありません。",
"runtime_unsupported": "このランタイムバージョンはまだ MCP 一覧を報告できません。",
"runtime_empty": "ランタイムのユーザー設定に MCP サーバーが見つかりませんでした。",
"edit_aria": "MCP Server を編集",
@@ -476,6 +477,7 @@
"runtime_offline": "ローカルランタイムはオフラインです。再接続すると更新できます。",
"runtime_discovering": "ローカルランタイムからスキルを検出中…",
"runtime_failed": "ランタイムのスキルを検出できませんでした。",
+ "runtime_forbidden": "このランタイムのスキルを表示する権限がありません。",
"runtime_unsupported": "このランタイムはローカルスキルを公開していません。",
"runtime_empty": "このランタイムにローカルスキルが見つかりませんでした。",
"detail_title": "スキルの詳細",
diff --git a/packages/views/locales/ko/agents.json b/packages/views/locales/ko/agents.json
index cb432eb81c..cdcb796596 100644
--- a/packages/views/locales/ko/agents.json
+++ b/packages/views/locales/ko/agents.json
@@ -382,6 +382,7 @@
"runtime_offline": "로컬 런타임이 오프라인입니다. 다시 연결하면 새로고침할 수 있습니다.",
"runtime_discovering": "로컬 런타임에서 MCP 서버를 탐색하는 중…",
"runtime_failed": "런타임 MCP 서버를 탐색하지 못했습니다.",
+ "runtime_forbidden": "이 런타임의 MCP 서버를 볼 수 있는 권한이 없습니다.",
"runtime_unsupported": "이 런타임 버전은 아직 MCP 목록을 보고할 수 없습니다.",
"runtime_empty": "런타임 사용자 설정에서 MCP 서버를 찾지 못했습니다.",
"edit_aria": "MCP Server 편집",
@@ -484,6 +485,7 @@
"runtime_offline": "로컬 런타임이 오프라인입니다. 다시 연결하면 새로고침할 수 있습니다.",
"runtime_discovering": "로컬 런타임에서 스킬을 탐색하는 중…",
"runtime_failed": "런타임 스킬을 탐색하지 못했습니다.",
+ "runtime_forbidden": "이 런타임의 스킬을 볼 수 있는 권한이 없습니다.",
"runtime_unsupported": "이 런타임은 로컬 스킬을 제공하지 않습니다.",
"runtime_empty": "이 런타임에서 로컬 스킬을 찾지 못했습니다.",
"detail_title": "스킬 상세 정보",
diff --git a/packages/views/locales/zh-Hans/agents.json b/packages/views/locales/zh-Hans/agents.json
index 46ba33186f..b0e037712b 100644
--- a/packages/views/locales/zh-Hans/agents.json
+++ b/packages/views/locales/zh-Hans/agents.json
@@ -381,7 +381,8 @@
"runtime_missing": "请先分配一个本地运行时,以发现继承的 MCP Server。",
"runtime_offline": "本地运行时处于离线状态,重新连接后即可刷新继承的 MCP Server。",
"runtime_discovering": "正在从本地运行时发现 MCP Server…",
- "runtime_failed": "无法发现运行时 MCP Server,请在运行时在线后重试。",
+ "runtime_failed": "无法发现运行时 MCP Server,请重试。",
+ "runtime_forbidden": "没有权限查看该运行时的 MCP Server。",
"runtime_unsupported": "当前运行时版本暂时无法上报 MCP 清单。",
"runtime_empty": "运行时的用户配置中没有发现 MCP Server。",
"edit_aria": "编辑 MCP Server",
@@ -484,7 +485,8 @@
"runtime_missing": "请先分配一个本地运行时,以发现继承的 skill。",
"runtime_offline": "本地运行时处于离线状态,重新连接后即可刷新继承的 skill。",
"runtime_discovering": "正在从本地运行时发现 skill…",
- "runtime_failed": "无法发现运行时 skill,请在运行时在线后重试。",
+ "runtime_failed": "无法发现运行时 skill,请重试。",
+ "runtime_forbidden": "没有权限查看该运行时的 skill。",
"runtime_unsupported": "该运行时不支持本地 skill 发现。",
"runtime_empty": "该运行时中没有发现本地 skill。",
"detail_title": "Skill 详情",
diff --git a/packages/views/settings/components/preferences-tab.test.tsx b/packages/views/settings/components/preferences-tab.test.tsx
index 414a95375d..7f0ff3a3bd 100644
--- a/packages/views/settings/components/preferences-tab.test.tsx
+++ b/packages/views/settings/components/preferences-tab.test.tsx
@@ -1,5 +1,14 @@
import type { ReactNode } from "react";
-import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
+import {
+ describe,
+ it,
+ expect,
+ beforeAll,
+ beforeEach,
+ afterAll,
+ afterEach,
+ vi,
+} from "vitest";
import { render, screen, act, cleanup, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { I18nProvider } from "@multica/core/i18n/react";
@@ -202,6 +211,22 @@ describe("PreferencesTab — Language switcher", () => {
});
describe("PreferencesTab — Timezone section", () => {
+ // Shrink the picker to the curated COMMON_TIMEZONES fallback. With the
+ // real Intl.supportedValuesOf the popup renders ~600 options, and
+ // userEvent traversal of that list blew past the per-test timeout on
+ // slow CI runners (MUL-4427). Everything these tests pick — Asia/Tokyo
+ // and the "(browser)" sentinel — exists in the fallback list too.
+ const intlWithValues = Intl as typeof Intl & {
+ supportedValuesOf?: (key: "timeZone") => string[];
+ };
+ const realSupportedValuesOf = intlWithValues.supportedValuesOf;
+ beforeAll(() => {
+ intlWithValues.supportedValuesOf = () => [];
+ });
+ afterAll(() => {
+ intlWithValues.supportedValuesOf = realSupportedValuesOf;
+ });
+
beforeEach(() => {
vi.clearAllMocks();
userRef.current = null;
@@ -235,8 +260,7 @@ describe("PreferencesTab — Timezone section", () => {
});
// handleChange PATCHes then updates the store asynchronously, so the
- // post-pick assertions must waitFor it to settle. The extended timeout
- // covers querying the Select's full ~600-option IANA list on slow CI.
+ // post-pick assertions must waitFor it to settle.
it("saving a new timezone PATCHes /api/me and updates the auth store", async () => {
userRef.current = { id: "user-1", timezone: "Asia/Shanghai" };
const updatedUser = { id: "user-1", timezone: "Asia/Tokyo" };
@@ -251,7 +275,7 @@ describe("PreferencesTab — Timezone section", () => {
expect(mockSetUser).toHaveBeenCalledWith(updatedUser);
expect(mockToastSuccess).toHaveBeenCalledTimes(1);
});
- }, 20000);
+ });
it("surfaces a toast when the PATCH fails", async () => {
userRef.current = { id: "user-1", timezone: "Asia/Shanghai" };
@@ -266,7 +290,7 @@ describe("PreferencesTab — Timezone section", () => {
expect(mockToastError).toHaveBeenCalledTimes(1);
});
expect(mockSetUser).not.toHaveBeenCalled();
- }, 20000);
+ });
it("clearing the preference sends an empty-string timezone", async () => {
userRef.current = { id: "user-1", timezone: "Asia/Shanghai" };
@@ -285,5 +309,5 @@ describe("PreferencesTab — Timezone section", () => {
// so the picker switches back to "(browser)" without a refetch.
expect(mockSetUser).toHaveBeenCalledWith(clearedUser);
});
- }, 20000);
+ });
});
diff --git a/server/internal/handler/runtime_local_skills.go b/server/internal/handler/runtime_local_skills.go
index 5bf93db659..4ab4faf125 100644
--- a/server/internal/handler/runtime_local_skills.go
+++ b/server/internal/handler/runtime_local_skills.go
@@ -542,31 +542,51 @@ func runtimeLocalSkillRequestTerminal(status RuntimeLocalSkillRequestStatus) boo
status == RuntimeLocalSkillTimeout || status == RuntimeLocalSkillConflict
}
-func (h *Handler) requireRuntimeLocalSkillAccess(w http.ResponseWriter, r *http.Request, runtimeID string) (runtimeIDAndWorkspace, bool) {
+// requireRuntimeCapabilityReadAccess resolves the runtime and asserts the
+// caller is a member of its workspace. This is the read-level gate for
+// capability discovery (local skills + the redacted MCP inventory): the
+// payload is deliberately non-secret so any member viewing an agent can see
+// what it inherits from its runtime, regardless of who owns that runtime.
+// Flows that copy skill files off the owner's machine must use the stricter
+// requireRuntimeLocalSkillAccess instead.
+func (h *Handler) requireRuntimeCapabilityReadAccess(w http.ResponseWriter, r *http.Request, runtimeID string) (runtimeIDAndWorkspace, db.Member, bool) {
runtimeUUID, ok := parseUUIDOrBadRequest(w, runtimeID, "runtime_id")
if !ok {
- return runtimeIDAndWorkspace{}, false
+ return runtimeIDAndWorkspace{}, db.Member{}, false
}
rt, err := h.Queries.GetAgentRuntime(r.Context(), runtimeUUID)
if err != nil {
writeError(w, http.StatusNotFound, "runtime not found")
- return runtimeIDAndWorkspace{}, false
+ return runtimeIDAndWorkspace{}, db.Member{}, false
}
wsID := uuidToString(rt.WorkspaceID)
member, ok := h.requireWorkspaceMember(w, r, wsID, "runtime not found")
+ if !ok {
+ return runtimeIDAndWorkspace{}, db.Member{}, false
+ }
+
+ return runtimeIDAndWorkspace{
+ runtimeID: uuidToString(rt.ID),
+ workspaceID: wsID,
+ provider: rt.Provider,
+ status: rt.Status,
+ ownerID: uuidToString(rt.OwnerID),
+ }, member, true
+}
+
+// requireRuntimeLocalSkillAccess additionally requires the caller to own the
+// runtime. Import reads full skill file contents from the owner's machine, so
+// it stays owner-only even for workspace owners/admins.
+func (h *Handler) requireRuntimeLocalSkillAccess(w http.ResponseWriter, r *http.Request, runtimeID string) (runtimeIDAndWorkspace, bool) {
+ rt, member, ok := h.requireRuntimeCapabilityReadAccess(w, r, runtimeID)
if !ok {
return runtimeIDAndWorkspace{}, false
}
- if rt.OwnerID.Valid && uuidToString(rt.OwnerID) == uuidToString(member.UserID) {
- return runtimeIDAndWorkspace{
- runtimeID: uuidToString(rt.ID),
- workspaceID: wsID,
- provider: rt.Provider,
- status: rt.Status,
- }, true
+ if rt.ownerID != "" && rt.ownerID == uuidToString(member.UserID) {
+ return rt, true
}
writeError(w, http.StatusForbidden, "insufficient permissions")
@@ -578,11 +598,12 @@ type runtimeIDAndWorkspace struct {
workspaceID string
provider string
status string
+ ownerID string
}
func (h *Handler) InitiateListLocalSkills(w http.ResponseWriter, r *http.Request) {
runtimeID := chi.URLParam(r, "runtimeId")
- rt, ok := h.requireRuntimeLocalSkillAccess(w, r, runtimeID)
+ rt, _, ok := h.requireRuntimeCapabilityReadAccess(w, r, runtimeID)
if !ok {
return
}
@@ -601,7 +622,7 @@ func (h *Handler) InitiateListLocalSkills(w http.ResponseWriter, r *http.Request
func (h *Handler) GetLocalSkillListRequest(w http.ResponseWriter, r *http.Request) {
runtimeID := chi.URLParam(r, "runtimeId")
- rt, ok := h.requireRuntimeLocalSkillAccess(w, r, runtimeID)
+ rt, _, ok := h.requireRuntimeCapabilityReadAccess(w, r, runtimeID)
if !ok {
return
}
diff --git a/server/internal/handler/runtime_local_skills_test.go b/server/internal/handler/runtime_local_skills_test.go
index c2b16f0dfa..b5b92df68c 100644
--- a/server/internal/handler/runtime_local_skills_test.go
+++ b/server/internal/handler/runtime_local_skills_test.go
@@ -219,21 +219,95 @@ func TestInMemoryLocalSkillImportStore_TimesOutRunningRequests(t *testing.T) {
}
}
-func TestInitiateListLocalSkills_RequiresRuntimeOwner(t *testing.T) {
+// Capability discovery (list + poll) is readable by any workspace member so
+// the Agent capabilities surfaces work for agents bound to someone else's
+// runtime. Import stays owner-only (tests below).
+func TestListLocalSkills_AllowsNonOwnerWorkspaceMember(t *testing.T) {
if testHandler == nil {
t.Skip("database not available")
}
runtimeID := createRuntimeLocalSkillTestRuntime(t, testUserID)
- adminUserID := createRuntimeLocalSkillTestMember(t, "admin")
+ memberUserID := createRuntimeLocalSkillTestMember(t, "member")
w := httptest.NewRecorder()
req := withURLParams(
- newRequestAsUser(adminUserID, http.MethodPost, "/api/runtimes/"+runtimeID+"/local-skills", nil),
+ newRequestAsUser(memberUserID, http.MethodPost, "/api/runtimes/"+runtimeID+"/local-skills", nil),
"runtimeId", runtimeID,
)
testHandler.InitiateListLocalSkills(w, req)
+ if w.Code != http.StatusOK {
+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+
+ var initResp RuntimeLocalSkillListRequest
+ if err := json.NewDecoder(w.Body).Decode(&initResp); err != nil {
+ t.Fatalf("decode initiate response: %v", err)
+ }
+
+ w = httptest.NewRecorder()
+ pollReq := withURLParams(
+ newRequestAsUser(memberUserID, http.MethodGet, "/api/runtimes/"+runtimeID+"/local-skills/"+initResp.ID, nil),
+ "runtimeId", runtimeID,
+ "requestId", initResp.ID,
+ )
+
+ testHandler.GetLocalSkillListRequest(w, pollReq)
+ if w.Code != http.StatusOK {
+ t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+}
+
+func TestListLocalSkills_RejectsNonMember(t *testing.T) {
+ if testHandler == nil {
+ t.Skip("database not available")
+ }
+
+ runtimeID := createRuntimeLocalSkillTestRuntime(t, testUserID)
+
+ var outsiderID string
+ email := fmt.Sprintf("runtime-local-skills-outsider-%[email protected]", time.Now().UnixNano())
+ if err := testPool.QueryRow(context.Background(), `
+ INSERT INTO "user" (name, email)
+ VALUES ('Runtime Local Skills Outsider', $1)
+ RETURNING id
+ `, email).Scan(&outsiderID); err != nil {
+ t.Fatalf("create user: %v", err)
+ }
+ t.Cleanup(func() {
+ testPool.Exec(context.Background(), `DELETE FROM "user" WHERE id = $1`, outsiderID)
+ })
+
+ w := httptest.NewRecorder()
+ req := withURLParams(
+ newRequestAsUser(outsiderID, http.MethodPost, "/api/runtimes/"+runtimeID+"/local-skills", nil),
+ "runtimeId", runtimeID,
+ )
+
+ testHandler.InitiateListLocalSkills(w, req)
+ if w.Code != http.StatusNotFound {
+ t.Fatalf("expected 404, got %d: %s", w.Code, w.Body.String())
+ }
+}
+
+func TestInitiateImportLocalSkill_RequiresRuntimeOwner(t *testing.T) {
+ if testHandler == nil {
+ t.Skip("database not available")
+ }
+
+ runtimeID := createRuntimeLocalSkillTestRuntime(t, testUserID)
+ adminUserID := createRuntimeLocalSkillTestMember(t, "admin")
+
+ w := httptest.NewRecorder()
+ req := withURLParams(
+ newRequestAsUser(adminUserID, http.MethodPost, "/api/runtimes/"+runtimeID+"/local-skills/import", map[string]any{
+ "skill_key": "review-helper",
+ }),
+ "runtimeId", runtimeID,
+ )
+
+ testHandler.InitiateImportLocalSkill(w, req)
if w.Code != http.StatusForbidden {
t.Fatalf("expected 403, got %d: %s", w.Code, w.Body.String())
}