Add Neo4j-backed TypeScript analysis backend and formalize backend contracts#159
Open
rahlk wants to merge 6 commits into
Open
Add Neo4j-backed TypeScript analysis backend and formalize backend contracts#159rahlk wants to merge 6 commits into
rahlk wants to merge 6 commits into
Conversation
Signed-off-by: Rahul Krishna <rkrsn@ibm.com>
…analyzer-ts graph) Add TSNeo4jBackend, a drop-in alternative to the in-memory TSCodeanalyzer that answers the exact same get_* query surface (call graph, callers/callees, class hierarchy, call sites, decorators, symbol/method/field lookups, imports/exports/ variables, ...) by running Cypher over a live Neo4j graph instead of walking the pydantic / NetworkX structures. The graph is the one codeanalyzer-typescript emits with `--emit neo4j` (schema schema.neo4j.json). The backend can populate the database for you over Bolt (running the analyzer with --emit neo4j --neo4j-uri), or query a DB that is already loaded (build_db=False). Results are re-hydrated into the same cldk.models.typescript pydantic objects the in-memory backend returns; lossy fields inherent to the projection (collapsed comments/type-params, aggregated import edges, the three round-tripped CALLS tag keys) are reconstructed best-effort and documented inline. - cldk/analysis/typescript/neo4j/: backend, model reconstruction, Neo4jConnectionConfig. - TypeScriptAnalysis / CLDK.analysis: optional neo4j_config selects the backend; default behavior unchanged. - pyproject: optional `neo4j` extra for the driver. - tests: live-DB integration tests (skipped when no Neo4j reachable) mirroring the in-memory backend's sample-app expectations, plus no-DB backend-selection unit tests.
Extract TSAnalysisBackend (cldk/analysis/typescript/backend.py), an abstract base declaring the full 40-method query surface the TypeScriptAnalysis facade delegates to. Both backends now implement it: - TSCodeanalyzer (in-memory pydantic / NetworkX) - TSNeo4jBackend (Cypher over Neo4j) The facade<->backend relationship is now enforced by the type system and at instantiation time, instead of matching only by convention. Facade `backend` is typed against the ABC. Added a contract test asserting both backends subclass it, fully implement it, and preserve every method signature.
Mirror the TypeScript TSAnalysisBackend pattern for Java and Python, in
anticipation of Neo4j/Cypher backends for those languages too:
- cldk/analysis/java/backend.py: JavaAnalysisBackend (36-method surface);
JCodeanalyzer now subclasses it.
- cldk/analysis/python/backend.py: PythonAnalysisBackend (21-method surface);
PyCodeanalyzer now subclasses it.
Both facades type their `backend` attribute against the ABC, so a future
alternative backend can be selected without touching the facade. Added contract
tests for each (subclass, abstract/not-instantiable, fully-implemented, and that
the ABC covers every method the facade delegates to).
use_ray is already lifted all the way up (CLDK.analysis → PythonAnalysis → PyCodeanalyzer → AnalysisOptions.using_ray), but unlike use_codeql and cache_dir it had no regression test. Add test_use_ray_forwarded_through_facade mirroring the existing use_codeql guard, so the facade can't silently drop the flag.
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.
Summary
Adds a Neo4j-backed analysis backend for TypeScript and formalizes the façade↔backend contract across all three languages so additional backends can be dropped in cleanly.
The latest
codeanalyzer-typescriptcan emit its analysis graph to Neo4j (--emit neo4j, schemaschema.neo4j.json). This PR adds an SDK backend that answers the exact sameget_*query surface as the in-memory backend, but by running Cypher over that graph instead of walking the pydantic / NetworkX structures.What's included
Neo4j TypeScript backend (
cldk/analysis/typescript/neo4j/)TSNeo4jBackend— a drop-in alternative toTSCodeanalyzerimplementing the full query surface (call graph, callers/callees, class hierarchy, call sites, decorators, symbol/method/field lookups, imports/exports/variables, …) via Cypher.--emit neo4j --neo4j-uri), or query a DB that is already loaded (build_db=False).cldk.models.typescriptpydantic objects. Fields the projection inherently flattens (collapsed comments/type-params, aggregated import edges, the three round-trippedCALLStag keys) are reconstructed best-effort and documented inline.No
neo4j_config→ the existing in-memory backend, unchanged.Shared backend contracts (ABCs)
TSAnalysisBackend,JavaAnalysisBackend,PythonAnalysisBackend— abstract bases declaring each façade's backend surface. The existing backends (TSCodeanalyzer,JCodeanalyzer,PyCodeanalyzer) and the newTSNeo4jBackendsubclass them, so the relationship is enforced by the type system and at instantiation time rather than only by convention. This sets up equivalent Neo4j backends for Java/Python later.Misc
neo4jextra (pip install cldk[neo4j]) for the driver.use_rayis forwarded through the Python façade (parity with the existinguse_codeql/cache_dirguards).Notes
codeanalyzer-typescript0.4.0+; the SDK pydantic models may need a follow-up bump to accept its newerentrypointsfield for the in-memory path.Generated by Claude Code