From f15bf836a729b781d21cffd196f54a8f979a7c79 Mon Sep 17 00:00:00 2001 From: roble Date: Thu, 5 Nov 2026 15:09:31 +0000 Subject: [PATCH 01/62] feat: add queue, schedule and workers tasks and a Taskfile sync command (sc-1110) Co-Authored-By: Claude Opus 5.5 --- .../Commands/SyncModuleTaskfileCommand.php | 35 +++++++++++ src/CoreServiceProvider.php | 2 + src/ModuleTaskfile.php | 36 ++++++++++- stubs/app/Taskfile.yml | 12 ++++ tests/Feature/InstallCommandTest.php | 12 ++++ .../Feature/SyncModuleTaskfileCommandTest.php | 59 +++++++++++++++++++ 6 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 src/Console/Commands/SyncModuleTaskfileCommand.php create mode 100644 tests/Feature/SyncModuleTaskfileCommandTest.php diff --git a/src/Console/Commands/SyncModuleTaskfileCommand.php b/src/Console/Commands/SyncModuleTaskfileCommand.php new file mode 100644 index 0000000..ecea57e --- /dev/null +++ b/src/Console/Commands/SyncModuleTaskfileCommand.php @@ -0,0 +1,35 @@ +modules() + ->filter(fn ($module): bool => file_exists($module->path('Taskfile.yml'))) + ->map(fn ($module): string => $module->name) + ->sort() + ->values() + ->all(); + + if (! ModuleTaskfile::sync($modules)) { + $this->components->error('Taskfile.yml needs the BEGIN MODULES and END MODULES markers.'); + + return self::FAILURE; + } + + $this->components->info(count($modules).' module(s) listed in Taskfile.yml.'); + + return self::SUCCESS; + } +} diff --git a/src/CoreServiceProvider.php b/src/CoreServiceProvider.php index 1856c7f..e73dd80 100644 --- a/src/CoreServiceProvider.php +++ b/src/CoreServiceProvider.php @@ -21,6 +21,7 @@ use Saucebase\Core\Console\Commands\RecipeToModuleCommand; use Saucebase\Core\Console\Commands\SeedModulesCommand; use Saucebase\Core\Console\Commands\SyncModuleBoostCommand; +use Saucebase\Core\Console\Commands\SyncModuleTaskfileCommand; use Saucebase\Core\Http\Middleware\HandleAppearance; use Saucebase\Core\Http\Middleware\HandleInertiaRequests; use Saucebase\Core\Http\Middleware\HandleLocalization; @@ -105,6 +106,7 @@ public function boot(): void ModuleSetupCommand::class, RecipeToModuleCommand::class, SeedModulesCommand::class, + SyncModuleTaskfileCommand::class, SyncModuleBoostCommand::class, ]); diff --git a/src/ModuleTaskfile.php b/src/ModuleTaskfile.php index 0c32ccf..8775114 100644 --- a/src/ModuleTaskfile.php +++ b/src/ModuleTaskfile.php @@ -25,7 +25,7 @@ public static function add(string $module): void throw new RuntimeException("Unable to read Taskfile at [{$taskfile}]."); } - $entry = " {$module}:\n taskfile: ./modules/{$module}/Taskfile.yml\n optional: true\n"; + $entry = self::entry($module); $marker = ' # ── END MODULES'; if (str_contains($content, "taskfile: ./modules/{$module}/Taskfile.yml")) { @@ -40,4 +40,38 @@ public static function add(string $module): void file_put_contents($taskfile, substr($content, 0, $markerPosition).$entry.substr($content, $markerPosition)); } + + /** + * Replaces everything between the markers with these modules. + * + * @param string[] $modules + * @return bool False when the app has no Taskfile or no markers: nothing is changed. + */ + public static function sync(array $modules): bool + { + $taskfile = base_path('Taskfile.yml'); + $content = file_exists($taskfile) ? file_get_contents($taskfile) : false; + + if ($content === false || ! preg_match('/^ *# ── BEGIN MODULES.*\n/m', $content, $begin, PREG_OFFSET_CAPTURE)) { + return false; + } + + $start = $begin[0][1] + strlen($begin[0][0]); + $end = strpos($content, ' # ── END MODULES', $start); + + if ($end === false) { + return false; + } + + $entries = implode('', array_map(self::entry(...), $modules)); + + file_put_contents($taskfile, substr($content, 0, $start).$entries.substr($content, $end)); + + return true; + } + + private static function entry(string $module): string + { + return " {$module}:\n taskfile: ./modules/{$module}/Taskfile.yml\n optional: true\n"; + } } diff --git a/stubs/app/Taskfile.yml b/stubs/app/Taskfile.yml index 4cc93e8..f89fc2c 100644 --- a/stubs/app/Taskfile.yml +++ b/stubs/app/Taskfile.yml @@ -21,6 +21,18 @@ tasks: desc: Start dev server (app, queue, logs, vite) cmd: composer dev + queue: + desc: Run the queue worker (restarts when code changes) + cmd: '{{.APP}} php artisan queue:listen --tries=1 --timeout=0' + + schedule: + desc: Run the scheduler (runs due tasks every minute) + cmd: '{{.APP}} php artisan schedule:work' + + workers: + desc: Run the queue worker and scheduler together + deps: [queue, schedule] + build: desc: Production build (includes SSR) cmd: npm run build diff --git a/tests/Feature/InstallCommandTest.php b/tests/Feature/InstallCommandTest.php index c403947..da779c9 100644 --- a/tests/Feature/InstallCommandTest.php +++ b/tests/Feature/InstallCommandTest.php @@ -6,6 +6,7 @@ use Illuminate\Filesystem\Filesystem; use PHPUnit\Framework\Attributes\DataProvider; use Saucebase\Core\Tests\TestCase; +use Symfony\Component\Yaml\Yaml; class InstallCommandTest extends TestCase { @@ -85,6 +86,17 @@ public function test_it_publishes_a_taskfile_with_an_empty_app_prefix(): void $this->assertStringContainsString("APP: ''", $this->read('Taskfile.yml')); } + public function test_the_taskfile_runs_the_queue_and_scheduler_without_a_web_server(): void + { + $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true])->assertSuccessful(); + + $tasks = Yaml::parse($this->read('Taskfile.yml'))['tasks']; + + $this->assertStringContainsString('{{.APP}} php artisan queue:listen', $tasks['queue']['cmd']); + $this->assertStringContainsString('{{.APP}} php artisan schedule:work', $tasks['schedule']['cmd']); + $this->assertSame(['queue', 'schedule'], $tasks['workers']['deps']); + } + public function test_the_published_example_test_migrates_the_database(): void { $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true])->assertSuccessful(); diff --git a/tests/Feature/SyncModuleTaskfileCommandTest.php b/tests/Feature/SyncModuleTaskfileCommandTest.php new file mode 100644 index 0000000..9039f94 --- /dev/null +++ b/tests/Feature/SyncModuleTaskfileCommandTest.php @@ -0,0 +1,59 @@ +taskfile( + "includes:\n # ── BEGIN MODULES\n gone:\n taskfile: ./modules/gone/Taskfile.yml\n optional: true\n # ── END MODULES\n\ntasks:\n # kept\n" + ); + + $this->artisan('saucebase:taskfile-sync')->assertSuccessful(); + + $content = file_get_contents($taskfile); + $this->assertStringContainsString(" module-test-fixture:\n taskfile: ./modules/module-test-fixture/Taskfile.yml\n optional: true\n # ── END MODULES", $content); + $this->assertStringNotContainsString('gone', $content); + $this->assertStringNotContainsString('module-order-fixture', $content); + $this->assertStringContainsString("tasks:\n # kept\n", $content); + } + + public function test_running_it_again_changes_nothing(): void + { + $taskfile = $this->taskfile("includes:\n # ── BEGIN MODULES\n # ── END MODULES\n"); + + $this->artisan('saucebase:taskfile-sync')->assertSuccessful(); + $first = file_get_contents($taskfile); + $this->artisan('saucebase:taskfile-sync')->assertSuccessful(); + + $this->assertSame($first, file_get_contents($taskfile)); + } + + public function test_a_taskfile_without_the_markers_is_left_alone(): void + { + $taskfile = $this->taskfile($content = "tasks:\n dev:\n cmd: npm run dev\n"); + + $this->artisan('saucebase:taskfile-sync')->assertFailed(); + + $this->assertSame($content, file_get_contents($taskfile)); + } + + private function taskfile(string $content): string + { + $appPath = sys_get_temp_dir().'/saucebase-taskfile-sync-'.uniqid(); + mkdir($appPath); + file_put_contents($appPath.'/Taskfile.yml', $content); + $this->app->setBasePath($appPath); + $this->beforeApplicationDestroyed(fn () => (new Filesystem)->deleteDirectory($appPath)); + + return $appPath.'/Taskfile.yml'; + } +} From 76d55af6f94dae849b8e93178b55a25221725ee1 Mon Sep 17 00:00:00 2001 From: roble Date: Thu, 5 Nov 2026 16:37:56 +0000 Subject: [PATCH 02/62] feat: create the E2E env file on install (sc-1108) Co-Authored-By: Claude Opus 5.5 --- src/Console/Commands/InstallCommand.php | 6 ++++++ stubs/app/README.md | 2 +- tests/Feature/InstallCommandTest.php | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Console/Commands/InstallCommand.php b/src/Console/Commands/InstallCommand.php index 640f6a8..6295af8 100644 --- a/src/Console/Commands/InstallCommand.php +++ b/src/Console/Commands/InstallCommand.php @@ -4,6 +4,7 @@ use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\ServiceProvider; use Saucebase\Core\Console\Traits\DisplaysBanner; use Saucebase\Core\ProjectConfig; @@ -83,6 +84,11 @@ public function handle(Filesystem $files, ProjectConfig $config): int $this->publishStack($files, $stubs.'/stack', $framework); + // A package's require-dev never reaches the app, so a manual install may not have it. + if (array_key_exists('playwright:env', Artisan::all())) { + $this->call('playwright:env', ['--no-interaction' => true]); + } + $this->components->info("Saucebase is installed with {$framework}."); $this->components->bulletList([ 'npm install && npm run build', diff --git a/stubs/app/README.md b/stubs/app/README.md index d0d0318..dd65708 100644 --- a/stubs/app/README.md +++ b/stubs/app/README.md @@ -40,7 +40,7 @@ php artisan test # PHPUnit npm run test:e2e # Playwright ``` -**`npm run test:e2e` runs on its own server and database**, from `.env.e2e`, so your app's data stays untouched. Create the file once with `php artisan playwright:env` (a copy of `.env` with its own SQLite database and port). +**`npm run test:e2e` runs on its own server and database**, from `.env.e2e`, so your app's data stays untouched. `saucebase:install` creates it, a copy of `.env` with its own SQLite database and port. Run `php artisan playwright:env` to create it again. ## Learn more diff --git a/tests/Feature/InstallCommandTest.php b/tests/Feature/InstallCommandTest.php index da779c9..4364185 100644 --- a/tests/Feature/InstallCommandTest.php +++ b/tests/Feature/InstallCommandTest.php @@ -4,6 +4,7 @@ use Database\Factories\UserFactory; use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Facades\Artisan; use PHPUnit\Framework\Attributes\DataProvider; use Saucebase\Core\Tests\TestCase; use Symfony\Component\Yaml\Yaml; @@ -97,6 +98,25 @@ public function test_the_taskfile_runs_the_queue_and_scheduler_without_a_web_ser $this->assertSame(['queue', 'schedule'], $tasks['workers']['deps']); } + public function test_it_writes_the_e2e_env_when_the_playwright_package_is_installed(): void + { + $ran = false; + Artisan::command('playwright:env', function () use (&$ran) { + $ran = ! $this->input->isInteractive(); + }); + + $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true])->assertSuccessful(); + + $this->assertTrue($ran, 'playwright:env should run, unattended, so it can never replace a file.'); + } + + public function test_it_installs_without_the_playwright_package(): void + { + $this->assertArrayNotHasKey('playwright:env', Artisan::all()); + + $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true])->assertSuccessful(); + } + public function test_the_published_example_test_migrates_the_database(): void { $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true])->assertSuccessful(); From 5b9a1ccb6feb23010df49002d9d284e42ab91454 Mon Sep 17 00:00:00 2001 From: roble Date: Fri, 6 Nov 2026 10:15:35 +0000 Subject: [PATCH 03/62] chore: forbid nested ternaries in both stacks' ESLint config Co-Authored-By: Claude Opus 5.5 --- stubs/stack/react/config/eslint.config.js | 2 ++ stubs/stack/vue/config/eslint.config.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/stubs/stack/react/config/eslint.config.js b/stubs/stack/react/config/eslint.config.js index d92f906..ff6e5f6 100644 --- a/stubs/stack/react/config/eslint.config.js +++ b/stubs/stack/react/config/eslint.config.js @@ -17,6 +17,8 @@ export default tseslint.config( { rules: { '@typescript-eslint/no-explicit-any': 'off', + // Nested conditionals read as a puzzle: an if/else, a lookup or a computed instead. + 'no-nested-ternary': 'error', // v7 rules designed for the React compiler — disable until the project adopts it 'react-hooks/refs': 'off', 'react-hooks/static-components': 'off', diff --git a/stubs/stack/vue/config/eslint.config.js b/stubs/stack/vue/config/eslint.config.js index 89b1aa1..b884211 100644 --- a/stubs/stack/vue/config/eslint.config.js +++ b/stubs/stack/vue/config/eslint.config.js @@ -61,6 +61,8 @@ export default defineConfigWithVueTs( rules: { 'vue/multi-word-component-names': 'off', '@typescript-eslint/no-explicit-any': 'off', + // Nested conditionals read as a puzzle: an if/else, a lookup or a computed instead. + 'no-nested-ternary': 'error', }, }, prettier, From 64f463b64eb95980a26ee67579462c4317d36b77 Mon Sep 17 00:00:00 2001 From: roble Date: Fri, 6 Nov 2026 14:00:01 +0000 Subject: [PATCH 04/62] feat: throw when two sources declare the same capability in a group (sc-1114) Co-Authored-By: Claude Opus 5.5 --- src/Capabilities.php | 46 ++++++++++++++++++++++++--- tests/Feature/CapabilitiesTest.php | 50 ++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/Capabilities.php b/src/Capabilities.php index c8046c9..8aa622c 100644 --- a/src/Capabilities.php +++ b/src/Capabilities.php @@ -5,6 +5,7 @@ use Closure; use InterNACHI\Modular\Support\ModuleConfig; use InterNACHI\Modular\Support\ModuleRegistry; +use LogicException; /** * One catalog of what can be granted, grouped by who reads it: `api` for what a @@ -19,7 +20,12 @@ */ class Capabilities { - /** @var array>|Closure(): array>>> */ + /** + * By group, then by where `add()` was called (`file:line`), so a declaration that runs + * again replaces itself. + * + * @var array>|Closure(): array>>> + */ private array $entries = []; private bool $loaded = false; @@ -29,13 +35,31 @@ public function __construct(private readonly ModuleRegistry $modules) {} /** @param array>|Closure(): array> $entries key => ['label' => …, 'description' => …] */ public function add(string $group, array|Closure $entries): void { - $this->entries[$group][] = $entries; + $this->entries[$group][self::caller()] = $entries; + } + + /** + * Where `add()` was called from, past the facade. Modular also requires a module's + * `routes/*.php` at boot, so without a route cache a capabilities file runs twice: + * keyed by its call site, the repeat is the same declaration, not a second one. + */ + private static function caller(): string + { + foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6) as $frame) { + $file = $frame['file'] ?? null; + + if ($file !== null && $file !== __FILE__ && ! str_ends_with($file, 'Facades/Facade.php')) { + return $file.':'.($frame['line'] ?? 0); + } + } + + return 'unknown'; } /** * Every entry in the group, labels translated (the key when there is none). * Keys besides label and description (`read_only`) pass through for the - * group's reader. + * group's reader. A key declared by two sources in one group throws; across groups it is fine. * * @return array> */ @@ -43,8 +67,20 @@ public function group(string $group): array { $this->load(); - return collect($this->entries[$group] ?? []) - ->flatMap(fn (array|Closure $entries): array => $entries instanceof Closure ? $entries() : $entries) + $all = []; + + foreach ($this->entries[$group] ?? [] as $entries) { + foreach ($entries instanceof Closure ? $entries() : $entries as $key => $entry) { + // Two sources would leave one silently replacing the other, even when they agree. + if (array_key_exists($key, $all)) { + throw new LogicException("The capability [{$key}] is declared twice in the [{$group}] group."); + } + + $all[$key] = $entry; + } + } + + return collect($all) ->map(fn (array $entry, string $key): array => [ ...$entry, 'label' => __($entry['label'] ?? $key), diff --git a/tests/Feature/CapabilitiesTest.php b/tests/Feature/CapabilitiesTest.php index ebe6c99..2c3c555 100644 --- a/tests/Feature/CapabilitiesTest.php +++ b/tests/Feature/CapabilitiesTest.php @@ -2,6 +2,7 @@ namespace Saucebase\Core\Tests\Feature; +use LogicException; use Saucebase\Core\Capabilities; use Saucebase\Core\Facades\Capabilities as CapabilitiesFacade; use Saucebase\Core\Tests\Concerns\InteractsWithFixtureModules; @@ -62,4 +63,53 @@ public function test_files_load_once_per_application(): void $this->assertCount(1, $capabilities->group('api')); $this->assertSame($capabilities, $this->app->make(Capabilities::class)); } + + /** + * Two sources claiming one key with different meanings would let the second silently + * win: say which key. + */ + public function test_a_key_declared_twice_in_a_group_throws(): void + { + CapabilitiesFacade::add('billing', ['webhooks' => []]); + CapabilitiesFacade::add('billing', fn (): array => ['webhooks' => ['label' => 'Again']]); + + $this->expectException(LogicException::class); + $this->expectExceptionMessage('[webhooks]'); + + CapabilitiesFacade::group('billing'); + } + + /** + * Modular also requires a module's `routes/*.php` at boot, so without a route cache its + * capabilities file runs twice. One declaration running again replaces itself. + */ + public function test_the_same_declaration_running_again_is_not_a_conflict(): void + { + $declare = fn () => CapabilitiesFacade::add('billing', ['webhooks' => ['label' => 'Webhooks']]); + $declare(); + $declare(); + + $this->assertSame(['webhooks' => ['label' => 'Webhooks', 'description' => '']], CapabilitiesFacade::group('billing')); + } + + /** Two sources are a conflict even when they agree: one of them should not be declaring it. */ + public function test_two_sources_declaring_an_identical_key_throw(): void + { + CapabilitiesFacade::add('billing', ['webhooks' => ['label' => 'Webhooks']]); + CapabilitiesFacade::add('billing', ['webhooks' => ['label' => 'Webhooks']]); + + $this->expectException(LogicException::class); + $this->expectExceptionMessage('[webhooks]'); + + CapabilitiesFacade::group('billing'); + } + + /** Groups are read by different readers, so one key may mean something in each. */ + public function test_the_same_key_may_appear_in_different_groups(): void + { + CapabilitiesFacade::add('billing', ['posts' => []]); + + $this->assertArrayHasKey('posts', CapabilitiesFacade::group('api')); + $this->assertArrayHasKey('posts', CapabilitiesFacade::group('billing')); + } } From 3a32e7cd3cb40c439607c10ee6758f3fab504c73 Mon Sep 17 00:00:00 2001 From: roble Date: Fri, 6 Nov 2026 19:57:10 +0000 Subject: [PATCH 05/62] feat: dashboard period filter, Period and TrendStat for widgets, and the app stub's dashboard (sc-1113) Co-Authored-By: Claude Opus 5.5 --- .../saucebase-filament-development/SKILL.md | 11 ++ src/Filament/Concerns/ReadsPeriod.php | 17 ++ src/Filament/Pages/Dashboard.php | 87 +++++++++ src/Filament/Period.php | 168 ++++++++++++++++++ src/Filament/TrendStat.php | 44 +++++ .../Filament/Admin/Widgets/UsersWidget.php | 47 +++++ .../Providers/Filament/AdminPanelProvider.php | 15 +- .../app/tests/Feature/AdminDashboardTest.php | 79 ++++++++ tests/Feature/DashboardPeriodTest.php | 87 +++++++++ tests/Feature/PeriodTest.php | 151 ++++++++++++++++ tests/Fixtures/Filament/PeriodWidget.php | 17 ++ tests/Fixtures/Filament/TestPanelProvider.php | 2 +- tests/Unit/Filament/TrendStatTest.php | 47 +++++ tests/Unit/Stubs/AdminPanelStubTest.php | 30 ++++ 14 files changed, 790 insertions(+), 12 deletions(-) create mode 100644 src/Filament/Concerns/ReadsPeriod.php create mode 100644 src/Filament/Pages/Dashboard.php create mode 100644 src/Filament/Period.php create mode 100644 src/Filament/TrendStat.php create mode 100644 stubs/app/app/Filament/Admin/Widgets/UsersWidget.php create mode 100644 stubs/app/tests/Feature/AdminDashboardTest.php create mode 100644 tests/Feature/DashboardPeriodTest.php create mode 100644 tests/Feature/PeriodTest.php create mode 100644 tests/Fixtures/Filament/PeriodWidget.php create mode 100644 tests/Unit/Filament/TrendStatTest.php create mode 100644 tests/Unit/Stubs/AdminPanelStubTest.php diff --git a/resources/boost/skills/saucebase-filament-development/SKILL.md b/resources/boost/skills/saucebase-filament-development/SKILL.md index f5309a4..a12d00b 100644 --- a/resources/boost/skills/saucebase-filament-development/SKILL.md +++ b/resources/boost/skills/saucebase-filament-development/SKILL.md @@ -69,6 +69,17 @@ class FeaturePlugin implements Plugin The `ModulePlugin` trait discovers Pages, Resources and Widgets under `src/Filament/`, and Livewire components under `src/Livewire/`. +### Dashboard widgets + +The panel's dashboard is core's `Filament\Pages\Dashboard`: Filament's, with its `FilterAction` (`HasFiltersAction`) as the period filter. The header button, top right, shows the active period and opens a slide-over: a preset (Today, 7 days, 30 days default, 3 months, 12 months, custom) plus From and To. A preset fills the dates; editing a date makes it custom. Presets include today. Filters are `period`, `start`, `end`, kept in the URL and session. Other dashboards extend it and list their own `getWidgets()` (billing's does). + +- **Period:** `use Concerns\ReadsPeriod;` then `$this->period()` gives a `Filament\Period` (`start`, `end`, `previous()`, `labels()`). `$period->series($query, 'sum(amount)')` returns one value per bucket: days up to 31 days, weeks up to 92, then months. The database groups by `date()`, the same in SQLite, MySQL and PostgreSQL. +- **Stats:** `TrendStat::make($label, $now, $before, $chart, lowerIsBetter:, format:)` shows the value, the change against the previous period (green when good), and a trend line. With no baseline it says so instead of a percentage. +- **Order bands (`$sort`):** 10–19 stats, 20–29 needs attention, 30+ charts. Taken: 10 users (app), 11 workspaces (tenancy), 12 billing, 13 packages, 14 newsletter, 20 billing attention, 21 roadmap attention. Pick a free slot; `AdminDashboardTest` fails on a tie. +- **Size:** the dashboard has 2 columns. A widget with one or two stats sets `$columnSpan = 1` and `$columns` to its stat count, so it pairs with its neighbour; three or more stats take `'full'`. +- **Cost:** each lazy widget is its own request. Cache what's expensive (billing's `BillingMetrics` uses `Cache::flexible`, keyed by the dates), never what a person must act on now (attention counts). `tests/Load/DashboardLoadTest.php` times every widget: `LOAD_TEST=1 php -d memory_limit=4G artisan test tests/Load`. +- **Empty states:** no misleading zeros. Hide a widget in `canView()` until there's something to show (no packages, newsletter not configured, nothing needing attention), or show one stat linking to setup (billing without plans). Keep the permission check in `canView()` too. + Optional plugin hooks, read by core's `ModulesPlugin`: - `public static function getNavigationGroupSort(): int` orders plugin registration, and so the module's diff --git a/src/Filament/Concerns/ReadsPeriod.php b/src/Filament/Concerns/ReadsPeriod.php new file mode 100644 index 0000000..2372501 --- /dev/null +++ b/src/Filament/Concerns/ReadsPeriod.php @@ -0,0 +1,17 @@ +pageFilters); + } +} diff --git a/src/Filament/Pages/Dashboard.php b/src/Filament/Pages/Dashboard.php new file mode 100644 index 0000000..f4e838e --- /dev/null +++ b/src/Filament/Pages/Dashboard.php @@ -0,0 +1,87 @@ +label(fn (): string => $this->periodLabel()) + ->icon('heroicon-m-calendar') + ->fillForm(fn (): array => $this->filtersWithDates($this->filters)) + ->schema([ + Select::make('period') + ->label(__('Period')) + ->options(Period::options()) + ->selectablePlaceholder(false) + ->live() + ->afterStateUpdated(function (?string $state, Set $set): void { + if ($state !== 'custom') { + $dates = $this->filtersWithDates(['period' => $state]); + $set('start', $dates['start']); + $set('end', $dates['end']); + } + }), + DatePicker::make('start') + ->label(__('From')) + ->required() + ->live() + ->afterStateUpdated(fn (Set $set) => $set('period', 'custom')), + DatePicker::make('end') + ->label(__('To')) + ->required() + ->afterOrEqual('start') + ->live() + ->afterStateUpdated(fn (Set $set) => $set('period', 'custom')), + ]), + ]; + } + + /** The preset's name, or the custom range's dates. */ + private function periodLabel(): string + { + $preset = Period::preset($this->filters); + $period = Period::fromFilters($this->filters); + + // A custom range without valid dates has fallen back to the default: say so. + if ($preset !== 'custom' || ($period->end->isToday() && $period->start->equalTo(Period::fromFilters(null)->start))) { + return Period::options()[$preset === 'custom' ? Period::DEFAULT : $preset]; + } + + return $period->start->translatedFormat('M j, Y').' – '.$period->end->translatedFormat('M j, Y'); + } + + /** + * The saved filters with both dates filled in, so the form shows what a preset covers. + * + * @param array|null $filters + * @return array{period: string, start: string, end: string} + */ + private function filtersWithDates(?array $filters): array + { + $period = Period::fromFilters($filters); + + return [ + 'period' => Period::preset($filters), + 'start' => $period->start->toDateString(), + 'end' => $period->end->toDateString(), + ]; + } +} diff --git a/src/Filament/Period.php b/src/Filament/Period.php new file mode 100644 index 0000000..396dd41 --- /dev/null +++ b/src/Filament/Period.php @@ -0,0 +1,168 @@ + */ + public static function options(): array + { + return [ + 'today' => __('Today'), + '7d' => __('Last 7 days'), + '30d' => __('Last 30 days'), + '90d' => __('Last 3 months'), + '12m' => __('Last 12 months'), + 'custom' => __('Custom range'), + ]; + } + + /** The longest custom range, counted back from its end: every bucket is a chart point and a query row. */ + public const MAX_YEARS = 5; + + /** + * Filters come from the URL and the session, so anything that isn't a known preset or + * a real `Y-m-d` date falls back to the default rather than failing the page. + * + * @param array|null $filters + */ + public static function fromFilters(?array $filters): self + { + $preset = self::preset($filters); + $today = CarbonImmutable::today(); + + if ($preset === 'custom' && ($start = self::date($filters['start'] ?? null)) && ($end = self::date($filters['end'] ?? null))) { + [$start, $end] = $start <= $end ? [$start, $end] : [$end, $start]; + + return new self(max($start, $end->subYears(self::MAX_YEARS)->addDay()), $end->endOfDay()); + } + + $start = match ($preset) { + 'today' => $today, + '7d' => $today->subDays(6), + '90d' => $today->subDays(89), + '12m' => $today->subMonths(11)->startOfMonth(), + default => $today->subDays(29), + }; + + return new self($start, $today->endOfDay()); + } + + /** + * The preset the filters name, if it is one; else the default. + * + * @param array|null $filters + */ + public static function preset(?array $filters): string + { + $preset = $filters['period'] ?? null; + + return is_string($preset) && isset(self::options()[$preset]) ? $preset : self::DEFAULT; + } + + private static function date(mixed $value): ?CarbonImmutable + { + if (! is_string($value) || ! preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) { + return null; + } + + $date = CarbonImmutable::createFromFormat('!Y-m-d', $value); + + return $date && $date->format('Y-m-d') === $value ? $date : null; // 2026-02-30 rolls over: refuse it + } + + /** The same number of days, ending the day before this one starts. */ + public function previous(): self + { + $days = $this->days(); + + return new self($this->start->subDays($days), $this->start->subDay()->endOfDay()); + } + + /** @return 'day'|'week'|'month' */ + public function unit(): string + { + return match (true) { + $this->days() <= 31 => 'day', + $this->days() <= 92 => 'week', + default => 'month', + }; + } + + /** Percentage change from `$before` to `$now`; null when there is nothing to compare with. */ + public static function change(int|float $now, int|float $before): ?float + { + return $before == 0 ? null : round(($now - $before) / $before * 100, 1); + } + + /** + * One value per bucket, oldest first, empty buckets as 0. The database + * groups by day (`date()` is the same in SQLite, MySQL and PostgreSQL); + * days are added up into weeks or months here. + * + * @return list + */ + public function series(Builder $query, string $aggregate = 'count(*)', string $column = 'created_at'): array + { + $buckets = array_fill_keys(array_keys($this->labels()), 0); + + $rows = $query->whereBetween($column, [$this->start, $this->end]) + ->selectRaw("date({$column}) as bucket_day, {$aggregate} as bucket_value") + ->groupBy('bucket_day') + ->pluck('bucket_value', 'bucket_day'); + + foreach ($rows as $day => $value) { + $buckets[$this->bucketOf(CarbonImmutable::parse($day))] += 0 + $value; + } + + return array_values($buckets); + } + + /** @return array bucket key => label */ + public function labels(): array + { + $labels = []; + $cursor = $this->bucketStart($this->start); + + while ($cursor <= $this->end) { + $labels[$this->bucketOf($cursor)] = $cursor->translatedFormat($this->unit() === 'month' ? 'M Y' : 'M j'); + $cursor = $cursor->add(1, $this->unit()); + } + + return $labels; + } + + private function bucketOf(CarbonImmutable $day): string + { + return $this->bucketStart($day)->format('Y-m-d'); + } + + private function bucketStart(CarbonImmutable $day): CarbonImmutable + { + return match ($this->unit()) { + 'day' => $day->startOfDay(), + 'week' => $day->startOfWeek(), + 'month' => $day->startOfMonth(), + }; + } + + private function days(): int + { + return (int) $this->start->diffInDays($this->end->addSecond()); + } +} diff --git a/src/Filament/TrendStat.php b/src/Filament/TrendStat.php new file mode 100644 index 0000000..1528106 --- /dev/null +++ b/src/Filament/TrendStat.php @@ -0,0 +1,44 @@ + $chart + * @param (Closure(int|float): string)|null $format + */ + public static function make(string $label, int|float $now, int|float $before, array $chart = [], bool $lowerIsBetter = false, ?Closure $format = null): Stat + { + $stat = Stat::make($label, $format ? $format($now) : number_format($now)); + + if (array_filter($chart)) { + $stat->chart($chart); + } + + $change = Period::change($now, $before); + + if ($change === null) { + return $stat->description(__('No data for the previous period'))->color('gray'); + } + + $good = $change == 0 ? null : ($change > 0) !== $lowerIsBetter; + $color = match ($good) { + true => 'success', + false => 'danger', + null => 'gray', + }; + + return $stat + ->description(__(':change% vs previous period', ['change' => ($change > 0 ? '+' : '').$change])) + ->descriptionIcon($change < 0 ? 'heroicon-m-arrow-trending-down' : 'heroicon-m-arrow-trending-up') + ->color($color); + } +} diff --git a/stubs/app/app/Filament/Admin/Widgets/UsersWidget.php b/stubs/app/app/Filament/Admin/Widgets/UsersWidget.php new file mode 100644 index 0000000..135c1a6 --- /dev/null +++ b/stubs/app/app/Filament/Admin/Widgets/UsersWidget.php @@ -0,0 +1,47 @@ +user()?->can('manage users') ?? false; + } + + protected function getStats(): array + { + $period = $this->period(); + $previous = $period->previous(); + + return [ + TrendStat::make( + __('New users'), + User::whereBetween('created_at', [$period->start, $period->end])->count(), + User::whereBetween('created_at', [$previous->start, $previous->end])->count(), + $period->series(User::query()), + ), + Stat::make(__('Total users'), number_format(User::count())) + ->descriptionIcon('heroicon-m-users'), + ]; + } +} diff --git a/stubs/app/app/Providers/Filament/AdminPanelProvider.php b/stubs/app/app/Providers/Filament/AdminPanelProvider.php index b73aa97..7e1d009 100644 --- a/stubs/app/app/Providers/Filament/AdminPanelProvider.php +++ b/stubs/app/app/Providers/Filament/AdminPanelProvider.php @@ -7,12 +7,9 @@ use Filament\Http\Middleware\AuthenticateSession; use Filament\Http\Middleware\DisableBladeIconComponents; use Filament\Http\Middleware\DispatchServingFilamentEvent; -use Filament\Pages\Dashboard; use Filament\Panel; use Filament\PanelProvider; use Filament\Support\Colors\Color; -use Filament\Widgets\AccountWidget; -use Filament\Widgets\FilamentInfoWidget; use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; use Illuminate\Cookie\Middleware\EncryptCookies; use Illuminate\Foundation\Http\Middleware\PreventRequestForgery; @@ -20,6 +17,7 @@ use Illuminate\Session\Middleware\StartSession; use Illuminate\View\Middleware\ShareErrorsFromSession; use Saucebase\Core\Filament\ModulesPlugin; +use Saucebase\Core\Filament\Pages\Dashboard; use Saucebase\Core\Filament\Pages\GeneralSettings; use Saucebase\Core\Filament\Pages\LocalizationSettings; use Saucebase\Core\Filament\Pages\SeoSettings; @@ -53,10 +51,9 @@ public function panel(Panel $panel): Panel ]) ->discoverResources(in: app_path('Filament/Admin/Resources'), for: 'App\Filament\Admin\Resources') ->discoverPages(in: app_path('Filament/Admin/Pages'), for: 'App\Filament\Admin\Pages') - // Core's own settings pages are named rather than discovered: they live in - // vendor/, where Filament's directory scan does not reach. Removing one is a - // deleted line here, which is the escape hatch for anybody rebranding. - // TODO: Consider adding a mechanism to allow discovery of core settings pages if needed. + // Core's own pages are named rather than discovered: scanning vendor/ would tie + // the app to where Composer puts core. Removing one is a deleted line here, + // which is the escape hatch for anybody rebranding. ->pages([ Dashboard::class, GeneralSettings::class, @@ -64,10 +61,6 @@ public function panel(Panel $panel): Panel SeoSettings::class, ]) ->discoverWidgets(in: app_path('Filament/Admin/Widgets'), for: 'App\Filament\Admin\Widgets') - ->widgets([ - AccountWidget::class, - FilamentInfoWidget::class, - ]) ->middleware([ EncryptCookies::class, AddQueuedCookiesToResponse::class, diff --git a/stubs/app/tests/Feature/AdminDashboardTest.php b/stubs/app/tests/Feature/AdminDashboardTest.php new file mode 100644 index 0000000..ddad0a6 --- /dev/null +++ b/stubs/app/tests/Feature/AdminDashboardTest.php @@ -0,0 +1,79 @@ +create(['created_at' => '2025-01-01']); + $admin->assignRole('admin'); + $this->actingAs($admin); + } + + public function test_the_dashboard_has_the_period_picker_and_no_filament_branding(): void + { + $this->get(Dashboard::getUrl())->assertOk()->assertDontSee('filamentphp.com'); + + $widgets = Filament::getPanel('admin')->getWidgets(); + $this->assertNotContains(FilamentInfoWidget::class, $widgets); + $this->assertNotContains(AccountWidget::class, $widgets); + $this->assertContains(UsersWidget::class, $widgets); + } + + public function test_the_period_starts_at_30_days(): void + { + Livewire::test(Dashboard::class)->assertActionExists('filter', fn ($action): bool => $action->getLabel() === 'Last 30 days'); + } + + /** Widgets are ordered by band (10 stats, 20 attention, 30 charts); users open the stats. */ + public function test_users_come_first(): void + { + $sorts = collect(Filament::getPanel('admin')->getWidgets()) + ->mapWithKeys(fn (string $widget) => [$widget => $widget::getSort()]); + + $this->assertSame(10, $sorts[UsersWidget::class]); + $this->assertSame($sorts->count(), $sorts->unique()->count(), 'Two widgets share a sort: '.$sorts->duplicates()->keys()->implode(', ')); + } + + /** Like every other widget, it asks for the permission behind its own admin page. */ + public function test_users_show_only_to_user_managers(): void + { + Permission::findOrCreate('access admin panel'); + Permission::findOrCreate('manage users'); + + $this->actingAs(User::factory()->create()->givePermissionTo('access admin panel')); + $this->assertFalse(UsersWidget::canView()); + + $this->actingAs(User::factory()->create()->givePermissionTo('access admin panel', 'manage users')); + $this->assertTrue(UsersWidget::canView()); + } + + public function test_users_show_signups_against_the_previous_period(): void + { + User::factory()->count(3)->create(['created_at' => '2026-11-05']); + User::factory()->create(['created_at' => '2026-10-28']); // previous 7 days + + Livewire::test(UsersWidget::class, ['pageFilters' => ['period' => '7d']]) + ->assertSee('New users') + ->assertSee('+200% vs previous period') + ->assertSee('Total users'); + } +} diff --git a/tests/Feature/DashboardPeriodTest.php b/tests/Feature/DashboardPeriodTest.php new file mode 100644 index 0000000..eefa1ca --- /dev/null +++ b/tests/Feature/DashboardPeriodTest.php @@ -0,0 +1,87 @@ +actingAs(User::factory()->create()); + } + + /** Filament's filter action: a header button, top right, opening a slide-over. */ + public function test_the_period_is_picked_from_the_header(): void + { + Livewire::test(Dashboard::class) + ->assertActionExists('filter', fn ($action): bool => $action->isModalSlideOver() && $action->getLabel() === 'Last 30 days') + ->mountAction('filter') + ->assertSchemaStateSet(['period' => Period::DEFAULT, 'start' => '2026-10-08', 'end' => '2026-11-06']); + } + + public function test_a_preset_fills_the_dates(): void + { + Livewire::test(Dashboard::class) + ->mountAction('filter') + ->fillForm(['period' => '7d']) + ->assertSchemaStateSet(['start' => '2026-10-31', 'end' => '2026-11-06']) + ->callMountedAction() + ->assertSet('filters.period', '7d') + ->assertActionExists('filter', fn ($action): bool => $action->getLabel() === 'Last 7 days'); + } + + public function test_changing_a_date_makes_the_range_custom(): void + { + Livewire::test(Dashboard::class) + ->mountAction('filter') + ->fillForm(['start' => '2026-01-01', 'end' => '2026-01-31']) + ->assertSchemaStateSet(['period' => 'custom']) + ->callMountedAction() + ->assertSet('filters', ['period' => 'custom', 'start' => '2026-01-01', 'end' => '2026-01-31']) + ->assertActionExists('filter', fn ($action): bool => $action->getLabel() === 'Jan 1, 2026 – Jan 31, 2026'); + } + + public function test_the_end_cannot_come_before_the_start(): void + { + Livewire::test(Dashboard::class) + ->mountAction('filter') + ->fillForm(['period' => 'custom', 'start' => '2026-02-01', 'end' => '2026-01-01']) + ->callMountedAction() + ->assertHasFormErrors(['end']); + } + + /** A crafted link must not break the page, nor the session it is saved in. */ + public function test_malformed_filters_in_the_url_fall_back(): void + { + foreach ([['period' => ['x']], ['period' => 'custom', 'start' => 'garbage', 'end' => '2026-01-01']] as $filters) { + Livewire::withQueryParams(['filters' => $filters]) + ->test(Dashboard::class) + ->assertOk() + ->assertActionExists('filter', fn ($action): bool => $action->getLabel() === 'Last 30 days'); + } + } + + public function test_a_widget_reads_the_period_from_the_page(): void + { + $widget = new PeriodWidget; + + $widget->pageFilters = ['period' => '7d']; + $this->assertSame('2026-10-31', $widget->start()); + + $widget->pageFilters = null; + $this->assertSame('2026-10-08', $widget->start()); + } +} diff --git a/tests/Feature/PeriodTest.php b/tests/Feature/PeriodTest.php new file mode 100644 index 0000000..2b6be9f --- /dev/null +++ b/tests/Feature/PeriodTest.php @@ -0,0 +1,151 @@ +assertSame('2026-10-08 00:00:00', $period->start->toDateTimeString()); + $this->assertSame('2026-11-06 23:59:59', $period->end->toDateTimeString()); + } + + public function test_reads_a_preset(): void + { + $period = Period::fromFilters(['period' => '7d']); + + $this->assertSame('2026-10-31 00:00:00', $period->start->toDateTimeString()); + } + + public function test_reads_a_custom_range(): void + { + $period = Period::fromFilters(['period' => 'custom', 'start' => '2026-01-01', 'end' => '2026-01-31']); + + $this->assertSame('2026-01-01 00:00:00', $period->start->toDateTimeString()); + $this->assertSame('2026-01-31 23:59:59', $period->end->toDateTimeString()); + } + + public function test_an_incomplete_custom_range_falls_back_to_the_default(): void + { + $period = Period::fromFilters(['period' => 'custom', 'start' => '2026-01-01']); + + $this->assertSame('2026-10-08 00:00:00', $period->start->toDateTimeString()); + } + + public function test_an_unknown_preset_falls_back_to_the_default(): void + { + $this->assertSame('2026-10-08 00:00:00', Period::fromFilters(['period' => 'nope'])->start->toDateTimeString()); + } + + /** Filters come from the URL and the session: anything that isn't a preset or a date falls back. */ + public function test_malformed_filters_fall_back_to_the_default(): void + { + foreach ([ + ['period' => ['x']], + ['period' => 'custom', 'start' => 'garbage', 'end' => '2026-01-31'], + ['period' => 'custom', 'start' => ['2026-01-01'], 'end' => '2026-01-31'], + ['period' => 'custom', 'start' => '2026-01-01 00:00:00; drop', 'end' => '2026-01-31'], + ['period' => 'custom', 'start' => '2026-02-30', 'end' => '2026-03-01'], + ] as $filters) { + $this->assertSame('2026-10-08 00:00:00', Period::fromFilters($filters)->start->toDateTimeString(), json_encode($filters)); + } + } + + public function test_a_reversed_range_is_put_the_right_way_round(): void + { + $period = Period::fromFilters(['period' => 'custom', 'start' => '2026-01-31', 'end' => '2026-01-01']); + + $this->assertSame('2026-01-01 00:00:00', $period->start->toDateTimeString()); + $this->assertSame('2026-01-31 23:59:59', $period->end->toDateTimeString()); + } + + /** At most five years, counted back from the end: every bucket is a chart point and a query row. */ + public function test_a_custom_range_is_capped(): void + { + $period = Period::fromFilters(['period' => 'custom', 'start' => '0001-01-01', 'end' => '2026-01-31']); + + $this->assertSame('2021-02-01 00:00:00', $period->start->toDateTimeString()); + $this->assertLessThanOrEqual(61, count($period->labels())); + } + + /** The previous period is the same length, ending just before this one starts. */ + public function test_the_previous_period_has_the_same_length(): void + { + $previous = Period::fromFilters(['period' => '7d'])->previous(); + + $this->assertSame('2026-10-24 00:00:00', $previous->start->toDateTimeString()); + $this->assertSame('2026-10-30 23:59:59', $previous->end->toDateTimeString()); + } + + public function test_the_bucket_size_follows_the_length(): void + { + $this->assertSame('day', Period::fromFilters(['period' => '30d'])->unit()); + $this->assertSame('week', Period::fromFilters(['period' => '90d'])->unit()); + $this->assertSame('month', Period::fromFilters(['period' => '12m'])->unit()); + } + + public function test_change_is_a_percentage_or_null_without_a_baseline(): void + { + $this->assertSame(50.0, Period::change(150, 100)); + $this->assertSame(-25.0, Period::change(75, 100)); + $this->assertNull(Period::change(10, 0)); + } + + public function test_series_fills_every_bucket_in_order(): void + { + Schema::create('events', function (Blueprint $table): void { + $table->id(); + $table->unsignedInteger('amount'); + $table->timestamp('created_at'); + }); + DB::table('events')->insert([ + ['amount' => 5, 'created_at' => '2026-11-04 10:00:00'], + ['amount' => 7, 'created_at' => '2026-11-04 22:00:00'], + ['amount' => 1, 'created_at' => '2026-11-06 01:00:00'], + ['amount' => 9, 'created_at' => '2026-10-01 01:00:00'], // before the period + ]); + + $period = Period::fromFilters(['period' => '7d']); + + $this->assertSame([0, 0, 0, 0, 2, 0, 1], $period->series(DB::table('events'))); + $this->assertSame([0, 0, 0, 0, 12, 0, 1], $period->series(DB::table('events'), 'sum(amount)')); + $this->assertCount(7, $period->labels()); + } + + public function test_weekly_and_monthly_series_add_up_the_days(): void + { + Schema::create('events', function (Blueprint $table): void { + $table->id(); + $table->timestamp('created_at'); + }); + DB::table('events')->insert([ + ['created_at' => '2026-10-01 10:00:00'], + ['created_at' => '2026-10-02 10:00:00'], + ['created_at' => '2026-11-05 10:00:00'], + ]); + + $monthly = Period::fromFilters(['period' => '12m'])->series(DB::table('events')); + $weekly = Period::fromFilters(['period' => '90d'])->series(DB::table('events')); + + $this->assertSame(3, array_sum($monthly)); + $this->assertSame([2, 1], array_slice($monthly, -2)); + $this->assertSame(3, array_sum($weekly)); + $this->assertSame(1, end($weekly)); + } +} diff --git a/tests/Fixtures/Filament/PeriodWidget.php b/tests/Fixtures/Filament/PeriodWidget.php new file mode 100644 index 0000000..3db1494 --- /dev/null +++ b/tests/Fixtures/Filament/PeriodWidget.php @@ -0,0 +1,17 @@ +period()->start->toDateString(); + } +} diff --git a/tests/Fixtures/Filament/TestPanelProvider.php b/tests/Fixtures/Filament/TestPanelProvider.php index 173f7c2..9ffb2b3 100644 --- a/tests/Fixtures/Filament/TestPanelProvider.php +++ b/tests/Fixtures/Filament/TestPanelProvider.php @@ -5,7 +5,6 @@ use Filament\Http\Middleware\Authenticate; use Filament\Http\Middleware\DisableBladeIconComponents; use Filament\Http\Middleware\DispatchServingFilamentEvent; -use Filament\Pages\Dashboard; use Filament\Panel; use Filament\PanelProvider; use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; @@ -15,6 +14,7 @@ use Illuminate\Session\Middleware\StartSession; use Illuminate\View\Middleware\ShareErrorsFromSession; use Saucebase\Core\Filament\ModulesPlugin; +use Saucebase\Core\Filament\Pages\Dashboard; use Saucebase\Core\Filament\Pages\GeneralSettings; use Saucebase\Core\Filament\Pages\LocalizationSettings; diff --git a/tests/Unit/Filament/TrendStatTest.php b/tests/Unit/Filament/TrendStatTest.php new file mode 100644 index 0000000..7bc56e0 --- /dev/null +++ b/tests/Unit/Filament/TrendStatTest.php @@ -0,0 +1,47 @@ +assertSame('150', (string) $stat->getValue()); + $this->assertSame('+50% vs previous period', (string) $stat->getDescription()); + $this->assertSame('heroicon-m-arrow-trending-up', $stat->getDescriptionIcon()); + $this->assertSame('success', $stat->getColor()); + $this->assertSame([1, 2, 3], $stat->getChart()); + } + + public function test_a_fall_is_red_unless_lower_is_better(): void + { + $this->assertSame('danger', TrendStat::make('Users', 50, 100)->getColor()); + $this->assertSame('-50% vs previous period', (string) TrendStat::make('Users', 50, 100)->getDescription()); + $this->assertSame('success', TrendStat::make('Churn', 50, 100, lowerIsBetter: true)->getColor()); + $this->assertSame('heroicon-m-arrow-trending-down', TrendStat::make('Churn', 50, 100)->getDescriptionIcon()); + } + + public function test_no_baseline_says_so_instead_of_a_misleading_percentage(): void + { + $stat = TrendStat::make('Users', 3, 0); + + $this->assertSame('No data for the previous period', (string) $stat->getDescription()); + $this->assertSame('gray', $stat->getColor()); + } + + public function test_the_value_is_formatted(): void + { + $this->assertSame('1,234', (string) TrendStat::make('Users', 1234, 1000)->getValue()); + $this->assertSame('$12.34', (string) TrendStat::make('Revenue', 1234, 1000, format: fn ($v) => '$'.number_format($v / 100, 2))->getValue()); + } + + public function test_a_chart_with_no_movement_is_left_out(): void + { + $this->assertNull(TrendStat::make('Users', 0, 0, [0, 0, 0])->getChart()); + } +} diff --git a/tests/Unit/Stubs/AdminPanelStubTest.php b/tests/Unit/Stubs/AdminPanelStubTest.php new file mode 100644 index 0000000..d12e3dc --- /dev/null +++ b/tests/Unit/Stubs/AdminPanelStubTest.php @@ -0,0 +1,30 @@ +assertStringContainsString('use Saucebase\Core\Filament\Pages\Dashboard;', $provider); + $this->assertStringNotContainsString('use Filament\Pages\Dashboard;', $provider); + $this->assertStringNotContainsString('FilamentInfoWidget', $provider); + $this->assertStringNotContainsString('AccountWidget', $provider); + } + + public function test_the_app_ships_the_users_widget_and_its_test(): void + { + $this->assertFileExists(self::APP.'app/Filament/Admin/Widgets/UsersWidget.php'); + $this->assertFileExists(self::APP.'tests/Feature/AdminDashboardTest.php'); + } +} From 6ed4b00fc29d72458ef39e0f5b9ea487dbeec981 Mon Sep 17 00:00:00 2001 From: roble Date: Fri, 6 Nov 2026 20:43:07 +0000 Subject: [PATCH 06/62] fix: keep every month in the 12-month period, warn when the E2E env isn't created, stop workers together From review on #38: the 12-month preset and the five-year cap no longer roll past a short month or a leap day; the installer says how to create .env.e2e when playwright:env fails; task workers fails fast. Co-Authored-By: Claude Opus 5.5 --- src/Console/Commands/InstallCommand.php | 7 +++++-- src/Filament/Period.php | 4 ++-- stubs/app/Taskfile.yml | 1 + tests/Feature/InstallCommandTest.php | 22 ++++++++++++++++++++++ tests/Feature/PeriodTest.php | 18 ++++++++++++++++++ 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/Console/Commands/InstallCommand.php b/src/Console/Commands/InstallCommand.php index 6295af8..c3cdafa 100644 --- a/src/Console/Commands/InstallCommand.php +++ b/src/Console/Commands/InstallCommand.php @@ -85,8 +85,11 @@ public function handle(Filesystem $files, ProjectConfig $config): int $this->publishStack($files, $stubs.'/stack', $framework); // A package's require-dev never reaches the app, so a manual install may not have it. - if (array_key_exists('playwright:env', Artisan::all())) { - $this->call('playwright:env', ['--no-interaction' => true]); + if (array_key_exists('playwright:env', Artisan::all()) + && $this->call('playwright:env', ['--no-interaction' => true]) !== self::SUCCESS + && ! $files->exists($this->laravel->basePath('.env.e2e'))) { + // Everything else is in place, so finish and say how to complete it. + $this->components->warn('The E2E environment file (.env.e2e) could not be created. Create it with: php artisan playwright:env'); } $this->components->info("Saucebase is installed with {$framework}."); diff --git a/src/Filament/Period.php b/src/Filament/Period.php index 396dd41..7752814 100644 --- a/src/Filament/Period.php +++ b/src/Filament/Period.php @@ -49,14 +49,14 @@ public static function fromFilters(?array $filters): self if ($preset === 'custom' && ($start = self::date($filters['start'] ?? null)) && ($end = self::date($filters['end'] ?? null))) { [$start, $end] = $start <= $end ? [$start, $end] : [$end, $start]; - return new self(max($start, $end->subYears(self::MAX_YEARS)->addDay()), $end->endOfDay()); + return new self(max($start, $end->subYearsNoOverflow(self::MAX_YEARS)->addDay()), $end->endOfDay()); } $start = match ($preset) { 'today' => $today, '7d' => $today->subDays(6), '90d' => $today->subDays(89), - '12m' => $today->subMonths(11)->startOfMonth(), + '12m' => $today->startOfMonth()->subMonths(11), // from the 1st: the 31st minus months can roll forward default => $today->subDays(29), }; diff --git a/stubs/app/Taskfile.yml b/stubs/app/Taskfile.yml index f89fc2c..5533df7 100644 --- a/stubs/app/Taskfile.yml +++ b/stubs/app/Taskfile.yml @@ -32,6 +32,7 @@ tasks: workers: desc: Run the queue worker and scheduler together deps: [queue, schedule] + failfast: true # one stopping stops both (Task 3.46.1+), so jobs never pile up unprocessed build: desc: Production build (includes SSR) diff --git a/tests/Feature/InstallCommandTest.php b/tests/Feature/InstallCommandTest.php index 4364185..7149bdf 100644 --- a/tests/Feature/InstallCommandTest.php +++ b/tests/Feature/InstallCommandTest.php @@ -96,6 +96,7 @@ public function test_the_taskfile_runs_the_queue_and_scheduler_without_a_web_ser $this->assertStringContainsString('{{.APP}} php artisan queue:listen', $tasks['queue']['cmd']); $this->assertStringContainsString('{{.APP}} php artisan schedule:work', $tasks['schedule']['cmd']); $this->assertSame(['queue', 'schedule'], $tasks['workers']['deps']); + $this->assertTrue($tasks['workers']['failfast'], 'one worker stopping must stop both'); } public function test_it_writes_the_e2e_env_when_the_playwright_package_is_installed(): void @@ -110,6 +111,27 @@ public function test_it_writes_the_e2e_env_when_the_playwright_package_is_instal $this->assertTrue($ran, 'playwright:env should run, unattended, so it can never replace a file.'); } + /** The rest is installed and `saucebase.json` written, so say how to finish instead of failing. */ + public function test_a_failed_e2e_env_says_how_to_create_it(): void + { + Artisan::command('playwright:env', fn () => 1); + + $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true]) + ->expectsOutputToContain('php artisan playwright:env') + ->assertSuccessful(); + } + + /** It also fails when it refuses to replace an existing `.env.e2e`: nothing to say then. */ + public function test_an_existing_e2e_env_is_not_reported(): void + { + file_put_contents($this->appPath.'/.env.e2e', "APP_ENV=e2e\n"); + Artisan::command('playwright:env', fn () => 1); + + $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true]) + ->doesntExpectOutputToContain('could not be created') + ->assertSuccessful(); + } + public function test_it_installs_without_the_playwright_package(): void { $this->assertArrayNotHasKey('playwright:env', Artisan::all()); diff --git a/tests/Feature/PeriodTest.php b/tests/Feature/PeriodTest.php index 2b6be9f..426fd32 100644 --- a/tests/Feature/PeriodTest.php +++ b/tests/Feature/PeriodTest.php @@ -84,6 +84,13 @@ public function test_a_custom_range_is_capped(): void $this->assertLessThanOrEqual(61, count($period->labels())); } + public function test_the_cap_does_not_roll_past_a_leap_day(): void + { + $period = Period::fromFilters(['period' => 'custom', 'start' => '2000-01-01', 'end' => '2028-02-29']); + + $this->assertSame('2023-03-01 00:00:00', $period->start->toDateTimeString()); + } + /** The previous period is the same length, ending just before this one starts. */ public function test_the_previous_period_has_the_same_length(): void { @@ -100,6 +107,17 @@ public function test_the_bucket_size_follows_the_length(): void $this->assertSame('month', Period::fromFilters(['period' => '12m'])->unit()); } + /** On the 31st, eleven months back can land in a month with no 31st and roll forward. */ + public function test_12_months_keeps_every_month_at_a_month_end(): void + { + Carbon::setTestNow('2027-03-31 12:00:00'); + + $period = Period::fromFilters(['period' => '12m']); + + $this->assertSame('2026-04-01 00:00:00', $period->start->toDateTimeString()); + $this->assertCount(12, $period->labels()); + } + public function test_change_is_a_percentage_or_null_without_a_baseline(): void { $this->assertSame(50.0, Period::change(150, 100)); From 680b5370edd7f117236db1191e72fb96620daed6 Mon Sep 17 00:00:00 2001 From: roble Date: Sun, 8 Nov 2026 17:19:45 +0000 Subject: [PATCH 07/62] chore: alias the dev branch as 2.13.x-dev dev installs as dev-dev, which no ^2.x constraint accepts, so apps could not test it against modules that require a release. A test fails once a release passes the alias, as a reminder to move it on. Co-Authored-By: Claude Opus 5.5 --- composer.json | 3 +++ tests/Unit/BranchAliasTest.php | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/Unit/BranchAliasTest.php diff --git a/composer.json b/composer.json index 019667e..1200935 100644 --- a/composer.json +++ b/composer.json @@ -61,6 +61,9 @@ } }, "extra": { + "branch-alias": { + "dev-dev": "2.13.x-dev" + }, "laravel": { "providers": [ "Saucebase\\Core\\CoreServiceProvider" diff --git a/tests/Unit/BranchAliasTest.php b/tests/Unit/BranchAliasTest.php new file mode 100644 index 0000000..f59a935 --- /dev/null +++ b/tests/Unit/BranchAliasTest.php @@ -0,0 +1,37 @@ +assertIsString($alias, 'composer.json needs extra.branch-alias.dev-dev'); + $this->assertMatchesRegularExpression('/^\d+\.\d+\.x-dev$/', $alias); + + $tags = new Process(['git', 'tag', '--list', 'v*', '--sort=-v:refname'], dirname(__DIR__, 2)); + $newest = strtok((string) $tags->mustRun()->getOutput(), "\n"); + + if ($newest === false) { + $this->markTestSkipped('No release tags in this checkout.'); + } + + // 2.13.x-dev against v2.12.0: compare the alias's minor as 2.13.0. + $this->assertTrue( + Comparator::greaterThan(str_replace('.x-dev', '.0', $alias), ltrim($newest, 'v')), + "dev-dev is aliased {$alias}, but {$newest} is already released: move the alias past it.", + ); + } +} From 33c8062f45ab0a90cc265449523abeb996176c52 Mon Sep 17 00:00:00 2001 From: roble Date: Tue, 10 Nov 2026 16:10:41 +0000 Subject: [PATCH 08/62] feat: named states replace --demo in modules:seed modules:seed --state= runs each module's {State}{Module}DatabaseSeeder after the required seeders; showcase is the sample content. A state no module provides fails, a failing seeder stops the run, and in production modules:seed asks once (--force skips, also on module-setup/module-install). Co-Authored-By: Claude Opus 5.5 --- config/saucebase.php | 2 +- resources/boost/guidelines/core.md | 4 +- .../saucebase-module-development/SKILL.md | 8 +- src/Attributes/SeedAfter.php | 2 +- src/Console/Commands/ModuleInstallCommand.php | 9 +- src/Console/Commands/ModuleSetupCommand.php | 7 +- src/Console/Commands/SeedModulesCommand.php | 54 ++++++++--- stubs/app/README.md | 4 +- stubs/app/Taskfile.yml | 10 +- stubs/recipes/basic/Taskfile.yml | 4 +- .../seeders/DemoModuleDatabaseSeeder.php | 18 ---- .../seeders/ShowcaseModuleDatabaseSeeder.php | 18 ++++ tests/Feature/ModuleInstallCommandTest.php | 19 +++- tests/Feature/ModuleSetupCommandTest.php | 42 +++++++-- tests/Feature/SeedModulesCommandTest.php | 92 ++++++++++++++++--- ...owcaseModuleTestFixtureDatabaseSeeder.php} | 2 +- tests/Fixtures/seed-order/seeders.php | 17 +++- 17 files changed, 229 insertions(+), 83 deletions(-) delete mode 100644 stubs/recipes/basic/database/seeders/DemoModuleDatabaseSeeder.php create mode 100644 stubs/recipes/basic/database/seeders/ShowcaseModuleDatabaseSeeder.php rename tests/Fixtures/modules/module-test-fixture/database/seeders/{DemoModuleTestFixtureDatabaseSeeder.php => ShowcaseModuleTestFixtureDatabaseSeeder.php} (77%) diff --git a/config/saucebase.php b/config/saucebase.php index 415a771..0a48f6a 100644 --- a/config/saucebase.php +++ b/config/saucebase.php @@ -13,7 +13,7 @@ 'ignore_files' => ['module.json'], /* - * The password of every account the demo seeders create. There is no default: + * The password of every account a state's seeders create. There is no default: * a known password on a reachable admin account is the risk this avoids. */ 'demo_password' => env('DEMO_PASSWORD'), diff --git a/resources/boost/guidelines/core.md b/resources/boost/guidelines/core.md index 095a515..bed94ca 100644 --- a/resources/boost/guidelines/core.md +++ b/resources/boost/guidelines/core.md @@ -25,8 +25,8 @@ module plugin. `canAccess()` and created by the module's `DatabaseSeeder`, and site-wide settings pages are `manage settings`. The `admin` role passes every check through core's `Gate::before`. Roles are defined in core's `RolesDatabaseSeeder`; `admin` and `user` (the role - every sign-up gets) are fixed names modules may assign. The one exception is demo data: a module's - `Demo…DatabaseSeeder` may create a staff role for its own area (`blog admin`, `blog@saucebase.dev`). + every sign-up gets) are fixed names modules may assign. The one exception is showcase data: a module's + `Showcase…DatabaseSeeder` may create a staff role for its own area (`blog admin`, `blog@saucebase.dev`). - Where a signed-in user lands is the app's choice: `Home::using(fn (Request $request, string $reason) => …)` in a service provider (null means the site root). Modules redirect with `Home::url($request, Home::LOGIN)` or link to `route('home')`, never `route('dashboard')`, which is only the dashboard page. diff --git a/resources/boost/skills/saucebase-module-development/SKILL.md b/resources/boost/skills/saucebase-module-development/SKILL.md index c9be4b3..1b296a5 100644 --- a/resources/boost/skills/saucebase-module-development/SKILL.md +++ b/resources/boost/skills/saucebase-module-development/SKILL.md @@ -159,11 +159,13 @@ redirects such as OAuth callbacks. ## Seeders `php artisan modules:seed` runs `Modules\\Database\Seeders\DatabaseSeeder` for every installed module -that has one; `--module=` limits it to one. `--demo` then also runs `DemoDatabaseSeeder`, after -every module's required data exists. Each set runs in registry order, except that a seeder marked +that has one; `--module=` limits it to one. `--state=` then also runs `DatabaseSeeder`, after +every module's required data exists; `showcase` is the sample content (`ShowcaseBlogDatabaseSeeder`). A state +no module provides fails. In production it asks first; `--force` (also on `saucebase:module-setup` and +`saucebase:module-install`) skips the question. Each set runs in registry order, except that a seeder marked `#[SeedAfter('billing')]` (`Saucebase\Core\Attributes\SeedAfter`) runs after the named modules' seeder of the same kind; modules that aren't installed are ignored. A module with an admin area creates its `manage {module}` permission -there (see `saucebase-filament-development`); demo seeders never hold anything an install needs. +there (see `saucebase-filament-development`); state seeders never hold anything an install needs. ## Patches diff --git a/src/Attributes/SeedAfter.php b/src/Attributes/SeedAfter.php index c2d47de..e910950 100644 --- a/src/Attributes/SeedAfter.php +++ b/src/Attributes/SeedAfter.php @@ -6,7 +6,7 @@ /** * Runs a module's seeder after the named modules' seeders of the same kind - * (required or demo), for data that builds on theirs. Modules that aren't + * (required, or the same state), for data that builds on theirs. Modules that aren't * installed are ignored. */ #[Attribute(Attribute::TARGET_CLASS)] diff --git a/src/Console/Commands/ModuleInstallCommand.php b/src/Console/Commands/ModuleInstallCommand.php index 3da8b5f..15d79b9 100644 --- a/src/Console/Commands/ModuleInstallCommand.php +++ b/src/Console/Commands/ModuleInstallCommand.php @@ -19,14 +19,15 @@ class ModuleInstallCommand extends Command { protected $signature = 'saucebase:module-install {modules?* : Module names (billing). Omit to pick from a list} - {--demo : Also seed demo content}'; + {--state= : Also seed a state (showcase: sample content)} + {--force : Seed in production without asking}'; protected $description = 'Install Saucebase modules into this application'; public function handle(): int { - if ($this->option('demo') && blank(config('saucebase.demo_password'))) { - $this->components->error('Set DEMO_PASSWORD in .env to seed demo data. Every demo account uses it.'); + if ($this->option('state') && blank(config('saucebase.demo_password'))) { + $this->components->error('Set DEMO_PASSWORD in .env to seed a state. Every account it creates uses it.'); return self::FAILURE; } @@ -66,7 +67,7 @@ public function handle(): int // TTY, so a module's own install command can ask its questions. return Process::path(base_path())->forever()->tty(SymfonyProcess::isTtySupported() && $this->input->isInteractive()) - ->run([PHP_BINARY, 'artisan', 'saucebase:module-setup', ...$modules, ...($this->option('demo') ? ['--demo'] : [])], $output) + ->run([PHP_BINARY, 'artisan', 'saucebase:module-setup', ...$modules, ...($this->option('state') ? ['--state='.$this->option('state')] : []), ...($this->option('force') ? ['--force'] : [])], $output) ->successful() ? self::SUCCESS : self::FAILURE; } diff --git a/src/Console/Commands/ModuleSetupCommand.php b/src/Console/Commands/ModuleSetupCommand.php index d061320..4f93602 100644 --- a/src/Console/Commands/ModuleSetupCommand.php +++ b/src/Console/Commands/ModuleSetupCommand.php @@ -18,7 +18,8 @@ class ModuleSetupCommand extends Command { protected $signature = 'saucebase:module-setup {modules* : Installed module names} - {--demo : Also seed demo content}'; + {--state= : Also seed a state (showcase: sample content)} + {--force : Seed in production without asking}'; protected $description = 'Apply patches, migrate and seed installed modules'; @@ -41,7 +42,7 @@ public function handle(ModuleRegistry $registry, ProjectConfig $config): int $steps = [ ['migrate', ['--force' => true]], // Together: seeding them one by one would hide each from the others' SeedAfter. - ['modules:seed', ['--module' => array_map(fn ($module) => $module->name, $modules), '--demo' => $this->option('demo')]], + ['modules:seed', ['--module' => array_map(fn ($module) => $module->name, $modules), '--state' => $this->option('state'), '--force' => $this->option('force')]], ]; foreach ($modules as $module) { @@ -68,7 +69,7 @@ public function handle(ModuleRegistry $registry, ProjectConfig $config): int foreach ($steps as [$command, $arguments]) { if ($this->runStep($command, $arguments) !== self::SUCCESS) { - $this->components->error("`{$command}` failed. Fix it, then run this again: php artisan saucebase:module-setup ".implode(' ', $this->argument('modules')).($this->option('demo') ? ' --demo' : '')); + $this->components->error("`{$command}` failed. Fix it, then run this again: php artisan saucebase:module-setup ".implode(' ', $this->argument('modules')).($this->option('state') ? ' --state='.$this->option('state') : '').($this->option('force') ? ' --force' : '')); return self::FAILURE; } diff --git a/src/Console/Commands/SeedModulesCommand.php b/src/Console/Commands/SeedModulesCommand.php index 23b1b52..e96f429 100644 --- a/src/Console/Commands/SeedModulesCommand.php +++ b/src/Console/Commands/SeedModulesCommand.php @@ -3,6 +3,7 @@ namespace Saucebase\Core\Console\Commands; use Illuminate\Console\Command; +use Illuminate\Console\ConfirmableTrait; use Illuminate\Support\Collection; use Illuminate\Support\Str; use InterNACHI\Modular\Support\ModuleRegistry; @@ -13,20 +14,31 @@ class SeedModulesCommand extends Command { + use ConfirmableTrait; + protected $signature = 'modules:seed {--module=* : Seed specific modules (case-insensitive), together. Omit to seed all.} - {--demo : Also run each module\'s Demo{Module}DatabaseSeeder with sample content.}'; + {--state= : Also run each module\'s seeder for this state, e.g. showcase runs ShowcaseBlogDatabaseSeeder} + {--force : Seed in production without asking}'; protected $description = 'Seed all installed modules that have a DatabaseSeeder'; public function handle(ModuleRegistry $registry): int { - if ($this->option('demo') && blank(config('saucebase.demo_password'))) { - $this->components->error('Set DEMO_PASSWORD in .env to seed demo data. Every demo account uses it.'); + $state = $this->option('state') ? Str::studly($this->option('state')) : null; + + if ($state !== null && blank(config('saucebase.demo_password'))) { + $this->components->error('Set DEMO_PASSWORD in .env to seed a state. Every account it creates uses it.'); return self::FAILURE; } + // Asked once here rather than by db:seed for every module. A state creates sample + // accounts and content: never in production by accident. + if (! $this->confirmToProceed()) { + return self::FAILURE; + } + $modules = $registry->modules(); // A string when another command calls this with one name. @@ -51,30 +63,38 @@ public function handle(ModuleRegistry $registry): int $modules = $named; } - $this->seed($modules, fn (string $studly) => 'DatabaseSeeder'); + $required = $this->seeders($modules, fn (string $studly) => 'DatabaseSeeder'); + $stated = $state === null ? collect() : $this->seeders($modules, fn (string $studly) => "{$state}{$studly}DatabaseSeeder"); + + if ($state !== null && $stated->isEmpty()) { + $this->components->error("No module has a \"{$this->option('state')}\" state."); - if ($this->option('demo')) { - // Every module's required data exists before any demo content refers to it. - $this->seed($modules, fn (string $studly) => "Demo{$studly}DatabaseSeeder"); + return self::FAILURE; } - return self::SUCCESS; + // Every module's required data exists before any state refers to it. + return $this->seed($required) && $this->seed($stated) ? self::SUCCESS : self::FAILURE; } /** * @param Collection $modules * @param callable(string): string $seederName + * @return Collection Module name => seeder class, for those that have one. */ - private function seed(Collection $modules, callable $seederName): void + private function seeders(Collection $modules, callable $seederName): Collection { - $seeders = $modules + return $modules ->mapWithKeys(function ($module) use ($seederName): array { $studly = Str::studly($module->name); return [$module->name => "Modules\\{$studly}\\Database\\Seeders\\".$seederName($studly)]; }) ->filter(fn (string $seeder): bool => class_exists($seeder)); + } + /** @param Collection $seeders */ + private function seed(Collection $seeders): bool + { $after = $seeders->map( fn (string $seeder): array => collect((new ReflectionClass($seeder)) ->getAttributes(SeedAfter::class)) @@ -85,10 +105,22 @@ private function seed(Collection $modules, callable $seederName): void foreach (DependencyOrder::sort($seeders->keys()->all(), $after->all()) as $name) { $seeder = $seeders[$name]; + $seeded = false; + $this->components->task( "{$name} ".class_basename($seeder), - fn () => $this->call('db:seed', ['--class' => $seeder]) === self::SUCCESS, + function () use ($seeder, &$seeded): bool { + // Asked once above; db:seed would ask again for every module. + return $seeded = $this->call('db:seed', ['--class' => $seeder, '--force' => true]) === self::SUCCESS; + }, ); + + // The modules after this one may build on its data. + if (! $seeded) { + return false; + } } + + return true; } } diff --git a/stubs/app/README.md b/stubs/app/README.md index dd65708..75a436e 100644 --- a/stubs/app/README.md +++ b/stubs/app/README.md @@ -15,10 +15,10 @@ Built with [Saucebase](https://github.com/saucebase-dev/saucebase), on Laravel a ## Sign in -With demo data, sign in as `chef@saucebase.dev`, a full admin. Every demo account uses the +With the showcase state, sign in as `chef@saucebase.dev`, a full admin. Every showcase account uses the password saved in `.env` as `DEMO_PASSWORD`. The admin panel is at `/admin`. -Reload the demo data with `task db:reset:demo`. +Reload the showcase data with `task db:reset:showcase`. ## Modules diff --git a/stubs/app/Taskfile.yml b/stubs/app/Taskfile.yml index 5533df7..e88fa7a 100644 --- a/stubs/app/Taskfile.yml +++ b/stubs/app/Taskfile.yml @@ -99,16 +99,16 @@ tasks: - '{{.APP}} php artisan migrate:fresh --seed' - '{{.APP}} php artisan modules:seed' - db:reset:demo: - desc: Reset database and load sample content (the auth module's demo includes an admin) + db:reset:showcase: + desc: Reset database and load sample content (the auth module's showcase includes an admin) prompt: This will erase ALL data. Are you sure? cmds: - '{{.APP}} php artisan migrate:fresh --seed' - - '{{.APP}} php artisan modules:seed --demo' + - '{{.APP}} php artisan modules:seed --state=showcase' - db:seed:demo: + db:seed:showcase: desc: Seed every module with sample content - cmd: '{{.APP}} php artisan modules:seed --demo' + cmd: '{{.APP}} php artisan modules:seed --state=showcase' # ── Translation ─────────────────────────────────────────────── diff --git a/stubs/recipes/basic/Taskfile.yml b/stubs/recipes/basic/Taskfile.yml index 86b45ac..8fe05a0 100644 --- a/stubs/recipes/basic/Taskfile.yml +++ b/stubs/recipes/basic/Taskfile.yml @@ -14,9 +14,9 @@ tasks: # ── Database ────────────────────────────────────────────────── - db:seed:demo: + db:seed:showcase: desc: Seed the {Module} module with sample content - cmd: '{{.APP}} php artisan modules:seed --module={module} --demo' + cmd: '{{.APP}} php artisan modules:seed --module={module} --state=showcase' # ── Code Generation ──────────────────────────────────────────── diff --git a/stubs/recipes/basic/database/seeders/DemoModuleDatabaseSeeder.php b/stubs/recipes/basic/database/seeders/DemoModuleDatabaseSeeder.php deleted file mode 100644 index 9a85d9a..0000000 --- a/stubs/recipes/basic/database/seeders/DemoModuleDatabaseSeeder.php +++ /dev/null @@ -1,18 +0,0 @@ - [['name' => 'laravel/sanctum', 'type' => 'library'], ...$packages]]); } - public function test_demo_is_passed_on_to_the_setup(): void + public function test_a_state_is_passed_on_to_the_setup(): void { Process::fake(); config(['saucebase.demo_password' => 'secret']); - $this->artisan('saucebase:module-install', ['modules' => ['blog'], '--demo' => true])->assertSuccessful(); + $this->artisan('saucebase:module-install', ['modules' => ['blog'], '--state' => 'showcase'])->assertSuccessful(); - Process::assertRan(fn (PendingProcess $p) => $p->command === [PHP_BINARY, 'artisan', 'saucebase:module-setup', 'blog', '--demo']); + Process::assertRan(fn (PendingProcess $p) => $p->command === [PHP_BINARY, 'artisan', 'saucebase:module-setup', 'blog', '--state=showcase']); } - public function test_demo_without_a_demo_password_fails_before_anything_runs(): void + public function test_force_is_passed_on_to_the_setup(): void + { + Process::fake(); + config(['saucebase.demo_password' => 'secret']); + $this->artisan('saucebase:module-install', ['modules' => ['blog'], '--state' => 'showcase', '--force' => true])->assertSuccessful(); + + Process::assertRan(fn (PendingProcess $p) => $p->command === [PHP_BINARY, 'artisan', 'saucebase:module-setup', 'blog', '--state=showcase', '--force']); + } + + public function test_a_state_without_a_demo_password_fails_before_anything_runs(): void { Process::fake(); config(['saucebase.demo_password' => null]); - $this->artisan('saucebase:module-install', ['modules' => ['blog'], '--demo' => true]) + $this->artisan('saucebase:module-install', ['modules' => ['blog'], '--state' => 'showcase']) ->expectsOutputToContain('Set DEMO_PASSWORD in .env') ->assertFailed(); diff --git a/tests/Feature/ModuleSetupCommandTest.php b/tests/Feature/ModuleSetupCommandTest.php index b810087..10dfab3 100644 --- a/tests/Feature/ModuleSetupCommandTest.php +++ b/tests/Feature/ModuleSetupCommandTest.php @@ -92,23 +92,53 @@ private function assertSetupWarns(string $user, bool $warns): void } } - public function test_demo_also_seeds_demo_content(): void + public function test_a_state_also_seeds_its_content(): void { Process::fake(); config(['saucebase.demo_password' => 'secret']); - $this->artisan('saucebase:module-setup', ['modules' => ['module-test-fixture'], '--demo' => true])->assertSuccessful(); + $this->artisan('saucebase:module-setup', ['modules' => ['module-test-fixture'], '--state' => 'showcase'])->assertSuccessful(); - $this->assertSame(['DatabaseSeeder', 'DemoModuleTestFixtureDatabaseSeeder'], DatabaseSeeder::$ran); + $this->assertSame(['DatabaseSeeder', 'ShowcaseModuleTestFixtureDatabaseSeeder'], DatabaseSeeder::$ran); + } + + public function test_in_production_seeding_asks_first(): void + { + Process::fake(); + config(['saucebase.demo_password' => 'secret']); + $this->app->detectEnvironment(fn () => 'production'); + + // migrate is forced; seeding a state is the operator's call. + $this->artisan('saucebase:module-setup', ['modules' => ['module-test-fixture'], '--state' => 'showcase']) + ->expectsConfirmation('Are you sure you want to run this command?', 'no') + ->assertFailed() + ->run(); + $this->app->detectEnvironment(fn () => 'testing'); + + $this->assertSame([], DatabaseSeeder::$ran); + } + + public function test_in_production_force_seeds_without_asking(): void + { + Process::fake(); + config(['saucebase.demo_password' => 'secret']); + $this->app->detectEnvironment(fn () => 'production'); + + $this->artisan('saucebase:module-setup', ['modules' => ['module-test-fixture'], '--state' => 'showcase', '--force' => true]) + ->assertSuccessful() + ->run(); + $this->app->detectEnvironment(fn () => 'testing'); + + $this->assertSame(['DatabaseSeeder', 'ShowcaseModuleTestFixtureDatabaseSeeder'], DatabaseSeeder::$ran); } public function test_a_failed_step_fails_the_setup_and_stops_there(): void { Process::fake(); - config(['saucebase.demo_password' => null]); // modules:seed --demo refuses without it + config(['saucebase.demo_password' => null]); // modules:seed --state refuses without it - $this->artisan('saucebase:module-setup', ['modules' => ['module-test-fixture'], '--demo' => true]) - ->expectsOutputToContain('run this again: php artisan saucebase:module-setup module-test-fixture --demo') + $this->artisan('saucebase:module-setup', ['modules' => ['module-test-fixture'], '--state' => 'showcase']) + ->expectsOutputToContain('run this again: php artisan saucebase:module-setup module-test-fixture --state=showcase') ->assertFailed(); $this->assertFalse(InstallFixtureCommand::$ran); diff --git a/tests/Feature/SeedModulesCommandTest.php b/tests/Feature/SeedModulesCommandTest.php index 80c384d..9a18d97 100644 --- a/tests/Feature/SeedModulesCommandTest.php +++ b/tests/Feature/SeedModulesCommandTest.php @@ -10,9 +10,9 @@ use Saucebase\Core\Tests\TestCase; /** - * `modules:seed` runs each module's required data, and with `--demo` its sample - * content too — required data first, for every module, so demo content can refer to - * anything another module needs to exist. + * `modules:seed` runs each module's required data, and with `--state=` each + * module's `{State}{Module}DatabaseSeeder` too — required data first, for every module, + * so a state can refer to anything another module needs to exist. */ class SeedModulesCommandTest extends TestCase { @@ -36,41 +36,89 @@ public function test_it_runs_only_the_required_seeder_by_default(): void $this->assertSame(['DatabaseSeeder'], DatabaseSeeder::$ran); } - public function test_demo_runs_the_demo_seeder_after_the_required_one(): void + public function test_a_state_runs_its_seeders_after_the_required_ones(): void { - $this->artisan('modules:seed', ['--demo' => true])->assertSuccessful(); + $this->artisan('modules:seed', ['--state' => 'showcase'])->assertSuccessful(); $this->assertSame( - ['DatabaseSeeder', 'DemoModuleTestFixtureDatabaseSeeder'], + ['DatabaseSeeder', 'ShowcaseModuleTestFixtureDatabaseSeeder'], DatabaseSeeder::$ran, ); } - public function test_demo_refuses_without_a_demo_password(): void + public function test_a_state_refuses_without_a_demo_password(): void { config(['saucebase.demo_password' => null]); - $this->artisan('modules:seed', ['--demo' => true]) + $this->artisan('modules:seed', ['--state' => 'showcase']) ->expectsOutputToContain('Set DEMO_PASSWORD in .env') ->assertFailed(); $this->assertSame([], DatabaseSeeder::$ran); } + public function test_a_state_no_module_provides_fails_without_seeding_anything(): void + { + $this->artisan('modules:seed', ['--state' => 'missing']) + ->expectsOutputToContain('No module has a "missing" state.') + ->assertFailed(); + + $this->assertSame([], DatabaseSeeder::$ran); + } + + public function test_a_state_in_production_asks_first(): void + { + $this->app->detectEnvironment(fn () => 'production'); + + $this->artisan('modules:seed', ['--state' => 'showcase']) + ->expectsConfirmation('Are you sure you want to run this command?', 'no') + ->assertFailed() + ->run(); + $this->app->detectEnvironment(fn () => 'testing'); // or teardown's rollback asks too + + $this->assertSame([], DatabaseSeeder::$ran); + } + + public function test_required_data_in_production_asks_first(): void + { + $this->app->detectEnvironment(fn () => 'production'); + + $this->artisan('modules:seed') + ->expectsConfirmation('Are you sure you want to run this command?', 'no') + ->assertFailed() + ->run(); + $this->app->detectEnvironment(fn () => 'testing'); + + $this->assertSame([], DatabaseSeeder::$ran); + } + + public function test_a_state_in_production_runs_with_force(): void + { + $this->app->detectEnvironment(fn () => 'production'); + + $this->artisan('modules:seed', ['--state' => 'showcase', '--force' => true])->assertSuccessful()->run(); + $this->app->detectEnvironment(fn () => 'testing'); + + $this->assertSame( + ['DatabaseSeeder', 'ShowcaseModuleTestFixtureDatabaseSeeder'], + DatabaseSeeder::$ran, + ); + } + public function test_module_option_matches_case_insensitively(): void { - $this->artisan('modules:seed', ['--module' => 'Module-Test-Fixture', '--demo' => true]) + $this->artisan('modules:seed', ['--module' => 'Module-Test-Fixture', '--state' => 'showcase']) ->assertSuccessful(); $this->assertSame( - ['DatabaseSeeder', 'DemoModuleTestFixtureDatabaseSeeder'], + ['DatabaseSeeder', 'ShowcaseModuleTestFixtureDatabaseSeeder'], DatabaseSeeder::$ran, ); } public function test_an_unknown_module_fails_without_seeding_anything(): void { - $this->artisan('modules:seed', ['--module' => 'missing', '--demo' => true]) + $this->artisan('modules:seed', ['--module' => 'missing', '--state' => 'showcase']) ->assertFailed(); $this->assertSame([], DatabaseSeeder::$ran); @@ -88,9 +136,23 @@ public function test_a_seeder_runs_after_the_installed_modules_it_names_in_seed_ 'omega' => new ModuleConfig('omega', '/tmp/omega', collect()), ])); - $this->artisan('modules:seed', ['--demo' => true])->assertSuccessful(); + $this->artisan('modules:seed', ['--state' => 'showcase'])->assertSuccessful(); + + $this->assertSame(['omega', 'alpha', 'omega showcase', 'alpha showcase'], self::$ran); + } + + public function test_a_failing_seeder_fails_the_command(): void + { + require_once dirname(__DIR__).'/Fixtures/seed-order/seeders.php'; + $registry = Mockery::mock($this->app->make(ModuleRegistry::class)); + $this->instance(ModuleRegistry::class, $registry); + $registry->shouldReceive('modules')->andReturn(collect([ + 'omega' => new ModuleConfig('omega', '/tmp/omega', collect()), + ])); + + $this->expectExceptionMessage('broken seeder'); - $this->assertSame(['omega', 'alpha', 'omega demo', 'alpha demo'], self::$ran); + $this->artisan('modules:seed', ['--state' => 'broken'])->run(); } /** Setting up modules together seeds them as one group, or SeedAfter sees only one at a time. */ @@ -107,9 +169,9 @@ public function test_module_setup_honours_seed_after_between_its_modules(): void $registry->shouldReceive('modules')->andReturn($modules); $registry->shouldReceive('module')->andReturnUsing(fn (string $name) => $modules[$name]); - $this->artisan('saucebase:module-setup', ['modules' => ['alpha', 'omega'], '--demo' => true]) + $this->artisan('saucebase:module-setup', ['modules' => ['alpha', 'omega'], '--state' => 'showcase']) ->assertSuccessful(); - $this->assertSame(['omega', 'alpha', 'omega demo', 'alpha demo'], self::$ran); + $this->assertSame(['omega', 'alpha', 'omega showcase', 'alpha showcase'], self::$ran); } } diff --git a/tests/Fixtures/modules/module-test-fixture/database/seeders/DemoModuleTestFixtureDatabaseSeeder.php b/tests/Fixtures/modules/module-test-fixture/database/seeders/ShowcaseModuleTestFixtureDatabaseSeeder.php similarity index 77% rename from tests/Fixtures/modules/module-test-fixture/database/seeders/DemoModuleTestFixtureDatabaseSeeder.php rename to tests/Fixtures/modules/module-test-fixture/database/seeders/ShowcaseModuleTestFixtureDatabaseSeeder.php index 8066d17..f26b3ee 100644 --- a/tests/Fixtures/modules/module-test-fixture/database/seeders/DemoModuleTestFixtureDatabaseSeeder.php +++ b/tests/Fixtures/modules/module-test-fixture/database/seeders/ShowcaseModuleTestFixtureDatabaseSeeder.php @@ -4,7 +4,7 @@ use Illuminate\Database\Seeder; -class DemoModuleTestFixtureDatabaseSeeder extends Seeder +class ShowcaseModuleTestFixtureDatabaseSeeder extends Seeder { public function run(): void { diff --git a/tests/Fixtures/seed-order/seeders.php b/tests/Fixtures/seed-order/seeders.php index d2fca54..917bddd 100644 --- a/tests/Fixtures/seed-order/seeders.php +++ b/tests/Fixtures/seed-order/seeders.php @@ -18,11 +18,11 @@ public function run(): void } #[SeedAfter('omega')] -class DemoAlphaDatabaseSeeder extends Seeder +class ShowcaseAlphaDatabaseSeeder extends Seeder { public function run(): void { - SeedModulesCommandTest::$ran[] = 'alpha demo'; + SeedModulesCommandTest::$ran[] = 'alpha showcase'; } } @@ -39,10 +39,19 @@ public function run(): void } } -class DemoOmegaDatabaseSeeder extends Seeder +class ShowcaseOmegaDatabaseSeeder extends Seeder { public function run(): void { - SeedModulesCommandTest::$ran[] = 'omega demo'; + SeedModulesCommandTest::$ran[] = 'omega showcase'; + } +} + +/** The `broken` state: fails, so the command must too. */ +class BrokenOmegaDatabaseSeeder extends Seeder +{ + public function run(): void + { + throw new \RuntimeException('broken seeder'); } } From d4e47653ad37ca70227f527a419f6a21dd50ab65 Mon Sep 17 00:00:00 2001 From: roble Date: Tue, 10 Nov 2026 16:51:07 +0000 Subject: [PATCH 09/62] feat: set up a template after the modules it requires Co-Authored-By: Claude Opus 5.5 --- src/Console/Commands/ModuleInstallCommand.php | 4 +-- tests/Feature/ModuleInstallCommandTest.php | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Console/Commands/ModuleInstallCommand.php b/src/Console/Commands/ModuleInstallCommand.php index 15d79b9..99b1021 100644 --- a/src/Console/Commands/ModuleInstallCommand.php +++ b/src/Console/Commands/ModuleInstallCommand.php @@ -71,11 +71,11 @@ public function handle(): int ->successful() ? self::SUCCESS : self::FAILURE; } - /** @return array Each Saucebase module in composer.lock => the modules it requires. */ + /** @return array Each Saucebase module or template in composer.lock => the modules it requires. */ private function lockedModules(): array { $packages = collect(json_decode((string) @file_get_contents(base_path('composer.lock')), true)['packages'] ?? []) - ->where('type', 'saucebase-module'); + ->whereIn('type', ['saucebase-module', 'saucebase-template']); $names = $packages->pluck('name')->all(); return $packages->mapWithKeys(fn (array $package): array => [ diff --git a/tests/Feature/ModuleInstallCommandTest.php b/tests/Feature/ModuleInstallCommandTest.php index ab36664..21c3cc9 100644 --- a/tests/Feature/ModuleInstallCommandTest.php +++ b/tests/Feature/ModuleInstallCommandTest.php @@ -72,6 +72,27 @@ public function test_a_module_composer_adds_as_a_dependency_is_set_up_first(): v Process::assertRan(fn (PendingProcess $p) => $p->command === [PHP_BINARY, 'artisan', 'saucebase:module-setup', 'auth', 'api-tokens']); } + public function test_a_template_is_set_up_with_and_after_the_modules_it_requires(): void + { + config(['saucebase.demo_password' => 'secret']); + $this->files->put($this->appPath.'/composer.lock', $this->lock([])); + Process::fake(function (PendingProcess $process) { + if ($process->command[0] === 'composer') { + $this->files->put($this->appPath.'/composer.lock', $this->lock([ + 'saucebase/auth' => [], + 'saucebase/billing' => ['saucebase/auth'], + 'saucebase/uptime' => ['saucebase/auth', 'saucebase/billing'], + ], templates: ['saucebase/uptime'])); + } + + return Process::result(); + }); + + $this->artisan('saucebase:module-install', ['modules' => ['uptime'], '--state' => 'uptime'])->assertSuccessful(); + + Process::assertRan(fn (PendingProcess $p) => $p->command === [PHP_BINARY, 'artisan', 'saucebase:module-setup', 'auth', 'billing', 'uptime', '--state=uptime']); + } + public function test_modules_are_set_up_after_the_modules_they_require(): void { // The lock lists packages alphabetically: api-tokens before the auth it requires. @@ -93,13 +114,16 @@ public function test_modules_are_set_up_after_the_modules_they_require(): void Process::assertRan(fn (PendingProcess $p) => $p->command === [PHP_BINARY, 'artisan', 'saucebase:module-setup', 'auth', 'api-tokens', 'packages']); } - /** @param array> $modules Names, or name => the modules it requires. */ - private function lock(array $modules): string + /** + * @param array> $modules Names, or name => the modules it requires. + * @param list $templates Which of them are templates. + */ + private function lock(array $modules, array $templates = []): string { $packages = []; foreach ($modules as $name => $requires) { [$name, $requires] = is_int($name) ? [$requires, []] : [$name, $requires]; - $packages[] = ['name' => $name, 'type' => 'saucebase-module', 'require' => array_fill_keys(['saucebase/core', ...$requires], '*')]; + $packages[] = ['name' => $name, 'type' => in_array($name, $templates, true) ? 'saucebase-template' : 'saucebase-module', 'require' => array_fill_keys(['saucebase/core', ...$requires], '*')]; } return (string) json_encode(['packages' => [['name' => 'laravel/sanctum', 'type' => 'library'], ...$packages]]); From fa3ca8d81dc15ffc59bfe457d00069bb7c6ca62a Mon Sep 17 00:00:00 2001 From: roble Date: Tue, 10 Nov 2026 20:27:46 +0000 Subject: [PATCH 10/62] feat: dashboard widgets fill gaps; drop the Discord links from the app stubs Co-Authored-By: Claude Opus 5.5 --- src/Filament/Pages/Dashboard.php | 11 +++++++++ stubs/app/routes/navigation.php | 31 -------------------------- stubs/stack/react/js/lib/navigation.ts | 2 -- stubs/stack/vue/js/lib/navigation.ts | 2 -- tests/Feature/DashboardLayoutTest.php | 25 +++++++++++++++++++++ 5 files changed, 36 insertions(+), 35 deletions(-) create mode 100644 tests/Feature/DashboardLayoutTest.php diff --git a/src/Filament/Pages/Dashboard.php b/src/Filament/Pages/Dashboard.php index f4e838e..3cb688c 100644 --- a/src/Filament/Pages/Dashboard.php +++ b/src/Filament/Pages/Dashboard.php @@ -7,6 +7,7 @@ use Filament\Pages\Dashboard\Actions\FilterAction; use Filament\Pages\Dashboard as BaseDashboard; use Filament\Pages\Dashboard\Concerns\HasFiltersAction; +use Filament\Schemas\Components\Component; use Filament\Schemas\Components\Utilities\Set; use Saucebase\Core\Filament\Period; @@ -19,6 +20,16 @@ class Dashboard extends BaseDashboard { use HasFiltersAction; + /** + * Widgets come from whichever modules are installed, so a half-width one can end up + * alone on its row. Dense flow lets a later widget that fits fill the gap, at the cost + * of the occasional widget moving up past its sort order. + */ + public function getWidgetsContentComponent(): Component + { + return parent::getWidgetsContentComponent()->extraAttributes(['style' => 'grid-auto-flow: row dense'], merge: true); + } + protected function getHeaderActions(): array { return [ diff --git a/stubs/app/routes/navigation.php b/stubs/app/routes/navigation.php index 45b53cd..bd6d2a1 100644 --- a/stubs/app/routes/navigation.php +++ b/stubs/app/routes/navigation.php @@ -53,37 +53,6 @@ function (Section $section) { } ); -Navigation::add( - 'Discord', - 'https://discord.gg/hCajBky39t', - function (Section $section) { - $section->attributes([ - 'group' => 'secondary', - 'slug' => 'discord', - 'icon' => 'discord', - 'external' => true, - 'newPage' => true, - 'order' => 5, - 'class' => 'bg-[#5865F2]/10 text-[#4752C4] hover:bg-[#5865F2]/20 hover:text-[#3C45A5] dark:text-[#949CF7] dark:hover:text-[#B5BAFA]', - ]); - } -); - -Navigation::add( - 'Discord', - 'https://discord.gg/hCajBky39t', - function (Section $section) { - $section->attributes([ - 'group' => 'landing', - 'slug' => 'discord', - 'external' => true, - 'newPage' => true, - 'order' => 99, - 'class' => 'text-[#4752C4] hover:text-[#3C45A5] dark:text-[#949CF7] dark:hover:text-[#B5BAFA]', - ]); - } -); - Navigation::addWhen( fn () => Auth::user()?->can('access admin panel') ?? false, 'Admin', diff --git a/stubs/stack/react/js/lib/navigation.ts b/stubs/stack/react/js/lib/navigation.ts index 8553f4e..9fc7b9e 100644 --- a/stubs/stack/react/js/lib/navigation.ts +++ b/stubs/stack/react/js/lib/navigation.ts @@ -6,7 +6,6 @@ import { ShieldCheck, SquareTerminal, } from 'lucide-react'; -import IconDiscord from '~icons/simple-icons/discord'; import IconGithub from '~icons/simple-icons/github'; /** @@ -23,7 +22,6 @@ export function registerNavigationDefaults(): void { registerIcon('dashboard', SquareTerminal); registerIcon('github', IconGithub); - registerIcon('discord', IconDiscord); registerIcon('admin', ShieldCheck); registerIcon('documentation', CircleHelp); registerIcon('docs', BookOpen); diff --git a/stubs/stack/vue/js/lib/navigation.ts b/stubs/stack/vue/js/lib/navigation.ts index 9326688..1e26adb 100644 --- a/stubs/stack/vue/js/lib/navigation.ts +++ b/stubs/stack/vue/js/lib/navigation.ts @@ -4,7 +4,6 @@ import { useColorMode } from '@vueuse/core'; import IconHelpCircle from '~icons/lucide/help-circle'; import IconShieldCheck from '~icons/lucide/shield-check'; import IconSquareTerminal from '~icons/lucide/square-terminal'; -import IconDiscord from '~icons/simple-icons/discord'; import IconGithub from '~icons/simple-icons/github'; /** @@ -23,7 +22,6 @@ export function registerNavigationDefaults(): void { registerIcon('dashboard', IconSquareTerminal); registerIcon('github', IconGithub); - registerIcon('discord', IconDiscord); registerIcon('admin', IconShieldCheck); registerIcon('documentation', IconHelpCircle); } diff --git a/tests/Feature/DashboardLayoutTest.php b/tests/Feature/DashboardLayoutTest.php new file mode 100644 index 0000000..9680cf0 --- /dev/null +++ b/tests/Feature/DashboardLayoutTest.php @@ -0,0 +1,25 @@ +actingAs(User::factory()->create()); + + Livewire::test(Dashboard::class)->assertSeeHtml('grid-auto-flow: row dense'); + } +} From c68c13cfb26360176cbc80746ce6487567ecc2cf Mon Sep 17 00:00:00 2001 From: roble Date: Fri, 13 Nov 2026 12:22:29 +0000 Subject: [PATCH 11/62] feat: template install and capture, module options - saucebase:template-install requires a template, copies its stubs (flattened per framework), sets up the template and its modules, then seeds its state in a process of its own, after every module's install command. - saucebase:template-capture copies a template workspace's app overrides into the template's stubs; --check fails when they are out of date. - A module (usually a template) answers another module's install command with extra.saucebase.module-options..