Prepare SaveMoney for future updates#1775
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the @pagopa/dx-savemoney package to prepare for future extensions by introducing a unified “Finding” domain model, a plugin-style analyzer registry, and new runtime helpers (limiter + in-run metrics caching), while keeping the current report output shape (AzureDetailedResourceReport) unchanged.
Changes:
- Introduces a unified
Findingmodel and an adapter to bridge legacyAnalysisResultintoFinding[]. - Adds a plugin architecture for Azure analyzers (registry + types) and rewrites the orchestrator to use it.
- Adds a small concurrency limiter and an in-memory cache for Azure Monitor metric calls (scoped to a single run).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/savemoney/src/index.ts | Re-exports new Phase 0 public APIs (Finding model, analyzer plugin layer, limiter). |
| packages/savemoney/src/finding.ts | Adds unified Finding types and an adapter from legacy AnalysisResult.reason. |
| packages/savemoney/src/concurrency.ts | Introduces a lightweight async concurrency limiter helper. |
| packages/savemoney/src/azure/utils.ts | Adds run-scoped in-memory caching for getMetric() plus reset/test hooks. |
| packages/savemoney/src/azure/types.ts | Extends AzureConfig with an optional concurrency setting. |
| packages/savemoney/src/azure/analyzers/types.ts | Defines analyzer plugin interfaces (Analyzer, AnalyzerContext, AzureClients). |
| packages/savemoney/src/azure/analyzers/registry.ts | Wraps existing per-resource analyzers into the new registry. |
| packages/savemoney/src/azure/analyzers/index.ts | Provides re-exports for the analyzer plugin layer. |
| packages/savemoney/src/azure/analyzer.ts | Rewrites orchestration to use analyzer registry + limiter; resets metrics cache at run start. |
| .nx/version-plans/version-plan-1779281691024.md | Declares a patch version bump for the refactor. |
Comments suppressed due to low confidence (1)
packages/savemoney/src/concurrency.ts:35
createLimitercan temporarily allow more thanmaxtasks to run. When a task completes,next()decrementsactiveand resolves the next waiter; before the resumed waiter incrementsactive, a new caller can observeactive < maxand start too, causingactiveto exceedmaxand breaking the concurrency guarantee. Consider a pool implementation that starts queued tasks without releasing the slot (or uses awhile (active >= max) await ...loop plus slot reservation) so there is no window where capacity is double-claimed.
return async <T>(fn: () => Promise<T>): Promise<T> => {
if (active >= max) {
await new Promise<void>((resolve) => queue.push(resolve));
}
active++;
gunzip
reviewed
May 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
packages/savemoney/src/azure/tests/utils.test.ts:167
- Same issue here:
as unknown as Parameters<typeof getMetric>[0]hides type mismatches in the failing-client mock. Using a smallMonitorClientLikeinterface (or aPick<>of the real client) would let this mock type-check without assertions and prevent accidental drift from the production call shape.
function makeFailingMonitorClient(calls: number[] = []) {
return {
metrics: {
list: vi.fn().mockImplementation(async () => {
calls.push(1);
throw new Error("network error");
}),
},
} as unknown as Parameters<typeof getMetric>[0];
}
gunzip
reviewed
May 20, 2026
lucacavallaro
approved these changes
May 21, 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.
Impact-free refactoring to prepare SaveMoney for future implementations:
Resolves: CES-2077