From 266c98a2ffbd8a059548168b9e77a21d80f2c214 Mon Sep 17 00:00:00 2001 From: Derek Bourgeois Date: Thu, 26 Mar 2026 22:15:51 -0400 Subject: [PATCH 1/2] fix: boot native surreal persistence during app startup --- app/Providers/AppServiceProvider.php | 3 +++ app/Providers/NativeAppServiceProvider.php | 3 --- tests/Feature/NativeRuntimePersistenceTest.php | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index db48dd1..d37417e 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -9,6 +9,7 @@ use App\Services\Surreal\SurrealDocumentStore; use App\Services\Surreal\SurrealHttpClient; use App\Services\Surreal\SurrealRuntimeManager; +use App\Support\Native\NativeRuntimePersistence; use Illuminate\Database\DatabaseManager; use Illuminate\Queue\QueueManager; use Illuminate\Session\DatabaseSessionHandler; @@ -26,6 +27,8 @@ public function register(): void public function boot(): void { + $this->app->make(NativeRuntimePersistence::class)->configure(); + $this->app->extend('migration.repository', function ($repository, $app): SurrealMigrationRepository { $migrations = $app['config']['database.migrations']; $table = is_array($migrations) ? ($migrations['table'] ?? 'migrations') : $migrations; diff --git a/app/Providers/NativeAppServiceProvider.php b/app/Providers/NativeAppServiceProvider.php index 0e8a226..f04e214 100644 --- a/app/Providers/NativeAppServiceProvider.php +++ b/app/Providers/NativeAppServiceProvider.php @@ -2,7 +2,6 @@ namespace App\Providers; -use App\Support\Native\NativeRuntimePersistence; use Native\Desktop\Contracts\ProvidesPhpIni; use Native\Desktop\Facades\Window; @@ -10,8 +9,6 @@ class NativeAppServiceProvider implements ProvidesPhpIni { public function boot(): void { - app(NativeRuntimePersistence::class)->configure(); - Window::open() ->url(route('home')) ->title(config('app.name')) diff --git a/tests/Feature/NativeRuntimePersistenceTest.php b/tests/Feature/NativeRuntimePersistenceTest.php index 0e4c8a8..b7a637e 100644 --- a/tests/Feature/NativeRuntimePersistenceTest.php +++ b/tests/Feature/NativeRuntimePersistenceTest.php @@ -1,5 +1,6 @@ set('queue.connections.surreal.connection', 'nativephp'); config()->set('ai.caching.embeddings.store', 'database'); - app(NativeRuntimePersistence::class)->configure(); + expect(app(NativeRuntimePersistence::class))->not->toBeNull(); + + (new AppServiceProvider(app()))->boot(); resetNativeRuntimePersistenceState(); From 5180089bd85e17c0062c61b8f586e6fbfb37ee79 Mon Sep 17 00:00:00 2001 From: Derek Bourgeois Date: Thu, 26 Mar 2026 22:47:59 -0400 Subject: [PATCH 2/2] test: bootstrap native persistence through app startup --- .../Feature/NativeRuntimePersistenceTest.php | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/tests/Feature/NativeRuntimePersistenceTest.php b/tests/Feature/NativeRuntimePersistenceTest.php index b7a637e..36b2644 100644 --- a/tests/Feature/NativeRuntimePersistenceTest.php +++ b/tests/Feature/NativeRuntimePersistenceTest.php @@ -1,11 +1,9 @@ refreshApplication(); + config()->set('surreal.host', '127.0.0.1'); config()->set('surreal.port', $server['port']); config()->set('surreal.endpoint', $server['endpoint']); @@ -41,30 +48,8 @@ config()->set('surreal.storage_path', $storagePath); config()->set('surreal.runtime', 'local'); config()->set('surreal.autostart', false); - - config()->set('nativephp-internal.running', true); - config()->set('database.default', 'nativephp'); - config()->set('database.migrations.connection', 'nativephp'); - config()->set('session.driver', 'file'); - config()->set('session.connection', null); config()->set('session.table', 'sessions'); config()->set('session.cookie', 'native-runtime-surreal'); - config()->set('cache.default', 'database'); - config()->set('cache.limiter', 'file'); - config()->set('cache.stores.database.connection', 'nativephp'); - config()->set('cache.stores.database.lock_connection', 'nativephp'); - config()->set('cache.stores.surreal.connection', 'nativephp'); - config()->set('cache.stores.surreal.lock_connection', 'nativephp'); - config()->set('queue.default', 'database'); - config()->set('queue.failed.database', 'nativephp'); - config()->set('queue.batching.database', 'nativephp'); - config()->set('queue.connections.database.connection', 'nativephp'); - config()->set('queue.connections.surreal.connection', 'nativephp'); - config()->set('ai.caching.embeddings.store', 'database'); - - expect(app(NativeRuntimePersistence::class))->not->toBeNull(); - - (new AppServiceProvider(app()))->boot(); resetNativeRuntimePersistenceState(); @@ -76,7 +61,6 @@ ->and(config('queue.default'))->toBe('surreal') ->and(config('queue.failed.database'))->toBe('surreal') ->and(config('queue.batching.database'))->toBe('surreal') - ->and(config('ai.caching.embeddings.store'))->toBe('surreal') ->and(cache()->driver(config('cache.limiter'))->getStore())->toBeInstanceOf(FileStore::class); expect(Artisan::call('migrate', [ @@ -123,6 +107,10 @@ ->and(DB::connection('surreal')->table('sessions')->count())->toBeGreaterThan(0); } finally { restoreNativeRuntimeConfig($originalConfig); + setNativeRuntimeEnvironment('NATIVEPHP_RUNNING', $originalNativeRunning); + setNativeRuntimeEnvironment('NATIVEPHP_STORAGE_PATH', $originalNativeStoragePath); + setNativeRuntimeEnvironment('NATIVEPHP_DATABASE_PATH', $originalNativeDatabasePath); + $this->refreshApplication(); resetNativeRuntimePersistenceState(); if (isset($server['process'])) { @@ -173,6 +161,20 @@ function restoreNativeRuntimeConfig(array $snapshot): void } } +function setNativeRuntimeEnvironment(string $key, string|false|null $value): void +{ + if ($value === false || $value === null) { + putenv($key); + unset($_ENV[$key], $_SERVER[$key]); + + return; + } + + putenv(sprintf('%s=%s', $key, $value)); + $_ENV[$key] = $value; + $_SERVER[$key] = $value; +} + function resetNativeRuntimePersistenceState(): void { app()->forgetInstance(SurrealConnection::class);