fix(utils): avoid module import binding conflicts #2498
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.47) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 286 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.339
Real PR Conversation Timeline
1 comments
"Review active on #2498"
general
weight: 0.35
kamilmysliwiec
PR Checklist
PR Type
What is the current behavior?
Generating a service or another module declaration can add an import whose local identifier is already bound, resulting in duplicate identifier errors or module metadata referencing the wrong class.
Previous attempts in #2486 and #2495 addressed import duplication but were closed after review identified problems with aliases, type-only imports, different module paths, and comments.
This PR follows the AST-based approach suggested in the [review of #2495](https://github.com/nestjs/schematics/pull/2495#issuecomment-6141699618).
Issue Number: N/A (follow-up to #2486 and #2495)
What is the new behavior?
ModuleImportDeclaratoruses the TypeScript AST to inspect existing imports and local declarations before adding a generated import.Import reuse is based on the generated module path and safe local bindings, without introducing cross-module symbol resolution.
Does this PR introduce a breaking change?
Other information
Added regression coverage for import variants, conflicting and shadowed bindings, comments, idempotence, and schematic rollback on generation failure.
Tests also compile generated TypeScript and execute module decorators to verify that the intended provider constructor is registered.
Validation: 884 tests across 45 files, typecheck, build, lint, Prettier, and
git diff --checkpassed.