Skip to content

Conversation

@anujhydrabadi
Copy link
Contributor

@anujhydrabadi anujhydrabadi commented Jun 30, 2025

  • Update add_input to support @namespace/name format
  • Add namespace support to get_output_types
  • Rename get_output_details to get_output_type_details with namespace support
  • Add comprehensive test coverage for all changes

Summary by CodeRabbit

  • New Features

    • Introduced a new CLI command to fetch and display detailed information about output types, including support for namespace-aware output type formats (e.g., @namespace/name).
    • Enhanced validation and error handling for output type formats across relevant commands.
  • Bug Fixes

    • Improved handling of output type properties and lookup trees, supporting both nested and direct property structures.
  • Tests

    • Added comprehensive tests for namespace-aware output types, new CLI commands, and various edge cases.
    • Expanded test coverage for error scenarios and custom namespaces.
  • Refactor

    • Updated CLI commands and outputs to consistently use the fully qualified @namespace/name format.
    • Replaced and removed legacy commands to reflect the new output type details functionality.

- Update add_input to support @namespace/name format
- Add namespace support to get_output_types
- Rename get_output_details to get_output_type_details with namespace support
- Add comprehensive test coverage for all changes
@coderabbitai
Copy link

coderabbitai bot commented Jun 30, 2025

"""

Walkthrough

The changes introduce namespace-aware output type handling in the CLI, requiring output types to be specified in the @namespace/name format. The get_output_details command is replaced by a more detailed get_output_type_details command. Related logic, tests, and documentation are updated to support and validate the new format and improved error handling.

Changes

File(s) Change Summary
ftf_cli/cli.py, ftf_cli/commands/__init__.py Updated imports and command registration to replace get_output_lookup_tree with get_output_type_details. Adjusted exported symbols to match new command.
ftf_cli/commands/add_input.py Introduced parse_namespace_and_name to validate and parse output types in @namespace/name format. Updated internal logic and error messages to use the full namespaced format. Improved property extraction from registered outputs.
ftf_cli/commands/get_output_details.py Removed the old get_output_lookup_tree command implementation.
ftf_cli/commands/get_output_type_details.py Added new get_output_type_details command. Validates and parses output types, fetches details from the control plane, and displays comprehensive information including properties and lookup tree. Enhanced error handling and output formatting.
ftf_cli/commands/get_output_types.py Modified output type listing to display fully qualified names in the @namespace/name format, defaulting namespace to @outputs if missing.
tests/commands/test_add_input.py Updated tests to use namespaced output types. Added tests for output type format validation, custom namespaces, and direct property structures. Enhanced coverage for error and success scenarios.
tests/commands/test_get_output_type_details.py New test suite for get_output_type_details command. Covers successful retrieval, format validation, missing data handling, authentication errors, and API failure scenarios.
tests/commands/test_get_output_types.py New test suite for get_output_types command. Tests various namespace scenarios, empty outputs, default namespace fallback, authentication, and API error handling.
ftf_cli/utils.py Added parse_namespace_and_name to parse and validate output type strings. Extended transform_properties_to_terraform to handle direct properties dictionaries without a "type" key and improved fallback for empty inputs.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant ControlPlaneAPI

    User->>CLI: Run get_output_type_details --output-type @namespace/name
    CLI->>CLI: Validate output type format
    CLI->>CLI: Check login credentials
    alt Not logged in
        CLI-->>User: Error: Please login
    else Logged in
        CLI->>ControlPlaneAPI: GET /cc-ui/v1/tf-outputs (with token)
        ControlPlaneAPI-->>CLI: List of output types
        CLI->>CLI: Find output type by namespace and name
        alt Output type found
            CLI-->>User: Display output type details, properties, lookup tree
        else Not found
            CLI-->>User: Error: Output type not found
        end
    end
Loading

Suggested reviewers

  • sanmesh-kakade

Poem

In the warren of code, a new path appears,
Namespaces and slashes, no more old fears.
Outputs now wear their full, proper names,
With details and trees in neat JSON frames.
Rabbits rejoice as the CLI grows wise—
Hopping through tests, with bright, happy eyes!
🐇✨
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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 (7)
ftf_cli/commands/add_input.py (2)

20-38: Consider extracting shared validation function to utils.

The parse_namespace_and_name function is identical to the one in get_output_type_details.py. To follow DRY principles, consider moving this function to ftf_cli/utils.py for reuse across commands.

If you'd like me to help create the shared utility function, I can generate the refactor for you.


149-150: Apply performance improvement from static analysis.

The static analysis tool correctly identifies an optimization opportunity.

Apply this diff to improve performance:

-        available_output_types = [f'{namespace}/{name}' for namespace, name in registered_outputs.keys()]
+        available_output_types = [f'{namespace}/{name}' for namespace, name in registered_outputs]
tests/commands/test_get_output_type_details.py (1)

2-2: Remove unused import.

The json module is imported but never used in the test file.

-import json
ftf_cli/commands/get_output_type_details.py (4)

2-2: Remove unused import.

The os module is imported but never used in this file.

-import os

77-77: Remove unnecessary .keys() call.

Using key in dict is more efficient than key in dict.keys().

-                available_outputs = [f'{ns}/{nm}' for ns, nm in registered_outputs.keys()]
+                available_outputs = [f'{ns}/{nm}' for ns, nm in registered_outputs]

94-94: Remove unnecessary f-string prefixes.

These strings don't contain any placeholders, so the f prefix is unnecessary.

-                click.echo(f"\n--- Properties ---")
+                click.echo("\n--- Properties ---")
-                click.echo(f"\n--- Properties ---")
+                click.echo("\n--- Properties ---")
-                click.echo(f"\n--- Lookup Tree ---")
+                click.echo("\n--- Lookup Tree ---")
-                click.echo(f"\n--- Lookup Tree ---")
+                click.echo("\n--- Lookup Tree ---")

Also applies to: 98-98, 103-103, 110-110


118-122: Improve exception handling.

Use raise ... from e to preserve the original exception context for better debugging.

    except Exception as e:
        traceback.print_exc()
        raise click.UsageError(
            f"❌ An error occurred while getting output details: {e}"
-        )
+        ) from e
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2514257 and 5fc27cc.

📒 Files selected for processing (9)
  • ftf_cli/cli.py (2 hunks)
  • ftf_cli/commands/__init__.py (2 hunks)
  • ftf_cli/commands/add_input.py (6 hunks)
  • ftf_cli/commands/get_output_details.py (0 hunks)
  • ftf_cli/commands/get_output_type_details.py (1 hunks)
  • ftf_cli/commands/get_output_types.py (2 hunks)
  • tests/commands/test_add_input.py (13 hunks)
  • tests/commands/test_get_output_type_details.py (1 hunks)
  • tests/commands/test_get_output_types.py (1 hunks)
💤 Files with no reviewable changes (1)
  • ftf_cli/commands/get_output_details.py
🧰 Additional context used
🧠 Learnings (2)
tests/commands/test_get_output_types.py (1)
Learnt from: anujhydrabadi
PR: Facets-cloud/module-development-cli#59
File: tests/commands/test_preview_module.py:91-99
Timestamp: 2025-05-30T10:34:53.821Z
Learning: When patching imported functions in Python unittest.mock, patch where the object is looked up by the system under test, not where it's defined. If there's a namespace collision (like Click commands exported in __init__.py), use patch.object() with direct module import to bypass the collision.
tests/commands/test_get_output_type_details.py (1)
Learnt from: anujhydrabadi
PR: Facets-cloud/module-development-cli#59
File: tests/commands/test_preview_module.py:91-99
Timestamp: 2025-05-30T10:34:53.821Z
Learning: When patching imported functions in Python unittest.mock, patch where the object is looked up by the system under test, not where it's defined. If there's a namespace collision (like Click commands exported in __init__.py), use patch.object() with direct module import to bypass the collision.
🧬 Code Graph Analysis (5)
ftf_cli/cli.py (1)
ftf_cli/commands/get_output_type_details.py (1)
  • get_output_type_details (46-122)
ftf_cli/commands/__init__.py (1)
ftf_cli/commands/get_output_type_details.py (1)
  • get_output_type_details (46-122)
tests/commands/test_get_output_types.py (3)
ftf_cli/commands/get_output_types.py (1)
  • get_output_types (15-54)
tests/commands/test_add_input.py (2)
  • runner (17-18)
  • mock_credentials (21-26)
tests/commands/test_get_output_type_details.py (2)
  • runner (13-14)
  • mock_credentials (17-22)
ftf_cli/commands/add_input.py (1)
ftf_cli/commands/get_output_type_details.py (1)
  • parse_namespace_and_name (11-29)
ftf_cli/commands/get_output_type_details.py (2)
ftf_cli/utils.py (2)
  • is_logged_in (504-537)
  • get_profile_with_priority (486-501)
ftf_cli/commands/add_input.py (1)
  • parse_namespace_and_name (20-38)
🪛 Ruff (0.11.9)
ftf_cli/commands/add_input.py

150-150: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

tests/commands/test_get_output_type_details.py

2-2: json imported but unused

Remove unused import: json

(F401)

ftf_cli/commands/get_output_type_details.py

2-2: os imported but unused

Remove unused import: os

(F401)


77-77: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


94-94: f-string without any placeholders

Remove extraneous f prefix

(F541)


98-98: f-string without any placeholders

Remove extraneous f prefix

(F541)


103-103: f-string without any placeholders

Remove extraneous f prefix

(F541)


110-110: f-string without any placeholders

Remove extraneous f prefix

(F541)


120-122: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

🪛 Flake8 (7.2.0)
tests/commands/test_get_output_type_details.py

[error] 2-2: 'json' imported but unused

(F401)

ftf_cli/commands/get_output_type_details.py

[error] 2-2: 'os' imported but unused

(F401)


[error] 94-94: f-string is missing placeholders

(F541)


[error] 98-98: f-string is missing placeholders

(F541)


[error] 103-103: f-string is missing placeholders

(F541)


[error] 110-110: f-string is missing placeholders

(F541)

🔇 Additional comments (16)
ftf_cli/cli.py (1)

11-11: LGTM! Clean refactoring to new command structure.

The import and command registration have been correctly updated to use the new get_output_type_details function, maintaining consistency across the CLI structure.

Also applies to: 31-31

ftf_cli/commands/__init__.py (1)

10-10: LGTM! Package exports correctly updated.

The import and __all__ list have been consistently updated to reflect the new command structure, maintaining proper package organization.

Also applies to: 26-26

ftf_cli/commands/get_output_types.py (1)

39-41: LGTM! Correct namespace-aware output formatting.

The implementation properly combines namespace and name with a sensible default fallback, correctly supporting the new @namespace/name format requirement.

tests/commands/test_get_output_types.py (1)

1-161: Excellent comprehensive test coverage.

The test suite thoroughly covers all scenarios including:

  • Successful output type retrieval with namespace formatting
  • Empty response handling
  • Default namespace fallback behavior
  • Authentication error cases
  • API failure scenarios

The use of pytest fixtures and proper mocking demonstrates good testing practices.

ftf_cli/commands/add_input.py (4)

75-75: LGTM! Clear help text specifying required format.

The help text clearly communicates the expected @namespace/name format with examples, improving user experience.


129-130: LGTM! Good practice with early validation.

Validating the output type format early in the function helps provide immediate feedback to users and prevents processing invalid input.


153-158: LGTM! Correct namespace-aware validation logic.

The validation correctly uses namespace/name tuples for lookup and provides helpful error messages with available options.


169-198: LGTM! Robust property structure handling.

The dual structure handling (direct vs nested properties) with proper error handling and fallbacks ensures compatibility with different API response formats while providing helpful warnings to users.

tests/commands/test_get_output_type_details.py (2)

9-67: Excellent test structure and fixtures.

The test class and fixtures are well-designed with comprehensive sample data that covers both default and custom namespaces. The API response fixture properly represents the expected data structure with namespace-qualified output types.


68-262: Comprehensive test coverage for all scenarios.

The test methods provide excellent coverage of:

  • Successful output type retrieval with proper format validation
  • Custom namespace handling
  • Error cases (not found, invalid format, not logged in, API errors)
  • Edge cases (missing properties, missing lookup tree)

The test assertions are thorough and verify both exit codes and output content appropriately.

ftf_cli/commands/get_output_type_details.py (1)

46-117: Command logic is well-implemented.

The core functionality correctly:

  • Validates the namespace/name format
  • Authenticates users and fetches credentials
  • Makes appropriate API calls
  • Handles response processing and error cases
  • Formats output with proper structure

The namespace-aware lookup and error messaging provide good user experience.

tests/commands/test_add_input.py (5)

64-64: Well-structured test data updates for namespace support.

The sample API response properly includes namespace fields and adds a custom namespace example (@anuj/sqs) with direct properties structure. This provides good test coverage for both default and custom namespaces.

Also applies to: 102-102, 117-128


175-175: Consistent migration to namespace-qualified format.

All test invocations have been properly updated to use the @namespace/name format (e.g., @outputs/database) instead of the old simple names. This ensures comprehensive testing of the new format requirements.

Also applies to: 220-220, 243-243, 273-273, 318-318, 359-359, 421-421, 452-452


459-518: Excellent format validation test coverage.

The new tests comprehensively validate the namespace format requirements:

  • Missing @ prefix is properly rejected
  • Missing slash separator is properly rejected
  • Error messages provide clear guidance on expected format

This ensures robust input validation for the namespace-aware functionality.


519-559: Good coverage for custom namespace functionality.

This test confirms that custom namespaces (like @anuj/sqs) work correctly, ensuring the namespace support isn't limited to just the default @outputs namespace.


560-605: Valuable edge case testing for direct properties structure.

This test ensures that outputs with direct attributes/interfaces structure (without nested "type": "object" wrappers) are handled correctly without warnings. This covers an important structural variation in the API responses.

- Handle both JSON Schema format and direct properties format
- Fix issue where @anuj/sqs type outputs generated 'any' instead of proper types
- Add support for empty interfaces/attributes objects
Copy link

@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: 0

🧹 Nitpick comments (1)
ftf_cli/commands/get_output_type_details.py (1)

95-99: Improve exception chaining for better debugging.

Consider using raise ... from e to preserve the exception chain, which helps with debugging by showing the original cause of the error.

    except Exception as e:
        traceback.print_exc()
        raise click.UsageError(
            f"❌ An error occurred while getting output details: {e}"
-        )
+        ) from e
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fc27cc and eab0570.

📒 Files selected for processing (6)
  • ftf_cli/commands/add_input.py (6 hunks)
  • ftf_cli/commands/get_output_type_details.py (1 hunks)
  • ftf_cli/utils.py (5 hunks)
  • tests/commands/test_add_input.py (13 hunks)
  • tests/commands/test_get_output_type_details.py (1 hunks)
  • tests/commands/test_get_output_types.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/commands/test_get_output_types.py
  • tests/commands/test_add_input.py
  • tests/commands/test_get_output_type_details.py
🧰 Additional context used
🧬 Code Graph Analysis (2)
ftf_cli/commands/add_input.py (1)
ftf_cli/utils.py (1)
  • parse_namespace_and_name (21-39)
ftf_cli/commands/get_output_type_details.py (1)
ftf_cli/utils.py (3)
  • is_logged_in (525-558)
  • get_profile_with_priority (507-522)
  • parse_namespace_and_name (21-39)
🪛 Ruff (0.11.9)
ftf_cli/commands/add_input.py

130-130: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

ftf_cli/commands/get_output_type_details.py

54-54: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


97-99: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

🔇 Additional comments (8)
ftf_cli/utils.py (2)

21-39: LGTM! Well-implemented utility function.

The parse_namespace_and_name function is well-designed with clear documentation, appropriate error handling, and helpful error messages that include examples. This implementation successfully addresses the DRY principle by centralizing the namespace/name parsing logic that was previously duplicated across multiple files.


894-930: LGTM! Improved handling of property structures.

The new logic correctly handles direct property dictionaries (like {"queue_arn": {"type": "string"}}) while maintaining backward compatibility with existing JSON Schema structures. The improved fallback to return "object({})" instead of "any" provides better type safety for empty or unknown structures.

ftf_cli/commands/add_input.py (3)

17-17: LGTM! Proper use of centralized utility function.

Good adoption of the centralized parse_namespace_and_name function from the utils module, following DRY principles.


109-110: LGTM! Good practice of early validation.

Validating the output type format early in the function provides immediate feedback and follows the fail-fast principle, avoiding unnecessary API calls when the format is invalid.


149-171: LGTM! Robust property extraction logic.

The updated logic correctly handles both direct and nested property structures, making the code more resilient to different API response formats. The fallback mechanism ensures graceful degradation when expected structures are not found.

ftf_cli/commands/get_output_type_details.py (3)

1-22: LGTM! Well-structured command implementation.

The command follows established CLI patterns with proper imports and option definitions. Good use of the centralized utility functions and consistent help text formatting.


26-35: LGTM! Proper validation and authentication flow.

Good practice of validating the output type format before proceeding with authentication and API calls. Clear error messages provide helpful guidance to users.


59-89: LGTM! Well-structured output display with good error handling.

The display logic is well-organized with clear sections and appropriate fallbacks. The JSON error handling for the lookup tree is particularly good, ensuring the command doesn't fail on malformed data while providing useful feedback.

@anujhydrabadi anujhydrabadi merged commit 6f00da0 into main Jun 30, 2025
6 checks passed
@anujhydrabadi anujhydrabadi deleted the add-namespace-support-to-outputs branch June 30, 2025 09:37
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.

2 participants