diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 818393f..a641087 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,4 +14,9 @@ jobs: uses: saucebase-dev/core/.github/workflows/test-module.yml@main with: module: chat - # dependencies: saucebase/auth # add space-separated packages if needed + # Every module the template requires, in the order their patches apply. + dependencies: saucebase/auth saucebase/billing saucebase/themes + private_dependencies: saucebase/ai-chat + secrets: + APP_ID: ${{ secrets.APP_ID }} + APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 6ab0eb7..feb54a4 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -3,10 +3,12 @@ namespace Modules\Chat\Database\Seeders; use Illuminate\Database\Seeder; +use Illuminate\Support\Str; use Modules\Billing\Enums\BillingScheme; use Modules\Billing\Enums\Currency; use Modules\Billing\Enums\PlanKind; use Modules\Billing\Models\Product; +use Saucebase\Core\Settings\GeneralSettings; /** * What every install needs, demo or not: the product's plans. Their limits @@ -22,7 +24,34 @@ class DatabaseSeeder extends Seeder 'description' => 'For people who work with it every day.', 'features' => ['2,000 messages a month', '100 images a month', 'Web search', 'Answers about your account', 'Chat history', 'Every model your admin offers', 'Email support']], ]; + /** The product's name, while the app still has the installer's default. */ + public const string NAME = 'AI Chat'; + public function run(): void + { + $this->name(); + $this->plans(); + } + + /** + * The installer names an app after its folder ("chat-template" becomes "Chat Template") + * unless given --app-name. Only that default gives way to the product's name, so a name + * the customer chose is never replaced. + * + * ponytail: guesses the default from the folder; an installer hook that pre-fills the + * app name from the template would make this exact. + */ + private function name(): void + { + $settings = app(GeneralSettings::class); + + if ($settings->site_name === Str::headline(basename(base_path()))) { + $settings->site_name = self::NAME; + $settings->save(); + } + } + + private function plans(): void { foreach (self::PLANS as $order => $plan) { $limits = ['ai_chat_messages' => $plan['messages'], 'ai_chat_images' => $plan['images']]; diff --git a/resources/boost/skills/saucebase-chat-development/SKILL.md b/resources/boost/skills/saucebase-chat-development/SKILL.md index 64534a3..37f4eb1 100644 --- a/resources/boost/skills/saucebase-chat-development/SKILL.md +++ b/resources/boost/skills/saucebase-chat-development/SKILL.md @@ -14,6 +14,7 @@ Paths are relative to `modules/chat/` unless they say otherwise. Commands run fr - The landing page quotes the plans (`stubs/resources/js/vue/components/landing/content.ts`): change the seeder and the copy together. - The template adds no routes of its own: `/chat` belongs to ai-chat. +- `ChatServiceProvider` sets `ai-chat.sessions` to `sidebar`: the chat list is the app sidebar (no "Chat" item, no second panel). ai-chat's default (`page`) is for apps where the chat is one feature among others. ## Testing diff --git a/src/Providers/ChatServiceProvider.php b/src/Providers/ChatServiceProvider.php index c4f13b0..94bb9b6 100644 --- a/src/Providers/ChatServiceProvider.php +++ b/src/Providers/ChatServiceProvider.php @@ -9,4 +9,12 @@ class ChatServiceProvider extends ModuleServiceProvider protected array $providers = [ // YourServiceProvider::class, ]; + + public function boot(): void + { + parent::boot(); + + // A chat-first app: the chat list is the app sidebar (no "Chat" item, no second panel). + config(['ai-chat.sessions' => 'sidebar']); + } } diff --git a/stubs/routes/navigation.php b/stubs/routes/navigation.php index 24ee2a8..ae16a4c 100644 --- a/stubs/routes/navigation.php +++ b/stubs/routes/navigation.php @@ -31,21 +31,6 @@ function (Section $section) { } ); -Navigation::add( - 'Documentation', - 'https://saucebase-dev.github.io/docs/', - function (Section $section) { - $section->attributes([ - 'group' => 'secondary', - 'slug' => 'documentation', - 'icon' => 'documentation', - 'external' => true, - 'newPage' => true, - 'order' => 0, - ]); - } -); - Navigation::addWhen( fn () => Auth::user()?->can('access admin panel') ?? false, 'Admin', diff --git a/tests/Feature/ChatListTest.php b/tests/Feature/ChatListTest.php new file mode 100644 index 0000000..7c24c26 --- /dev/null +++ b/tests/Feature/ChatListTest.php @@ -0,0 +1,14 @@ +assertSame('sidebar', config('ai-chat.sessions')); + } +} diff --git a/tests/Feature/NavigationTest.php b/tests/Feature/NavigationTest.php new file mode 100644 index 0000000..0279fbd --- /dev/null +++ b/tests/Feature/NavigationTest.php @@ -0,0 +1,23 @@ +withoutVite(); + + $response = $this->actingAs(User::factory()->create())->get(route('ai-chat.index')); + + $slugs = collect($response->viewData('page')['props']['navigation']['secondary'] ?? [])->pluck('slug'); + $this->assertContains('github', $slugs); + $this->assertNotContains('documentation', $slugs); + } +} diff --git a/tests/Feature/SiteNameTest.php b/tests/Feature/SiteNameTest.php new file mode 100644 index 0000000..d3b3a92 --- /dev/null +++ b/tests/Feature/SiteNameTest.php @@ -0,0 +1,45 @@ +site_name = $name; + $settings->save(); + } + + return $settings->refresh()->site_name; + } + + public function test_the_installers_folder_name_becomes_the_product_name(): void + { + // `saucebase new chat-template` names the app after its folder: "Chat Template". + $this->siteName(Str::headline(basename(base_path()))); + + $this->seed(DatabaseSeeder::class); + + $this->assertSame('AI Chat', $this->siteName()); + } + + public function test_a_name_the_customer_chose_is_kept(): void + { + $this->siteName('Acme Assistant'); + + $this->seed(DatabaseSeeder::class); + + $this->assertSame('Acme Assistant', $this->siteName()); + } +} diff --git a/tests/e2e/chat.spec.ts b/tests/e2e/chat.spec.ts new file mode 100644 index 0000000..9f05d98 --- /dev/null +++ b/tests/e2e/chat.spec.ts @@ -0,0 +1,20 @@ +import { expect, test } from '@e2e/fixtures'; + +// What the template changes about ai-chat, not how it looks: adopters restyle it freely. +test.describe('Chat template', () => { + test('signing in lands on the chat, with the list in the app sidebar', async ({ + page, + credentials, + loginAs, + }) => { + await loginAs(credentials.user); + await page.goto('/dashboard'); + + await expect(page).toHaveURL(/\/chat$/); + await expect( + page.locator('[data-sidebar="content"]').getByTestId('new-chat'), + ).toBeVisible(); + // ai-chat's own panel is for apps where the chat is one feature among others. + await expect(page.getByTestId('chat-panel')).toHaveCount(0); + }); +});