Skip to content

Conversation

@fatih-acar
Copy link
Contributor

@fatih-acar fatih-acar commented Oct 14, 2025

GPT-5-Codex

Summary by CodeRabbit

  • New Features

    • Added an "infrahubctl task" CLI group with a "list" command to view tasks.
    • Supports filters and options: state, limit, offset, include related nodes, include logs, JSON output, and debug logging.
  • Documentation

    • New documentation page describing the "infrahubctl task" command, usage, options, and examples.
    • Sidebar updated to include the new command.
  • Tests

    • Added unit tests for list output, JSON formatting, state filtering, and invalid state handling.

@github-actions github-actions bot added the type/documentation Improvements or additions to documentation label Oct 14, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 14, 2025

Walkthrough

Adds a new AsyncTyper CLI group "task" (infrahub_sdk/ctl/task.py) with a list command supporting state, limit, offset, include-related-nodes, include-logs, --json and debug flags, and registers it on the main CLI. Changes infrahub_sdk/task/models.py::from_graphql to use explicit key membership checks for related_nodes and logs. Adds documentation page docs/docs/infrahubctl/infrahubctl-task.mdx and sidebar entry, and adds unit tests for list output, JSON output, state filtering, and invalid-state handling.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the primary change—adding the “task list” subcommand to the infrahubctl CLI app—using conventional commit style and clear phrasing.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fac-tasks-command

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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 14, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6b8f6a3
Status: ✅  Deploy successful!
Preview URL: https://a71476c5.infrahub-sdk-python.pages.dev
Branch Preview URL: https://fac-tasks-command.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

❌ Patch coverage is 98.46154% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/task/models.py 83.33% 0 Missing and 1 partial ⚠️
@@            Coverage Diff             @@
##           stable     #579      +/-   ##
==========================================
+ Coverage   75.69%   75.90%   +0.21%     
==========================================
  Files         100      101       +1     
  Lines        8894     8957      +63     
  Branches     1751     1766      +15     
==========================================
+ Hits         6732     6799      +67     
+ Misses       1680     1677       -3     
+ Partials      482      481       -1     
Flag Coverage Δ
integration-tests 34.68% <36.92%> (+<0.01%) ⬆️
python-3.10 48.64% <98.46%> (+0.43%) ⬆️
python-3.11 48.64% <98.46%> (+0.40%) ⬆️
python-3.12 48.59% <98.46%> (+0.40%) ⬆️
python-3.13 48.62% <98.46%> (+0.40%) ⬆️
python-3.9 47.31% <98.46%> (+0.46%) ⬆️
python-filler-3.12 24.81% <0.00%> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/ctl/cli_commands.py 70.85% <100.00%> (+0.23%) ⬆️
infrahub_sdk/ctl/task.py 100.00% <100.00%> (ø)
infrahub_sdk/task/models.py 98.27% <83.33%> (-1.73%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 (2)
infrahub_sdk/ctl/task.py (2)

87-87: Consider using a less aggressive logging level.

Setting the logging level to CRITICAL will suppress all errors and warnings from the SDK. Consider using WARNING or ERROR instead to allow important diagnostic information through while still reducing noise.

Apply this diff to use a less aggressive level:

-    logging.getLogger("infrahub_sdk").setLevel(logging.CRITICAL)
+    logging.getLogger("infrahub_sdk").setLevel(logging.WARNING)

103-107: Remove redundant JSON serialization.

The code serializes to JSON with ujson.dumps, then passes the resulting string to console.print_json, which will parse it again. This is inefficient and unnecessary.

Apply this diff to pass the data structure directly:

     if json_output:
-        console.print_json(
-            ujson.dumps([task.model_dump(mode="json") for task in tasks], indent=2, sort_keys=True), highlight=False
-        )
+        console.print_json(
+            data=[task.model_dump(mode="json") for task in tasks],
+            indent=2,
+            sort_keys=True,
+        )
         return
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8f58b5 and 1e7b83a.

📒 Files selected for processing (6)
  • docs/docs/infrahubctl/infrahubctl-task.mdx (1 hunks)
  • docs/sidebars-infrahubctl.ts (1 hunks)
  • infrahub_sdk/ctl/cli_commands.py (2 hunks)
  • infrahub_sdk/ctl/task.py (1 hunks)
  • infrahub_sdk/task/models.py (1 hunks)
  • tests/unit/ctl/test_task_app.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method

Files:

  • infrahub_sdk/ctl/cli_commands.py
  • infrahub_sdk/task/models.py
  • tests/unit/ctl/test_task_app.py
  • infrahub_sdk/ctl/task.py
infrahub_sdk/ctl/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

infrahub_sdk/ctl/**/*.py: Build CLI commands with Typer
Organize and keep all CLI commands within infrahub_sdk/ctl/

Files:

  • infrahub_sdk/ctl/cli_commands.py
  • infrahub_sdk/ctl/task.py
tests/unit/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Place and write unit tests under tests/unit/ (isolated component tests)

Files:

  • tests/unit/ctl/test_task_app.py
tests/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Use the custom pytest plugin (infrahub_sdk.pytest_plugin) fixtures for clients, configuration, and Infrahub-specific testing

Files:

  • tests/unit/ctl/test_task_app.py
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (CLAUDE.md)

docs/**/*.{md,mdx}: Follow the Diataxis framework and classify docs as Tutorials, How-to guides, Explanation, or Reference
Structure How-to guides with required frontmatter and sections: introduction, prerequisites, step-by-step steps, validation, related resources
Structure Topics (Explanation) docs with introduction, concepts & definitions, background & context, architecture & design, connections, further reading
Use a professional, concise, informative tone with consistent structure across documents
Use proper language tags on all code blocks
Include both async and sync examples where applicable using the Tabs component
Add validation steps to guides to confirm success and expected outputs
Use callouts for warnings, tips, and important notes
Define new terms on first use and use domain-relevant terminology consistent with Infrahub’s model/UI
Conform to markdown style rules in .markdownlint.yaml and Vale styles in .vale/styles/

Files:

  • docs/docs/infrahubctl/infrahubctl-task.mdx
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Build CLI commands with Typer
📚 Learning: 2025-08-24T13:35:12.998Z
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Build CLI commands with Typer

Applied to files:

  • infrahub_sdk/ctl/cli_commands.py
  • infrahub_sdk/ctl/task.py
📚 Learning: 2025-08-24T13:35:12.998Z
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Organize and keep all CLI commands within infrahub_sdk/ctl/

Applied to files:

  • docs/sidebars-infrahubctl.ts
🧬 Code graph analysis (1)
infrahub_sdk/ctl/task.py (4)
infrahub_sdk/async_typer.py (2)
  • AsyncTyper (11-31)
  • command (29-31)
infrahub_sdk/task/models.py (3)
  • TaskFilter (63-74)
  • Task (32-60)
  • TaskState (9-18)
infrahub_sdk/ctl/client.py (1)
  • initialize_client (10-25)
infrahub_sdk/ctl/utils.py (1)
  • catch_exception (78-106)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.12)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (5)
infrahub_sdk/task/models.py (1)

52-58: LGTM! Defensive key membership checks.

The change from implicit truthiness checks to explicit in membership tests is a defensive pattern that prevents edge cases where keys might be present with falsy values (e.g., empty lists).

docs/sidebars-infrahubctl.ts (1)

27-27: LGTM! Documentation navigation updated.

The new task command is properly integrated into the sidebar navigation.

infrahub_sdk/ctl/cli_commands.py (1)

35-35: LGTM! CLI group registration follows established pattern.

The task app is properly imported and registered under the "task" namespace, consistent with other CLI groups in this file.

Also applies to: 67-67

docs/docs/infrahubctl/infrahubctl-task.mdx (1)

1-40: LGTM! Comprehensive command documentation.

The documentation clearly describes the task command and its options, following the established format for CLI documentation.

tests/unit/ctl/test_task_app.py (1)

1-100: LGTM! Comprehensive test coverage.

The test suite covers key scenarios:

  • Basic task listing with table output
  • JSON output format validation
  • State filtering behavior
  • Invalid state handling

Tests appropriately mock GraphQL responses and verify both exit codes and output content.

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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e7b83a and 4aeec5d.

📒 Files selected for processing (6)
  • docs/docs/infrahubctl/infrahubctl-task.mdx (1 hunks)
  • docs/sidebars-infrahubctl.ts (1 hunks)
  • infrahub_sdk/ctl/cli_commands.py (2 hunks)
  • infrahub_sdk/ctl/task.py (1 hunks)
  • infrahub_sdk/task/models.py (1 hunks)
  • tests/unit/ctl/test_task_app.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • docs/docs/infrahubctl/infrahubctl-task.mdx
  • infrahub_sdk/ctl/cli_commands.py
  • tests/unit/ctl/test_task_app.py
  • infrahub_sdk/ctl/task.py
  • docs/sidebars-infrahubctl.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method

Files:

  • infrahub_sdk/task/models.py
🧬 Code graph analysis (1)
infrahub_sdk/task/models.py (1)
infrahub_sdk/operation.py (1)
  • related_nodes (57-59)

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)
infrahub_sdk/ctl/task.py (1)

91-102: Consider using filters.limit and filters.offset for consistency.

The TaskFilter model includes limit and offset fields, but the code passes these as separate parameters to client.task.filter(). While this works, setting filters.limit = limit and filters.offset = offset would centralize filter configuration and align with the model design.

If you prefer to keep pagination separate from logical filters, consider documenting this design choice.

Apply this diff if you choose to consolidate:

 client = initialize_client()
 filters = TaskFilter()
 parsed_states = _parse_states(state)
 if parsed_states:
     filters.state = parsed_states
+if limit is not None:
+    filters.limit = limit
+if offset is not None:
+    filters.offset = offset

 tasks = await client.task.filter(
     filter=filters,
-    limit=limit,
-    offset=offset,
     include_related_nodes=include_related_nodes,
     include_logs=include_logs,
 )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ead0d2f and 6b8f6a3.

📒 Files selected for processing (6)
  • docs/docs/infrahubctl/infrahubctl-task.mdx (1 hunks)
  • docs/sidebars-infrahubctl.ts (1 hunks)
  • infrahub_sdk/ctl/cli_commands.py (2 hunks)
  • infrahub_sdk/ctl/task.py (1 hunks)
  • infrahub_sdk/task/models.py (1 hunks)
  • tests/unit/ctl/test_task_app.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/docs/infrahubctl/infrahubctl-task.mdx
🚧 Files skipped from review as they are similar to previous changes (2)
  • infrahub_sdk/ctl/cli_commands.py
  • tests/unit/ctl/test_task_app.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method

Files:

  • infrahub_sdk/task/models.py
  • infrahub_sdk/ctl/task.py
infrahub_sdk/ctl/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

infrahub_sdk/ctl/**/*.py: Build CLI commands with Typer
Organize and keep all CLI commands within infrahub_sdk/ctl/

Files:

  • infrahub_sdk/ctl/task.py
🧠 Learnings (2)
📚 Learning: 2025-08-24T13:35:12.998Z
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Organize and keep all CLI commands within infrahub_sdk/ctl/

Applied to files:

  • docs/sidebars-infrahubctl.ts
📚 Learning: 2025-08-24T13:35:12.998Z
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Build CLI commands with Typer

Applied to files:

  • infrahub_sdk/ctl/task.py
🧬 Code graph analysis (2)
infrahub_sdk/task/models.py (1)
infrahub_sdk/task/manager.py (2)
  • get (190-203)
  • get (423-436)
infrahub_sdk/ctl/task.py (4)
infrahub_sdk/async_typer.py (2)
  • AsyncTyper (11-31)
  • command (29-31)
infrahub_sdk/task/models.py (3)
  • TaskFilter (65-76)
  • Task (32-62)
  • TaskState (9-18)
infrahub_sdk/ctl/client.py (1)
  • initialize_client (10-25)
infrahub_sdk/ctl/utils.py (2)
  • catch_exception (78-106)
  • init_logging (42-50)
🔇 Additional comments (7)
infrahub_sdk/task/models.py (2)

52-55: LGTM! Past review concerns addressed.

The nested if checks now properly prevent TypeError when related_nodes is None or missing. The outer check confirms key existence, and the inner check ensures the value is truthy before iteration.


57-60: Verify edges field is not None before iteration.

While the nested if protects against data["logs"] being None, if GraphQL returns {"edges": None} the outer check passes (dict is truthy) but line 59 raises TypeError: 'NoneType' object is not iterable.

Apply this diff for defensive handling:

 if "logs" in data:
     if data.get("logs"):
-        logs = [TaskLog(**item["node"]) for item in data["logs"]["edges"]]
+        edges = data["logs"].get("edges") or []
+        logs = [TaskLog(**item["node"]) for item in edges]
     del data["logs"]
docs/sidebars-infrahubctl.ts (1)

27-27: LGTM!

The sidebar entry is correctly placed in alphabetical order and follows the established naming convention.

infrahub_sdk/ctl/task.py (4)

1-22: LGTM!

The module structure follows established CLI patterns: AsyncTyper for async command support, Rich for output formatting, and appropriate relative imports. The callback provides clear documentation for the task command group.

Based on coding guidelines.


25-39: LGTM! Good error handling and UX.

State validation is robust: normalizes input to uppercase, validates against the TaskState enum, and provides a helpful error message listing available states when validation fails.


42-69: LGTM! Clean table rendering.

The table formatting is well-structured: handles empty results gracefully, formats optional fields with fallbacks, and uses appropriate Rich styling for readability.

Based on learnings.


72-110: LGTM! Well-structured command with proper async handling.

The command implementation is solid: uses catch_exception for error handling, initializes logging, supports multiple output formats, and properly handles pagination and filters.

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

Labels

type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant