Skip to content

feat(stac_cli): add unit testing infrastructure and core command tests#472

Open
Pratikdate wants to merge 6 commits into
StacDev:devfrom
Pratikdate:dev
Open

feat(stac_cli): add unit testing infrastructure and core command tests#472
Pratikdate wants to merge 6 commits into
StacDev:devfrom
Pratikdate:dev

Conversation

@Pratikdate
Copy link
Copy Markdown

@Pratikdate Pratikdate commented Apr 3, 2026

Description

This PR adds a comprehensive unit testing layer to the stac_cli package and integrates it into the monorepo's CI pipeline. Key changes include:

  • Infrastructure Set-up: Initialized the test/ directory within packages/stac_cli to manage command and utility tests.
  • Environment Mocking: Added a mechanism to safely stub out required environment variables (like STAC_BASE_API_URL and STAC_GOOGLE_CLIENT_ID) during tests to prevent initialization crashes without real API keys.
  • Core Command Tests: Implemented tests for BuildCommand, InitCommand, and DeployCommand to verify registration, name, and descriptions.
  • Utility Reliability: Added tests for FileUtils to validate file system operations (create, read, delete) with automated sandbox cleanup.
  • CI Pipeline Integration:
    • Added a test command to the root melos.yaml.
    • Updated .github/workflows/all_plugins.yaml to include a global test step for all packages.

Related Issues

Closes # (Insert issue number if applicable)

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Code refactor
  • Build configuration change
  • Documentation
  • Chore

Summary by CodeRabbit

  • Tests
    • Added test coverage for core CLI commands (Build, Init, Deploy) to verify proper registration and functionality.
    • Added file utility tests for home directory configuration, filesystem operations including file creation, reading, writing, and deletion.

Review Change Stack

@Pratikdate Pratikdate mentioned this pull request Apr 3, 2026
3 tasks
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 5, 2026

CLA assistant check
All committers have signed the CLA.

@Pratikdate Pratikdate marked this pull request as draft April 11, 2026 06:49
@Pratikdate Pratikdate marked this pull request as ready for review April 11, 2026 06:49
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

📝 Walkthrough

Walkthrough

This 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.

Changes

Core Utility Test Suites

Layer / File(s) Summary
CLI commands registration tests
packages/stac_cli/test/commands/cli_commands_test.dart
Configures mocked CLI environment in setUp and registers three command classes via CommandRunner<int>. Tests verify BuildCommand, InitCommand, and DeployCommand are registered with expected name and non-empty description properties.
File utilities integration tests
packages/stac_cli/test/utils/file_utils_test.dart
Tests verify FileUtils.homeDirectory and FileUtils.configDirectory return non-empty values. Async test creates, reads, writes, and deletes files in a temporary directory with guaranteed cleanup via finally block.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A pair of tests now guard the CLI way,
Commands and files in their rightful display,
With mocked and real, they stand as one,
The testing dance—beautifully done! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding unit testing infrastructure and core command tests to the stac_cli package, which aligns perfectly with the changeset contents.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/stac_cli/test/utils/file_utils_test.dart (1)

10-18: ⚡ Quick win

Consider validating directory paths beyond non-empty checks.

The current tests only verify that homeDirectory and configDirectory return 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2907c6a and f48feea.

📒 Files selected for processing (2)
  • packages/stac_cli/test/commands/cli_commands_test.dart
  • packages/stac_cli/test/utils/file_utils_test.dart

Comment on lines +13 to +26
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());
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants