Skip to content

refactor: extract shared packages for azd extensions#18

Merged
jongio merged 5 commits into
mainfrom
refactor
Feb 21, 2026
Merged

refactor: extract shared packages for azd extensions#18
jongio merged 5 commits into
mainfrom
refactor

Conversation

@jongio

@jongio jongio commented Feb 19, 2026

Copy link
Copy Markdown
Owner

Summary

Extract common code from azd-exec, azd-rest, azd-copilot, and azd-app into shared azd-core packages, eliminating duplication across the extension ecosystem.

New Packages

Package Purpose
version Shared version info struct + reusable cobra command builder
cmdutil Generic command execution (RunCommand, RunWithTimeout, hooks, line writer)
cache Thread-safe file-based cache manager with TTL and versioning
auth Azure token management with thread-safe caching and scope detection
httpclient HTTP client with retry, pagination, and header redaction
progress Spinner and progress bar UI components
yamlutil Comment-preserving YAML manipulation
notify Desktop notifications via gen2brain/beeep
healthcheck Health check types and profiles
registry Service registry pattern
projecttype Project type detection types
logutil ComponentLogger for structured slog logging

Community Packages Adopted

  • pkg/browser - replaces custom platform-specific browser launch code
  • gen2brain/beeep - replaces 3 platform-specific notification files

Security Fixes

  • Fixed race condition in auth.getCached() (token expiration check outside RLock)
  • Added context parameter to GetAzureToken() for cancellation support
  • Guard against panic in yamlutil on negative indentDelta
  • Enforce timeout in browser.Launch() via select/time.After

Quality

  • All 24 test packages pass
  • golangci-lint v2 clean (76 issues fixed)
  • Coverage: 62-98% across packages

jongio and others added 4 commits February 18, 2026 23:54
Add new packages to azd-core:
- version: extension version info and cobra command builder
- cmdutil: generic command execution framework
- logutil/ComponentLogger: component-scoped structured logging
- cache: thread-safe file-based cache manager
- auth: Azure token management and scope detection
- httpclient: HTTP client with retry, pagination, header redaction
- progress: multi-progress bar system with spinners
- yamlutil: comment-preserving YAML manipulation
- notify: cross-platform OS notifications
- healthcheck: service health monitoring with circuit breaker
- registry: in-memory service registry
- projecttype: project type detection types

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace custom browser launch code with pkg/browser
- Replace platform-specific notify implementations with gen2brain/beeep
- Simplify cross-platform code, reduce maintenance burden

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix race condition in auth token cache expiration check (getCached)
- Add context parameter to GetAzureToken for caller-controlled cancellation
- Add timeout enforcement around browser.OpenURL call
- Add bounds check in yamlutil FindServiceInSection to prevent panic on malformed YAML

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix golangci-lint v2 issues (errcheck, staticcheck, revive)
- Fix test reliability issues
- All preflight checks now pass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- auth/auth_test.go: Remove brittle error message assertion in
  TestAzureTokenProvider_InvalidScope that fails in CI where no Azure
  credentials are available (error is auth-related, not scope-related)
- Remove redundant // +build tags from 6 test files that already have
  the modern //go:build directive (fixes golangci-lint govet warnings)

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.52010% with 736 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.11%. Comparing base (dcdf451) to head (b1f5b21).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
healthcheck/checker.go 57.05% 197 Missing and 25 partials ⚠️
progress/progress.go 62.96% 106 Missing and 14 partials ⚠️
httpclient/client.go 67.14% 69 Missing and 22 partials ⚠️
healthcheck/metrics.go 0.00% 78 Missing ⚠️
auth/auth.go 51.31% 33 Missing and 4 partials ⚠️
yamlutil/update_service_port.go 70.90% 19 Missing and 13 partials ⚠️
cmdutil/hooks.go 53.12% 21 Missing and 9 partials ⚠️
cache/cache.go 73.00% 18 Missing and 9 partials ⚠️
yamlutil/update_logs_config.go 79.13% 13 Missing and 11 partials ⚠️
healthcheck/profiles.go 88.00% 12 Missing and 3 partials ⚠️
... and 10 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #18      +/-   ##
==========================================
- Coverage   80.97%   73.11%   -7.86%     
==========================================
  Files          16       39      +23     
  Lines        1335     3649    +2314     
==========================================
+ Hits         1081     2668    +1587     
- Misses        193      797     +604     
- Partials       61      184     +123     
Flag Coverage Δ
unittests 73.11% <68.52%> (-7.86%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@jongio jongio merged commit dd4e15d into main Feb 21, 2026
8 checks passed
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.

2 participants