Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(dead-code): stamp Grafana plugin modules beside plugin.json as reachability roots (#3060) (#3080)
Rishabh Mishra08b3989b2761
diff --git a/packages/core/src/repowise/core/ingestion/graph_warmups.py b/packages/core/src/repowise/core/ingestion/graph_warmups.pyindex 3784aca32..785f44904 100644--- a/packages/core/src/repowise/core/ingestion/graph_warmups.py+++ b/packages/core/src/repowise/core/ingestion/graph_warmups.py@@ -399,6 +399,7 @@ def _warmup_typescript(ctx: ResolverContext) -> None:being anywhere a reader enters."""from .resolvers.ts_workspace import (+ find_grafana_plugin_targets,find_mdx_import_targets,find_npm_script_entry_targets,find_vitest_include_targets,@@ -423,6 +424,9 @@ def _warmup_typescript(ctx: ResolverContext) -> None:entry_paths |= find_mdx_import_targets(ctx)with contextlib.suppress(Exception):entry_paths |= find_vitest_include_targets(ctx)+ # Grafana plugin entry files (module.ts/js beside plugin.json or in src/).+ with contextlib.suppress(Exception):+ entry_paths |= find_grafana_plugin_targets(ctx)# ``package.json`` ``scripts.*`` references: benchmark / bench-runner /# rollup-input paths that ship as live code but are never imported# by the main entry graph.diff --git a/packages/core/src/repowise/core/ingestion/resolvers/ts_workspace.py b/packages/core/src/repowise/core/ingestion/resolvers/ts_workspace.pyindex 66a8b66f1..378668716 100644--- a/packages/core/src/repowise/core/ingestion/resolvers/ts_workspace.py+++ b/packages/core/src/repowise/core/ingestion/resolvers/ts_workspace.py@@ -93,6 +93,7 @@ class _RepoFileScan:mdx_files: list[Path] = field(default_factory=list)vitest_configs: list[Path] = field(default_factory=list)package_jsons: list[Path] = field(default_factory=list)+ plugin_jsons: list[Path] = field(default_factory=list)def _scan_repo_files(repo_path: Path, *, prune_nested_git: bool = True) -> _RepoFileScan:@@ -114,6 +115,8 @@ def _scan_repo_files(repo_path: Path, *, prune_nested_git: bool = True) -> _Reposcan.vitest_configs.append(Path(dirpath) / fname)elif fname == "package.json":scan.package_jsons.append(Path(dirpath) / fname)+ elif fname == "plugin.json":+ scan.plugin_jsons.append(Path(dirpath) / fname)return scan@@ -1124,6 +1127,44 @@ def find_vitest_include_targets(ctx: ResolverContext) -> set[str]:return targets+# ---------------------------------------------------------------------------+# Grafana plugin entry detection+# ---------------------------------------------------------------------------++_GRAFANA_ENTRY_EXTS: tuple[str, ...] = (+ ".ts", ".tsx", ".js", ".jsx",+)+++def find_grafana_plugin_targets(ctx: ResolverContext) -> set[str]:+ """Return repo-relative paths for Grafana plugin module entry points.++ Grafana plugins are loaded by convention: Grafana reads ``plugin.json``+ and loads ``module.ts`` / ``module.tsx`` / ``module.js`` / ``module.jsx``+ located in the same directory or in a sibling ``src/`` directory.+ """+ if ctx.repo_path is None:+ return set()++ targets: set[str] = set()+ for plugin_file in _get_repo_scan(ctx).plugin_jsons:+ try:+ rel_dir = plugin_file.parent.relative_to(ctx.repo_path).as_posix()+ except ValueError:+ continue++ dir_prefix = "" if rel_dir == "." else f"{rel_dir}/"+ candidate_prefixes = (dir_prefix, f"{dir_prefix}src/")++ for prefix in candidate_prefixes:+ for ext in _GRAFANA_ENTRY_EXTS:+ candidate = f"{prefix}module{ext}"+ if candidate in ctx.path_set:+ targets.add(candidate)++ return targets++# ---------------------------------------------------------------------------# npm-script entry detection# ---------------------------------------------------------------------------diff --git a/tests/unit/ingestion/test_manifest_entry_points.py b/tests/unit/ingestion/test_manifest_entry_points.pyindex 95bd23c2a..74b72785f 100644--- a/tests/unit/ingestion/test_manifest_entry_points.py+++ b/tests/unit/ingestion/test_manifest_entry_points.py@@ -293,3 +293,30 @@ def test_exports_subpath_is_a_root_not_an_entry(tmp_path: Path) -> None:assert idx.graph.nodes["packages/lib/src/index.ts"]["is_entry_point"]util = idx.graph.nodes["packages/lib/src/util.ts"]assert util.get("is_reachability_root") and not util.get("is_entry_point")+++def test_grafana_plugin_module_is_reachable_root(tmp_path: Path) -> None:+ """Grafana plugin entry module beside plugin.json is stamped as reachability root."""+ repo = _write(+ tmp_path,+ {+ "package.json": json.dumps({"name": "demo", "main": "./public/app/index.ts"}),+ "public/app/index.ts": "export const boot = () => {};\n",+ "plugins/test-ds/plugin.json": json.dumps(+ {"type": "datasource", "name": "Test DS", "id": "test-ds"}+ ),+ "plugins/test-ds/module.ts": "import './datasource';\nexport const plugin = {};\n",+ "plugins/test-ds/datasource.ts": "export class DS {}\n",+ "plugins/sandbox-panel/plugin.json": json.dumps(+ {"type": "panel", "name": "Sandbox Panel"}+ ),+ "plugins/sandbox-panel/src/module.tsx": "export const plugin = {};\n",+ },+ )+ idx = _index(repo)+ assert is_file_reachable("plugins/test-ds/module.ts", idx.graph)+ assert is_file_reachable("plugins/test-ds/datasource.ts", idx.graph)+ assert is_file_reachable("plugins/sandbox-panel/src/module.tsx", idx.graph)+ assert idx.graph.nodes["plugins/test-ds/module.ts"].get("is_reachability_root")+ assert idx.graph.nodes["plugins/sandbox-panel/src/module.tsx"].get("is_reachability_root")+diff --git a/tests/unit/ingestion/test_ts_workspace_index.py b/tests/unit/ingestion/test_ts_workspace_index.pyindex 87b2a7673..9e17d4e25 100644--- a/tests/unit/ingestion/test_ts_workspace_index.py+++ b/tests/unit/ingestion/test_ts_workspace_index.py@@ -11,6 +11,7 @@ import networkx as nxfrom repowise.core.ingestion.resolvers.context import ResolverContextfrom repowise.core.ingestion.resolvers.ts_workspace import (build_ts_workspace_index,+ find_grafana_plugin_targets,find_mdx_import_targets,find_npm_script_entry_targets,find_vitest_include_targets,@@ -263,3 +264,68 @@ class TestNpmScriptEntryScanner:ctx = _ctx(tmp_path, [])# No source files referenced — empty set, no crashes from ``-`` tokens.assert find_npm_script_entry_targets(ctx) == set()+++class TestGrafanaPluginEntries:+ def test_module_beside_plugin_json_discovered(self, tmp_path: Path) -> None:+ _write(+ tmp_path,+ "e2e-playwright/test-plugins/grafana-test-datasource/plugin.json",+ '{"type":"datasource","name":"Test DS","id":"grafana-test-datasource"}',+ )+ _write(+ tmp_path,+ "e2e-playwright/test-plugins/grafana-test-datasource/module.ts",+ "export const plugin = {};\n",+ )+ _write(+ tmp_path,+ "e2e-playwright/test-plugins/grafana-test-datasource/datasource.ts",+ "export class TestDataSource {}\n",+ )+ ctx = _ctx(+ tmp_path,+ [+ "e2e-playwright/test-plugins/grafana-test-datasource/module.ts",+ "e2e-playwright/test-plugins/grafana-test-datasource/datasource.ts",+ ],+ )+ targets = find_grafana_plugin_targets(ctx)+ assert targets == {"e2e-playwright/test-plugins/grafana-test-datasource/module.ts"}++ def test_module_inside_src_discovered(self, tmp_path: Path) -> None:+ _write(+ tmp_path,+ "plugins/my-panel/plugin.json",+ '{"type":"panel","name":"My Panel","id":"my-panel"}',+ )+ _write(+ tmp_path,+ "plugins/my-panel/src/module.tsx",+ "export const plugin = {};\n",+ )+ ctx = _ctx(tmp_path, ["plugins/my-panel/src/module.tsx"])+ targets = find_grafana_plugin_targets(ctx)+ assert targets == {"plugins/my-panel/src/module.tsx"}++ def test_js_module_discovered(self, tmp_path: Path) -> None:+ _write(+ tmp_path,+ "plugins/legacy-panel/plugin.json",+ '{"type":"panel","name":"Legacy Panel"}',+ )+ _write(+ tmp_path,+ "plugins/legacy-panel/module.js",+ "define([], function() { return {}; });\n",+ )+ ctx = _ctx(tmp_path, ["plugins/legacy-panel/module.js"])+ targets = find_grafana_plugin_targets(ctx)+ assert targets == {"plugins/legacy-panel/module.js"}++ def test_module_without_plugin_json_not_targeted(self, tmp_path: Path) -> None:+ _write(tmp_path, "packages/core/src/module.ts", "export const x = 1;\n")+ ctx = _ctx(tmp_path, ["packages/core/src/module.ts"])+ targets = find_grafana_plugin_targets(ctx)+ assert targets == set()+