fix(skills): distinguish marketplace installation sources
This commit is contained in:
1 parent
6a4bb4d270
commit
70eca8343b
17 files changed
+518
-135
No files matched your search
@@ -5,11 +5,15 @@ import { SkillsMarketplace } from "@/components/settings/SkillsMarketplace";
|
||||
import { SkillsCatalogSettings } from "@/components/settings/SkillsCatalogSettings";
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
import {
|
||||
ApiError,
|
||||
fetchMarketplaceSkillTrends,
|
||||
fetchSkills,
|
||||
fetchTrendingMarketplaceSkills,
|
||||
installMarketplaceSkill,
|
||||
searchMarketplaceSkills,
|
||||
} from "@/lib/api";
|
||||
import type { NanobotClient } from "@/lib/nanobot-client";
|
||||
import type { MarketplaceSkillSummary } from "@/lib/types";
|
||||
import { requestSkillsRefresh, SKILLS_CHANGED_EVENT } from "@/lib/skill-events";
|
||||
import { ClientProvider } from "@/providers/ClientProvider";
|
||||
import { useSkills } from "@/hooks/useSkills";
|
||||
@@ -19,7 +23,9 @@ vi.mock("@/lib/api", async (importOriginal) => {
|
||||
return {
|
||||
...actual,
|
||||
fetchSkills: vi.fn(),
|
||||
fetchMarketplaceSkillTrends: vi.fn(),
|
||||
fetchTrendingMarketplaceSkills: vi.fn(),
|
||||
installMarketplaceSkill: vi.fn(),
|
||||
searchMarketplaceSkills: vi.fn(),
|
||||
};
|
||||
});
|
||||
@@ -243,6 +249,8 @@ describe("useSkills", () => {
|
||||
describe("SkillsMarketplace", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.mocked(fetchMarketplaceSkillTrends).mockReset().mockResolvedValue({ trends: {} });
|
||||
vi.mocked(installMarketplaceSkill).mockReset();
|
||||
vi.mocked(fetchTrendingMarketplaceSkills).mockReset().mockResolvedValue({
|
||||
period: "mixed",
|
||||
provider: "all",
|
||||
@@ -263,6 +271,76 @@ describe("SkillsMarketplace", () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
const originSkill = (source: string, status?: MarketplaceSkillSummary["installation_status"]): MarketplaceSkillSummary => ({
|
||||
id: `${source}/agent-browser`, skill_id: "agent-browser", name: "agent-browser",
|
||||
source, provider: "skills_sh", installs: 42, url: `https://skills.sh/${source}/agent-browser`,
|
||||
installed: status === "installed", installation_status: status,
|
||||
install_supported: true, metric: "installs_total",
|
||||
});
|
||||
|
||||
it("shows source matches, conflicts and unconfirmed legacy hosts without inferring from local names", async () => {
|
||||
vi.mocked(fetchTrendingMarketplaceSkills).mockResolvedValue({
|
||||
period: "mixed", provider: "all", install_supported: true,
|
||||
skills: [
|
||||
originSkill("vercel-labs/agent-browser", "installed"),
|
||||
originSkill("101-skills/superpowers", "conflict"),
|
||||
originSkill("local/unknown", "unknown"),
|
||||
{ ...originSkill("legacy/host"), installed: true },
|
||||
originSkill("new/source", "available"),
|
||||
],
|
||||
});
|
||||
render(<ClientProvider client={client} token="tok"><SkillsMarketplace
|
||||
installedSkills={[{ name: "agent-browser", source: "workspace", description: "Local", available: true }]}
|
||||
installing="" onInstallingChange={vi.fn()}
|
||||
/></ClientProvider>);
|
||||
await act(async () => {});
|
||||
expect(screen.getAllByRole("button", { name: "Installed agent-browser" })).toHaveLength(1);
|
||||
expect(screen.getAllByRole("button", { name: "Name already in use agent-browser" })).toHaveLength(3);
|
||||
expect(screen.getAllByText("Installed source unknown")).toHaveLength(2);
|
||||
const available = screen.getByRole("button", { name: "Install agent-browser" });
|
||||
expect(available).toBeEnabled();
|
||||
fireEvent.click(available);
|
||||
expect(screen.getByRole("alertdialog")).toHaveTextContent("new/source");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
expect(installMarketplaceSkill).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("refreshes server identity after installation instead of marking every same-name result", async () => {
|
||||
const response = (installed: boolean) => ({
|
||||
period: "mixed" as const, provider: "all" as const, install_supported: true,
|
||||
skills: [originSkill("vercel-labs/agent-browser", installed ? "installed" : "available"),
|
||||
originSkill("101-skills/superpowers", installed ? "conflict" : "available")],
|
||||
});
|
||||
vi.mocked(fetchTrendingMarketplaceSkills).mockResolvedValueOnce(response(false)).mockResolvedValue(response(true));
|
||||
vi.mocked(installMarketplaceSkill).mockResolvedValue({
|
||||
skills: [], last_action: { name: "agent-browser", installed: true, already_installed: false },
|
||||
});
|
||||
render(marketplace("tok"));
|
||||
await act(async () => {});
|
||||
fireEvent.click(screen.getAllByRole("button", { name: "Install agent-browser" })[0]);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Install skill" }));
|
||||
await act(async () => {});
|
||||
expect(installMarketplaceSkill).toHaveBeenCalledWith(client, "skills_sh", "vercel-labs/agent-browser", "agent-browser", undefined);
|
||||
expect(screen.getAllByRole("button", { name: "Installed agent-browser" })).toHaveLength(1);
|
||||
expect(screen.getByRole("button", { name: "Name already in use agent-browser" })).toBeDisabled();
|
||||
});
|
||||
|
||||
it("keeps a localized conflict error visible after refreshing a stale search result", async () => {
|
||||
vi.mocked(searchMarketplaceSkills).mockResolvedValue({
|
||||
query: "browser", provider: "all", install_supported: true,
|
||||
skills: [originSkill("vercel-labs/agent-browser", "available")],
|
||||
});
|
||||
vi.mocked(installMarketplaceSkill).mockRejectedValue(new ApiError(409, "a skill with this name already exists"));
|
||||
render(marketplace("tok"));
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "Search skills" }), { target: { value: "browser" } });
|
||||
await act(async () => { await vi.advanceTimersByTimeAsync(300); });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Install agent-browser" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Install skill" }));
|
||||
await act(async () => { await vi.advanceTimersByTimeAsync(300); });
|
||||
expect(screen.getByRole("alert")).toHaveTextContent("Installation conflict.");
|
||||
expect(screen.queryByRole("button", { name: "Installed agent-browser" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows discovery skeletons while trending or the first search is pending and keeps loaded search results", async () => {
|
||||
const skill = {
|
||||
id: "skillhub:react-testing", skill_id: "react-testing", name: "React Testing",
|
||||
|
||||
Reference in new issue
Block a user