Skip to content

Fix #30: server.region matches the chosen cloud provider#35

Merged
obaid merged 1 commit into
mainfrom
fix/issue-30-region-per-provider
May 22, 2026
Merged

Fix #30: server.region matches the chosen cloud provider#35
obaid merged 1 commit into
mainfrom
fix/issue-30-region-per-provider

Conversation

@obaid
Copy link
Copy Markdown
Contributor

@obaid obaid commented May 22, 2026

Summary

The servers.region column had a Hetzner-centric migration default ('nbg1'), and the three call sites that insert Server rows all omitted region from the create payload. A team provisioned on DigitalOcean therefore ended up with server.region='nbg1' even though the droplet was actually created in 'nyc1' (the DO job hardcodes its own region from config('cloud.regions.us-east.digitalocean')).

Mostly cosmetic — the DO API ignores our column — but it misrepresented the actual provider in dashboards / Telescope / observability, and any future code that reads server.region to call provider APIs would break.

Fixes #30.

Changes

  • app/Enums/CloudProvider.php: new defaultProviderRegion() that returns the provider-specific code:

    • DigitalOcean'nyc1'
    • Hetzner'ash'
    • Linode'us-east'
    • Docker'local'

    Reads from cloud.regions.us-east.<provider> config first (so any deploy-level region remap works), falls back to hardcoded per-provider defaults if config is missing.

  • app/Http/Controllers/Settings/TeamController::provisionServer: set region from $cloudProvider->defaultProviderRegion() when creating the Server row.

  • app/Http/Controllers/AgentController::ensureTeamHasServer: same.

  • app/Console/Commands/FixServerStatus::handle: same.

Three sites, one source of truth.

Tests

7 new tests across two files:

  • tests/Feature/Enums/CloudProviderTest.php (5): each provider's default code, plus the config-absent fallback path.
  • tests/Feature/Teams/TeamCreationProvisioningTest.php (2): end-to-end team creation through the actual controller — asserting server.region matches the chosen provider for both DO and Hetzner.

Full suite:

php artisan test --compact tests/Feature tests/Unit
Tests:    106 skipped, 686 passed (2223 assertions)
Duration: 23.90s

Pint: clean.

Out of scope

The migration default 'nbg1' is still in the schema. Changing it would require a migration on existing data and isn't necessary now that all create sites set the column explicitly. If the cosmetic schema default bothers you, a follow-up can change the default to 'local' or drop it.

Live E2E status

⚠️ Live E2E not run on this branch — plane wifi too flaky for full DO provision. The feature tests exercise the controller end-to-end so the regression is locked in. Manual verification on stable internet:

  1. Create a team on DigitalOcean
  2. php artisan tinker --execute='echo App\Models\Server::latest()->first()->region;' → expect nyc1
  3. Create a team on Hetzner → expect ash

Test plan

  • CI green
  • Live E2E on stable internet — confirm server.region matches the provider for each cloud

The servers.region column had a Hetzner-centric migration default
('nbg1'), and the three Server::create() call sites all omitted region
from the insert payload. So a team created on DigitalOcean ended up
with server.region='nbg1' even though the droplet was actually
created in 'nyc1' (the DO job hardcoded its own region from config
'cloud.regions.us-east.digitalocean').

This was mostly cosmetic — the DO API ignores our column — but it
masked the wrong provider in observability and would have broken any
future region-aware code reading server.region.

Fix:
- New CloudProvider::defaultProviderRegion() returns the provider-
  specific code ('nyc1', 'ash', 'us-east', 'local') from the
  cloud.regions.us-east.<provider> config, with hardcoded fallbacks
  for safety.
- TeamController::provisionServer, AgentController::ensureTeamHasServer,
  and FixServerStatus::handle now set 'region' on the Server row using
  the helper. Three sites, one source of truth.

Tests: 7 new tests covering each provider's default code, the config-
absent fallback path, and end-to-end team creation asserting
server.region matches the chosen provider. Full suite: 686 passed,
106 skipped.

Fixes #30
@obaid obaid merged commit 1812840 into main May 22, 2026
1 of 2 checks passed
@obaid obaid deleted the fix/issue-30-region-per-provider branch May 22, 2026 18:18
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.

team.region defaults to Hetzner 'nbg1' even when cloud_provider is DigitalOcean

1 participant