(tools: readonly ToolSummary[])
| 156 | // --------------------------------------------------------------------------- |
| 157 | |
| 158 | const buildTree = (tools: readonly ToolSummary[]): TreeNode => { |
| 159 | const root: TreeNode = { segment: "", path: "", children: new Map() }; |
| 160 | |
| 161 | for (const tool of tools) { |
| 162 | const parts = tool.name.split("."); |
| 163 | let node = root; |
| 164 | let path = ""; |
| 165 | for (const part of parts) { |
| 166 | path = path ? `${path}.${part}` : part; |
| 167 | let child = node.children.get(part); |
| 168 | if (!child) { |
| 169 | child = { segment: part, path, children: new Map() }; |
| 170 | node.children.set(part, child); |
| 171 | } |
| 172 | node = child; |
| 173 | } |
| 174 | node.tool = tool; |
| 175 | } |
| 176 | |
| 177 | return root; |
| 178 | }; |
| 179 | |
| 180 | const countLeaves = (node: TreeNode): number => { |
| 181 | let count = node.tool ? 1 : 0; |
no test coverage detected