Skip to content

refactor(region): simplify and fix region selection plugin#897

Merged
cmendible merged 1 commit into
mainfrom
cmendible/analyze-region-selection-plugin
Jun 10, 2026
Merged

refactor(region): simplify and fix region selection plugin#897
cmendible merged 1 commit into
mainfrom
cmendible/analyze-region-selection-plugin

Conversation

@cmendible

Copy link
Copy Markdown
Member

Closes #896

What

Analysis and cleanup of the region selection plugin based on a code review.

Changes

Bug fixes

  • January date bug (cost.go): replace now.Month()-1 with now.AddDate(0,-1,0) — idiomatic, unambiguous previous-month calculation
  • State leak between calls (plugin.go, scan.go): removed targetRegionsFlag package-level global. The --target-regions CLI flag value is now bridged through stageConfigs in scanWithPlugin, making the CLI and MCP paths consistent (both use ScanParams.Stages). A second scan call with no target-regions no longer silently inherits regions from the previous call.

Simplifications

  • Replace 3+ inline strings.ToLower(strings.ReplaceAll(region, " ", "")) expressions with normalizeRegionName() (selection.go, availability.go, latency.go)
  • Remove skuInfo single-field struct; use string directly (types.go, selection.go)
  • Remove stale "can be made configurable via CLI flags in future" comment from calculateScores (selection.go)

Testing

  • go test ./internal/scanners/plugins/region/...
  • go test ./internal/mcpserver/...
  • go build ./cmd/azqr/...

- Replace inline region normalization with normalizeRegionName() everywhere
- Remove skuInfo single-field struct; use string directly
- Fix January date bug: use now.AddDate(0,-1,0) instead of now.Month()-1
- Remove targetRegionsFlag package-level global; bridge --target-regions
  CLI flag through stageConfigs in scanWithPlugin so target regions flow
  through ScanParams.Stages (same as MCP path) with no global state
- Remove stale 'can be made configurable' comment from calculateScores

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 14.28571% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.32%. Comparing base (b87194c) to head (ee113de).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/scanners/plugins/region/selection.go 0.00% 5 Missing ⚠️
cmd/azqr/commands/scan.go 0.00% 4 Missing ⚠️
internal/scanners/plugins/region/cost.go 0.00% 2 Missing ⚠️
internal/scanners/plugins/region/availability.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #897      +/-   ##
==========================================
+ Coverage   20.84%   21.32%   +0.47%     
==========================================
  Files         107      107              
  Lines        7526     7518       -8     
==========================================
+ Hits         1569     1603      +34     
+ Misses       5843     5801      -42     
  Partials      114      114              
Flag Coverage Δ
unittests 21.32% <14.28%> (+0.47%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cmendible cmendible merged commit f580014 into main Jun 10, 2026
12 checks passed
@cmendible cmendible deleted the cmendible/analyze-region-selection-plugin branch June 10, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(region): simplify and fix region selection plugin

2 participants