feat(metrics): --exclude <segment> to drop test/vendor code from rankings (#234)#235
Conversation
…ings (#234) cgis metrics ranks the whole graph, so on a real backend test scaffolding drowns the architectural signal — dogfooded on owner-api the top bottleneck and top PageRank node were both test helpers, and 8/12 God classes were Test* classes. Add a repeatable --exclude <segment> option (CLI -x, plus the cgis_metrics MCP tool) that drops any node whose FQN contains the given dot-segment anywhere, so one `--exclude tests` removes both tests.* and domains.*.tests.* while keeping false-positives like domains.testservice. Threaded through all three sections (bottlenecks, God classes, PageRank — excluded nodes leave the PageRank propagation graph entirely). Opt-in; injection-safe via parameterized LIKE … ESCAPE with metacharacters escaped. On owner-api, `--exclude tests` swaps the test-helper ranking for the real load-bearing nodes: verify_resource_ownership (authz, in 33), enqueue_task, MetricsService, ReservationService, the validators. 4 new tests (segment match across sections, opt-in default, LIKE-metachar escaping). make format/lint/type-check/pytest/doc-coverage all green — 970 tests, mypy strict, doc 99.6%. Closes #234 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces an exclusion feature to the architectural metrics queries, allowing users to filter out specific FQN dot-segments (such as test or vendor scaffolding) from coupling bottlenecks, God classes, and PageRank metrics. This is exposed via the MCP server tool and a new --exclude (-x) CLI option. Feedback on the changes suggests hardening the SQL segment exclusion logic to deduplicate input segments and ignore empty or whitespace-only strings, preventing accidental exclusion of all nodes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Code review —
|
…nt (#235 review) Address PR #235 review (gemini-code-assist + cross-lane): - `_segment_exclusion` now dedupes via dict.fromkeys (order-preserving) and skips empty/whitespace-only segments — these yielded a '%..%' pattern that matches no real FQN (a silent no-op), so guard them explicitly for clarity. - Add the two requested tests: multi-segment AND-composition (drop if ANY segment matches) and the empty/whitespace no-op. 19 metric tests green, ruff + mypy strict clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Addressed in @gemini-code-assist (dedupe + skip empty/whitespace): applied your suggestion almost verbatim — One technical correction for the record: an empty segment didn't actually exclude all nodes. The pattern is @zaebee (multi-segment test gap + the
The case-sensitivity nit I left as-is (Python test dirs are lowercase by convention; a TS-mixed-case follow-up can revisit) — shout if you'd rather fold a 19 metric tests (4→6 new), full suite 972 green, ruff + mypy strict clean. |
|
Great work on finalizing these changes, @zaebee. The addition of the |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an exclusion feature (--exclude / -x) to filter out specific FQNs (such as test or vendor scaffolding) from architectural metrics, including coupling bottlenecks, God classes, and PageRank. The feedback suggests adding a guard clause to handle None values gracefully in the segment exclusion helper to prevent a potential TypeError.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…235 review) gemini re-review: guard the top of _segment_exclusion so an empty sequence short-circuits (reachable via the default ()) and a None caller can't reach dict.fromkeys(None). None is unreachable today (param is Sequence[str]; CLI passes [], MCP passes `exclude or []`), so this is belt-and-suspenders that also tidies the legitimate empty path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@gemini-code-assist applied in Rigor note: the Full suite green, ruff + mypy strict clean. |
|
|
The implementation looks excellent, @zaebee. The addition of the early-return guard in |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an exclusion feature to the architectural metrics tool, allowing users to filter out specific FQNs (such as test or vendor scaffolding) by dot-segments. This is implemented across the MCP server tool, the CLI, and the underlying DuckDB analyzer queries with proper SQL escaping to avoid injection and wildcard issues. Comprehensive unit tests have been added to verify the filtering behavior. I have no feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.



What
Closes #234. Adds a repeatable
--exclude <segment>option tocgis metrics(CLI
-x) and thecgis_metricsMCP tool. It drops any node whose FQN containsthe given dot-segment anywhere, so a single
--exclude testsremoves bothtop-level
tests.*and nesteddomains.*.tests.*, while keeping false-positiveslike
domains.testservice(substring, not a segment).Surfaced by dogfooding the metrics layer on Ownima's
owner-api(10 368 nodes):test scaffolding dominated every ranking and buried the real architecture.
Why
cgis metricsranks the whole graph. On a real backend that means:tests.utils.utils.random_lower_string(in 129)Test*classes, 8 of top-12Result on owner-api —
--exclude testsThe real load-bearing nodes finally surface.
Design
both at
tests.*and nested underdomains.*.tests.*; a prefix flag would missthe nested ones. Matches a whole dot-delimited component (
'.' || id || '.' LIKE '%.tests.%').propagation graph entirely (cleanest).
?params viaLIKE … ESCAPE '\'with
%/_/\escaped (a_in a segment matches literally, never as a wildcard).Tests
4 new (
tests/unit/test_metrics.py): segment match drops tests across all threesections + keeps the
testservicefalse-positive; opt-in default still showstests; LIKE-metacharacter escaping.
make format lint type-check pytest doc-coverageall green — 970 tests, mypy strict, doc 99.6%.🤖 Generated with Claude Code