File size: 3,582 Bytes
3201ca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { describe, expect, it } from "vitest";
import type { Automation } from "#/types/automation";
import type { SkillInfo } from "#/types/settings";
import {
  CONVERSATION_OVERVIEW_PROJECT_SCOPE,
  countAutomationsForRepository,
  countSkillsForProject,
  filterAutomationsByProjectScope,
  filterSkillsByProjectScope,
  isAutomationForRepository,
  sortAutomationsByProjectRelevance,
  sortSkillsByProjectRelevance,
} from "#/utils/conversation-overview-project-scope";

function buildAutomation(
  overrides: Partial<Automation> & Pick<Automation, "id" | "name">,
): Automation {
  return {
    trigger: { type: "cron", schedule: "0 * * * *" },
    enabled: true,
    created_at: "2026-01-01T00:00:00Z",
    updated_at: "2026-01-01T00:00:00Z",
    prompt: null,
    ...overrides,
  };
}

function buildSkill(
  overrides: Partial<SkillInfo> & Pick<SkillInfo, "name">,
): SkillInfo {
  return {
    type: "knowledge",
    source: "public",
    description: null,
    triggers: [],
    license: null,
    compatibility: null,
    metadata: null,
    allowed_tools: null,
    is_agentskills_format: true,
    disable_model_invocation: false,
    ...overrides,
  };
}

describe("conversation overview project scope", () => {
  it("matches automations to the open repository case-insensitively", () => {
    expect(
      isAutomationForRepository(
        buildAutomation({
          id: "1",
          name: "A",
          repository: "OpenHands/Agent-Canvas.git",
        }),
        "openhands/agent-canvas",
      ),
    ).toBe(true);
    expect(
      isAutomationForRepository(
        buildAutomation({ id: "2", name: "B", repository: "other/repo" }),
        "openhands/agent-canvas",
      ),
    ).toBe(false);
    expect(
      isAutomationForRepository(
        buildAutomation({ id: "3", name: "C" }),
        "openhands/agent-canvas",
      ),
    ).toBe(false);
  });

  it("filters and sorts automations for project vs all scopes", () => {
    const automations = [
      buildAutomation({ id: "1", name: "Zeta", repository: "other/repo" }),
      buildAutomation({
        id: "2",
        name: "Alpha",
        repository: "openhands/agent-canvas",
      }),
      buildAutomation({
        id: "3",
        name: "Beta",
        repository: "openhands/agent-canvas",
      }),
    ];

    expect(
      filterAutomationsByProjectScope(
        automations,
        CONVERSATION_OVERVIEW_PROJECT_SCOPE.project,
        "openhands/agent-canvas",
      ).map((automation) => automation.id),
    ).toEqual(["2", "3"]);

    expect(
      sortAutomationsByProjectRelevance(
        automations,
        "openhands/agent-canvas",
      ).map((automation) => automation.name),
    ).toEqual(["Alpha", "Beta", "Zeta"]);

    expect(
      countAutomationsForRepository(automations, "openhands/agent-canvas"),
    ).toBe(2);
  });

  it("filters and sorts skills with project skills first", () => {
    const skills = [
      buildSkill({ name: "public-z", source: "public" }),
      buildSkill({ name: "project-a", source: "project" }),
      buildSkill({ name: "personal-b", source: "user" }),
    ];

    expect(
      filterSkillsByProjectScope(
        skills,
        CONVERSATION_OVERVIEW_PROJECT_SCOPE.project,
        "/workspace/demo",
      ).map((skill) => skill.name),
    ).toEqual(["project-a"]);

    expect(
      sortSkillsByProjectRelevance(skills, "/workspace/demo").map(
        (skill) => skill.name,
      ),
    ).toEqual(["project-a", "personal-b", "public-z"]);

    expect(countSkillsForProject(skills, "/workspace/demo")).toBe(1);
  });
});