File size: 4,782 Bytes
fd2c364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { describe, expect, it } from "vitest";
import {
  buildPluginsViewModel,
  matchesPluginStatus,
} from "#/components/features/plugins/build-plugins-view-model";
import type { MarketplacePlugin, LocalPlugin } from "#/api/plugins-service";
import type { InstalledPluginInfo } from "#/api/plugins-management-service";

const catalogPlugin: MarketplacePlugin = {
  name: "demo-plugin",
  description: "Catalog description",
  source: "github:OpenHands/extensions",
  ref: null,
  repo_path: "plugins/demo-plugin",
  installed: false,
};

const installedPlugin: InstalledPluginInfo = {
  name: "demo-plugin",
  version: "2.0.0",
  description: "Installed description",
  enabled: false,
  source: "github:OpenHands/extensions",
  resolved_ref: "main",
  repo_path: "plugins/demo-plugin",
  installed_at: "2026-06-01T00:00:00Z",
  install_path: "/home/.openhands/plugins/installed/demo-plugin",
};

const localPlugin: LocalPlugin = {
  name: "ambient-plugin",
  version: "1.0.0",
  description: "Ambient description",
};

describe("buildPluginsViewModel", () => {
  it("merges a plugin present in both the catalog and the installed list into one installed entry", () => {
    const result = buildPluginsViewModel([catalogPlugin], [installedPlugin]);

    expect(result).toHaveLength(1);
    expect(result[0]).toMatchObject({
      name: "demo-plugin",
      installed: true,
      inCatalog: true,
      enabled: false,
      version: "2.0.0",
    });
  });

  it("marks a catalog-only plugin as not installed", () => {
    const result = buildPluginsViewModel([catalogPlugin], []);

    expect(result).toHaveLength(1);
    expect(result[0]).toMatchObject({
      name: "demo-plugin",
      installed: false,
      inCatalog: true,
    });
  });

  it("keeps an installed plugin that is absent from the catalog", () => {
    const result = buildPluginsViewModel([], [installedPlugin]);

    expect(result).toHaveLength(1);
    expect(result[0]).toMatchObject({
      name: "demo-plugin",
      installed: true,
      inCatalog: false,
      enabled: false,
    });
  });

  it("adds a locally-discovered plugin as a read-only local entry", () => {
    const result = buildPluginsViewModel([], [], [localPlugin]);

    expect(result).toHaveLength(1);
    expect(result[0]).toMatchObject({
      name: "ambient-plugin",
      isLocal: true,
      installed: false,
      inCatalog: false,
      version: "1.0.0",
    });
  });

  it("does not add a separate local entry when the plugin is already installed", () => {
    const result = buildPluginsViewModel(
      [],
      [installedPlugin],
      [{ ...localPlugin, name: installedPlugin.name }],
    );

    expect(result).toHaveLength(1);
    expect(result[0]).toMatchObject({
      name: "demo-plugin",
      installed: true,
      isLocal: false,
    });
  });

  it("classifies a local plugin under the local filter and not the available filter", () => {
    const [local] = buildPluginsViewModel([], [], [localPlugin]);

    expect(matchesPluginStatus(local, "local")).toBe(true);
    expect(matchesPluginStatus(local, "available")).toBe(false);
  });

  it("prefers the installed copy's contents over the catalog's", () => {
    const result = buildPluginsViewModel(
      [
        {
          ...catalogPlugin,
          path: "/cache/plugins/demo-plugin",
          skills: [{ name: "catalog-skill" }],
          files: ["catalog.md"],
        },
      ],
      [
        {
          ...installedPlugin,
          skills: [{ name: "installed-skill" }],
          files: ["installed.md"],
        },
      ],
    );

    expect(result[0]).toMatchObject({
      path: installedPlugin.install_path,
      skills: [{ name: "installed-skill" }],
      files: ["installed.md"],
    });
  });

  it("falls back to the catalog's contents when the installed entry has none", () => {
    const result = buildPluginsViewModel(
      [
        {
          ...catalogPlugin,
          path: "/cache/plugins/demo-plugin",
          skills: [{ name: "catalog-skill" }],
          files: ["catalog.md"],
        },
      ],
      [installedPlugin],
    );

    expect(result[0]).toMatchObject({
      path: "/cache/plugins/demo-plugin",
      skills: [{ name: "catalog-skill" }],
      files: ["catalog.md"],
    });
  });

  it("carries a local plugin's contents into its entry", () => {
    const result = buildPluginsViewModel(
      [],
      [],
      [
        {
          ...localPlugin,
          path: "/home/.agents/plugins/ambient-plugin",
          skills: [{ name: "ambient-skill" }],
          files: ["SKILL.md"],
        },
      ],
    );

    expect(result[0]).toMatchObject({
      path: "/home/.agents/plugins/ambient-plugin",
      skills: [{ name: "ambient-skill" }],
      files: ["SKILL.md"],
    });
  });
});