From cd7fbb208828c39bf0fd39ffd4c8b01f7f63dfa5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 9 Aug 2025 03:45:34 +0000 Subject: [PATCH] I've added a feature to provide warnings for missing `rulesync.md` files. With this change, a warning will appear when you run the `rulesync generate` command without a global, local, or any `rulesync.md` files. You will be prompted to save your preference to hide these warnings in the future. I implemented the warnings in the `GenerateCommand` and the preferences are stored via the `ConfigService`. I also added feature tests to verify the new warning logic and the ability to suppress the warnings. --- app/Commands/GenerateCommand.php | 32 ++++++++++++ app/Services/ConfigService.php | 33 +++++++++++++ tests/Feature/GenerateCommandTest.php | 59 ++++++++++++++++++++++- tests/Unit/Services/ConfigServiceTest.php | 26 ++++++++++ 4 files changed, 149 insertions(+), 1 deletion(-) diff --git a/app/Commands/GenerateCommand.php b/app/Commands/GenerateCommand.php index 5a32c38..f452090 100644 --- a/app/Commands/GenerateCommand.php +++ b/app/Commands/GenerateCommand.php @@ -98,6 +98,28 @@ private function getSourceFile(ConfigService $configService): ?string $localExists = File::exists($localRulesFile); $globalExists = File::exists($globalRulesFile); + if (! $localExists && ! $globalExists) { + return $this->handleMissingSourceFile($configService); + } + + if (! $globalExists && $configService->getWarnOnMissingGlobalRules()) { + $this->line(''); + $this->warn('No global rulesync.md file found at ~/.config/rulesync/rulesync.md'); + + if ($this->confirm('Do you want to hide this warning in the future?')) { + $configService->setWarnOnMissingGlobalRules(false); + } + } + + if (! $localExists && $configService->getWarnOnMissingLocalRules()) { + $this->line(''); + $this->warn('No local rulesync.md file found in the current directory.'); + + if ($this->confirm('Do you want to hide this warning in the future?')) { + $configService->setWarnOnMissingLocalRules(false); + } + } + // If both local and global files exist, handle augmentation if ($localExists && $globalExists && $localRulesFile !== $globalRulesFile) { return $this->handleAugmentation($configService, $localRulesFile, $globalRulesFile); @@ -112,6 +134,7 @@ private function getSourceFile(ConfigService $configService): ?string return $globalRulesFile; } + // This part should not be reachable if the logic is correct, but as a fallback: return $this->handleMissingSourceFile($configService); } @@ -235,6 +258,15 @@ private function isUnderVersionControl(): bool private function handleMissingSourceFile(ConfigService $configService): ?string { + if ($configService->getWarnOnMissingRules()) { + $this->line(''); + $this->warn('No rulesync.md file found globally or locally.'); + + if ($this->confirm('Do you want to hide this warning in the future?')) { + $configService->setWarnOnMissingRules(false); + } + } + $this->error('No source file found.'); $existingRuleFiles = $this->findExistingRuleFiles(); diff --git a/app/Services/ConfigService.php b/app/Services/ConfigService.php index 29cbf86..ffa4db1 100644 --- a/app/Services/ConfigService.php +++ b/app/Services/ConfigService.php @@ -94,6 +94,39 @@ public function setAugmentPreference(bool $augment): void $this->saveConfig(); } + public function getWarnOnMissingGlobalRules(): bool + { + return $this->config['warn_on_missing_global_rules'] ?? true; + } + + public function setWarnOnMissingGlobalRules(bool $warn): void + { + $this->config['warn_on_missing_global_rules'] = $warn; + $this->saveConfig(); + } + + public function getWarnOnMissingLocalRules(): bool + { + return $this->config['warn_on_missing_local_rules'] ?? true; + } + + public function setWarnOnMissingLocalRules(bool $warn): void + { + $this->config['warn_on_missing_local_rules'] = $warn; + $this->saveConfig(); + } + + public function getWarnOnMissingRules(): bool + { + return $this->config['warn_on_missing_rules'] ?? true; + } + + public function setWarnOnMissingRules(bool $warn): void + { + $this->config['warn_on_missing_rules'] = $warn; + $this->saveConfig(); + } + private function ensureConfigDirectoryExists(): void { $directory = dirname($this->configPath); diff --git a/tests/Feature/GenerateCommandTest.php b/tests/Feature/GenerateCommandTest.php index 817ecf6..7744114 100644 --- a/tests/Feature/GenerateCommandTest.php +++ b/tests/Feature/GenerateCommandTest.php @@ -36,7 +36,9 @@ public function test_fails_when_no_source_file(): void File::ensureDirectoryExists($this->tempDir.'/.git'); File::put($this->tempDir.'/.git/config', ''); - $this->artisan('generate --force') + $this->artisan('generate') + ->expectsOutput('No rulesync.md file found globally or locally.') + ->expectsQuestion('Do you want to hide this warning in the future?', false) ->expectsOutputToContain('No source file found.') ->assertExitCode(1); } @@ -105,4 +107,59 @@ public function test_basic_generation_works(): void ->expectsOutputToContain('Generation complete:') ->assertExitCode(0); } + + public function test_hides_missing_global_rules_warning_when_confirmed(): void + { + File::put($this->tempDir.'/rulesync.md', '# My Rules'); + File::ensureDirectoryExists($this->tempDir.'/.git'); + File::put($this->tempDir.'/.git/config', ''); + + // First run: expect warning and confirm to hide it + $this->artisan('generate') + ->expectsOutput('No global rulesync.md file found at ~/.config/rulesync/rulesync.md') + ->expectsQuestion('Do you want to hide this warning in the future?', true) + ->assertExitCode(0); + + // Second run: expect no warning + $this->artisan('generate') + ->doesntExpectOutput('No global rulesync.md file found at ~/.config/rulesync/rulesync.md') + ->assertExitCode(0); + } + + public function test_hides_missing_local_rules_warning_when_confirmed(): void + { + $globalConfigDir = $this->tempDir.'/.config/rulesync'; + File::ensureDirectoryExists($globalConfigDir); + File::put($globalConfigDir.'/rulesync.md', '# Global Rules'); + File::ensureDirectoryExists($this->tempDir.'/.git'); + File::put($this->tempDir.'/.git/config', ''); + + // First run: expect warning and confirm to hide it + $this->artisan('generate') + ->expectsOutput('No local rulesync.md file found in the current directory.') + ->expectsQuestion('Do you want to hide this warning in the future?', true) + ->assertExitCode(0); + + // Second run: expect no warning + $this->artisan('generate') + ->doesntExpectOutput('No local rulesync.md file found in the current directory.') + ->assertExitCode(0); + } + + public function test_hides_missing_rules_warning_when_confirmed(): void + { + File::ensureDirectoryExists($this->tempDir.'/.git'); + File::put($this->tempDir.'/.git/config', ''); + + // First run: expect warning and confirm to hide it + $this->artisan('generate') + ->expectsOutput('No rulesync.md file found globally or locally.') + ->expectsQuestion('Do you want to hide this warning in the future?', true) + ->assertExitCode(1); + + // Second run: expect no warning + $this->artisan('generate') + ->doesntExpectOutput('No rulesync.md file found globally or locally.') + ->assertExitCode(1); + } } diff --git a/tests/Unit/Services/ConfigServiceTest.php b/tests/Unit/Services/ConfigServiceTest.php index 5aba523..74f47ea 100644 --- a/tests/Unit/Services/ConfigServiceTest.php +++ b/tests/Unit/Services/ConfigServiceTest.php @@ -141,6 +141,32 @@ public function test_returns_null_augment_preference_when_not_set(): void expect($this->configService->getAugmentPreference())->toBeNull(); } + public function test_can_set_warning_preferences(): void + { + // Test defaults + expect($this->configService->getWarnOnMissingGlobalRules())->toBeTrue(); + expect($this->configService->getWarnOnMissingLocalRules())->toBeTrue(); + expect($this->configService->getWarnOnMissingRules())->toBeTrue(); + + // Test setting to false + $this->configService->setWarnOnMissingGlobalRules(false); + $this->configService->setWarnOnMissingLocalRules(false); + $this->configService->setWarnOnMissingRules(false); + + expect($this->configService->getWarnOnMissingGlobalRules())->toBeFalse(); + expect($this->configService->getWarnOnMissingLocalRules())->toBeFalse(); + expect($this->configService->getWarnOnMissingRules())->toBeFalse(); + + // Test setting back to true + $this->configService->setWarnOnMissingGlobalRules(true); + $this->configService->setWarnOnMissingLocalRules(true); + $this->configService->setWarnOnMissingRules(true); + + expect($this->configService->getWarnOnMissingGlobalRules())->toBeTrue(); + expect($this->configService->getWarnOnMissingLocalRules())->toBeTrue(); + expect($this->configService->getWarnOnMissingRules())->toBeTrue(); + } + public function test_persists_config_to_file(): void { $this->configService->disableRule('claude');