feat(stac_cli): add unit testing infrastructure and core command tests#472
feat(stac_cli): add unit testing infrastructure and core command tests#472Pratikdate wants to merge 6 commits into
Conversation
📝 WalkthroughWalkthroughThis PR adds two complementary test suites to the Stac CLI project: one verifying command registration for build, init, and deploy commands, and another testing file utility functions including directory resolution and filesystem operations with proper cleanup. ChangesCore Utility Test Suites
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/stac_cli/test/utils/file_utils_test.dart (1)
10-18: ⚡ Quick winConsider validating directory paths beyond non-empty checks.
The current tests only verify that
homeDirectoryandconfigDirectoryreturn non-empty strings. They don't validate that these are actual valid directory paths or that they exist. While acceptable for initial test infrastructure, consider adding path validity checks in future iterations.📁 Example enhancement to validate paths
test('homeDirectory returns a non-empty string on this OS', () { final home = FileUtils.homeDirectory; expect(home, isNotEmpty); + expect(Directory(home).existsSync(), isTrue, + reason: 'homeDirectory should point to an existing directory'); }); test('configDirectory path is generated', () { final config = FileUtils.configDirectory; expect(config, isNotEmpty); + expect(path.isAbsolute(config), isTrue, + reason: 'configDirectory should be an absolute path'); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/stac_cli/test/utils/file_utils_test.dart` around lines 10 - 18, The tests only assert non-empty strings; update the tests for FileUtils.homeDirectory and FileUtils.configDirectory to also validate that the returned paths point to existing directories by constructing a Directory from each path and asserting Directory(path).exists() (and optionally Directory(path).stat() indicates a directory) so the tests ensure the paths are valid and are directories rather than merely non-empty strings.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/stac_cli/test/commands/cli_commands_test.dart`:
- Around line 13-26: The tests set environment variables in the setUp using
configureEnvironment but never clear them, so add a tearDown block that resets
or clears those keys after each test; implement tearDown(() {
configureEnvironment({'STAC_BASE_API_URL': null, 'STAC_GOOGLE_CLIENT_ID': null,
'STAC_FIREBASE_API_KEY': null}); }) or call your existing environment-reset
helper to remove those variables so configureEnvironment and setUp no longer
leak state between tests.
---
Nitpick comments:
In `@packages/stac_cli/test/utils/file_utils_test.dart`:
- Around line 10-18: The tests only assert non-empty strings; update the tests
for FileUtils.homeDirectory and FileUtils.configDirectory to also validate that
the returned paths point to existing directories by constructing a Directory
from each path and asserting Directory(path).exists() (and optionally
Directory(path).stat() indicates a directory) so the tests ensure the paths are
valid and are directories rather than merely non-empty strings.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4105edd3-5e6e-4cc4-b1e5-44517536bfa9
📒 Files selected for processing (2)
packages/stac_cli/test/commands/cli_commands_test.dartpackages/stac_cli/test/utils/file_utils_test.dart
| setUp(() { | ||
| // Initialize environment with mock values to satisfy required checks in services. | ||
| // This allows testing command configuration without needing real API keys. | ||
| configureEnvironment({ | ||
| 'STAC_BASE_API_URL': 'https://api.test.stac.dev', | ||
| 'STAC_GOOGLE_CLIENT_ID': 'test-client-id', | ||
| 'STAC_FIREBASE_API_KEY': 'test-api-key', | ||
| }); | ||
|
|
||
| runner = CommandRunner<int>('stac', 'Stac CLI test runner'); | ||
| runner.addCommand(BuildCommand()); | ||
| runner.addCommand(InitCommand()); | ||
| runner.addCommand(DeployCommand()); | ||
| }); |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Add tearDown to reset environment configuration.
The setUp configures environment variables before each test, but there's no corresponding tearDown to clean up. This could cause state pollution if other test groups or subsequent test runs expect a clean environment.
🧹 Proposed fix to add tearDown
runner.addCommand(DeployCommand());
});
+
+ tearDown(() {
+ // Reset environment to prevent state pollution between tests
+ configureEnvironment({});
+ });
test('build command has correct name and description', () {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| setUp(() { | |
| // Initialize environment with mock values to satisfy required checks in services. | |
| // This allows testing command configuration without needing real API keys. | |
| configureEnvironment({ | |
| 'STAC_BASE_API_URL': 'https://api.test.stac.dev', | |
| 'STAC_GOOGLE_CLIENT_ID': 'test-client-id', | |
| 'STAC_FIREBASE_API_KEY': 'test-api-key', | |
| }); | |
| runner = CommandRunner<int>('stac', 'Stac CLI test runner'); | |
| runner.addCommand(BuildCommand()); | |
| runner.addCommand(InitCommand()); | |
| runner.addCommand(DeployCommand()); | |
| }); | |
| setUp(() { | |
| // Initialize environment with mock values to satisfy required checks in services. | |
| // This allows testing command configuration without needing real API keys. | |
| configureEnvironment({ | |
| 'STAC_BASE_API_URL': 'https://api.test.stac.dev', | |
| 'STAC_GOOGLE_CLIENT_ID': 'test-client-id', | |
| 'STAC_FIREBASE_API_KEY': 'test-api-key', | |
| }); | |
| runner = CommandRunner<int>('stac', 'Stac CLI test runner'); | |
| runner.addCommand(BuildCommand()); | |
| runner.addCommand(InitCommand()); | |
| runner.addCommand(DeployCommand()); | |
| }); | |
| tearDown(() { | |
| // Reset environment to prevent state pollution between tests | |
| configureEnvironment({}); | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/stac_cli/test/commands/cli_commands_test.dart` around lines 13 - 26,
The tests set environment variables in the setUp using configureEnvironment but
never clear them, so add a tearDown block that resets or clears those keys after
each test; implement tearDown(() { configureEnvironment({'STAC_BASE_API_URL':
null, 'STAC_GOOGLE_CLIENT_ID': null, 'STAC_FIREBASE_API_KEY': null}); }) or call
your existing environment-reset helper to remove those variables so
configureEnvironment and setUp no longer leak state between tests.
Description
This PR adds a comprehensive unit testing layer to the
stac_clipackage and integrates it into the monorepo's CI pipeline. Key changes include:test/directory withinpackages/stac_clito manage command and utility tests.STAC_BASE_API_URLandSTAC_GOOGLE_CLIENT_ID) during tests to prevent initialization crashes without real API keys.BuildCommand,InitCommand, andDeployCommandto verify registration, name, and descriptions.FileUtilsto validate file system operations (create, read, delete) with automated sandbox cleanup.testcommand to the rootmelos.yaml..github/workflows/all_plugins.yamlto include a global test step for all packages.Related Issues
Closes # (Insert issue number if applicable)
Type of Change
Summary by CodeRabbit