Repository navigation
fix(analytics): locate the backend under the scan root instead of assuming its depth (#12853) - #12943
Merged
Merged
Conversation
…uming its depth (#12853) BackendEndpointScanner read routes from project_root/'api' and the router registry from project_root/'backend'/'initialization'/'router_registry'. Both assume a layout that no longer exists: this repo keeps the backend in autobot-backend/, so the route scan found 0 endpoints and the registry path matched nothing, leaving every endpoint without its router prefix. Zero endpoints is what made the report claim thousands of missing endpoints -- with an empty map, every frontend call matches nothing. find_backend_dir() now locates the backend under the scan root, preferring a candidate that also carries the router registry so a stray api/ directory cannot win, and falling back to the root unchanged. The registry is read from the resolved backend, and every *_routers.py there is parsed rather than a hand-maintained list that had already missed integration_routers.py. Measured against the repo root: 0 -> 1986 endpoints, prefix map 16 -> 871, 1736 of 2159 real app.openapi() paths matched (80.4%).
Contributor
✅ SSOT Configuration Compliance: Passing🎉 No hardcoded values detected that have SSOT config equivalents! |
This was referenced Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12944. Refs #12853 — which stays open for the remaining coverage gap and live per-source validation (see "What remains").
Thinking Path
#12853 attributes the 0-route scan to
resolve_project_root()returning the deployed tree rather than the analyzed source, and proposes wiring the scan to the source's indexed tree. I checked that premise first, and the wiring already exists:resolve_source_root(source_id)returnssource.clone_path,_build_analysis_tasksthreads it asscan_root, and_get_api_endpoint_analysis(project_root=scan_root)passes it to the scanner (#12372). Handing the scanner a correct root would not have fixed anything.The actual defect is what the scanner does with the root. It looks for routes at
project_root / "api"and for the router registry atproject_root / "backend" / "initialization" / "router_registry". Neither exists in this repo — the backend isautobot-backend/:Running the unmodified scanner at two roots isolates it — the root is fine, the assumed depth is not:
That is the whole "0 of ~2156 routes" symptom: with an empty endpoint map every frontend call matches nothing, which is what produced the ~2400 "missing endpoints" that were 97% false.
A second defect surfaced while confirming the first. The registry path is built from a different wrong assumption (
project_root/"backend"/…), so it resolves nowhere in any layout — even when the route scan works:So endpoints were being recorded without their router prefixes, meaning even a populated map would mismatch against frontend calls. Fixing the route path alone would have left the report wrong in a subtler way. While fixing it I also found
integration_routers.pyabsent from the hand-maintainedconfig_tuple_fileslist, so its routers carried no prefix either.What Changed
api/codebase_analytics/api_endpoint_scanner.py:find_backend_dir(project_root), which resolves the backend amongautobot-backend/,backend/, and the root itself. It prefers a candidate that also holdsinitialization/router_registry, so a directory that merely happens to containapi/cannot win, and falls back to the root unchanged — callers already pointing at the backend are unaffected.backend_pathand the router-registry path both derive from that resolved directory.*_routers.py) instead of hand-maintained, which picks upintegration_routers.pyand anything added later.api_endpoint_scanner_test.py: 7 tests — nested layout, backend-at-root, decoyapi/losing to the registry-bearing candidate, unrecognised-layout fallback, the scanner pointing at the nested backend, the registry resolving under the backend, and every*_routers.pybeing parsed.Verification
Scanning from the repo root (the case that previously returned nothing), before → after:
/api/Cross-checked against the authoritative table from
app.openapi()(2159 unique normalized paths):What remains
The issue's acceptance criteria are not fully met, so this does not close it:
app.openapi()does not expose — prefix reconstruction is still imperfect for some routers.source_id→ indexed-tree case on a real instance, and confirmingscan_errorstays empty) is untouched here — I verified against this checkout, not a running instance.file: "?"/method: UNKNOWNloss noted at the end of bug(analytics): backend endpoint scan resolves /opt/autobot, not the analyzed source — finds 0 of ~2156 routes #12853 is a separate path and not addressed.This PR fixes the primary defect and makes those remaining numbers measurable rather than hidden behind a zero.
Model Used
claude-opus-5