summaryrefslogtreecommitdiffhomepage
path: root/src/features/plugins/logic/workspace-row.test.ts
blob: 4c7d29e35dcac8f600210af413ea0cddc8c9dc9b (plain)
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
import type { WorkspacePluginRow } from "@dispatch/transport-contract";
import { describe, expect, it } from "vitest";
import { rowBlockReason, rowChecked, rowSelectable, stateLabel } from "./workspace-row";

function row(overrides: Partial<WorkspacePluginRow> = {}): WorkspacePluginRow {
  return {
    pluginId: "mcp",
    tier: "standard",
    state: "undefined",
    loaded: true,
    locked: false,
    ...overrides,
  };
}

describe("rowChecked", () => {
  it("is true only for an explicit enabled record", () => {
    expect(rowChecked(row({ state: "enabled" }))).toBe(true);
    expect(rowChecked(row({ state: "disabled" }))).toBe(false);
    expect(rowChecked(row({ state: "undefined" }))).toBe(false);
  });
});

describe("rowSelectable", () => {
  it("is true for a loaded, unlocked row (all three states)", () => {
    for (const state of ["enabled", "disabled", "undefined"] as const) {
      expect(rowSelectable(row({ state }))).toBe(true);
    }
  });

  it("is false for an UNLOADED plugin (§7 strict layering — greyed out)", () => {
    expect(rowSelectable(row({ loaded: false, state: "disabled" }))).toBe(false);
  });

  it("is false for a LOCKED (core) row — the server refuses the PUT (409)", () => {
    expect(rowSelectable(row({ tier: "core", locked: true, state: "enabled" }))).toBe(false);
  });
});

describe("rowBlockReason", () => {
  it("points at the global manager for unloaded plugins", () => {
    const reason = rowBlockReason(row({ loaded: false }));
    expect(reason).toContain("plugin manager");
  });

  it("explains the core lock", () => {
    const reason = rowBlockReason(row({ tier: "core", locked: true }));
    expect(reason).toContain("Core plugins are enabled by default");
  });

  it("prefers the unloaded reason when both apply", () => {
    const reason = rowBlockReason(row({ loaded: false, tier: "core", locked: true }));
    expect(reason).toContain("plugin manager");
  });

  it("is null for an interactive row", () => {
    expect(rowBlockReason(row())).toBeNull();
  });
});

describe("stateLabel", () => {
  it("renders the three wire states in a uniform grammar", () => {
    expect(stateLabel("enabled")).toBe("enabled");
    expect(stateLabel("disabled")).toBe("disabled");
    expect(stateLabel("undefined")).toBe("not set");
  });
});