From 180b5dd6caf1a24016092a2789da45ee49801623 Mon Sep 17 00:00:00 2001 From: roble Date: Mon, 16 Nov 2026 11:37:51 +0000 Subject: [PATCH 1/6] chore: alias dev as 3.x-dev, so it never falls behind a minor release Co-Authored-By: Claude Opus 5.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ea084bc..6c94ea1 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ ] }, "branch-alias": { - "dev-dev": "3.6.x-dev" + "dev-dev": "3.x-dev" } }, "autoload": { From 07f09b9548a39ad4bb9c41520675e866911560b7 Mon Sep 17 00:00:00 2001 From: roble Date: Mon, 16 Nov 2026 12:29:54 +0000 Subject: [PATCH 2/6] feat: the demo seeder declares its accounts (#[DemoAccount]) The installer and modules:seed name the featured ones; a test checks the seeder creates every account it declares. Co-Authored-By: Claude Opus 5.5 --- database/seeders/ShowcaseThemesDatabaseSeeder.php | 2 ++ tests/Feature/ShowcaseStaffTest.php | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/database/seeders/ShowcaseThemesDatabaseSeeder.php b/database/seeders/ShowcaseThemesDatabaseSeeder.php index e81f8ae..96f790a 100644 --- a/database/seeders/ShowcaseThemesDatabaseSeeder.php +++ b/database/seeders/ShowcaseThemesDatabaseSeeder.php @@ -4,8 +4,10 @@ use App\Models\User; use Illuminate\Database\Seeder; +use Saucebase\Core\Attributes\DemoAccount; use Spatie\Permission\Models\Role; +#[DemoAccount('themes@saucebase.dev', 'staff: the themes admin')] class ShowcaseThemesDatabaseSeeder extends Seeder { public function run(): void diff --git a/tests/Feature/ShowcaseStaffTest.php b/tests/Feature/ShowcaseStaffTest.php index 7caf2d6..890e5ac 100644 --- a/tests/Feature/ShowcaseStaffTest.php +++ b/tests/Feature/ShowcaseStaffTest.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Hash; use Modules\Themes\Database\Seeders\DatabaseSeeder; use Modules\Themes\Database\Seeders\ShowcaseThemesDatabaseSeeder; +use Saucebase\Core\Testing\AssertsDemoAccounts; use Tests\TestCase; /** @@ -15,6 +16,7 @@ */ class ShowcaseStaffTest extends TestCase { + use AssertsDemoAccounts; use RefreshDatabase; public function test_the_demo_adds_a_staff_account_for_this_module_only(): void @@ -35,4 +37,10 @@ public function test_demo_accounts_use_the_configured_demo_password(): void $this->assertTrue(Hash::check('not-the-old-default', User::where('email', 'themes@saucebase.dev')->value('password'))); } + + /** The accounts the seeder declares (#[DemoAccount]) are the ones it creates. */ + public function test_every_declared_demo_account_is_created(): void + { + $this->assertDemoAccountsSeeded(ShowcaseThemesDatabaseSeeder::class); + } } From 82a23e8524565cbde07979d5c26b2617df711b74 Mon Sep 17 00:00:00 2001 From: roble Date: Wed, 18 Nov 2026 10:57:11 +0000 Subject: [PATCH 3/6] test: isolate user themes from the app's storage The feature tests read and wrote the app's real storage/app/themes. An app that ships its own default.json (the Uptime template does) failed four tests, and the update test overwrote that file. IsolatesUserThemes points storage at a temporary directory per test and removes it afterwards. Co-Authored-By: Claude Opus 5.5 --- .../saucebase-themes-development/SKILL.md | 2 ++ tests/Feature/AdminThemeSettingsPageTest.php | 2 ++ tests/Feature/AdminThemeTest.php | 2 ++ tests/Feature/ApplyThemeCommandTest.php | 3 +++ tests/Feature/ShowcaseStaffTest.php | 2 ++ tests/Feature/ThemesAccessTest.php | 2 ++ tests/Feature/ThemesApplyTest.php | 2 ++ tests/Feature/ThemesConfigTest.php | 2 ++ tests/Feature/ThemesControllerTest.php | 2 ++ tests/Feature/ThemesPermissionTest.php | 2 ++ tests/Support/IsolatesUserThemes.php | 26 +++++++++++++++++++ 11 files changed, 47 insertions(+) create mode 100644 tests/Support/IsolatesUserThemes.php diff --git a/resources/boost/skills/saucebase-themes-development/SKILL.md b/resources/boost/skills/saucebase-themes-development/SKILL.md index 71f0cfb..88472dd 100644 --- a/resources/boost/skills/saucebase-themes-development/SKILL.md +++ b/resources/boost/skills/saucebase-themes-development/SKILL.md @@ -273,4 +273,6 @@ npx playwright test --project="@themes*" # E2E - `tests/Feature/AdminTheme*Test.php`: Filament admin theme - `resources/js/lib/*.test.ts`: colour maths, fields, theme vars, panel payload, Tailwind palette +Feature tests use `Modules\Themes\Tests\Support\IsolatesUserThemes`, which points storage at a temporary directory per test: an app's own `storage/app/themes/*.json` (a template ships a `default.json`) must neither change what a test sees nor be overwritten by it. A new feature test that reads or writes user themes uses it too. + Tests that post to the write routes disable `PreventRequestForgery` (`allowWrites()` in `ThemesApplyTest`), so the CSRF check stays out of what they test. diff --git a/tests/Feature/AdminThemeSettingsPageTest.php b/tests/Feature/AdminThemeSettingsPageTest.php index 9a54e99..72ac01c 100644 --- a/tests/Feature/AdminThemeSettingsPageTest.php +++ b/tests/Feature/AdminThemeSettingsPageTest.php @@ -8,10 +8,12 @@ use Modules\Themes\Admin\AdminTheme; use Modules\Themes\Filament\Pages\AdminThemeSettings as AdminThemeSettingsPage; use Modules\Themes\Settings\AdminThemeSettings; +use Modules\Themes\Tests\Support\IsolatesUserThemes; use Tests\TestCase; class AdminThemeSettingsPageTest extends TestCase { + use IsolatesUserThemes; use RefreshDatabase; private function actingAsAdmin(): void diff --git a/tests/Feature/AdminThemeTest.php b/tests/Feature/AdminThemeTest.php index e15a972..f97ed6b 100644 --- a/tests/Feature/AdminThemeTest.php +++ b/tests/Feature/AdminThemeTest.php @@ -11,6 +11,7 @@ use Illuminate\Testing\TestResponse; use Modules\Themes\Admin\AdminTheme; use Modules\Themes\Settings\AdminThemeSettings; +use Modules\Themes\Tests\Support\IsolatesUserThemes; use Tests\TestCase; /** @@ -19,6 +20,7 @@ */ class AdminThemeTest extends TestCase { + use IsolatesUserThemes; use RefreshDatabase; private function saveSettings(array $values): void diff --git a/tests/Feature/ApplyThemeCommandTest.php b/tests/Feature/ApplyThemeCommandTest.php index 3935e17..6f57776 100644 --- a/tests/Feature/ApplyThemeCommandTest.php +++ b/tests/Feature/ApplyThemeCommandTest.php @@ -3,10 +3,13 @@ namespace Modules\Themes\Tests\Feature; use Modules\Themes\Services\ThemeService; +use Modules\Themes\Tests\Support\IsolatesUserThemes; use Tests\TestCase; class ApplyThemeCommandTest extends TestCase { + use IsolatesUserThemes; + private string $themeCssPath; private string $originalCss; diff --git a/tests/Feature/ShowcaseStaffTest.php b/tests/Feature/ShowcaseStaffTest.php index 7caf2d6..76a3610 100644 --- a/tests/Feature/ShowcaseStaffTest.php +++ b/tests/Feature/ShowcaseStaffTest.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Hash; use Modules\Themes\Database\Seeders\DatabaseSeeder; use Modules\Themes\Database\Seeders\ShowcaseThemesDatabaseSeeder; +use Modules\Themes\Tests\Support\IsolatesUserThemes; use Tests\TestCase; /** @@ -15,6 +16,7 @@ */ class ShowcaseStaffTest extends TestCase { + use IsolatesUserThemes; use RefreshDatabase; public function test_the_demo_adds_a_staff_account_for_this_module_only(): void diff --git a/tests/Feature/ThemesAccessTest.php b/tests/Feature/ThemesAccessTest.php index 6ceadf0..f57639d 100644 --- a/tests/Feature/ThemesAccessTest.php +++ b/tests/Feature/ThemesAccessTest.php @@ -3,11 +3,13 @@ namespace Modules\Themes\Tests\Feature; use Illuminate\Foundation\Testing\RefreshDatabase; +use Modules\Themes\Tests\Support\IsolatesUserThemes; use Saucebase\Core\ProjectConfig; use Tests\TestCase; class ThemesAccessTest extends TestCase { + use IsolatesUserThemes; use RefreshDatabase; private string $storageDir; diff --git a/tests/Feature/ThemesApplyTest.php b/tests/Feature/ThemesApplyTest.php index cada67e..510d359 100644 --- a/tests/Feature/ThemesApplyTest.php +++ b/tests/Feature/ThemesApplyTest.php @@ -5,11 +5,13 @@ use Illuminate\Foundation\Http\Middleware\PreventRequestForgery; use Illuminate\Foundation\Testing\RefreshDatabase; use Modules\Themes\Services\ThemeService; +use Modules\Themes\Tests\Support\IsolatesUserThemes; use Saucebase\Core\ProjectConfig; use Tests\TestCase; class ThemesApplyTest extends TestCase { + use IsolatesUserThemes; use RefreshDatabase; private string $themeCssPath; diff --git a/tests/Feature/ThemesConfigTest.php b/tests/Feature/ThemesConfigTest.php index 1755a4a..c98ff94 100644 --- a/tests/Feature/ThemesConfigTest.php +++ b/tests/Feature/ThemesConfigTest.php @@ -3,11 +3,13 @@ namespace Modules\Themes\Tests\Feature; use Illuminate\Foundation\Testing\RefreshDatabase; +use Modules\Themes\Tests\Support\IsolatesUserThemes; use Saucebase\Core\ProjectConfig; use Tests\TestCase; class ThemesConfigTest extends TestCase { + use IsolatesUserThemes; use RefreshDatabase; private string $storageDir; diff --git a/tests/Feature/ThemesControllerTest.php b/tests/Feature/ThemesControllerTest.php index e015b70..13d105a 100644 --- a/tests/Feature/ThemesControllerTest.php +++ b/tests/Feature/ThemesControllerTest.php @@ -3,10 +3,12 @@ namespace Modules\Themes\Tests\Feature; use Illuminate\Foundation\Testing\RefreshDatabase; +use Modules\Themes\Tests\Support\IsolatesUserThemes; use Tests\TestCase; class ThemesControllerTest extends TestCase { + use IsolatesUserThemes; use RefreshDatabase; private string $storageDir; diff --git a/tests/Feature/ThemesPermissionTest.php b/tests/Feature/ThemesPermissionTest.php index ee3df9a..ef89c07 100644 --- a/tests/Feature/ThemesPermissionTest.php +++ b/tests/Feature/ThemesPermissionTest.php @@ -6,6 +6,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Modules\Themes\Database\Seeders\DatabaseSeeder; use Modules\Themes\Filament\Pages\AdminThemeSettings; +use Modules\Themes\Tests\Support\IsolatesUserThemes; use Spatie\Permission\Models\Permission; use Tests\TestCase; @@ -15,6 +16,7 @@ */ class ThemesPermissionTest extends TestCase { + use IsolatesUserThemes; use RefreshDatabase; protected function setUp(): void diff --git a/tests/Support/IsolatesUserThemes.php b/tests/Support/IsolatesUserThemes.php new file mode 100644 index 0000000..a13d604 --- /dev/null +++ b/tests/Support/IsolatesUserThemes.php @@ -0,0 +1,26 @@ +isolatedStorage = sys_get_temp_dir().'/themes-test-'.bin2hex(random_bytes(6)); + $this->app->useStoragePath($this->isolatedStorage); + } + + protected function tearDownIsolatesUserThemes(): void + { + File::deleteDirectory($this->isolatedStorage); + } +} From 8ccf9c4715bdf5c0e743a2168bc86f801082c20b Mon Sep 17 00:00:00 2001 From: roble Date: Thu, 19 Nov 2026 09:16:07 +0000 Subject: [PATCH 4/6] fix: applying a theme uses the saved preset the picker shows discoverThemes() lets a user's preset win over a shipped theme with the same name, but getTheme() checked the shipped file first, so saucebase:theme:apply wrote the shipped palette instead of the one shown. getTheme() now looks at the user's file first too. Co-Authored-By: Claude Opus 5.5 --- src/Services/ThemeService.php | 13 +++++-------- tests/Feature/ApplyThemeCommandTest.php | 8 ++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Services/ThemeService.php b/src/Services/ThemeService.php index 9592a48..6ff83c5 100644 --- a/src/Services/ThemeService.php +++ b/src/Services/ThemeService.php @@ -148,14 +148,11 @@ public static function discoverThemes(): array */ public static function getTheme(string $theme): string|false { - $bundlePath = static::getBundleThemePath($theme); - if (file_exists($bundlePath)) { - return file_get_contents($bundlePath); - } - - $userPath = static::getUserThemePath($theme); - if (file_exists($userPath)) { - return file_get_contents($userPath); + // The user's file first, as discoverThemes() does: what the picker shows is what gets applied. + foreach ([static::getUserThemePath($theme), static::getBundleThemePath($theme)] as $path) { + if (file_exists($path)) { + return file_get_contents($path); + } } return false; diff --git a/tests/Feature/ApplyThemeCommandTest.php b/tests/Feature/ApplyThemeCommandTest.php index 6f57776..1e1560c 100644 --- a/tests/Feature/ApplyThemeCommandTest.php +++ b/tests/Feature/ApplyThemeCommandTest.php @@ -30,6 +30,14 @@ protected function tearDown(): void parent::tearDown(); } + /** A saved preset named like a shipped theme is the one the picker shows, so it is the one applied. */ + public function test_a_saved_preset_wins_over_the_shipped_theme_of_the_same_name(): void + { + ThemeService::saveUserTheme('beetroot', ['cssVars' => ['theme' => [], 'light' => ['primary' => 'mine'], 'dark' => []]]); + + $this->assertStringContainsString('"mine"', (string) ThemeService::getTheme('beetroot')); + } + // ── New shadcn format ───────────────────────────────────────────────────── public function test_new_format_patches_light_vars_into_root_block(): void From 879306f7ac7ddd80a485379acce3685de04b0e02 Mon Sep 17 00:00:00 2001 From: roble Date: Fri, 20 Nov 2026 21:16:40 +0000 Subject: [PATCH 5/6] chore: require core ^3.1 for the demo account attribute Co-Authored-By: Claude Opus 5.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a01abcf..9fd176e 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "license": "MIT", "version": "v3.5.1", "require": { - "saucebase/core": "^3.0" + "saucebase/core": "^3.1" }, "authors": [ { From fa1fd4e27e16a03b51966541a8025e51bd914d57 Mon Sep 17 00:00:00 2001 From: roble Date: Fri, 20 Nov 2026 21:16:40 +0000 Subject: [PATCH 6/6] fix: a saved preset the picker skips is not the one applied Co-Authored-By: Claude Opus 5.5 --- src/Services/ThemeService.php | 15 +++++++++------ tests/Feature/ApplyThemeCommandTest.php | 10 +++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Services/ThemeService.php b/src/Services/ThemeService.php index 6ff83c5..56a6a0d 100644 --- a/src/Services/ThemeService.php +++ b/src/Services/ThemeService.php @@ -148,14 +148,17 @@ public static function discoverThemes(): array */ public static function getTheme(string $theme): string|false { - // The user's file first, as discoverThemes() does: what the picker shows is what gets applied. - foreach ([static::getUserThemePath($theme), static::getBundleThemePath($theme)] as $path) { - if (file_exists($path)) { - return file_get_contents($path); - } + // The user's file first, as discoverThemes() does, and only one it accepts: what the + // picker shows is what gets applied. + $user = static::getUserThemePath($theme); + + if (static::parseThemeFile($user) !== null) { + return file_get_contents($user); } - return false; + $bundle = static::getBundleThemePath($theme); + + return file_exists($bundle) ? file_get_contents($bundle) : false; } /** diff --git a/tests/Feature/ApplyThemeCommandTest.php b/tests/Feature/ApplyThemeCommandTest.php index 1e1560c..4e2d56f 100644 --- a/tests/Feature/ApplyThemeCommandTest.php +++ b/tests/Feature/ApplyThemeCommandTest.php @@ -33,11 +33,19 @@ protected function tearDown(): void /** A saved preset named like a shipped theme is the one the picker shows, so it is the one applied. */ public function test_a_saved_preset_wins_over_the_shipped_theme_of_the_same_name(): void { - ThemeService::saveUserTheme('beetroot', ['cssVars' => ['theme' => [], 'light' => ['primary' => 'mine'], 'dark' => []]]); + ThemeService::saveUserTheme('beetroot', ['name' => 'Beetroot', 'cssVars' => ['theme' => [], 'light' => ['primary' => 'mine'], 'dark' => []]]); $this->assertStringContainsString('"mine"', (string) ThemeService::getTheme('beetroot')); } + /** A saved file the picker skips (no name) is not what gets applied: the shipped theme is. */ + public function test_a_saved_preset_the_picker_skips_leaves_the_shipped_theme(): void + { + ThemeService::saveUserTheme('beetroot', ['cssVars' => ['theme' => [], 'light' => ['primary' => 'mine'], 'dark' => []]]); + + $this->assertStringNotContainsString('"mine"', (string) ThemeService::getTheme('beetroot')); + } + // ── New shadcn format ───────────────────────────────────────────────────── public function test_new_format_patches_light_vars_into_root_block(): void