summaryrefslogtreecommitdiffhomepage
path: root/src/features/plugins/logic/last-provider.test.ts
blob: f85ba8925039dd312a5eed18a741c09fc88b53ca (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
68
69
70
import { describe, expect, it } from "vitest";
import { isLastProvider, unloadBlockReason } from "./last-provider";
import { node } from "./test-fixtures";

describe("isLastProvider", () => {
  it("is true for a loaded provider when it is the only one", () => {
    const nodes = [node({ id: "opencode", tier: "providers" })];
    expect(isLastProvider("opencode", nodes)).toBe(true);
  });

  it("is false for a loaded provider when another provider is loaded", () => {
    const nodes = [
      node({ id: "opencode", tier: "providers" }),
      node({ id: "kimi", tier: "providers" }),
    ];
    expect(isLastProvider("opencode", nodes)).toBe(false);
  });

  it("is false for a non-provider target (even when alone)", () => {
    const nodes = [node({ id: "solo", tier: "standard" })];
    expect(isLastProvider("solo", nodes)).toBe(false);
  });

  it("is false for an UNLOADED provider", () => {
    const nodes = [node({ id: "opencode", tier: "providers", loaded: false })];
    expect(isLastProvider("opencode", nodes)).toBe(false);
  });

  it("is false for an unknown id", () => {
    expect(isLastProvider("ghost", [])).toBe(false);
  });

  it("is false for a core-only list (no providers at all)", () => {
    const nodes = [node({ id: "kernel", tier: "core", locked: true })];
    expect(isLastProvider("kernel", nodes)).toBe(false);
  });
});

describe("unloadBlockReason", () => {
  it("explains the core lock", () => {
    const nodes = [node({ id: "kernel", tier: "core", locked: true })];
    const reason = unloadBlockReason("kernel", nodes);
    expect(reason).toContain("Core plugins cannot be unloaded");
  });

  it("explains the last-provider lock", () => {
    const nodes = [node({ id: "opencode", tier: "providers" })];
    const reason = unloadBlockReason("opencode", nodes);
    expect(reason).toContain("last provider");
  });

  it("is null for an interactive row", () => {
    const nodes = [
      node({ id: "opencode", tier: "providers" }),
      node({ id: "kimi", tier: "providers" }),
      node({ id: "app" }),
    ];
    expect(unloadBlockReason("app", nodes)).toBeNull();
    expect(unloadBlockReason("opencode", nodes)).toBeNull();
  });

  it("prefers the core lock when both would apply", () => {
    const nodes = [node({ id: "kernel", tier: "core", locked: true })];
    expect(unloadBlockReason("kernel", nodes)).toContain("Core");
  });

  it("is null for an unknown id", () => {
    expect(unloadBlockReason("ghost", [])).toBeNull();
  });
});