create(['is_admin' => true]); } it('gates the add-host page', function () { $this->get(route('admin.hosts.create'))->assertRedirect('/login'); $this->actingAs(User::factory()->create(['is_admin' => false]))->get(route('admin.hosts.create'))->assertForbidden(); $this->actingAs(admin())->get(route('admin.hosts.create'))->assertOk()->assertSee(__('hosts.create_title')); }); it('gates the host detail page', function () { $host = Host::factory()->create(); $this->get(route('admin.hosts.show', $host))->assertRedirect('/login'); $this->actingAs(User::factory()->create(['is_admin' => false]))->get(route('admin.hosts.show', $host))->assertForbidden(); $this->actingAs(admin())->get(route('admin.hosts.show', $host))->assertOk()->assertSee($host->name); }); it('lists real hosts for admins', function () { Host::factory()->active()->create(['name' => 'pve-zzz-1']); $this->actingAs(admin())->get(route('admin.hosts'))->assertOk()->assertSee('pve-zzz-1'); }); it('creates a host and starts onboarding with an encrypted password', function () { Queue::fake(); Livewire::actingAs(admin()) ->test(HostCreate::class) ->set('name', 'pve-fsn-7') ->set('datacenter', 'fsn') ->set('public_ip', '203.0.113.7') ->set('root_password', 'supersecret') ->call('save') ->assertRedirect(); $host = Host::query()->where('name', 'pve-fsn-7')->first(); expect($host)->not->toBeNull()->and($host->status)->toBe('pending'); $run = ProvisioningRun::query()->where('subject_id', $host->id)->first(); expect($run)->not->toBeNull() ->and($run->pipeline)->toBe('host') ->and(Crypt::decryptString($run->context('root_password')))->toBe('supersecret'); Queue::assertPushed(AdvanceRunJob::class); }); it('rejects a duplicate public ip', function () { Host::factory()->create(['public_ip' => '203.0.113.99']); Livewire::actingAs(admin()) ->test(HostCreate::class) ->set('name', 'pve-dup') ->set('datacenter', 'fsn') ->set('public_ip', '203.0.113.99') ->set('root_password', 'supersecret') ->call('save') ->assertHasErrors(['public_ip']); }); it('validates the add-host form', function () { Livewire::actingAs(admin()) ->test(HostCreate::class) ->set('name', '') ->set('public_ip', 'not-an-ip') ->set('root_password', 'short') ->call('save') ->assertHasErrors(['name', 'public_ip', 'root_password']); }); it('retries a failed run from the detail page', function () { Queue::fake(); $host = Host::factory()->create(['status' => 'error']); $run = ProvisioningRun::factory()->forHost($host)->create([ 'status' => 'failed', 'current_step' => 3, 'error' => 'boom', 'started_at' => now()->subHour(), ]); Livewire::actingAs(admin())->test(HostDetail::class, ['host' => $host])->call('retry'); $run->refresh(); expect($run->status)->toBe('running') ->and($run->error)->toBeNull() ->and($run->started_at->greaterThan(now()->subMinute()))->toBeTrue() ->and($host->fresh()->status)->toBe('onboarding'); Queue::assertPushed(AdvanceRunJob::class); }); it('removes the host record and its wireguard peer without wiping the server', function () { $services = fakeServices(); $host = Host::factory()->active()->create(['wg_pubkey' => 'HOSTPUB=']); $services['hub']->addPeer('HOSTPUB=', $host->wg_ip); ProvisioningRun::factory()->forHost($host)->create(); Livewire::actingAs(admin()) ->test(ConfirmRemoveHost::class, ['uuid' => $host->uuid]) ->call('remove') ->assertRedirect(route('admin.hosts')); expect(Host::query()->find($host->id))->toBeNull() ->and($services['hub']->peers())->not->toHaveKey('HOSTPUB='); }); it('renders the live stepper for a running host', function () { $host = Host::factory()->create(['status' => 'onboarding']); ProvisioningRun::factory()->forHost($host)->create(['status' => 'running', 'current_step' => 2]); $this->actingAs(admin())->get(route('admin.hosts.show', $host)) ->assertOk() ->assertSee(__('hosts.step.prepare_base_system')) ->assertSee(__('hosts.progress')); });