Skip to content

Conversation

@minitriga
Copy link
Contributor

@minitriga minitriga commented Sep 5, 2025

Summary by CodeRabbit

  • New Features
    • Create diff summaries between two timestamps, with optional background execution.
    • Retrieve diff summaries filtered by name and/or time range.
  • Bug Fixes
    • Top-level node actions in diff summaries now show UPDATED when applicable instead of None.
  • Documentation
    • Changelog entry added for the new diff creation API and time-range support.
  • Tests
    • Unit tests updated to reflect corrected top-level node action behavior.

@coderabbitai
Copy link

coderabbitai bot commented Sep 5, 2025

Walkthrough

Adds synchronous and asynchronous create_diff methods that accept branch, name, from_time, to_time, and wait_until_completion (returns task id when non-blocking or ok boolean when completed). Extends synchronous and asynchronous get_diff_summary to accept optional name, from_time, to_time (validated, serialized via ISO) and passes them as GraphQL variables. Updates GraphQL DiffTree query to accept these inputs. Maps top-level NodeDiff.action from node status. Updates tests to expect UPDATED top-level actions and adds a changelog entry.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch atg-20250904-diff

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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 5, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: c7db393
Status: ✅  Deploy successful!
Preview URL: https://486e2c36.infrahub-sdk-python.pages.dev
Branch Preview URL: https://atg-20250904-diff.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Sep 5, 2025

Codecov Report

❌ Patch coverage is 30.30303% with 23 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/client.py 30.30% 19 Missing and 4 partials ⚠️
@@            Coverage Diff             @@
##           stable     #531      +/-   ##
==========================================
- Coverage   75.98%   75.55%   -0.43%     
==========================================
  Files         100      100              
  Lines        9369     8899     -470     
  Branches     1932     1748     -184     
==========================================
- Hits         7119     6724     -395     
+ Misses       1727     1693      -34     
+ Partials      523      482      -41     
Flag Coverage Δ
integration-tests 34.66% <0.00%> (-0.01%) ⬇️
python-3.10 48.10% <18.18%> (-0.70%) ⬇️
python-3.11 48.12% <18.18%> (-0.68%) ⬇️
python-3.12 48.08% <18.18%> (-0.70%) ⬇️
python-3.13 48.10% <18.18%> (-0.68%) ⬇️
python-3.9 46.78% <18.18%> (-0.73%) ⬇️
python-filler-3.12 24.98% <12.12%> (-0.26%) ⬇️

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

Files with missing lines Coverage Δ
infrahub_sdk/diff.py 95.34% <ø> (ø)
infrahub_sdk/client.py 67.41% <30.30%> (-5.77%) ⬇️

... and 4 files 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: 4

🧹 Nitpick comments (2)
changelog/529.added.md (1)

1-2: Confirm changelog fragment number and note behavioral change in NodeDiff.action.

  • The file is named 529.added.md while this PR is #531—confirm whether 529 is intentional (e.g., towncrier/issue id) or should be 531 to avoid release note tooling misses.
  • Please also note in the changelog that NodeDiff.action is now derived from status (previously action/None). This is a user-visible change.
infrahub_sdk/client.py (1)

1154-1176: Confirm server input field: wait_until_completion vs background_execution.

Comment suggests background_execution is still the server field. If so, swap to background_execution = not wait_until_completion (or add compat shim) until the server changes.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f4035f0 and ae3ff08.

📒 Files selected for processing (4)
  • changelog/529.added.md (1 hunks)
  • infrahub_sdk/client.py (4 hunks)
  • infrahub_sdk/diff.py (2 hunks)
  • tests/unit/sdk/test_diff_summary.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.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:

  • tests/unit/sdk/test_diff_summary.py
  • infrahub_sdk/diff.py
  • infrahub_sdk/client.py
tests/unit/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

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

Files:

  • tests/unit/sdk/test_diff_summary.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/sdk/test_diff_summary.py
infrahub_sdk/client.py

📄 CodeRabbit inference engine (CLAUDE.md)

infrahub_sdk/client.py: Use HTTPX for transport with proxy support (single proxy or HTTP/HTTPS mounts)
Support authentication via API tokens or JWT with automatic refresh

Files:

  • infrahub_sdk/client.py
🧬 Code graph analysis (1)
infrahub_sdk/client.py (2)
infrahub_sdk/graphql.py (3)
  • Mutation (170-201)
  • render (158-167)
  • render (178-201)
infrahub_sdk/diff.py (2)
  • NodeDiff (10-16)
  • get_diff_summary_query (38-74)
⏰ 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). (2)
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: integration-tests-latest-infrahub
🔇 Additional comments (5)
infrahub_sdk/diff.py (2)

40-41: LGTM: Query now supports optional name/from_time/to_time.


124-124: Behavior change: action now mirrors node.status.

Good alignment with server payload, but this changes client-observable values. Ensure downstream consumers expect UPDATED/ADDED/REMOVED and not None.

tests/unit/sdk/test_diff_summary.py (1)

112-112: LGTM: Expected actions updated to UPDATED at top-level.

Matches the new mapping in diff.py.

Also applies to: 127-127, 143-143

infrahub_sdk/client.py (2)

8-8: LGTM: datetime import required for new APIs.


28-28: LGTM: Using MUTATION_QUERY_TASK for background mode selection set.

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

♻️ Duplicate comments (2)
infrahub_sdk/client.py (2)

1154-1177: Bug: create_diff runs on default branch; pass branch_name to scope the mutation.

Without branch_name, DiffUpdate may execute against the default branch even when a different branch is intended.

Apply:

-        response = await self.execute_graphql(query=query.render(), tracker="mutation-diff-update")
+        response = await self.execute_graphql(
+            query=query.render(),
+            branch_name=branch,
+            tracker="mutation-diff-update",
+        )

2327-2350: Bug: create_diff (sync) also needs branch scoping.

Same issue as async: mutation is executed without branch_name.

Apply:

-        response = self.execute_graphql(query=query.render(), tracker="mutation-diff-update")
+        response = self.execute_graphql(
+            query=query.render(),
+            branch_name=branch,
+            tracker="mutation-diff-update",
+        )
🧹 Nitpick comments (2)
infrahub_sdk/client.py (2)

1157-1166: Optional: enforce timezone-aware datetimes to avoid ambiguous ranges.

If from_time/to_time are naive, .isoformat() may be interpreted inconsistently by the API. Either require tz-aware or normalize to UTC.

Apply one of:

         if from_time > to_time:
             raise ValueError("from_time must be <= to_time")
+        if from_time.tzinfo is None or to_time.tzinfo is None:
+            raise ValueError("from_time and to_time must be timezone-aware")

Or normalize:

+        from datetime import timezone
+        from_time = from_time.astimezone(timezone.utc)
+        to_time = to_time.astimezone(timezone.utc)

2330-2339: Optional: enforce timezone-aware datetimes (sync).

Mirror the async guard/normalization to avoid ambiguous naive times.

Apply one of:

         if from_time > to_time:
             raise ValueError("from_time must be <= to_time")
+        if from_time.tzinfo is None or to_time.tzinfo is None:
+            raise ValueError("from_time and to_time must be timezone-aware")

or normalize to UTC as shown in the async comment.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ae3ff08 and c7db393.

📒 Files selected for processing (1)
  • infrahub_sdk/client.py (4 hunks)
🧰 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/client.py
infrahub_sdk/client.py

📄 CodeRabbit inference engine (CLAUDE.md)

infrahub_sdk/client.py: Use HTTPX for transport with proxy support (single proxy or HTTP/HTTPS mounts)
Support authentication via API tokens or JWT with automatic refresh

Files:

  • infrahub_sdk/client.py
🧬 Code graph analysis (1)
infrahub_sdk/client.py (2)
infrahub_sdk/graphql.py (3)
  • Mutation (170-201)
  • render (158-167)
  • render (178-201)
infrahub_sdk/diff.py (2)
  • NodeDiff (10-16)
  • get_diff_summary_query (38-74)
⏰ 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). (6)
  • GitHub Check: unit-tests (3.12)
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.11)
  • GitHub Check: unit-tests (3.10)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (4)
infrahub_sdk/client.py (4)

8-8: LGTM: datetime import added for new APIs.


28-28: LGTM: task query import wired.


1181-1205: Good: open-ended time filters and order validation handled; variables passed correctly.


2354-2378: Good: sync get_diff_summary parity with async (open-ended range + validation).

Copy link
Contributor

@ogenstad ogenstad left a comment

Choose a reason for hiding this comment

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

LGTM, though it would be good with some integration tests as well so we can validate that the new methods are working as intended.

@minitriga
Copy link
Contributor Author

@ogenstad Yes I was unsure if they would be required as we dont have any integration tests for a similar API (branch create).

@minitriga minitriga merged commit 71c150d into stable Sep 8, 2025
20 checks passed
@minitriga minitriga deleted the atg-20250904-diff branch September 8, 2025 16:12
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